diff --git a/examples/core/core_custom_logging.c b/examples/core/core_custom_logging.c index 94a9c6582..9794d14b9 100644 --- a/examples/core/core_custom_logging.c +++ b/examples/core/core_custom_logging.c @@ -18,7 +18,7 @@ #include // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen() #include // Required for: time_t, tm, time(), localtime(), strftime() -// Custom logging funtion +// Custom logging function void CustomLog(int msgType, const char *text, va_list args) { char timeStr[64] = { 0 }; diff --git a/examples/shapes/shapes_basic_shapes.c b/examples/shapes/shapes_basic_shapes.c index 5b02a5498..d06c2ee15 100644 --- a/examples/shapes/shapes_basic_shapes.c +++ b/examples/shapes/shapes_basic_shapes.c @@ -2,7 +2,7 @@ * * raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...) * -* Example originally created with raylib 1.0, last time updated with raylib 4.0 +* Example originally created with raylib 1.0, last time updated with raylib 4.2 * * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * BSD-like license that allows static linking with closed source software @@ -25,6 +25,8 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing"); + float rotation = 0.0f; + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -33,7 +35,7 @@ int main(void) { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + rotation += 0.2f; //---------------------------------------------------------------------------------- // Draw @@ -55,17 +57,18 @@ int main(void) DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines // Triangle shapes and lines - DrawTriangle((Vector2){screenWidth/4.0f *3.0f, 80.0f}, - (Vector2){screenWidth/4.0f *3.0f - 60.0f, 150.0f}, - (Vector2){screenWidth/4.0f *3.0f + 60.0f, 150.0f}, VIOLET); + DrawTriangle((Vector2){ screenWidth/4.0f *3.0f, 80.0f }, + (Vector2){ screenWidth/4.0f *3.0f - 60.0f, 150.0f }, + (Vector2){ screenWidth/4.0f *3.0f + 60.0f, 150.0f }, VIOLET); - DrawTriangleLines((Vector2){screenWidth/4.0f*3.0f, 160.0f}, - (Vector2){screenWidth/4.0f*3.0f - 20.0f, 230.0f}, - (Vector2){screenWidth/4.0f*3.0f + 20.0f, 230.0f}, DARKBLUE); + DrawTriangleLines((Vector2){ screenWidth/4.0f*3.0f, 160.0f }, + (Vector2){ screenWidth/4.0f*3.0f - 20.0f, 230.0f }, + (Vector2){ screenWidth/4.0f*3.0f + 20.0f, 230.0f }, DARKBLUE); // Polygon shapes and lines - DrawPoly((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, BROWN); - DrawPolyLinesEx((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, 6, BEIGE); + DrawPoly((Vector2){ screenWidth/4.0f*3, 330 }, 6, 80, rotation, BROWN); + DrawPolyLines((Vector2){ screenWidth/4.0f*3, 330 }, 6, 90, rotation, BROWN); + DrawPolyLinesEx((Vector2){ screenWidth/4.0f*3, 330 }, 6, 85, rotation, 6, BEIGE); // NOTE: We draw all LINES based shapes together to optimize internal drawing, // this way, all LINES are rendered in a single draw pass diff --git a/src/raylib.h b/src/raylib.h index 3f03effe6..693da1409 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1039,8 +1039,8 @@ RLAPI void SetConfigFlags(unsigned int flags); // Setup init RLAPI void TraceLog(int logLevel, const char *text, ...); // Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) RLAPI void SetTraceLogLevel(int logLevel); // Set the current threshold (minimum) log level -RLAPI void *MemAlloc(int size); // Internal memory allocator -RLAPI void *MemRealloc(void *ptr, int size); // Internal memory reallocator +RLAPI void *MemAlloc(unsigned int size); // Internal memory allocator +RLAPI void *MemRealloc(void *ptr, unsigned int size); // Internal memory reallocator RLAPI void MemFree(void *ptr); // Internal memory free RLAPI void OpenURL(const char *url); // Open URL with default system browser (if available) diff --git a/src/rcore.c b/src/rcore.c index 7cf9b0e78..d86bab7f5 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -2376,7 +2376,7 @@ VrStereoConfig LoadVrStereoConfig(VrDeviceInfo device) { VrStereoConfig config = { 0 }; - if ((rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20)) + if ((rlGetVersion() == RL_OPENGL_33) || (rlGetVersion() == RL_OPENGL_ES_20)) { // Compute aspect ratio float aspect = ((float)device.hResolution*0.5f)/(float)device.vResolution; @@ -4043,12 +4043,12 @@ static bool InitGraphicsDevice(int width, int height) // For example, if using OpenGL 1.1, driver can provide a 4.3 context forward compatible. // Check selection OpenGL version - if (rlGetVersion() == OPENGL_21) + if (rlGetVersion() == RL_OPENGL_21) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); // Choose OpenGL major version (just hint) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // Choose OpenGL minor version (just hint) } - else if (rlGetVersion() == OPENGL_33) + else if (rlGetVersion() == RL_OPENGL_33) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Choose OpenGL major version (just hint) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint) @@ -4061,7 +4061,7 @@ static bool InitGraphicsDevice(int width, int height) #endif //glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // Request OpenGL DEBUG context } - else if (rlGetVersion() == OPENGL_43) + else if (rlGetVersion() == RL_OPENGL_43) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // Choose OpenGL major version (just hint) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint) @@ -4071,7 +4071,7 @@ static bool InitGraphicsDevice(int width, int height) glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); // Enable OpenGL Debug Context #endif } - else if (rlGetVersion() == OPENGL_ES_20) // Request OpenGL ES 2.0 context + else if (rlGetVersion() == RL_OPENGL_ES_20) // Request OpenGL ES 2.0 context { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); diff --git a/src/rlgl.h b/src/rlgl.h index 363b45bd3..2c83d08a4 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1,6 +1,6 @@ /********************************************************************************************** * -* rlgl v4.0 - A multi-OpenGL abstraction layer with an immediate-mode style API +* rlgl v4.2 - A multi-OpenGL abstraction layer with an immediate-mode style API * * An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0) * that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...) @@ -107,7 +107,7 @@ #ifndef RLGL_H #define RLGL_H -#define RLGL_VERSION "4.0" +#define RLGL_VERSION "4.2" // Function specifiers in case library is build/used as a shared library (Windows) // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll @@ -243,7 +243,7 @@ #define RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST #define RL_TEXTURE_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR #define RL_TEXTURE_FILTER_ANISOTROPIC 0x3000 // Anisotropic filter (custom identifier) -#define RL_TEXTURE_MIPMAP_BIAS_RATIO 0x4000 // Texture mipmap bias (percentage ratio) +#define RL_TEXTURE_MIPMAP_BIAS_RATIO 0x4000 // Texture mipmap bias, percentage ratio (custom identifier) #define RL_TEXTURE_WRAP_REPEAT 0x2901 // GL_REPEAT #define RL_TEXTURE_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE @@ -283,37 +283,23 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- -typedef enum { - OPENGL_11 = 1, - OPENGL_21, - OPENGL_33, - OPENGL_43, - OPENGL_ES_20 -} rlGlVersion; +#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800) + #include +#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE) + // Boolean type +typedef enum bool { false = 0, true = !false } bool; +#endif -typedef enum { - RL_ATTACHMENT_COLOR_CHANNEL0 = 0, - RL_ATTACHMENT_COLOR_CHANNEL1, - RL_ATTACHMENT_COLOR_CHANNEL2, - RL_ATTACHMENT_COLOR_CHANNEL3, - RL_ATTACHMENT_COLOR_CHANNEL4, - RL_ATTACHMENT_COLOR_CHANNEL5, - RL_ATTACHMENT_COLOR_CHANNEL6, - RL_ATTACHMENT_COLOR_CHANNEL7, - RL_ATTACHMENT_DEPTH = 100, - RL_ATTACHMENT_STENCIL = 200, -} rlFramebufferAttachType; - -typedef enum { - RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, - RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, - RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, - RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, - RL_ATTACHMENT_TEXTURE2D = 100, - RL_ATTACHMENT_RENDERBUFFER = 200, -} rlFramebufferAttachTextureType; +#if !defined(RL_MATRIX_TYPE) +// Matrix, 4x4 components, column major, OpenGL style, right handed +typedef struct Matrix { + float m0, m4, m8, m12; // Matrix first row (4 components) + float m1, m5, m9, m13; // Matrix second row (4 components) + float m2, m6, m10, m14; // Matrix third row (4 components) + float m3, m7, m11, m15; // Matrix fourth row (4 components) +} Matrix; +#define RL_MATRIX_TYPE +#endif // Dynamic vertex buffers (position + texcoords + colors + indices arrays) typedef struct rlVertexBuffer { @@ -344,8 +330,8 @@ typedef struct rlDrawCall { //unsigned int shaderId; // Shader id to be used on the draw -> Using RLGL.currentShaderId unsigned int textureId; // Texture id to be used on the draw -> Use to create new draw call if changes - //Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default - //Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default + //Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default + //Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default } rlDrawCall; // rlRenderBatch type @@ -359,38 +345,30 @@ typedef struct rlRenderBatch { float currentDepth; // Current depth value for next draw } rlRenderBatch; -#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800) - #include -#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE) - // Boolean type -typedef enum bool { false = 0, true = !false } bool; -#endif - -#if !defined(RL_MATRIX_TYPE) -// Matrix, 4x4 components, column major, OpenGL style, right handed -typedef struct Matrix { - float m0, m4, m8, m12; // Matrix first row (4 components) - float m1, m5, m9, m13; // Matrix second row (4 components) - float m2, m6, m10, m14; // Matrix third row (4 components) - float m3, m7, m11, m15; // Matrix fourth row (4 components) -} Matrix; -#define RL_MATRIX_TYPE -#endif +// OpenGL version +typedef enum { + RL_OPENGL_11 = 1, // OpenGL 1.1 + RL_OPENGL_21, // OpenGL 2.1 (GLSL 120) + RL_OPENGL_33, // OpenGL 3.3 (GLSL 330) + RL_OPENGL_43, // OpenGL 4.3 (using GLSL 330) + RL_OPENGL_ES_20 // OpenGL ES 2.0 (GLSL 100) +} rlGlVersion; // Trace log level // NOTE: Organized by priority level typedef enum { - RL_LOG_ALL = 0, // Display all logs - RL_LOG_TRACE, // Trace logging, intended for internal use only - RL_LOG_DEBUG, // Debug logging, used for internal debugging, it should be disabled on release builds - RL_LOG_INFO, // Info logging, used for program execution info - RL_LOG_WARNING, // Warning logging, used on recoverable failures - RL_LOG_ERROR, // Error logging, used on unrecoverable failures - RL_LOG_FATAL, // Fatal logging, used to abort program: exit(EXIT_FAILURE) - RL_LOG_NONE // Disable logging + RL_LOG_ALL = 0, // Display all logs + RL_LOG_TRACE, // Trace logging, intended for internal use only + RL_LOG_DEBUG, // Debug logging, used for internal debugging, it should be disabled on release builds + RL_LOG_INFO, // Info logging, used for program execution info + RL_LOG_WARNING, // Warning logging, used on recoverable failures + RL_LOG_ERROR, // Error logging, used on unrecoverable failures + RL_LOG_FATAL, // Fatal logging, used to abort program: exit(EXIT_FAILURE) + RL_LOG_NONE // Disable logging } rlTraceLogLevel; -// Texture formats (support depends on OpenGL version) +// Texture pixel formats +// NOTE: Support depends on OpenGL version typedef enum { RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha) RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, // 8*2 bpp (2 channels) @@ -419,79 +397,106 @@ typedef enum { // NOTE 1: Filtering considers mipmaps if available in the texture // NOTE 2: Filter is accordingly set for minification and magnification typedef enum { - RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel approximation - RL_TEXTURE_FILTER_BILINEAR, // Linear filtering - RL_TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) - RL_TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x - RL_TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x - RL_TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x + RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel approximation + RL_TEXTURE_FILTER_BILINEAR, // Linear filtering + RL_TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps) + RL_TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x + RL_TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x + RL_TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x } rlTextureFilter; // Color blending modes (pre-defined) typedef enum { - RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default) - RL_BLEND_ADDITIVE, // Blend textures adding colors - RL_BLEND_MULTIPLIED, // Blend textures multiplying colors - RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative) - RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative) - RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha - RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors()) + RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default) + RL_BLEND_ADDITIVE, // Blend textures adding colors + RL_BLEND_MULTIPLIED, // Blend textures multiplying colors + RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative) + RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative) + RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha + RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors()) } rlBlendMode; // Shader location point type typedef enum { - RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position - RL_SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01 - RL_SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02 - RL_SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal - RL_SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent - RL_SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color - RL_SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection - RL_SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform) - RL_SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection - RL_SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform) - RL_SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal - RL_SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view - RL_SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color - RL_SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color - RL_SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color - RL_SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE) - RL_SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR) - RL_SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal - RL_SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness - RL_SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion - RL_SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission - RL_SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height - RL_SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap - RL_SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance - RL_SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter - RL_SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf -} rlShaderLocationIndex; - -#define RL_SHADER_LOC_MAP_DIFFUSE RL_SHADER_LOC_MAP_ALBEDO -#define RL_SHADER_LOC_MAP_SPECULAR RL_SHADER_LOC_MAP_METALNESS - -// Shader uniform data type -typedef enum { - RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float - RL_SHADER_UNIFORM_VEC2, // Shader uniform type: vec2 (2 float) - RL_SHADER_UNIFORM_VEC3, // Shader uniform type: vec3 (3 float) - RL_SHADER_UNIFORM_VEC4, // Shader uniform type: vec4 (4 float) - RL_SHADER_UNIFORM_INT, // Shader uniform type: int - RL_SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int) - RL_SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int) - RL_SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int) - RL_SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d + RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position + RL_SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01 + RL_SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02 + RL_SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal + RL_SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent + RL_SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color + RL_SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection + RL_SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform) + RL_SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection + RL_SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform) + RL_SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal + RL_SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view + RL_SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color + RL_SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color + RL_SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color + RL_SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE) + RL_SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR) + RL_SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal + RL_SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness + RL_SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion + RL_SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission + RL_SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height + RL_SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap + RL_SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance + RL_SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter + RL_SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf +} rlShaderLocationIndex; + +#define RL_SHADER_LOC_MAP_DIFFUSE RL_SHADER_LOC_MAP_ALBEDO +#define RL_SHADER_LOC_MAP_SPECULAR RL_SHADER_LOC_MAP_METALNESS + +// Shader uniform data type +typedef enum { + RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float + RL_SHADER_UNIFORM_VEC2, // Shader uniform type: vec2 (2 float) + RL_SHADER_UNIFORM_VEC3, // Shader uniform type: vec3 (3 float) + RL_SHADER_UNIFORM_VEC4, // Shader uniform type: vec4 (4 float) + RL_SHADER_UNIFORM_INT, // Shader uniform type: int + RL_SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int) + RL_SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int) + RL_SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int) + RL_SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d } rlShaderUniformDataType; // Shader attribute data types typedef enum { - RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float - RL_SHADER_ATTRIB_VEC2, // Shader attribute type: vec2 (2 float) - RL_SHADER_ATTRIB_VEC3, // Shader attribute type: vec3 (3 float) - RL_SHADER_ATTRIB_VEC4 // Shader attribute type: vec4 (4 float) + RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float + RL_SHADER_ATTRIB_VEC2, // Shader attribute type: vec2 (2 float) + RL_SHADER_ATTRIB_VEC3, // Shader attribute type: vec3 (3 float) + RL_SHADER_ATTRIB_VEC4 // Shader attribute type: vec4 (4 float) } rlShaderAttributeDataType; +// Framebuffer attachment type +// NOTE: By default up to 8 color channels defined but it can be more +typedef enum { + RL_ATTACHMENT_COLOR_CHANNEL0 = 0, // Framebuffer attachmment type: color 0 + RL_ATTACHMENT_COLOR_CHANNEL1, // Framebuffer attachmment type: color 1 + RL_ATTACHMENT_COLOR_CHANNEL2, // Framebuffer attachmment type: color 2 + RL_ATTACHMENT_COLOR_CHANNEL3, // Framebuffer attachmment type: color 3 + RL_ATTACHMENT_COLOR_CHANNEL4, // Framebuffer attachmment type: color 4 + RL_ATTACHMENT_COLOR_CHANNEL5, // Framebuffer attachmment type: color 5 + RL_ATTACHMENT_COLOR_CHANNEL6, // Framebuffer attachmment type: color 6 + RL_ATTACHMENT_COLOR_CHANNEL7, // Framebuffer attachmment type: color 7 + RL_ATTACHMENT_DEPTH = 100, // Framebuffer attachmment type: depth + RL_ATTACHMENT_STENCIL = 200, // Framebuffer attachmment type: stencil +} rlFramebufferAttachType; + +// Framebuffer texture attachment type +typedef enum { + RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0, // Framebuffer texture attachment type: cubemap, +X side + RL_ATTACHMENT_CUBEMAP_NEGATIVE_X, // Framebuffer texture attachment type: cubemap, -X side + RL_ATTACHMENT_CUBEMAP_POSITIVE_Y, // Framebuffer texture attachment type: cubemap, +Y side + RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y, // Framebuffer texture attachment type: cubemap, -Y side + RL_ATTACHMENT_CUBEMAP_POSITIVE_Z, // Framebuffer texture attachment type: cubemap, +Z side + RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z, // Framebuffer texture attachment type: cubemap, -Z side + RL_ATTACHMENT_TEXTURE2D = 100, // Framebuffer texture attachment type: texture2d + RL_ATTACHMENT_RENDERBUFFER = 200, // Framebuffer texture attachment type: renderbuffer +} rlFramebufferAttachTextureType; + //------------------------------------------------------------------------------------ // Functions Declaration - Matrix operations //------------------------------------------------------------------------------------ @@ -595,18 +600,18 @@ RLAPI void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Functions Declaration - rlgl functionality //------------------------------------------------------------------------------------ // rlgl initialization functions -RLAPI void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states) -RLAPI void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures) -RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions (loader function required) -RLAPI int rlGetVersion(void); // Get current OpenGL version -RLAPI void rlSetFramebufferWidth(int width); // Set current framebuffer width -RLAPI int rlGetFramebufferWidth(void); // Get default framebuffer width -RLAPI void rlSetFramebufferHeight(int height); // Set current framebuffer height -RLAPI int rlGetFramebufferHeight(void); // Get default framebuffer height +RLAPI void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states) +RLAPI void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures) +RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions (loader function required) +RLAPI int rlGetVersion(void); // Get current OpenGL version +RLAPI void rlSetFramebufferWidth(int width); // Set current framebuffer width +RLAPI int rlGetFramebufferWidth(void); // Get default framebuffer width +RLAPI void rlSetFramebufferHeight(int height); // Set current framebuffer height +RLAPI int rlGetFramebufferHeight(void); // Get default framebuffer height -RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id -RLAPI unsigned int rlGetShaderIdDefault(void); // Get default shader id -RLAPI int *rlGetShaderLocsDefault(void); // Get default shader locations +RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id +RLAPI unsigned int rlGetShaderIdDefault(void); // Get default shader id +RLAPI int *rlGetShaderLocsDefault(void); // Get default shader locations // Render batch management // NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode @@ -617,7 +622,8 @@ RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // D RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal) RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex -RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits + +RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits //------------------------------------------------------------------------------------------------------------------------ @@ -1307,17 +1313,6 @@ void rlEnd(void) // as well as depth buffer bit-depth (16bit or 24bit or 32bit) // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) RLGL.currentBatch->currentDepth += (1.0f/20000.0f); - - // Verify internal buffers limits - // NOTE: This check is combined with usage of rlCheckRenderBatchLimit() - if (RLGL.State.vertexCounter >= (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4)) - { - // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(), - // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call! - // If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw - for (int i = RLGL.State.stackCounter; i >= 0; i--) rlPopMatrix(); - rlDrawRenderBatch(RLGL.currentBatch); - } } // Define one vertex (position) @@ -1336,32 +1331,51 @@ void rlVertex3f(float x, float y, float z) tz = RLGL.State.transform.m2*x + RLGL.State.transform.m6*y + RLGL.State.transform.m10*z + RLGL.State.transform.m14; } - // Verify that current vertex buffer elements limit has not been reached - if (RLGL.State.vertexCounter < (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4)) + // WARNING: We can't break primitives when launching a new batch. + // RL_LINES comes in pairs, RL_TRIANGLES come in groups of 3 vertices and RL_QUADS come in groups of 4 vertices. + // We must check current draw.mode when a new vertex is required and finish the batch only if the draw.mode draw.vertexCount is %2, %3 or %4 + if (RLGL.State.vertexCounter > (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4)) { - // Add vertices - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter] = tx; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 1] = ty; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 2] = tz; - - // Add current texcoord - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter] = RLGL.State.texcoordx; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter + 1] = RLGL.State.texcoordy; - - // TODO: Add current normal - // By default rlVertexBuffer type does not store normals - - // Add current color - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 1] = RLGL.State.colorg; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 2] = RLGL.State.colorb; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 3] = RLGL.State.colora; - - RLGL.State.vertexCounter++; - - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++; + if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) && + (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%2 == 0)) + { + // Reached the maximum number of vertices for RL_LINES drawing + // Launch a draw call but keep current state for next vertices comming + // NOTE: We add +1 vertex to the check for security + rlCheckRenderBatchLimit(2 + 1); + } + else if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) && + (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%3 == 0)) + { + rlCheckRenderBatchLimit(3 + 1); + } + else if ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_QUADS) && + (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4 == 0)) + { + rlCheckRenderBatchLimit(4 + 1); + } } - else TRACELOG(RL_LOG_ERROR, "RLGL: Batch elements overflow"); + + // Add vertices + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter] = tx; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 1] = ty; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 2] = tz; + + // Add current texcoord + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter] = RLGL.State.texcoordx; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter + 1] = RLGL.State.texcoordy; + + // TODO: Add current normal + // By default rlVertexBuffer type does not store normals + + // Add current color + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 1] = RLGL.State.colorg; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 2] = RLGL.State.colorb; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 3] = RLGL.State.colora; + + RLGL.State.vertexCounter++; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++; } // Define one vertex (position) @@ -2211,22 +2225,22 @@ int rlGetVersion(void) { int glVersion = 0; #if defined(GRAPHICS_API_OPENGL_11) - glVersion = OPENGL_11; + glVersion = RL_OPENGL_11; #endif #if defined(GRAPHICS_API_OPENGL_21) #if defined(__APPLE__) - glVersion = OPENGL_33; // NOTE: Force OpenGL 3.3 on OSX + glVersion = RL_OPENGL_33; // NOTE: Force OpenGL 3.3 on OSX #else - glVersion = OPENGL_21; + glVersion = RL_OPENGL_21; #endif #elif defined(GRAPHICS_API_OPENGL_33) - glVersion = OPENGL_33; + glVersion = RL_OPENGL_33; #endif #if defined(GRAPHICS_API_OPENGL_43) - glVersion = OPENGL_43; + glVersion = RL_OPENGL_43; #endif #if defined(GRAPHICS_API_OPENGL_ES2) - glVersion = OPENGL_ES_20; + glVersion = RL_OPENGL_ES_20; #endif return glVersion; } @@ -2696,10 +2710,12 @@ bool rlCheckRenderBatchLimit(int vCount) if ((RLGL.State.vertexCounter + vCount) >= (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4)) { + overflow = true; + + // Store current primitive drawing mode and texture id int currentMode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode; int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId; - overflow = true; rlDrawRenderBatch(RLGL.currentBatch); // NOTE: Stereo rendering is checked inside // Restore state of last batch so we can continue adding vertices diff --git a/src/rmodels.c b/src/rmodels.c index 710cfabad..cb6551eb7 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -163,11 +163,6 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, unsigned int // Draw a line in 3D world space void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) { - // WARNING: Be careful with internal buffer vertex alignment - // when using RL_LINES or RL_TRIANGLES, data is aligned to fit - // lines-triangles-quads in the same indexed buffers!!! - rlCheckRenderBatchLimit(8); - rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); rlVertex3f(startPos.x, startPos.y, startPos.z); @@ -178,8 +173,6 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) // Draw a point in 3D space, actually a small line void DrawPoint3D(Vector3 position, Color color) { - rlCheckRenderBatchLimit(8); - rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); rlBegin(RL_LINES); @@ -193,8 +186,6 @@ void DrawPoint3D(Vector3 position, Color color) // Draw a circle in 3D world space void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color) { - rlCheckRenderBatchLimit(2*36); - rlPushMatrix(); rlTranslatef(center.x, center.y, center.z); rlRotatef(rotationAngle, rotationAxis.x, rotationAxis.y, rotationAxis.z); @@ -214,8 +205,6 @@ void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rota // Draw a color-filled triangle (vertex in counter-clockwise order!) void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) { - rlCheckRenderBatchLimit(8); - rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); rlVertex3f(v1.x, v1.y, v1.z); @@ -227,30 +216,27 @@ void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) // Draw a triangle strip defined by points void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color) { - if (pointCount >= 3) - { - rlCheckRenderBatchLimit(3*(pointCount - 2)); + if (pointCount < 3) return; - rlBegin(RL_TRIANGLES); - rlColor4ub(color.r, color.g, color.b, color.a); + rlBegin(RL_TRIANGLES); + rlColor4ub(color.r, color.g, color.b, color.a); - for (int i = 2; i < pointCount; i++) + for (int i = 2; i < pointCount; i++) + { + if ((i%2) == 0) { - if ((i%2) == 0) - { - rlVertex3f(points[i].x, points[i].y, points[i].z); - rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); - rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); - } - else - { - rlVertex3f(points[i].x, points[i].y, points[i].z); - rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); - rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); - } + rlVertex3f(points[i].x, points[i].y, points[i].z); + rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); + rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); } - rlEnd(); - } + else + { + rlVertex3f(points[i].x, points[i].y, points[i].z); + rlVertex3f(points[i - 1].x, points[i - 1].y, points[i - 1].z); + rlVertex3f(points[i - 2].x, points[i - 2].y, points[i - 2].z); + } + } + rlEnd(); } // Draw cube @@ -261,8 +247,6 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c float y = 0.0f; float z = 0.0f; - rlCheckRenderBatchLimit(36); - rlPushMatrix(); // NOTE: Transformation is applied in inverse order (scale -> rotate -> translate) rlTranslatef(position.x, position.y, position.z); @@ -342,65 +326,67 @@ void DrawCubeWires(Vector3 position, float width, float height, float length, Co float y = 0.0f; float z = 0.0f; - rlCheckRenderBatchLimit(36); - rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - // Front face ----------------------------------------------------- + // Front face + //------------------------------------------------------------------ // Bottom line - rlVertex3f(x-width/2, y-height/2, z+length/2); // Bottom left - rlVertex3f(x+width/2, y-height/2, z+length/2); // Bottom right + rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom left + rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom right // Left line - rlVertex3f(x+width/2, y-height/2, z+length/2); // Bottom right - rlVertex3f(x+width/2, y+height/2, z+length/2); // Top right + rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom right + rlVertex3f(x + width/2, y + height/2, z + length/2); // Top right // Top line - rlVertex3f(x+width/2, y+height/2, z+length/2); // Top right - rlVertex3f(x-width/2, y+height/2, z+length/2); // Top left + rlVertex3f(x + width/2, y + height/2, z + length/2); // Top right + rlVertex3f(x - width/2, y + height/2, z + length/2); // Top left // Right line - rlVertex3f(x-width/2, y+height/2, z+length/2); // Top left - rlVertex3f(x-width/2, y-height/2, z+length/2); // Bottom left + rlVertex3f(x - width/2, y + height/2, z + length/2); // Top left + rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom left - // Back face ------------------------------------------------------ + // Back face + //------------------------------------------------------------------ // Bottom line - rlVertex3f(x-width/2, y-height/2, z-length/2); // Bottom left - rlVertex3f(x+width/2, y-height/2, z-length/2); // Bottom right + rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom left + rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom right // Left line - rlVertex3f(x+width/2, y-height/2, z-length/2); // Bottom right - rlVertex3f(x+width/2, y+height/2, z-length/2); // Top right + rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom right + rlVertex3f(x + width/2, y + height/2, z - length/2); // Top right // Top line - rlVertex3f(x+width/2, y+height/2, z-length/2); // Top right - rlVertex3f(x-width/2, y+height/2, z-length/2); // Top left + rlVertex3f(x + width/2, y + height/2, z - length/2); // Top right + rlVertex3f(x - width/2, y + height/2, z - length/2); // Top left // Right line - rlVertex3f(x-width/2, y+height/2, z-length/2); // Top left - rlVertex3f(x-width/2, y-height/2, z-length/2); // Bottom left + rlVertex3f(x - width/2, y + height/2, z - length/2); // Top left + rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom left - // Top face ------------------------------------------------------- + // Top face + //------------------------------------------------------------------ // Left line - rlVertex3f(x-width/2, y+height/2, z+length/2); // Top left front - rlVertex3f(x-width/2, y+height/2, z-length/2); // Top left back + rlVertex3f(x - width/2, y + height/2, z + length/2); // Top left front + rlVertex3f(x - width/2, y + height/2, z - length/2); // Top left back // Right line - rlVertex3f(x+width/2, y+height/2, z+length/2); // Top right front - rlVertex3f(x+width/2, y+height/2, z-length/2); // Top right back + rlVertex3f(x + width/2, y + height/2, z + length/2); // Top right front + rlVertex3f(x + width/2, y + height/2, z - length/2); // Top right back - // Bottom face --------------------------------------------------- + // Bottom face + //------------------------------------------------------------------ // Left line - rlVertex3f(x-width/2, y-height/2, z+length/2); // Top left front - rlVertex3f(x-width/2, y-height/2, z-length/2); // Top left back + rlVertex3f(x - width/2, y - height/2, z + length/2); // Top left front + rlVertex3f(x - width/2, y - height/2, z - length/2); // Top left back // Right line - rlVertex3f(x+width/2, y-height/2, z+length/2); // Top right front - rlVertex3f(x+width/2, y-height/2, z-length/2); // Top right back + rlVertex3f(x + width/2, y - height/2, z + length/2); // Top right front + rlVertex3f(x + width/2, y - height/2, z - length/2); // Top right back rlEnd(); rlPopMatrix(); } @@ -419,8 +405,6 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei float y = position.y; float z = position.z; - rlCheckRenderBatchLimit(36); - rlSetTexture(texture.id); //rlPushMatrix(); @@ -432,37 +416,37 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei rlBegin(RL_QUADS); rlColor4ub(color.r, color.g, color.b, color.a); // Front Face - rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer + rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad // Back Face - rlNormal3f(0.0f, 0.0f, - 1.0f); // Normal Pointing Away From Viewer + rlNormal3f(0.0f, 0.0f, - 1.0f); // Normal Pointing Away From Viewer rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad // Top Face - rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up + rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left Of The Texture and Quad rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right Of The Texture and Quad rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad // Bottom Face - rlNormal3f(0.0f, - 1.0f, 0.0f); // Normal Pointing Down + rlNormal3f(0.0f, - 1.0f, 0.0f); // Normal Pointing Down rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Right Of The Texture and Quad rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Left Of The Texture and Quad rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad // Right face - rlNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right + rlNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad // Left Face - rlNormal3f( - 1.0f, 0.0f, 0.0f); // Normal Pointing Left + rlNormal3f( - 1.0f, 0.0f, 0.0f); // Normal Pointing Left rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad @@ -482,8 +466,6 @@ void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, f float texWidth = (float)texture.width; float texHeight = (float)texture.height; - rlCheckRenderBatchLimit(36); - rlSetTexture(texture.id); rlBegin(RL_QUADS); @@ -569,9 +551,6 @@ void DrawSphere(Vector3 centerPos, float radius, Color color) // Draw sphere with extended parameters void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color) { - int numVertex = (rings + 2)*slices*6; - rlCheckRenderBatchLimit(numVertex); - rlPushMatrix(); // NOTE: Transformation is applied in inverse order (scale -> translate) rlTranslatef(centerPos.x, centerPos.y, centerPos.z); @@ -612,9 +591,6 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color // Draw sphere wires void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color) { - int numVertex = (rings + 2)*slices*6; - rlCheckRenderBatchLimit(numVertex); - rlPushMatrix(); // NOTE: Transformation is applied in inverse order (scale -> translate) rlTranslatef(centerPos.x, centerPos.y, centerPos.z); @@ -659,9 +635,6 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h { if (sides < 3) sides = 3; - int numVertex = sides*6; - rlCheckRenderBatchLimit(numVertex); - rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); @@ -718,9 +691,6 @@ void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float e { if (sides < 3) sides = 3; - int numVertex = sides*6; - rlCheckRenderBatchLimit(numVertex); - Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z }; if ((direction.x == 0) && (direction.y == 0) && (direction.z == 0)) return; @@ -777,9 +747,6 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl { if (sides < 3) sides = 3; - int numVertex = sides*8; - rlCheckRenderBatchLimit(numVertex); - rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); @@ -811,9 +778,6 @@ void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, fl { if (sides < 3) sides = 3; - int numVertex = sides*6; - rlCheckRenderBatchLimit(numVertex); - Vector3 direction = { endPos.x - startPos.x, endPos.y - startPos.y, endPos.z - startPos.z }; if ((direction.x == 0) && (direction.y == 0) && (direction.z == 0))return; @@ -853,12 +817,9 @@ void DrawCylinderWiresEx(Vector3 startPos, Vector3 endPos, float startRadius, fl rlEnd(); } - // Draw a plane void DrawPlane(Vector3 centerPos, Vector2 size, Color color) { - rlCheckRenderBatchLimit(4); - // NOTE: Plane is always created on XZ ground rlPushMatrix(); rlTranslatef(centerPos.x, centerPos.y, centerPos.z); @@ -895,8 +856,6 @@ void DrawGrid(int slices, float spacing) { int halfSlices = slices/2; - rlCheckRenderBatchLimit((slices + 2)*4); - rlBegin(RL_LINES); for (int i = -halfSlices; i <= halfSlices; i++) { @@ -3421,8 +3380,6 @@ void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector bottomRight = Vector3Add(bottomRight, position); bottomLeft = Vector3Add(bottomLeft, position); - rlCheckRenderBatchLimit(8); - rlSetTexture(texture.id); rlBegin(RL_QUADS); @@ -5372,9 +5329,9 @@ static Model LoadM3D(const char *fileName) { model.bones[i].parent = m3d->bone[i].parent; strncpy(model.bones[i].name, m3d->bone[i].name, sizeof(model.bones[i].name)); - model.bindPose[i].translation.x = m3d->vertex[m3d->bone[i].pos].x; - model.bindPose[i].translation.y = m3d->vertex[m3d->bone[i].pos].y; - model.bindPose[i].translation.z = m3d->vertex[m3d->bone[i].pos].z; + model.bindPose[i].translation.x = m3d->vertex[m3d->bone[i].pos].x*m3d->scale; + model.bindPose[i].translation.y = m3d->vertex[m3d->bone[i].pos].y*m3d->scale; + model.bindPose[i].translation.z = m3d->vertex[m3d->bone[i].pos].z*m3d->scale; model.bindPose[i].rotation.x = m3d->vertex[m3d->bone[i].ori].x; model.bindPose[i].rotation.y = m3d->vertex[m3d->bone[i].ori].y; model.bindPose[i].rotation.z = m3d->vertex[m3d->bone[i].ori].z; @@ -5490,9 +5447,9 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, unsigned int { for (j = 0; j < m3d->numbone; j++) { - animations[a].framePoses[i][j].translation.x = m3d->vertex[pose[j].pos].x; - animations[a].framePoses[i][j].translation.y = m3d->vertex[pose[j].pos].y; - animations[a].framePoses[i][j].translation.z = m3d->vertex[pose[j].pos].z; + animations[a].framePoses[i][j].translation.x = m3d->vertex[pose[j].pos].x*m3d->scale; + animations[a].framePoses[i][j].translation.y = m3d->vertex[pose[j].pos].y*m3d->scale; + animations[a].framePoses[i][j].translation.z = m3d->vertex[pose[j].pos].z*m3d->scale; animations[a].framePoses[i][j].rotation.x = m3d->vertex[pose[j].ori].x; animations[a].framePoses[i][j].rotation.y = m3d->vertex[pose[j].ori].y; animations[a].framePoses[i][j].rotation.z = m3d->vertex[pose[j].ori].z; diff --git a/src/rshapes.c b/src/rshapes.c index 5e79d893f..12ed247f6 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -106,8 +106,8 @@ void DrawPixel(int posX, int posY, Color color) { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2i(posX, posY); - rlVertex2i(posX + 1, posY + 1); + rlVertex2f(posX, posY); + rlVertex2f(posX + 1, posY + 1); rlEnd(); } @@ -126,8 +126,8 @@ void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color colo { rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2i(startPosX, startPosY); - rlVertex2i(endPosX, endPosY); + rlVertex2f(startPosX, startPosY); + rlVertex2f(endPosX, endPosY); rlEnd(); } @@ -238,8 +238,6 @@ void DrawLineStrip(Vector2 *points, int pointCount, Color color) { if (pointCount >= 2) { - rlCheckRenderBatchLimit(pointCount); - rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -287,8 +285,6 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA float angle = startAngle; #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4*segments/2); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -333,8 +329,6 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlSetTexture(0); #else - rlCheckRenderBatchLimit(3*segments); - rlBegin(RL_TRIANGLES); for (int i = 0; i < segments; i++) { @@ -377,13 +371,7 @@ void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float float stepLength = (endAngle - startAngle)/(float)segments; float angle = startAngle; - - // Hide the cap lines when the circle is full bool showCapLines = true; - int limit = 2*(segments + 2); - if ((int)(endAngle - startAngle)%360 == 0) { limit = 2*segments; showCapLines = false; } - - rlCheckRenderBatchLimit(limit); rlBegin(RL_LINES); if (showCapLines) @@ -416,8 +404,6 @@ void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float // NOTE: Gradient goes from center (color1) to border (color2) void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2) { - rlCheckRenderBatchLimit(3*36); - rlBegin(RL_TRIANGLES); for (int i = 0; i < 360; i += 10) { @@ -441,8 +427,6 @@ void DrawCircleV(Vector2 center, float radius, Color color) // Draw circle outline void DrawCircleLines(int centerX, int centerY, float radius, Color color) { - rlCheckRenderBatchLimit(2*36); - rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -458,8 +442,6 @@ void DrawCircleLines(int centerX, int centerY, float radius, Color color) // Draw ellipse void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color) { - rlCheckRenderBatchLimit(3*36); - rlBegin(RL_TRIANGLES); for (int i = 0; i < 360; i += 10) { @@ -474,8 +456,6 @@ void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color c // Draw ellipse outline void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color) { - rlCheckRenderBatchLimit(2*36); - rlBegin(RL_LINES); for (int i = 0; i < 360; i += 10) { @@ -532,8 +512,6 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA float angle = startAngle; #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4*segments); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -559,8 +537,6 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA rlSetTexture(0); #else - rlCheckRenderBatchLimit(6*segments); - rlBegin(RL_TRIANGLES); for (int i = 0; i < segments; i++) { @@ -623,12 +599,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float s float stepLength = (endAngle - startAngle)/(float)segments; float angle = startAngle; - bool showCapLines = true; - int limit = 4*(segments + 1); - if ((int)(endAngle - startAngle)%360 == 0) { limit = 4*segments; showCapLines = false; } - - rlCheckRenderBatchLimit(limit); rlBegin(RL_LINES); if (showCapLines) @@ -720,8 +691,6 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color } #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -745,8 +714,6 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color rlSetTexture(0); #else - rlCheckRenderBatchLimit(6); - rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -781,8 +748,6 @@ void DrawRectangleGradientH(int posX, int posY, int width, int height, Color col // NOTE: Colors refer to corners, starting at top-lef corner and counter-clockwise void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4) { - rlCheckRenderBatchLimit(4); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -821,17 +786,17 @@ void DrawRectangleLines(int posX, int posY, int width, int height, Color color) #else rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2i(posX + 1, posY + 1); - rlVertex2i(posX + width, posY + 1); + rlVertex2f(posX + 1, posY + 1); + rlVertex2f(posX + width, posY + 1); - rlVertex2i(posX + width, posY + 1); - rlVertex2i(posX + width, posY + height); + rlVertex2f(posX + width, posY + 1); + rlVertex2f(posX + width, posY + height); - rlVertex2i(posX + width, posY + height); - rlVertex2i(posX + 1, posY + height); + rlVertex2f(posX + width, posY + height); + rlVertex2f(posX + 1, posY + height); - rlVertex2i(posX + 1, posY + height); - rlVertex2i(posX + 1, posY + 1); + rlVertex2f(posX + 1, posY + height); + rlVertex2f(posX + 1, posY + 1); rlEnd(); #endif } @@ -923,8 +888,6 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co const float angles[4] = { 180.0f, 90.0f, 0.0f, 270.0f }; #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(16*segments/2 + 5*4); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -1022,8 +985,6 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co rlEnd(); rlSetTexture(0); #else - rlCheckRenderBatchLimit(12*segments + 5*6); // 4 corners with 3 vertices per segment + 5 rectangles with 6 vertices each - rlBegin(RL_TRIANGLES); // Draw all of the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner @@ -1155,8 +1116,6 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo if (lineThick > 1) { #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4*4*segments + 4*4); // 4 corners with 4 vertices for each segment + 4 rectangles with 4 vertices each - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -1229,8 +1188,6 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo rlEnd(); rlSetTexture(0); #else - rlCheckRenderBatchLimit(4*6*segments + 4*6); // 4 corners with 6(2*3) vertices for each segment + 4 rectangles with 6 vertices each - rlBegin(RL_TRIANGLES); // Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner @@ -1296,8 +1253,6 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo else { // Use LINES to draw the outline - rlCheckRenderBatchLimit(8*segments + 4*2); // 4 corners with 2 vertices for each segment + 4 rectangles with 2 vertices each - rlBegin(RL_LINES); // Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner @@ -1332,8 +1287,6 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); @@ -1354,8 +1307,6 @@ void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) rlSetTexture(0); #else - rlCheckRenderBatchLimit(3); - rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(v1.x, v1.y); @@ -1369,8 +1320,6 @@ void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) // NOTE: Vertex must be provided in counter-clockwise order void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { - rlCheckRenderBatchLimit(6); - rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(v1.x, v1.y); @@ -1391,8 +1340,6 @@ void DrawTriangleFan(Vector2 *points, int pointCount, Color color) { if (pointCount >= 3) { - rlCheckRenderBatchLimit((pointCount - 2)*4); - rlSetTexture(texShapes.id); rlBegin(RL_QUADS); rlColor4ub(color.r, color.g, color.b, color.a); @@ -1422,8 +1369,6 @@ void DrawTriangleStrip(Vector2 *points, int pointCount, Color color) { if (pointCount >= 3) { - rlCheckRenderBatchLimit(3*(pointCount - 2)); - rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -1450,143 +1395,114 @@ void DrawTriangleStrip(Vector2 *points, int pointCount, Color color) void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color) { if (sides < 3) sides = 3; - float centralAngle = 0.0f; + float centralAngle = rotation; #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4*sides); // Each side is a quad + rlSetTexture(texShapes.id); + + rlBegin(RL_QUADS); + for (int i = 0; i < sides; i++) + { + rlColor4ub(color.r, color.g, color.b, color.a); + + rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x, center.y); + + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + + centralAngle += 360.0f/(float)sides; + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + } + rlEnd(); + rlSetTexture(0); #else - rlCheckRenderBatchLimit(3*sides); + rlBegin(RL_TRIANGLES); + for (int i = 0; i < sides; i++) + { + rlColor4ub(color.r, color.g, color.b, color.a); + + rlVertex2f(center.x, center.y); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + + centralAngle += 360.0f/(float)sides; + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + } + rlEnd(); #endif - - rlPushMatrix(); - rlTranslatef(center.x, center.y, 0.0f); - rlRotatef(rotation, 0.0f, 0.0f, 1.0f); - -#if defined(SUPPORT_QUADS_DRAW_MODE) - rlSetTexture(texShapes.id); - - rlBegin(RL_QUADS); - for (int i = 0; i < sides; i++) - { - rlColor4ub(color.r, color.g, color.b, color.a); - - rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(0, 0); - - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - - centralAngle += 360.0f/(float)sides; - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - } - rlEnd(); - rlSetTexture(0); -#else - rlBegin(RL_TRIANGLES); - for (int i = 0; i < sides; i++) - { - rlColor4ub(color.r, color.g, color.b, color.a); - - rlVertex2f(0, 0); - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - - centralAngle += 360.0f/(float)sides; - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - } - rlEnd(); -#endif - rlPopMatrix(); } // Draw a polygon outline of n sides void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color) { if (sides < 3) sides = 3; - float centralAngle = 0.0f; + float centralAngle = rotation; - rlCheckRenderBatchLimit(2*sides); + rlBegin(RL_LINES); + for (int i = 0; i < sides; i++) + { + rlColor4ub(color.r, color.g, color.b, color.a); - rlPushMatrix(); - rlTranslatef(center.x, center.y, 0.0f); - rlRotatef(rotation, 0.0f, 0.0f, 1.0f); - - rlBegin(RL_LINES); - for (int i = 0; i < sides; i++) - { - rlColor4ub(color.r, color.g, color.b, color.a); - - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - centralAngle += 360.0f/(float)sides; - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - } - rlEnd(); - rlPopMatrix(); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + centralAngle += 360.0f/(float)sides; + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + } + rlEnd(); } void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, float lineThick, Color color) { if (sides < 3) sides = 3; - float centralAngle = 0.0f; + float centralAngle = rotation; float exteriorAngle = 360.0f/(float)sides; float innerRadius = radius - (lineThick*cosf(DEG2RAD*exteriorAngle/2.0f)); #if defined(SUPPORT_QUADS_DRAW_MODE) - rlCheckRenderBatchLimit(4*sides); + rlSetTexture(texShapes.id); + + rlBegin(RL_QUADS); + for (int i = 0; i < sides; i++) + { + rlColor4ub(color.r, color.g, color.b, color.a); + + rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); + + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + + centralAngle += exteriorAngle; + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); + } + rlEnd(); + rlSetTexture(0); #else - rlCheckRenderBatchLimit(6*sides); + rlBegin(RL_TRIANGLES); + for (int i = 0; i < sides; i++) + { + rlColor4ub(color.r, color.g, color.b, color.a); + float nextAngle = centralAngle + exteriorAngle; + + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); + rlVertex2f(center.x + sinf(DEG2RAD*nextAngle)*radius, center.y + cosf(DEG2RAD*nextAngle)*radius); + + rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); + rlVertex2f(center.x + sinf(DEG2RAD*nextAngle)*radius, center.y + cosf(DEG2RAD*nextAngle)*radius); + rlVertex2f(center.x + sinf(DEG2RAD*nextAngle)*innerRadius, center.y + cosf(DEG2RAD*nextAngle)*innerRadius); + + centralAngle = nextAngle; + } + rlEnd(); #endif - - rlPushMatrix(); - rlTranslatef(center.x, center.y, 0.0f); - rlRotatef(rotation, 0.0f, 0.0f, 1.0f); - -#if defined(SUPPORT_QUADS_DRAW_MODE) - rlSetTexture(texShapes.id); - - rlBegin(RL_QUADS); - for (int i = 0; i < sides; i++) - { - rlColor4ub(color.r, color.g, color.b, color.a); - - rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*innerRadius, cosf(DEG2RAD*centralAngle)*innerRadius); - - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - - centralAngle += exteriorAngle; - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(sinf(DEG2RAD*centralAngle)*innerRadius, cosf(DEG2RAD*centralAngle)*innerRadius); - } - rlEnd(); - rlSetTexture(0); -#else - rlBegin(RL_TRIANGLES); - for (int i = 0; i < sides; i++) - { - rlColor4ub(color.r, color.g, color.b, color.a); - float nextAngle = centralAngle + exteriorAngle; - - rlVertex2f(sinf(DEG2RAD*centralAngle)*radius, cosf(DEG2RAD*centralAngle)*radius); - rlVertex2f(sinf(DEG2RAD*centralAngle)*innerRadius, cosf(DEG2RAD*centralAngle)*innerRadius); - rlVertex2f(sinf(DEG2RAD*nextAngle)*radius, cosf(DEG2RAD*nextAngle)*radius); - - rlVertex2f(sinf(DEG2RAD*centralAngle)*innerRadius, cosf(DEG2RAD*centralAngle)*innerRadius); - rlVertex2f(sinf(DEG2RAD*nextAngle)*radius, cosf(DEG2RAD*nextAngle)*radius); - rlVertex2f(sinf(DEG2RAD*nextAngle)*innerRadius, cosf(DEG2RAD*nextAngle)*innerRadius); - - centralAngle = nextAngle; - } - rlEnd(); -#endif - rlPopMatrix(); } //---------------------------------------------------------------------------------- diff --git a/src/rtextures.c b/src/rtextures.c index 2490d1d10..24fbafd2a 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -3362,8 +3362,6 @@ void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 bottomRight.y = y + (dx + dest.width)*sinRotation + (dy + dest.height)*cosRotation; } - rlCheckRenderBatchLimit(4); // Make sure there is enough free space on the batch buffer - rlSetTexture(texture.id); rlBegin(RL_QUADS); @@ -3494,8 +3492,6 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, coordD.x = (nPatchInfo.source.x + nPatchInfo.source.width)/width; coordD.y = (nPatchInfo.source.y + nPatchInfo.source.height)/height; - rlCheckRenderBatchLimit(9 * 3 * 2); // Maxium number of verts that could happen - rlSetTexture(texture.id); rlPushMatrix(); @@ -3639,8 +3635,6 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, // without crossing perimeter, points must be in anticlockwise order void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint) { - rlCheckRenderBatchLimit((pointCount - 1)*4); - rlSetTexture(texture.id); // Texturing is only supported on RL_QUADS diff --git a/src/utils.c b/src/utils.c index 9809e904a..208a483a7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -160,14 +160,14 @@ void TraceLog(int logType, const char *text, ...) // Internal memory allocator // NOTE: Initializes to zero by default -void *MemAlloc(int size) +void *MemAlloc(unsigned int size) { void *ptr = RL_CALLOC(size, 1); return ptr; } // Internal memory reallocator -void *MemRealloc(void *ptr, int size) +void *MemRealloc(void *ptr, unsigned int size) { void *ret = RL_REALLOC(ptr, size); return ret;