summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2023-10-26 20:09:16 +0300
committerjussi2023-10-26 20:09:16 +0300
commit56c365c8cc88455d69df42e7842c986e760c776e (patch)
treed4ad09280cdad3ad0e46146aa4cd149f5400b9b0
parent168f4959d4a265d7615a81b667917754ca85bfce (diff)
downloadreilua-enhanced-56c365c8cc88455d69df42e7842c986e760c776e.tar.gz
reilua-enhanced-56c365c8cc88455d69df42e7842c986e760c776e.tar.bz2
reilua-enhanced-56c365c8cc88455d69df42e7842c986e760c776e.zip
Buffer userdata object and rlgl Vertex buffers management.
-rw-r--r--API.md619
-rw-r--r--README.md1
-rw-r--r--ReiLua_API.lua91
-rw-r--r--changelog2
-rw-r--r--devnotes22
-rw-r--r--docgen.lua8
-rw-r--r--examples/rlgl/main.lua21
-rw-r--r--include/core.h1
-rw-r--r--include/lrlgl.h8
-rw-r--r--include/lua_core.h14
-rw-r--r--src/core.c74
-rw-r--r--src/gl.c2
-rw-r--r--src/lua_core.c30
-rw-r--r--src/rlgl.c268
14 files changed, 1070 insertions, 91 deletions
diff --git a/API.md b/API.md
index 601cd69..6484d0c 100644
--- a/API.md
+++ b/API.md
@@ -47,645 +47,1173 @@ Arguments are stored in 'RL.arg' array.
## Globals - ConfigFlags
FLAG_VSYNC_HINT = 64
+
FLAG_FULLSCREEN_MODE = 2
+
FLAG_WINDOW_RESIZABLE = 4
+
FLAG_WINDOW_UNDECORATED = 8
+
FLAG_WINDOW_HIDDEN = 128
+
FLAG_WINDOW_MINIMIZED = 512
+
FLAG_WINDOW_MAXIMIZED = 1024
+
FLAG_WINDOW_UNFOCUSED = 2048
+
FLAG_WINDOW_TOPMOST = 4096
+
FLAG_WINDOW_ALWAYS_RUN = 256
+
FLAG_WINDOW_TRANSPARENT = 16
+
FLAG_WINDOW_HIGHDPI = 8192
+
FLAG_MSAA_4X_HINT = 32
+
FLAG_INTERLACED_HINT = 65536
+
## Globals - TraceLogLevel
LOG_ALL = 0
+
LOG_TRACE = 1
+
LOG_DEBUG = 2
+
LOG_INFO = 3
+
LOG_WARNING = 4
+
LOG_ERROR = 5
+
LOG_FATAL = 6
+
LOG_NONE = 7
+
## Globals - KeyboardKey
GLFW_KEY_UNKNOWN = nil
+
KEY_NULL = 0
+
KEY_APOSTROPHE = 39
+
KEY_COMMA = 44
+
KEY_MINUS = 45
+
KEY_PERIOD = 46
+
KEY_SLASH = 47
+
KEY_ZERO = 48
+
KEY_ONE = 49
+
KEY_TWO = 50
+
KEY_THREE = 51
+
KEY_FOUR = 52
+
KEY_FIVE = 53
+
KEY_SIX = 54
+
KEY_SEVEN = 55
+
KEY_EIGHT = 56
+
KEY_NINE = 57
+
KEY_SEMICOLON = 59
+
KEY_EQUAL = 61
+
KEY_A = 65
+
KEY_B = 66
+
KEY_C = 67
+
KEY_D = 68
+
KEY_E = 69
+
KEY_F = 70
+
KEY_G = 71
+
KEY_H = 72
+
KEY_I = 73
+
KEY_J = 74
+
KEY_K = 75
+
KEY_L = 76
+
KEY_M = 77
+
KEY_N = 78
+
KEY_O = 79
+
KEY_P = 80
+
KEY_Q = 81
+
KEY_R = 82
+
KEY_S = 83
+
KEY_T = 84
+
KEY_U = 85
+
KEY_V = 86
+
KEY_W = 87
+
KEY_X = 88
+
KEY_Y = 89
+
KEY_Z = 90
+
KEY_LEFT_BRACKET = 91
+
KEY_BACKSLASH = 92
+
KEY_RIGHT_BRACKET = 93
+
KEY_GRAVE = 96
+
KEY_SPACE = 32
+
KEY_ESCAPE = 256
+
KEY_ENTER = 257
+
KEY_TAB = 258
+
KEY_BACKSPACE = 259
+
KEY_INSERT = 260
+
KEY_DELETE = 261
+
KEY_RIGHT = 262
+
KEY_LEFT = 263
+
KEY_DOWN = 264
+
KEY_UP = 265
+
KEY_PAGE_UP = 266
+
KEY_PAGE_DOWN = 267
+
KEY_HOME = 268
+
KEY_END = 269
+
KEY_CAPS_LOCK = 280
+
KEY_SCROLL_LOCK = 281
+
KEY_NUM_LOCK = 282
+
KEY_PRINT_SCREEN = 283
+
KEY_PAUSE = 284
+
KEY_F1 = 290
+
KEY_F2 = 291
+
KEY_F3 = 292
+
KEY_F4 = 293
+
KEY_F5 = 294
+
KEY_F6 = 295
+
KEY_F7 = 296
+
KEY_F8 = 297
+
KEY_F9 = 298
+
KEY_F10 = 299
+
KEY_F11 = 300
+
KEY_F12 = 301
+
KEY_LEFT_SHIFT = 340
+
KEY_LEFT_CONTROL = 341
+
KEY_LEFT_ALT = 342
+
KEY_LEFT_SUPER = 343
+
KEY_RIGHT_SHIFT = 344
+
KEY_RIGHT_CONTROL = 345
+
KEY_RIGHT_ALT = 346
+
KEY_RIGHT_SUPER = 347
+
KEY_KB_MENU = 348
+
KEY_KP_0 = 320
+
KEY_KP_1 = 321
+
KEY_KP_2 = 322
+
KEY_KP_3 = 323
+
KEY_KP_4 = 324
+
KEY_KP_5 = 325
+
KEY_KP_6 = 326
+
KEY_KP_7 = 327
+
KEY_KP_8 = 328
+
KEY_KP_9 = 329
+
KEY_KP_DECIMAL = 330
+
KEY_KP_DIVIDE = 331
+
KEY_KP_MULTIPLY = 332
+
KEY_KP_SUBTRACT = 333
+
KEY_KP_ADD = 334
+
KEY_KP_ENTER = 335
+
KEY_KP_EQUAL = 336
+
KEY_BACK = 4
+
KEY_MENU = 82
+
KEY_VOLUME_UP = 24
+
KEY_VOLUME_DOWN = 25
+
## Globals - MouseButtons
MOUSE_BUTTON_LEFT = 0
+
MOUSE_BUTTON_RIGHT = 1
+
MOUSE_BUTTON_MIDDLE = 2
+
MOUSE_BUTTON_SIDE = 3
+
MOUSE_BUTTON_EXTRA = 4
+
MOUSE_BUTTON_FORWARD = 5
+
MOUSE_BUTTON_BACK = 6
+
## Globals - MouseCursor
MOUSE_CURSOR_DEFAULT = 0
+
MOUSE_CURSOR_ARROW = 1
+
MOUSE_CURSOR_IBEAM = 2
+
MOUSE_CURSOR_CROSSHAIR = 3
+
MOUSE_CURSOR_POINTING_HAND = 4
+
MOUSE_CURSOR_RESIZE_EW = 5
+
MOUSE_CURSOR_RESIZE_NS = 6
+
MOUSE_CURSOR_RESIZE_NWSE = 7
+
MOUSE_CURSOR_RESIZE_NESW = 8
+
MOUSE_CURSOR_RESIZE_ALL = 9
+
MOUSE_CURSOR_NOT_ALLOWED = 10
+
## Globals - GamepadButtons
GAMEPAD_BUTTON_UNKNOWN = 0
+
GAMEPAD_BUTTON_LEFT_FACE_UP = 1
+
GAMEPAD_BUTTON_LEFT_FACE_RIGHT = 2
+
GAMEPAD_BUTTON_LEFT_FACE_DOWN = 3
+
GAMEPAD_BUTTON_LEFT_FACE_LEFT = 4
+
GAMEPAD_BUTTON_RIGHT_FACE_UP = 5
+
GAMEPAD_BUTTON_RIGHT_FACE_RIGHT = 6
+
GAMEPAD_BUTTON_RIGHT_FACE_DOWN = 7
+
GAMEPAD_BUTTON_RIGHT_FACE_LEFT = 8
+
GAMEPAD_BUTTON_LEFT_TRIGGER_1 = 9
+
GAMEPAD_BUTTON_LEFT_TRIGGER_2 = 10
+
GAMEPAD_BUTTON_RIGHT_TRIGGER_1 = 11
+
GAMEPAD_BUTTON_RIGHT_TRIGGER_2 = 12
+
GAMEPAD_BUTTON_MIDDLE_LEFT = 13
+
GAMEPAD_BUTTON_MIDDLE = 14
+
GAMEPAD_BUTTON_MIDDLE_RIGHT = 15
+
GAMEPAD_BUTTON_LEFT_THUMB = 16
+
GAMEPAD_BUTTON_RIGHT_THUMB = 17
+
## Globals - GamepadAxis
GAMEPAD_AXIS_LEFT_X = 0
+
GAMEPAD_AXIS_LEFT_Y = 1
+
GAMEPAD_AXIS_RIGHT_X = 2
+
GAMEPAD_AXIS_RIGHT_Y = 3
+
GAMEPAD_AXIS_LEFT_TRIGGER = 4
+
GAMEPAD_AXIS_RIGHT_TRIGGER = 5
+
## Globals - MapTypes
MATERIAL_MAP_ALBEDO = 0
+
MATERIAL_MAP_METALNESS = 1
+
MATERIAL_MAP_NORMAL = 2
+
MATERIAL_MAP_ROUGHNESS = 3
+
MATERIAL_MAP_OCCLUSION = 4
+
MATERIAL_MAP_EMISSION = 5
+
MATERIAL_MAP_HEIGHT = 6
+
MATERIAL_MAP_CUBEMAP = 7
+
MATERIAL_MAP_IRRADIANCE = 8
+
MATERIAL_MAP_PREFILTER = 9
+
MATERIAL_MAP_BRDF = 10
+
MATERIAL_MAP_DIFFUSE = 0
+
MATERIAL_MAP_SPECULAR = 1
+
## Globals - ShaderLocationIndex
SHADER_LOC_VERTEX_POSITION = 0
+
SHADER_LOC_VERTEX_TEXCOORD01 = 1
+
SHADER_LOC_VERTEX_TEXCOORD02 = 2
+
SHADER_LOC_VERTEX_NORMAL = 3
+
SHADER_LOC_VERTEX_TANGENT = 4
+
SHADER_LOC_VERTEX_COLOR = 5
+
SHADER_LOC_MATRIX_MVP = 6
+
SHADER_LOC_MATRIX_VIEW = 7
+
SHADER_LOC_MATRIX_PROJECTION = 8
+
SHADER_LOC_MATRIX_MODEL = 9
+
SHADER_LOC_MATRIX_NORMAL = 10
+
SHADER_LOC_VECTOR_VIEW = 11
+
SHADER_LOC_COLOR_DIFFUSE = 12
+
SHADER_LOC_COLOR_SPECULAR = 13
+
SHADER_LOC_COLOR_AMBIENT = 14
+
SHADER_LOC_MAP_ALBEDO = 15
+
SHADER_LOC_MAP_METALNESS = 16
+
SHADER_LOC_MAP_NORMAL = 17
+
SHADER_LOC_MAP_ROUGHNESS = 18
+
SHADER_LOC_MAP_OCCLUSION = 19
+
SHADER_LOC_MAP_EMISSION = 20
+
SHADER_LOC_MAP_HEIGHT = 21
+
SHADER_LOC_MAP_CUBEMAP = 22
+
SHADER_LOC_MAP_IRRADIANCE = 23
+
SHADER_LOC_MAP_PREFILTER = 24
+
SHADER_LOC_MAP_BRDF = 25
+
SHADER_LOC_MAP_DIFFUSE = 15
+
SHADER_LOC_MAP_SPECULAR = 16
+
## Globals - ShaderUniformDataType
SHADER_UNIFORM_FLOAT = 0
+
SHADER_UNIFORM_VEC2 = 1
+
SHADER_UNIFORM_VEC3 = 2
+
SHADER_UNIFORM_VEC4 = 3
+
SHADER_UNIFORM_INT = 4
+
SHADER_UNIFORM_IVEC2 = 5
+
SHADER_UNIFORM_IVEC3 = 6
+
SHADER_UNIFORM_IVEC4 = 7
+
SHADER_UNIFORM_SAMPLER2D = 8
+
## Globals - ShaderAttributeDataTypes
SHADER_ATTRIB_FLOAT = 0
+
SHADER_ATTRIB_VEC2 = 1
+
SHADER_ATTRIB_VEC3 = 2
+
SHADER_ATTRIB_VEC4 = 3
+
## Globals - PixelFormats
PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1
+
PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA = 2
+
PIXELFORMAT_UNCOMPRESSED_R5G6B5 = 3
+
PIXELFORMAT_UNCOMPRESSED_R8G8B8 = 4
+
PIXELFORMAT_UNCOMPRESSED_R5G5B5A1 = 5
+
PIXELFORMAT_UNCOMPRESSED_R4G4B4A4 = 6
+
PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 = 7
+
PIXELFORMAT_UNCOMPRESSED_R32 = 8
+
PIXELFORMAT_UNCOMPRESSED_R32G32B32 = 9
+
PIXELFORMAT_UNCOMPRESSED_R32G32B32A32 = 10
+
PIXELFORMAT_COMPRESSED_DXT1_RGB = 11
+
PIXELFORMAT_COMPRESSED_DXT1_RGBA = 12
+
PIXELFORMAT_COMPRESSED_DXT3_RGBA = 13
+
PIXELFORMAT_COMPRESSED_DXT5_RGBA = 14
+
PIXELFORMAT_COMPRESSED_ETC1_RGB = 15
+
PIXELFORMAT_COMPRESSED_ETC2_RGB = 16
+
PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA = 17
+
PIXELFORMAT_COMPRESSED_PVRT_RGB = 18
+
PIXELFORMAT_COMPRESSED_PVRT_RGBA = 19
+
PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA = 20
+
PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA = 21
+
## Globals - TextureFilters
TEXTURE_FILTER_POINT = 0
+
TEXTURE_FILTER_BILINEAR = 1
+
TEXTURE_FILTER_TRILINEAR = 2
+
TEXTURE_FILTER_ANISOTROPIC_4X = 3
+
TEXTURE_FILTER_ANISOTROPIC_8X = 4
+
TEXTURE_FILTER_ANISOTROPIC_16X = 5
+
## Globals - TextureWrap
TEXTURE_WRAP_REPEAT = 0
+
TEXTURE_WRAP_CLAMP = 1
+
TEXTURE_WRAP_MIRROR_REPEAT = 2
+
TEXTURE_WRAP_MIRROR_CLAMP = 3
+
## Globals - CubemapLayout
CUBEMAP_LAYOUT_AUTO_DETECT = 0
+
CUBEMAP_LAYOUT_LINE_VERTICAL = 1
+
CUBEMAP_LAYOUT_LINE_HORIZONTAL = 2
+
CUBEMAP_LAYOUT_CROSS_THREE_BY_FOUR = 3
+
CUBEMAP_LAYOUT_CROSS_FOUR_BY_THREE = 4
+
CUBEMAP_LAYOUT_PANORAMA = 5
+
## Globals - FontType
FONT_DEFAULT = 0
+
FONT_BITMAP = 1
+
FONT_SDF = 2
+
## Globals - BlendModes
BLEND_ALPHA = 0
+
BLEND_ADDITIVE = 1
+
BLEND_MULTIPLIED = 2
+
BLEND_ADD_COLORS = 3
+
BLEND_SUBTRACT_COLORS = 4
+
BLEND_ALPHA_PREMULTIPLY = 5
+
BLEND_CUSTOM = 6
+
BLEND_CUSTOM_SEPARATE = 7
+
## Globals - Gesture
GESTURE_NONE = 0
+
GESTURE_TAP = 1
+
GESTURE_DOUBLETAP = 2
+
GESTURE_HOLD = 4
+
GESTURE_DRAG = 8
+
GESTURE_SWIPE_RIGHT = 16
+
GESTURE_SWIPE_LEFT = 32
+
GESTURE_SWIPE_UP = 64
+
GESTURE_SWIPE_DOWN = 128
+
GESTURE_PINCH_IN = 256
+
GESTURE_PINCH_OUT = 512
+
## Globals - CameraMode
CAMERA_CUSTOM = 0
+
CAMERA_FREE = 1
+
CAMERA_ORBITAL = 2
+
CAMERA_FIRST_PERSON = 3
+
CAMERA_THIRD_PERSON = 4
+
## Globals - CameraProjections
CAMERA_PERSPECTIVE = 0
+
CAMERA_ORTHOGRAPHIC = 1
+
## Globals - N-patchLayout
NPATCH_NINE_PATCH = 0
+
NPATCH_THREE_PATCH_VERTICAL = 1
+
NPATCH_THREE_PATCH_HORIZONTAL = 2
+
## Globals - TextureTypes
TEXTURE_TYPE_TEXTURE = 0
+
TEXTURE_TYPE_RENDER_TEXTURE = 1
+
## Globals - Colors
LIGHTGRAY = { 200, 200, 200, 255 }
+
GRAY = { 130, 130, 130, 255 }
+
DARKGRAY = { 80, 80, 80, 255 }
+
YELLOW = { 253, 249, 0, 255 }
+
GOLD = { 255, 203, 0, 255 }
+
ORANGE = { 255, 161, 0, 255 }
+
PINK = { 255, 109, 194, 255 }
+
RED = { 230, 41, 55, 255 }
+
MAROON = { 190, 33, 55, 255 }
+
GREEN = { 0, 228, 48, 255 }
+
LIME = { 0, 158, 47, 255 }
+
DARKGREEN = { 0, 117, 44, 255 }
+
SKYBLUE = { 102, 191, 255, 255 }
+
BLUE = { 0, 121, 241, 255 }
+
DARKBLUE = { 0, 82, 172, 255 }
+
PURPLE = { 200, 122, 255, 255 }
+
VIOLET = { 135, 60, 190, 255 }
+
DARKPURPLE = { 112, 31, 126, 255 }
+
BEIGE = { 211, 176, 131, 255 }
+
BROWN = { 127, 106, 79, 255 }
+
DARKBROWN = { 76, 63, 47, 255 }
+
WHITE = { 255, 255, 255, 255 }
+
BLACK = { 0, 0, 0, 255 }
+
BLANK = { 0, 0, 0, 0 }
+
MAGENTA = { 255, 0, 255, 255 }
+
RAYWHITE = { 245, 245, 245, 255 }
+
## Globals - Math
PI = 3.1415927410126
+
DEG2RAD = 0.017453292384744
+
RAD2DEG = 57.295776367188
+
## Globals - GuiControlState
STATE_NORMAL = 0
+
STATE_FOCUSED = 1
+
STATE_PRESSED = 2
+
STATE_DISABLED = 3
+
## Globals - GuiTextAlignment
TEXT_ALIGN_LEFT = 0
+
TEXT_ALIGN_CENTER = 1
+
TEXT_ALIGN_RIGHT = 2
+
## Globals - GuiControl
DEFAULT = 0
+
LABEL = 1
+
BUTTON = 2
+
TOGGLE = 3
+
SLIDER = 4
+
PROGRESSBAR = 5
+
CHECKBOX = 6
+
COMBOBOX = 7
+
DROPDOWNBOX = 8
+
TEXTBOX = 9
+
VALUEBOX = 10
+
SPINNER = 11
+
LISTVIEW = 12
+
COLORPICKER = 13
+
SCROLLBAR = 14
+
STATUSBAR = 15
+
## Globals - GuiControlProperty
BORDER_COLOR_NORMAL = 0
+
BASE_COLOR_NORMAL = 1
+
TEXT_COLOR_NORMAL = 2
+
BORDER_COLOR_FOCUSED = 3
+
BASE_COLOR_FOCUSED = 4
+
TEXT_COLOR_FOCUSED = 5
+
BORDER_COLOR_PRESSED = 6
+
BASE_COLOR_PRESSED = 7
+
TEXT_COLOR_PRESSED = 8
+
BORDER_COLOR_DISABLED = 9
+
BASE_COLOR_DISABLED = 10
+
TEXT_COLOR_DISABLED = 11
+
BORDER_WIDTH = 12
+
TEXT_PADDING = 13
+
TEXT_ALIGNMENT = 14
+
RESERVED = 15
+
## Globals - GuiDefaultProperty
TEXT_SIZE = 16
+
TEXT_SPACING = 17
+
LINE_COLOR = 18
+
BACKGROUND_COLOR = 19
+
## Globals - GuiToggleProperty
GROUP_PADDING = 16
+
## Globals - GuiSliderProperty
SLIDER_WIDTH = 16
+
SLIDER_PADDING = 17
+
## Globals - GuiProgressBarProperty
PROGRESS_PADDING = 16
+
## Globals - GuiScrollBarProperty
ARROWS_SIZE = 16
+
ARROWS_VISIBLE = 17
+
SCROLL_SLIDER_PADDING = 18
+
SCROLL_SLIDER_SIZE = 19
+
SCROLL_PADDING = 20
+
SCROLL_SPEED = 21
+
## Globals - GuiCheckBoxProperty
CHECK_PADDING = 16
+
## Globals - GuiComboBoxProperty
COMBO_BUTTON_WIDTH = 16
+
COMBO_BUTTON_SPACING = 17
+
## Globals - GuiDropdownBoxProperty
ARROW_PADDING = 16
+
DROPDOWN_ITEMS_SPACING = 17
+
## Globals - GuiTextBoxProperty
TEXT_INNER_PADDING = 16
+
TEXT_LINES_SPACING = 17
+
## Globals - GuiSpinnerProperty
SPIN_BUTTON_WIDTH = 16
+
SPIN_BUTTON_SPACING = 17
+
## Globals - GuiListViewProperty
LIST_ITEMS_HEIGHT = 16
+
LIST_ITEMS_SPACING = 17
+
SCROLLBAR_WIDTH = 18
+
SCROLLBAR_SIDE = 19
+
## Globals - GuiColorPickerProperty
COLOR_SELECTOR_SIZE = 16
+
HUEBAR_WIDTH = 17
+
HUEBAR_PADDING = 18
+
HUEBAR_SELECTOR_HEIGHT = 19
+
HUEBAR_SELECTOR_OVERFLOW = 20
+
## Globals - LightType
LIGHT_DIRECTIONAL = 0
+
LIGHT_POINT = 1
+
## Globals - RLGL
RL_DEFAULT_BATCH_BUFFER_ELEMENTS = 8192
+
RL_DEFAULT_BATCH_BUFFERS = 1
+
RL_DEFAULT_BATCH_DRAWCALLS = 256
+
RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS = 4
+
## Globals - RLGL
RL_MAX_MATRIX_STACK_SIZE = 32
+
## Globals - RLGL
RL_MAX_SHADER_LOCATIONS = 32
+
## Globals - RLGL
RL_CULL_DISTANCE_NEAR = 0.01
+
RL_CULL_DISTANCE_FAR = 1000.0
+
## Globals - RLGL
RL_TEXTURE_WRAP_S = 10242
+
RL_TEXTURE_WRAP_T = 10243
+
RL_TEXTURE_MAG_FILTER = 10240
+
RL_TEXTURE_MIN_FILTER = 10241
+
RL_TEXTURE_FILTER_NEAREST = 9728
+
RL_TEXTURE_FILTER_LINEAR = 9729
+
RL_TEXTURE_FILTER_MIP_NEAREST = 9984
+
RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR = 9986
+
RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST = 9985
+
RL_TEXTURE_FILTER_MIP_LINEAR = 9987
+
RL_TEXTURE_FILTER_ANISOTROPIC = 12288
+
RL_TEXTURE_MIPMAP_BIAS_RATIO = 16384
+
RL_TEXTURE_WRAP_REPEAT = 10497
+
RL_TEXTURE_WRAP_CLAMP = 33071
+
RL_TEXTURE_WRAP_MIRROR_REPEAT = 33648
+
RL_TEXTURE_WRAP_MIRROR_CLAMP = 34626
+
## Globals - RLGL
RL_MODELVIEW = 5888
+
RL_PROJECTION = 5889
+
RL_TEXTURE = 5890
+
## Globals - RLGL
RL_LINES = 1
+
RL_TRIANGLES = 4
+
RL_QUADS = 7
+
## Globals - RLGL
RL_UNSIGNED_BYTE = 5121
+
RL_FLOAT = 5126
+
## Globals - RLGL
RL_STREAM_DRAW = 35040
+
RL_STREAM_READ = 35041
+
RL_STREAM_COPY = 35042
+
RL_STATIC_DRAW = 35044
+
RL_STATIC_READ = 35045
+
RL_STATIC_COPY = 35046
+
RL_DYNAMIC_DRAW = 35048
+
RL_DYNAMIC_READ = 35049
+
RL_DYNAMIC_COPY = 35050
+
## Globals - RLGL
RL_FRAGMENT_SHADER = 35632
+
RL_VERTEX_SHADER = 35633
+
RL_COMPUTE_SHADER = 37305
+
## Globals - RLGL
RL_ZERO = 0
+
RL_ONE = 1
+
RL_SRC_COLOR = 768
+
RL_ONE_MINUS_SRC_COLOR = 769
+
RL_SRC_ALPHA = 770
+
RL_ONE_MINUS_SRC_ALPHA = 771
+
RL_DST_ALPHA = 772
+
RL_ONE_MINUS_DST_ALPHA = 773
+
RL_DST_COLOR = 774
+
RL_ONE_MINUS_DST_COLOR = 775
+
RL_SRC_ALPHA_SATURATE = 776
+
RL_CONSTANT_COLOR = 32769
+
RL_ONE_MINUS_CONSTANT_COLOR = 32770
+
RL_CONSTANT_ALPHA = 32771
+
RL_ONE_MINUS_CONSTANT_ALPHA = 32772
+
## Globals - RLGL
RL_FUNC_ADD = 32774
+
RL_MIN = 32775
+
RL_MAX = 32776
+
RL_FUNC_SUBTRACT = 32778
+
RL_FUNC_REVERSE_SUBTRACT = 32779
+
RL_BLEND_EQUATION = 32777
+
RL_BLEND_EQUATION_RGB = 32777
+
RL_BLEND_EQUATION_ALPHA = 34877
+
RL_BLEND_DST_RGB = 32968
+
RL_BLEND_SRC_RGB = 32969
+
RL_BLEND_DST_ALPHA = 32970
+
RL_BLEND_SRC_ALPHA = 32971
+
RL_BLEND_COLOR = 32773
+
## Globals - RLGL
RL_OPENGL_11 = 1
+
RL_OPENGL_21 = 2
+
RL_OPENGL_33 = 3
+
RL_OPENGL_43 = 4
+
RL_OPENGL_ES_20 = 5
+
## Globals - RLGL
RL_ATTACHMENT_COLOR_CHANNEL0 = 0
+
RL_ATTACHMENT_COLOR_CHANNEL1 = 1
+
RL_ATTACHMENT_COLOR_CHANNEL2 = 2
+
RL_ATTACHMENT_COLOR_CHANNEL3 = 3
+
RL_ATTACHMENT_COLOR_CHANNEL4 = 4
+
RL_ATTACHMENT_COLOR_CHANNEL5 = 5
+
RL_ATTACHMENT_COLOR_CHANNEL6 = 6
+
RL_ATTACHMENT_COLOR_CHANNEL7 = 7
+
RL_ATTACHMENT_DEPTH = 100
+
RL_ATTACHMENT_STENCIL = 200
+
## Globals - RLGL
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0
+
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X = 1
+
RL_ATTACHMENT_CUBEMAP_POSITIVE_Y = 2
+
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y = 3
+
RL_ATTACHMENT_CUBEMAP_POSITIVE_Z = 4
+
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z = 5
+
RL_ATTACHMENT_TEXTURE2D = 100
+
RL_ATTACHMENT_RENDERBUFFER = 200
+
## Globals - RLGL
RL_CULL_FACE_FRONT = 0
+
RL_CULL_FACE_BACK = 1
+
## Globals - OpenGL
GL_COLOR_BUFFER_BIT = 16384
+
GL_DEPTH_BUFFER_BIT = 256
+
GL_STENCIL_BUFFER_BIT = 1024
+
GL_NEAREST = 9728
+
GL_LINEAR = 9729
+
## Globals - GLFW
GLFW_RELEASE = 0
+
GLFW_PRESS = 1
+
GLFW_REPEAT = 2
+
+## Globals - CBuffer
+BUFFER_UNSIGNED_CHAR = 0
+
+BUFFER_UNSIGNED_SHORT = 1
+
+BUFFER_UNSIGNED_INT = 2
+
+BUFFER_FLOAT = 3
+
+
## Globals - Window
EVENT_WINDOW_SIZE = 0
+
EVENT_WINDOW_MAXIMIZE = 1
+
EVENT_WINDOW_ICONYFY = 2
+
EVENT_WINDOW_FOCUS = 3
+
EVENT_WINDOW_DROP = 4
+
## Globals - Input
EVENT_KEY = 5
+
EVENT_CHAR = 6
+
EVENT_MOUSE_BUTTON = 7
+
EVENT_MOUSE_CURSOR_POS = 8
+
EVENT_MOUSE_SCROLL = 9
+
EVENT_CURSOR_ENTER = 10
+
## Types
Raylib structs in Lua
@@ -855,6 +1383,12 @@ int id. ModelAnimations
---
+> Buffer = Buffer userdata
+
+Userdata.
+
+---
+
## Events
Content of event table received by RL.event.
@@ -2461,6 +2995,15 @@ Get the world space position for a 2d camera screen space position
---
+> buffer = RL.LoadBuffer( data{} buffer, int type )
+
+Creates buffer as userdata. Type should be one of the Buffer types
+
+- Failure return false
+- Success return Buffer
+
+---
+
## Shapes - Drawing
---
@@ -7075,15 +7618,42 @@ Load vertex array (vao) if supported
---
-> vboId = RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )
+> vboId = RL.rlLoadVertexBuffer( Buffer buffer, bool dynamic )
-Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
+Load a vertex buffer attribute
- Failure return -1
- Success return int
---
+> vboId = RL.rlLoadVertexBufferElement( Buffer buffer, bool dynamic )
+
+Load a new attributes element buffer
+
+- Failure return -1
+- Success return int
+
+---
+
+> success = RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset )
+
+Update GPU buffer with new data
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset )
+
+Update vertex buffer elements with new data
+
+- Failure return false
+- Success return true
+
+---
+
> success = RL.rlUnloadVertexArray( int vaoId )
Unload vertex array object (VAO)
@@ -7111,6 +7681,24 @@ Set vertex attribute
---
+> success = RL.rlSetVertexAttributeDivisor( int index, int divisor )
+
+Set vertex attribute divisor
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType )
+
+Set vertex attribute default value
+
+- Failure return false
+- Success return true
+
+---
+
> success = RL.rlDrawVertexArray( int offset, int count )
Draw vertex array
@@ -7120,6 +7708,33 @@ Draw vertex array
---
+> success = RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer )
+
+Draw vertex array elements
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL.rlDrawVertexArrayInstanced( int offset, int count, int instances )
+
+Draw vertex array instanced
+
+- Failure return false
+- Success return true
+
+---
+
+> success = RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances )
+
+Draw vertex array elements instanced
+
+- Failure return false
+- Success return true
+
+---
+
## RLGL - Textures management
---
diff --git a/README.md b/README.md
index 5f7cdc7..7b6ed76 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ Included submodules.
* Raymath
* Lights
* Easings
+* RLGL WIP
List of some MISSING features that are planned to be included. For specific function, check API.
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 3b78623..06b12a7 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -707,6 +707,13 @@ RL.GLFW_RELEASE=0
RL.GLFW_PRESS=1
RL.GLFW_REPEAT=2
+-- Globals - CBuffer
+
+RL.BUFFER_UNSIGNED_CHAR=0
+RL.BUFFER_UNSIGNED_SHORT=1
+RL.BUFFER_UNSIGNED_INT=2
+RL.BUFFER_FLOAT=3
+
-- Globals - Window
RL.EVENT_WINDOW_SIZE=0
@@ -1907,6 +1914,14 @@ function RL.GetWorldToScreen2D( position, camera ) end
---@return any position
function RL.GetScreenToWorld2D( position, camera ) end
+---Creates buffer as userdata. Type should be one of the Buffer types
+---- Failure return false
+---- Success return Buffer
+---@param buffer any
+---@param type integer
+---@return any buffer
+function RL.LoadBuffer( buffer, type ) end
+
-- Shapes - Drawing
---Set texture and rectangle to be used on shapes drawing
@@ -6063,14 +6078,39 @@ function RL.rlSetTexture( id ) end
---@return any vaoId
function RL.rlLoadVertexArray() end
----Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
+---Load a vertex buffer attribute
---- Failure return -1
---- Success return int
---@param buffer any
----@param type integer
---@param dynamic boolean
---@return any vboId
-function RL.rlLoadVertexBuffer( buffer, type, dynamic ) end
+function RL.rlLoadVertexBuffer( buffer, dynamic ) end
+
+---Load a new attributes element buffer
+---- Failure return -1
+---- Success return int
+---@param buffer any
+---@param dynamic boolean
+---@return any vboId
+function RL.rlLoadVertexBufferElement( buffer, dynamic ) end
+
+---Update GPU buffer with new data
+---- Failure return false
+---- Success return true
+---@param bufferId integer
+---@param buffer any
+---@param offset integer
+---@return any success
+function RL.rlUpdateVertexBuffer( bufferId, buffer, offset ) end
+
+---Update vertex buffer elements with new data
+---- Failure return false
+---- Success return true
+---@param id integer
+---@param buffer any
+---@param offset integer
+---@return any success
+function RL.rlUpdateVertexBufferElements( id, buffer, offset ) end
---Unload vertex array object (VAO)
---- Failure return false
@@ -6098,6 +6138,23 @@ function RL.rlUnloadVertexBuffer( vboId ) end
---@return any success
function RL.rlSetVertexAttribute( index, compSize, type, normalized, stride, pointer ) end
+---Set vertex attribute divisor
+---- Failure return false
+---- Success return true
+---@param index integer
+---@param divisor integer
+---@return any success
+function RL.rlSetVertexAttributeDivisor( index, divisor ) end
+
+---Set vertex attribute default value
+---- Failure return false
+---- Success return true
+---@param locIndex integer
+---@param value any
+---@param attribType integer
+---@return any success
+function RL.rlSetVertexAttributeDefault( locIndex, value, attribType ) end
+
---Draw vertex array
---- Failure return false
---- Success return true
@@ -6106,6 +6163,34 @@ function RL.rlSetVertexAttribute( index, compSize, type, normalized, stride, poi
---@return any success
function RL.rlDrawVertexArray( offset, count ) end
+---Draw vertex array elements
+---- Failure return false
+---- Success return true
+---@param offset integer
+---@param count integer
+---@param buffer any
+---@return any success
+function RL.rlDrawVertexArrayElements( offset, count, buffer ) end
+
+---Draw vertex array instanced
+---- Failure return false
+---- Success return true
+---@param offset integer
+---@param count integer
+---@param instances integer
+---@return any success
+function RL.rlDrawVertexArrayInstanced( offset, count, instances ) end
+
+---Draw vertex array elements instanced
+---- Failure return false
+---- Success return true
+---@param offset integer
+---@param count integer
+---@param buffer any
+---@param instances integer
+---@return any success
+function RL.rlDrawVertexArrayElementsInstanced( offset, count, buffer, instances ) end
+
-- RLGL - Textures management
---Load texture in GPU
diff --git a/changelog b/changelog
index 3d7f71b..38ceea8 100644
--- a/changelog
+++ b/changelog
@@ -35,6 +35,8 @@ KEY CHANGES:
- ADDED: RL.event function with input events.
- ADDED: Window events.
- ADDED: rlgl Matrix state management.
+ - ADDED: Buffer userdata object.
+ - ADDED: rlgl Vertex buffers management.
Detailed changes:
- FIXED: uluaGetRay was looking for integers instead of tables
diff --git a/devnotes b/devnotes
index c9644b1..b3e7380 100644
--- a/devnotes
+++ b/devnotes
@@ -1,6 +1,5 @@
Current {
* rlgl
- * Vertex buffers management
* Shaders management
* Compute shader management
}
@@ -22,17 +21,20 @@ Backlog {
* Models
* LoadMaterials (Load materials from model file)
* LoadMaterialsFromModel (Could then for example edit and set back to model)
- * Needs Testing
- * UpdateTexture
- * UpdateTextureRec
- * LoadSoundFromWave
- * LoadFont
- * LoadFontEx
- * LoadFontFromImage
- * UpdateMesh
- * LoadModelFromMesh
}
Bugs {
* CameraLib. Lateral movement is slower if looking down or up.
}
+
+Needs Testing {
+ * UpdateTexture
+ * UpdateTextureRec
+ * LoadSoundFromWave
+ * LoadFont
+ * LoadFontEx
+ * LoadFontFromImage
+ * UpdateMesh
+ * LoadModelFromMesh
+ * RLGL - Matrix state management
+}
diff --git a/docgen.lua b/docgen.lua
index 1927633..d3fc047 100644
--- a/docgen.lua
+++ b/docgen.lua
@@ -155,18 +155,18 @@ repeat
globalVariableCount = globalVariableCount + 1
if value == nil then
- apiFile:write( "\n"..globalName.." = nil\n" )
+ apiFile:write( "\n"..globalName.." = nil\n\n" )
luaApiFile:write( "RL."..globalName.."=nil\n" )
elseif type( value ) == "table" then
-- All tables are colors.
apiFile:write( globalName.." = { "
..math.tointeger( value[1] )..", "..math.tointeger( value[2] )..", "
- ..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n" )
+ ..math.tointeger( value[3] )..", "..math.tointeger( value[4] ).." }\n\n" )
luaApiFile:write( "RL."..globalName.."={"
..math.tointeger( value[1] )..","..math.tointeger( value[2] )..","
..math.tointeger( value[3] )..","..math.tointeger( value[4] ).."}\n" )
else
- apiFile:write( globalName.." = "..value.."\n" )
+ apiFile:write( globalName.." = "..value.."\n\n" )
luaApiFile:write( "RL."..globalName.."="..value.."\n" )
end
end
@@ -257,6 +257,8 @@ apiFile:write( "\n> NPatchInfo = { { 0, 0, 24, 24 }, 8, 8, 8, 8, NPATCH_NINE_PAT
{ Texture source rectangle, Left border offset, Top border offset, Right border offset, Bottom border offset, Layout of the n-patch: 3x3, 1x3 or 3x1 }\n\n---\n" )
apiFile:write( "\n> ModelAnimations = ModelAnimationsId\n\
int id. ModelAnimations\n\n---\n" )
+apiFile:write( "\n> Buffer = Buffer userdata\n\
+Userdata.\n\n---\n" )
-- Events.
diff --git a/examples/rlgl/main.lua b/examples/rlgl/main.lua
index ac6bf53..4b59419 100644
--- a/examples/rlgl/main.lua
+++ b/examples/rlgl/main.lua
@@ -9,9 +9,9 @@ local vertices = {
triSize, 0.0, triSize
}
local colors = {
- RL.RED, RL.RED, RL.RED,
- RL.GREEN, RL.GREEN, RL.GREEN,
- RL.BLUE, RL.BLUE, RL.BLUE
+ 255, 0, 0,
+ 0, 255, 0,
+ 0, 0, 255
}
local VBO_VERTEX_POS = 0
@@ -25,23 +25,26 @@ local mesh = {
}
}
-function uploadMesh()
+local function uploadMesh()
mesh.vaoId = RL.rlLoadVertexArray()
RL.rlEnableVertexArray( mesh.vaoId )
-
+
-- Vertices.
- mesh.vboIds.vertices = RL.rlLoadVertexBuffer( vertices, RL.RL_FLOAT, false )
+ local vertexBuffer = RL.LoadBuffer( vertices, RL.BUFFER_FLOAT )
+ mesh.vboIds.vertices = RL.rlLoadVertexBuffer( vertexBuffer, false )
RL.rlSetVertexAttribute( VBO_VERTEX_POS, 3, RL.RL_FLOAT, false, 0, 0 )
RL.rlEnableVertexAttribute( VBO_VERTEX_POS )
+
-- Colors.
- mesh.vboIds.colors = RL.rlLoadVertexBuffer( vertices, RL.RL_UNSIGNED_BYTE, false )
+ local colorBuffer = RL.LoadBuffer( colors, RL.BUFFER_UNSIGNED_CHAR )
+ mesh.vboIds.colors = RL.rlLoadVertexBuffer( colorBuffer, false )
RL.rlSetVertexAttribute( VBO_COLOR_POS, 4, RL.RL_UNSIGNED_BYTE, false, 0, 0 )
RL.rlEnableVertexAttribute( VBO_COLOR_POS )
RL.rlDisableVertexArray()
- print( "Mesh:" )
+ print( "\nMesh:" )
print( "\tvaoId: "..mesh.vaoId )
print( "\tvboIds.vertices: "..mesh.vboIds.vertices )
print( "\tvboIds.colors: "..mesh.vboIds.colors )
@@ -59,7 +62,7 @@ function RL.init()
uploadMesh()
end
-function drawMesh()
+local function drawMesh()
end
function RL.draw()
diff --git a/include/core.h b/include/core.h
index bfedf81..bc3a0e0 100644
--- a/include/core.h
+++ b/include/core.h
@@ -46,6 +46,7 @@ int lcoreSetTraceLogLevel( lua_State *L );
int lcoreSetLogLevelInvalid( lua_State *L );
int lcoreGetLogLevelInvalid( lua_State *L );
int lcoreOpenURL( lua_State *L );
+int lcoreLoadBuffer( lua_State *L );
/* Cursor. */
int lcoreShowCursor( lua_State *L );
int lcoreHideCursor( lua_State *L );
diff --git a/include/lrlgl.h b/include/lrlgl.h
index 7ca2740..e414215 100644
--- a/include/lrlgl.h
+++ b/include/lrlgl.h
@@ -83,10 +83,18 @@ int lrlglSetTexture( lua_State *L );
/* Vertex buffers management */
int lrlglLoadVertexArray( lua_State *L );
int lrlglLoadVertexBuffer( lua_State *L );
+int lrlglLoadVertexBufferElement( lua_State *L );
+int lrlglUpdateVertexBuffer( lua_State *L );
+int lrlglUpdateVertexBufferElements( lua_State *L );
int lrlglUnloadVertexArray( lua_State *L );
int lrlglUnloadVertexBuffer( lua_State *L );
int lrlglSetVertexAttribute( lua_State *L );
+int lrlglSetVertexAttributeDivisor( lua_State *L );
+int lrlglSetVertexAttributeDefault( lua_State *L );
int lrlglDrawVertexArray( lua_State *L );
+int lrlglDrawVertexArrayElements( lua_State *L );
+int lrlglDrawVertexArrayInstanced( lua_State *L );
+int lrlglDrawVertexArrayElementsInstanced( lua_State *L );
/* Textures management */
int lrlglLoadTexture( lua_State *L );
int lrlglLoadTextureDepth( lua_State *L );
diff --git a/include/lua_core.h b/include/lua_core.h
index ed5fb7d..32c809c 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -14,6 +14,20 @@ enum EventType {
EVENT_CURSOR_ENTER
};
+enum BufferType {
+ BUFFER_UNSIGNED_CHAR,
+ BUFFER_UNSIGNED_SHORT,
+ BUFFER_UNSIGNED_INT,
+ BUFFER_FLOAT,
+};
+
+typedef struct {
+ size_t size;
+ void *data;
+ int x;
+ int y;
+} Buffer;
+
bool luaInit( int argn, const char **argc );
int luaTraceback( lua_State *L );
bool luaCallMain();
diff --git a/src/core.c b/src/core.c
index a4bd9cd..e49c84d 100644
--- a/src/core.c
+++ b/src/core.c
@@ -3558,3 +3558,77 @@ int lcoreGetScreenToWorld2D( lua_State *L ) {
return 1;
}
+
+/*
+> buffer = RL.LoadBuffer( data{} buffer, int type )
+
+Creates buffer as userdata. Type should be one of the Buffer types
+
+- Failure return false
+- Success return Buffer
+*/
+int lcoreLoadBuffer( lua_State *L ) {
+ if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadBuffer( data{} buffer, int type )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int type = lua_tointeger( L, 2 );
+ Buffer *buffer = lua_newuserdata( L, sizeof( Buffer ) );
+ int len = uluaGetTableLenIndex( L, 1 );
+
+ switch ( type ) {
+ case BUFFER_UNSIGNED_CHAR:
+ buffer->size = len * sizeof( unsigned char );
+ break;
+ case BUFFER_UNSIGNED_SHORT:
+ buffer->size = len * sizeof( unsigned short );
+ break;
+ case BUFFER_UNSIGNED_INT:
+ buffer->size = len * sizeof( unsigned int );
+ break;
+ case BUFFER_FLOAT:
+ buffer->size = len * sizeof( float );
+ break;
+ default:
+ break;
+ }
+ buffer->data = malloc( buffer->size );
+
+ int t = 1;
+ int i = 0;
+ unsigned char *up = buffer->data;
+ unsigned short *sp = buffer->data;
+ unsigned int *ip = buffer->data;
+ float *fp = buffer->data;
+
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ switch ( type ) {
+ case BUFFER_UNSIGNED_CHAR:
+ *up = (unsigned char)lua_tointeger( L, -1 );
+ up++;
+ break;
+ case BUFFER_UNSIGNED_SHORT:
+ *sp = (unsigned short)lua_tointeger( L, -1 );
+ up++;
+ break;
+ case BUFFER_UNSIGNED_INT:
+ *ip = (unsigned int)lua_tointeger( L, -1 );
+ up++;
+ break;
+ case BUFFER_FLOAT:
+ *fp = (float)lua_tonumber( L, -1 );
+ fp++;
+ break;
+ default:
+ break;
+ }
+ lua_pop( L, 1 );
+ i++;
+ }
+ luaL_setmetatable( L, "Buffer" );
+
+ return 1;
+}
diff --git a/src/gl.c b/src/gl.c
index a6e0e0e..36a0637 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -58,4 +58,4 @@ int lglBlitFramebuffer( lua_State *L ) {
lua_pushboolean( L, true );
return 1;
-} \ No newline at end of file
+}
diff --git a/src/lua_core.c b/src/lua_core.c
index f8b25bb..1d6372b 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -618,6 +618,11 @@ static void defineGlobals() {
assignGlobalInt( GLFW_RELEASE, "GLFW_RELEASE" );
assignGlobalInt( GLFW_PRESS, "GLFW_PRESS" );
assignGlobalInt( GLFW_REPEAT, "GLFW_REPEAT" );
+ /* CBuffer Data Types */
+ assignGlobalInt( BUFFER_UNSIGNED_CHAR, "BUFFER_UNSIGNED_CHAR" );
+ assignGlobalInt( BUFFER_UNSIGNED_SHORT, "BUFFER_UNSIGNED_SHORT" );
+ assignGlobalInt( BUFFER_UNSIGNED_INT, "BUFFER_UNSIGNED_INT" );
+ assignGlobalInt( BUFFER_FLOAT, "BUFFER_FLOAT" );
/* Window Events. */
assignGlobalInt( EVENT_WINDOW_SIZE, "EVENT_WINDOW_SIZE" );
assignGlobalInt( EVENT_WINDOW_MAXIMIZE, "EVENT_WINDOW_MAXIMIZE" );
@@ -636,6 +641,21 @@ static void defineGlobals() {
lua_pop( L, -1 );
}
+static int freeBuffer( lua_State *L ) {
+ Buffer *buffer = luaL_checkudata ( L, 1, "Buffer" );
+ free( buffer->data );
+}
+
+static void defineCBuffer() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Buffer" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, freeBuffer );
+ lua_setfield( L, -2, "__gc" );
+}
+
// Custom logging funtion.
static void logCustom( int logLevel, const char *text, va_list args ) {
char string[ STRING_LEN ] = {'\0'};
@@ -1019,6 +1039,7 @@ bool luaInit( int argn, const char **argc ) {
return false;
}
defineGlobals();
+ defineCBuffer();
/* Set arguments. */
lua_getglobal( L, "RL" );
@@ -1235,6 +1256,7 @@ void luaRegister() {
assingGlobalFunction( "SetLogLevelInvalid", lcoreSetLogLevelInvalid );
assingGlobalFunction( "GetLogLevelInvalid", lcoreGetLogLevelInvalid );
assingGlobalFunction( "OpenURL", lcoreOpenURL );
+ assingGlobalFunction( "LoadBuffer", lcoreLoadBuffer );
/* Cursor. */
assingGlobalFunction( "ShowCursor", lcoreShowCursor );
assingGlobalFunction( "HideCursor", lcoreHideCursor );
@@ -1944,10 +1966,18 @@ void luaRegister() {
/* Vertex buffers management. */
assingGlobalFunction( "rlLoadVertexArray", lrlglLoadVertexArray );
assingGlobalFunction( "rlLoadVertexBuffer", lrlglLoadVertexBuffer );
+ assingGlobalFunction( "rlLoadVertexBufferElement", lrlglLoadVertexBufferElement );
+ assingGlobalFunction( "rlUpdateVertexBuffer", lrlglUpdateVertexBuffer );
+ assingGlobalFunction( "rlUpdateVertexBufferElements", lrlglUpdateVertexBufferElements );
assingGlobalFunction( "rlUnloadVertexArray", lrlglUnloadVertexArray );
assingGlobalFunction( "rlUnloadVertexBuffer", lrlglUnloadVertexBuffer );
assingGlobalFunction( "rlSetVertexAttribute", lrlglSetVertexAttribute );
+ assingGlobalFunction( "rlSetVertexAttributeDivisor", lrlglSetVertexAttributeDivisor );
+ assingGlobalFunction( "rlSetVertexAttributeDefault", lrlglSetVertexAttributeDefault );
assingGlobalFunction( "rlDrawVertexArray", lrlglDrawVertexArray );
+ assingGlobalFunction( "rlDrawVertexArrayElements", lrlglDrawVertexArrayElements );
+ assingGlobalFunction( "rlDrawVertexArrayInstanced", lrlglDrawVertexArrayInstanced );
+ assingGlobalFunction( "rlDrawVertexArrayElementsInstanced", lrlglDrawVertexArrayElementsInstanced );
/* Textures management. */
assingGlobalFunction( "rlLoadTexture", lrlglLoadTexture );
assingGlobalFunction( "rlLoadTextureDepth", lrlglLoadTextureDepth );
diff --git a/src/rlgl.c b/src/rlgl.c
index b369047..6f5ece1 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -3,58 +3,6 @@
#include "lua_core.h"
#include "lrlgl.h"
-static void* getVertexBuffer( lua_State *L, int *type, unsigned int *size ) {
- *type = lua_tointeger( L, 2 );
- size_t len = uluaGetTableLenIndex( L, 1 );
- unsigned char *uByteArray;
- float *floatArray;
-
- switch ( *type ) {
- case RL_UNSIGNED_BYTE:
- *size = len * sizeof( unsigned char );
- uByteArray = MemAlloc( *size );
- break;
- case RL_FLOAT:
- *size = len * sizeof( float );
- floatArray = MemAlloc( *size );
- break;
- default:
- break;
- }
-
- int t = 1;
- int i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- switch ( *type ) {
- case RL_UNSIGNED_BYTE:
- uByteArray[i] = lua_tointeger( L, -1 );
- break;
- case RL_FLOAT:
- floatArray[i] = lua_tointeger( L, -1 );
- break;
- default:
- break;
- }
-
- lua_pop( L, 1 );
- i++;
- }
-
- switch ( *type ) {
- case RL_UNSIGNED_BYTE:
- return uByteArray;
- break;
- case RL_FLOAT:
- return floatArray;
- break;
- default:
- return NULL;
- break;
- }
-}
-
/*
## RLGL - Matrix operations
*/
@@ -1308,29 +1256,93 @@ int lrlglLoadVertexArray( lua_State *L ) {
}
/*
-> vboId = RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )
+> vboId = RL.rlLoadVertexBuffer( Buffer buffer, bool dynamic )
-Load a vertex buffer attribute. Type should be RL_UNSIGNED_BYTE or RL_FLOAT
+Load a vertex buffer attribute
- Failure return -1
- Success return int
*/
int lrlglLoadVertexBuffer( lua_State *L ) {
- if ( !lua_istable( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isboolean( L, 3 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer{} buffer, int type, bool dynamic )" );
+ if ( !lua_isuserdata( L, 1 ) || !lua_isboolean( L, 2 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBuffer( Buffer buffer, bool dynamic )" );
+ lua_pushinteger( L, -1 );
+ return 1;
+ }
+ Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
+ bool dynamic = lua_tointeger( L, 2 );
+
+ lua_pushinteger( L, rlLoadVertexBuffer( buffer->data, buffer->size, dynamic ) );
+
+ return 1;
+}
+
+/*
+> vboId = RL.rlLoadVertexBufferElement( Buffer buffer, bool dynamic )
+
+Load a new attributes element buffer
+
+- Failure return -1
+- Success return int
+*/
+int lrlglLoadVertexBufferElement( lua_State *L ) {
+ if ( !lua_isuserdata( L, 1 ) || !lua_isboolean( L, 2 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlLoadVertexBufferElement( Buffer buffer, bool dynamic )" );
lua_pushinteger( L, -1 );
return 1;
}
- unsigned int size = 0;
- int type = 0;
- void *vertexBuffer = getVertexBuffer( L, &type, &size );
- bool dynamic = lua_tointeger( L, 3 );
+ Buffer *buffer = luaL_checkudata( L, 1, "Buffer" );
+ bool dynamic = lua_tointeger( L, 2 );
+
+ lua_pushinteger( L, rlLoadVertexBufferElement( buffer->data, buffer->size, dynamic ) );
+
+ return 1;
+}
+
+/*
+> success = RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset )
+
+Update GPU buffer with new data
+
+- Failure return false
+- Success return true
+*/
+int lrlglUpdateVertexBuffer( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isuserdata( L, 2 ) || !lua_isnumber( L, 3 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUpdateVertexBuffer( int bufferId, Buffer buffer, int offset )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int bufferId = lua_tointeger( L, 1 );
+ Buffer *buffer = luaL_checkudata( L, 2, "Buffer" );
+ int offset = lua_tointeger( L, 3 );
+
+ rlUpdateVertexBuffer( bufferId, buffer->data, buffer->size, offset );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
- lua_pushinteger( L, rlLoadVertexBuffer( vertexBuffer, size, dynamic ) );
+/*
+> success = RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset )
+
+Update vertex buffer elements with new data
- if ( vertexBuffer != NULL ) {
- MemFree( vertexBuffer );
+- Failure return false
+- Success return true
+*/
+int lrlglUpdateVertexBufferElements( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isuserdata( L, 2 ) || !lua_isnumber( L, 3 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlUpdateVertexBufferElements( int id, Buffer buffer, int offset )" );
+ lua_pushboolean( L, false );
+ return 1;
}
+ int bufferId = lua_tointeger( L, 1 );
+ Buffer *buffer = luaL_checkudata( L, 2, "Buffer" );
+ int offset = lua_tointeger( L, 3 );
+
+ rlUpdateVertexBufferElements( bufferId, buffer->data, buffer->size, offset );
+ lua_pushboolean( L, true );
return 1;
}
@@ -1404,6 +1416,63 @@ int lrlglSetVertexAttribute( lua_State *L ) {
}
/*
+> success = RL.rlSetVertexAttributeDivisor( int index, int divisor )
+
+Set vertex attribute divisor
+
+- Failure return false
+- Success return true
+*/
+int lrlglSetVertexAttributeDivisor( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttributeDivisor( int index, int divisor )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ unsigned int index = (unsigned int)lua_tointeger( L, 1 );
+ int divisor = lua_tointeger( L, 2 );
+
+ rlSetVertexAttributeDivisor( index, divisor );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType )
+
+Set vertex attribute default value
+
+- Failure return false
+- Success return true
+*/
+int lrlglSetVertexAttributeDefault( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_istable( L, 2 ) || !lua_isnumber( L, 3 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlSetVertexAttributeDefault( int locIndex, float{} value, int attribType )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int locIndex = lua_tointeger( L, 1 );
+ int attribType = lua_tointeger( L, 3 );
+ int count = uluaGetTableLenIndex( L, 2 );
+ float value[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+
+ int t = 2;
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ value[i] = lua_tonumber( L, -1 );
+ lua_pop( L, 1 );
+ i++;
+ }
+ rlSetVertexAttributeDefault( locIndex, value, attribType, count );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
> success = RL.rlDrawVertexArray( int offset, int count )
Draw vertex array
@@ -1427,6 +1496,79 @@ int lrlglDrawVertexArray( lua_State *L ) {
}
/*
+> success = RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer )
+
+Draw vertex array elements
+
+- Failure return false
+- Success return true
+*/
+int lrlglDrawVertexArrayElements( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isuserdata( L, 3 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayElements( int offset, int count, Buffer buffer )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int offset = lua_tointeger( L, 1 );
+ int count = lua_tointeger( L, 2 );
+ Buffer *buffer = luaL_checkudata( L, 3, "Buffer" );
+
+ rlDrawVertexArrayElements( offset, count, buffer->data );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlDrawVertexArrayInstanced( int offset, int count, int instances )
+
+Draw vertex array instanced
+
+- Failure return false
+- Success return true
+*/
+int lrlglDrawVertexArrayInstanced( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isnumber( L, 3 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayInstanced( int offset, int count, int instances )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int offset = lua_tointeger( L, 1 );
+ int count = lua_tointeger( L, 2 );
+ int instances = lua_tointeger( L, 3 );
+
+ rlDrawVertexArrayInstanced( offset, count, instances );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
+> success = RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances )
+
+Draw vertex array elements instanced
+
+- Failure return false
+- Success return true
+*/
+int lrlglDrawVertexArrayElementsInstanced( lua_State *L ) {
+ if ( !lua_isnumber( L, 1 ) || !lua_isnumber( L, 2 ) || !lua_isuserdata( L, 3 ) || !lua_isnumber( L, 4 ) ) {
+ TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.rlDrawVertexArrayElementsInstanced( int offset, int count, Buffer buffer, int instances )" );
+ lua_pushboolean( L, false );
+ return 1;
+ }
+ int offset = lua_tointeger( L, 1 );
+ int count = lua_tointeger( L, 2 );
+ Buffer *buffer = luaL_checkudata( L, 3, "Buffer" );
+ int instances = lua_tointeger( L, 4 );
+
+ rlDrawVertexArrayElementsInstanced( offset, count, buffer->data, instances );
+ lua_pushboolean( L, true );
+
+ return 1;
+}
+
+/*
## RLGL - Textures management
*/