From 6ffb3c72fbbdd73467e7ef36b542f20a5b1f9300 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 21 Sep 2015 12:48:43 +0200 Subject: Solved bug with depth when drawing... ...shapes based on LINES, TRIANGLES and QUADS. Now the calling order of the drawing functions is respected! --- src/rlgl.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index ec23e988..70a03047 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -200,6 +200,8 @@ static int currentMatrixMode; static DrawMode currentDrawMode; +static float currentDepth = -1.0f; + // Vertex arrays for lines, triangles and quads static VertexPositionColorBuffer lines; // No texture support static VertexPositionColorBuffer triangles; // No texture support @@ -580,6 +582,11 @@ void rlEnd(void) } break; default: break; } + + // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values, + // as well as depth buffer bit-depth (16bit or 24bit or 32bit) + // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits) + currentDepth += (1.0f/20000.0f); } // Define one vertex (position) @@ -648,13 +655,13 @@ void rlVertex3f(float x, float y, float z) // Define one vertex (position) void rlVertex2f(float x, float y) { - rlVertex3f(x, y, 0.0f); + rlVertex3f(x, y, currentDepth); } // Define one vertex (position) void rlVertex2i(int x, int y) { - rlVertex3f((float)x, (float)y, 0.0f); + rlVertex3f((float)x, (float)y, currentDepth); } // Define one vertex (texture coordinate) @@ -1395,6 +1402,9 @@ void rlglDraw(void) quads.vCounter = 0; quads.tcCounter = 0; quads.cCounter = 0; + + // Reset depth for next draw + currentDepth = -1.0f; #endif } @@ -1583,7 +1593,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height) rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix rlLoadIdentity(); // Reset current matrix (PROJECTION) - rlOrtho(0, width - offsetX, height - offsetY, 0, 0, 1); // Config orthographic mode: top-left corner --> (0,0) + rlOrtho(0, width - offsetX, height - offsetY, 0, 0.0f, 1.0f); // Config orthographic mode: top-left corner --> (0,0) rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix rlLoadIdentity(); // Reset current matrix (MODELVIEW) -- cgit v1.2.3 From 11a8dacb0fe08baf106ec7b88c9922a6779a0e24 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 6 Oct 2015 17:25:27 +0200 Subject: Multiple code changes: - Renamed function rlEnableFBO() -> rlEnablePostproFBO() - Defined struct FBO - Moved FBO creation to function: rlglLoadFBO() - Reviewed rlglReadTexturePixels(), trying to support OpenGL ES -IN PROGRESS- --- src/rlgl.c | 194 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 143 insertions(+), 51 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 70a03047..d632a3ac 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -182,6 +182,13 @@ typedef struct { unsigned char a; } pixel; +// Framebuffer Object type +typedef struct { + GLuint id; + GLuint colorTextureId; + GLuint depthTextureId; +} FBO; + #if defined(RLGL_STANDALONE) typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType; #endif @@ -238,7 +245,7 @@ static bool texCompPVRTSupported = false; // PVR texture compression support static bool texCompASTCSupported = false; // ASTC texture compression support // Framebuffer object and texture -static GLuint fbo, fboColorTexture, fboDepthTexture; +static FBO postproFbo; static Model postproQuad; // Shaders related variables @@ -278,6 +285,9 @@ static void UpdateBuffers(void); static char *TextFileRead(char *fn); static void LoadCompressedTexture(unsigned char *data, int width, int height, int mipmapCount, int compressedFormat); + +FBO rlglLoadFBO(int width, int height); +void rlglUnloadFBO(FBO fbo); #endif #if defined(GRAPHICS_API_OPENGL_11) @@ -776,10 +786,10 @@ void rlDeleteTextures(unsigned int id) } // Enable rendering to postprocessing FBO -void rlEnableFBO(void) +void rlEnablePostproFBO() { #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glBindFramebuffer(GL_FRAMEBUFFER, postproFbo.id); #endif } @@ -910,8 +920,8 @@ void rlglInit(void) #elif defined(GLAD_EXTENSIONS_LOADER) // NOTE: glad is generated and contains only required OpenGL version and core extensions - if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n"); - //if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) TraceLog(ERROR, "Failed to initialize glad\n"); + //if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n"); + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) TraceLog(ERROR, "Failed to initialize glad\n"); // No GLFW3 in this module... if (GLAD_GL_VERSION_3_3) { @@ -1080,44 +1090,78 @@ void rlglInit(void) // Init postpro system // NOTE: Uses global variables screenWidth and screenHeight +// Modifies global variables: postproFbo, postproQuad void rlglInitPostpro(void) { + postproFbo = rlglLoadFBO(screenWidth, screenHeight); + + if (postproFbo.id > 0) + { + // Create a simple quad model to render fbo texture + VertexData quadData; + + quadData.vertexCount = 6; + + float w = screenWidth; + float h = screenHeight; + + float quadPositions[6*3] = { w, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, h, 0.0, 0, h, 0.0, w, h, 0.0, w, 0.0, 0.0 }; + float quadTexcoords[6*2] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0 }; + float quadNormals[6*3] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; + unsigned char quadColors[6*4] = { 255 }; + + quadData.vertices = quadPositions; + quadData.texcoords = quadTexcoords; + quadData.normals = quadNormals; + quadData.colors = quadColors; + + postproQuad = rlglLoadModel(quadData); + + // NOTE: postproFbo.colorTextureId must be assigned to postproQuad model shader + } +} + +// Load a framebuffer object +FBO rlglLoadFBO(int width, int height) +{ + FBO fbo; + fbo.id = 0; + #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Create the texture that will serve as the color attachment for the framebuffer - glGenTextures(1, &fboColorTexture); - glBindTexture(GL_TEXTURE_2D, fboColorTexture); + glGenTextures(1, &fbo.colorTextureId); + glBindTexture(GL_TEXTURE_2D, fbo.colorTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); // Create the renderbuffer that will serve as the depth attachment for the framebuffer. - glGenRenderbuffers(1, &fboDepthTexture); - glBindRenderbuffer(GL_RENDERBUFFER, fboDepthTexture); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screenWidth, screenHeight); + glGenRenderbuffers(1, &fbo.depthTextureId); + glBindRenderbuffer(GL_RENDERBUFFER, fbo.depthTextureId); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); // NOTE: We can also use a texture for depth buffer (GL_ARB_depth_texture/GL_OES_depth_texture extensions) // A renderbuffer is simpler than a texture and could offer better performance on embedded devices /* - glGenTextures(1, &fboDepthTexture); - glBindTexture(GL_TEXTURE_2D, fboDepthTexture); + glGenTextures(1, &fbo.depthTextureId); + glBindTexture(GL_TEXTURE_2D, fbo.depthTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, GetScreenWidth(), GetScreenHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); */ - // Create the framebuffer object - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glGenFramebuffers(1, &fbo.id); + glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); // Attach color texture and depth renderbuffer to FBO - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboColorTexture, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fboDepthTexture); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo.colorTextureId, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo.depthTextureId); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); @@ -1135,36 +1179,26 @@ void rlglInitPostpro(void) case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: TraceLog(WARNING, "Framebuffer incomplete missing attachment"); break; default: break; } - } - else - { - TraceLog(INFO, "[FBO ID %i] Framebuffer object created successfully", fbo); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - // Create a simple quad model to render fbo texture - VertexData quadData; - - quadData.vertexCount = 6; - - float w = screenWidth; - float h = screenHeight; - float quadPositions[6*3] = { w, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, h, 0.0, 0, h, 0.0, w, h, 0.0, w, 0.0, 0.0 }; - float quadTexcoords[6*2] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0 }; - float quadNormals[6*3] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; - unsigned char quadColors[6*4] = { 255 }; - - quadData.vertices = quadPositions; - quadData.texcoords = quadTexcoords; - quadData.normals = quadNormals; - quadData.colors = quadColors; - - postproQuad = rlglLoadModel(quadData); - - // NOTE: fboColorTexture id must be assigned to postproQuad model shader + glDeleteTextures(1, &fbo.colorTextureId); + glDeleteTextures(1, &fbo.depthTextureId); } + else TraceLog(INFO, "[FBO ID %i] Framebuffer object created successfully", fbo); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); #endif + + return fbo; +} + +// Unload framebuffer object +void rlglUnloadFBO(FBO fbo) +{ + glDeleteFramebuffers(1, &fbo.id); + glDeleteTextures(1, &fbo.colorTextureId); + glDeleteTextures(1, &fbo.depthTextureId); + + TraceLog(INFO, "[FBO ID %i] Unloaded framebuffer object successfully", fbo.id); } // Vertex Buffer Object deinitialization (memory free) @@ -1223,9 +1257,9 @@ void rlglClose(void) glDeleteTextures(1, &whiteTexture); TraceLog(INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture); - if (fbo != 0) + if (postproFbo.id != 0) { - glDeleteFramebuffers(1, &fbo); + rlglUnloadFBO(postproFbo); // Unload postpro quad model data #if defined(GRAPHICS_API_OPENGL_11) @@ -1240,7 +1274,7 @@ void rlglClose(void) rlDeleteVertexArrays(postproQuad.mesh.vaoId); - TraceLog(INFO, "[FBO %i] Unloaded postprocessing data", fbo); + TraceLog(INFO, "Unloaded postprocessing data"); } free(draws); @@ -2010,7 +2044,7 @@ unsigned char *rlglReadScreenPixels(int width, int height) } // Read texture pixel data -// NOTE: Retrieving pixel data from GPU not supported on OpenGL ES 2.0 +// NOTE: Retrieving pixel data from GPU (glGetTexImage()) not supported on OpenGL ES 2.0 void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) { void *pixels = NULL; @@ -2028,11 +2062,31 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) int glFormat = 0, glType = 0; unsigned int size = width*height; + + // NOTE: GL_LUMINANCE and GL_LUMINANCE_ALPHA are removed since OpenGL 3.1 + // Must be replaced by GL_RED and GL_RG on Core OpenGL 3.3 and data must be swizzled switch (format) { +#if defined(GRAPHICS_API_OPENGL_11) case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_LUMINANCE; glType = GL_UNSIGNED_BYTE; break; // 8 bit per pixel (no alpha) case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_LUMINANCE_ALPHA; glType = GL_UNSIGNED_BYTE; break; // 16 bpp (2 channels) +#elif defined(GRAPHICS_API_OPENGL_33) + case UNCOMPRESSED_GRAYSCALE: // 8 bit per pixel (no alpha) + { + pixels = (unsigned char *)malloc(size); glFormat = GL_RED; glType = GL_UNSIGNED_BYTE; + + GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } break; + case UNCOMPRESSED_GRAY_ALPHA: // 16 bpp (2 channels) + { + pixels = (unsigned char *)malloc(size*2); glFormat = GL_RG; glType = GL_UNSIGNED_BYTE; + + GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN }; + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); + } break; +#endif case UNCOMPRESSED_R5G6B5: pixels = (unsigned short *)malloc(size); glFormat = GL_RGB; glType = GL_UNSIGNED_SHORT_5_6_5; break; // 16 bpp case UNCOMPRESSED_R8G8B8: pixels = (unsigned char *)malloc(size*3); glFormat = GL_RGB; glType = GL_UNSIGNED_BYTE; break; // 24 bpp case UNCOMPRESSED_R5G5B5A1: pixels = (unsigned short *)malloc(size); glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_5_5_5_1; break; // 16 bpp (1 bit alpha) @@ -2052,6 +2106,44 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) glBindTexture(GL_TEXTURE_2D, 0); #endif +#if defined(GRAPHICS_API_OPENGL_ES2) + // TODO: Look for some way to retrieve texture width and height from id + int width = 1024; + int height = 1024; + + FBO fbo = rlglLoadFBO(width, height); + + // NOTE: Altenatively we can bind texture to color fbo and glReadPixels() + + // Render texture to fbo + glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearDepthf(1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glViewport(0, 0, width, height); + //glMatrixMode(GL_PROJECTION); + //glLoadIdentity(); + rlOrtho(0.0, width, height, 0.0, 0.0, 1.0); + //glMatrixMode(GL_MODELVIEW); + //glLoadIdentity(); + //glDisable(GL_TEXTURE_2D); + //glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + + //Model quad = GenModelQuad(width, height); + //DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE); + + pixels = (unsigned char *)malloc(width*height*4*sizeof(unsigned char)); + + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + // Bind framebuffer 0, which means render to back buffer + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + // Clean up temporal fbo + rlglUnloadFBO(fbo); +#endif + return pixels; } @@ -2282,7 +2374,7 @@ void SetPostproShader(Shader shader) SetModelShader(&postproQuad, shader); Texture2D texture; - texture.id = fboColorTexture; + texture.id = postproFbo.colorTextureId; texture.width = screenWidth; texture.height = screenHeight; -- cgit v1.2.3 From 8c117cfb570874e726d6a24a4b85573e0c7b1669 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 24 Oct 2015 11:19:04 +0200 Subject: Reviewed NPOT messages and usage --- src/rlgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index d632a3ac..797833e6 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1028,7 +1028,7 @@ void rlglInit(void) else TraceLog(WARNING, "[EXTENSION] VAO extension not found, VAO usage not supported"); if (npotSupported) TraceLog(INFO, "[EXTENSION] NPOT textures extension detected, full NPOT textures supported"); - else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, NPOT textures not supported"); + else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, NPOT textures support is limited (no-mipmaps, no-repeat"); #endif if (texCompDXTSupported) TraceLog(INFO, "[EXTENSION] DXT compressed textures supported"); -- cgit v1.2.3 From d1f099374c1d35b82b2a5d9d5ccf4b133aca25a2 Mon Sep 17 00:00:00 2001 From: Ray San Date: Mon, 26 Oct 2015 11:50:13 +0100 Subject: Added support for s3tc compression on web --- src/rlgl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 797833e6..ebff0d53 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1008,7 +1008,8 @@ void rlglInit(void) #endif // DDS texture compression support - if (strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) texCompDXTSupported = true; + if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) || + (strcmp(extList[i], (const char *)"GL_WEBKIT_WEBGL_compressed_texture_s3tc") == 0)) texCompDXTSupported = true; // ETC1 texture compression support if (strcmp(extList[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) texCompETC1Supported = true; -- cgit v1.2.3 From 76024b5036f060a19a1a2eea49c401d6db81cda8 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 4 Nov 2015 18:33:46 +0100 Subject: Added some texture functionality (view details) LoadTextureEx() - Simplified parameters UpdateTexture() - Added, allows updating GPU texture data --- src/rlgl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index ebff0d53..0befad3f 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1880,6 +1880,38 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma return id; } +void rlglUpdateTexture(unsigned int id, int width, int height, int format, void *data) +{ + glBindTexture(GL_TEXTURE_2D, id); + +#if defined(GRAPHICS_API_OPENGL_33) + switch (format) + { + case UNCOMPRESSED_GRAYSCALE: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RED, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + case UNCOMPRESSED_GRAY_ALPHA: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RG, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + case UNCOMPRESSED_R5G6B5: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)data); break; + case UNCOMPRESSED_R8G8B8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + case UNCOMPRESSED_R5G5B5A1: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break; + case UNCOMPRESSED_R4G4B4A4: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break; + case UNCOMPRESSED_R8G8B8A8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + default: TraceLog(WARNING, "Texture format updating not supported"); break; + } +#elif defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_ES2) + // NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA + switch (format) + { + case UNCOMPRESSED_GRAYSCALE: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + case UNCOMPRESSED_GRAY_ALPHA: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + case UNCOMPRESSED_R5G6B5: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (unsigned short *)data); break; + case UNCOMPRESSED_R8G8B8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + case UNCOMPRESSED_R5G5B5A1: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, (unsigned short *)data); break; + case UNCOMPRESSED_R4G4B4A4: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, (unsigned short *)data); break; + case UNCOMPRESSED_R8G8B8A8: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)data); break; + default: TraceLog(WARNING, "Texture format updating not supported"); break; + } +#endif +} + // Generate mipmap data for selected texture void rlglGenerateMipmaps(unsigned int textureId) { @@ -2046,6 +2078,7 @@ unsigned char *rlglReadScreenPixels(int width, int height) // Read texture pixel data // NOTE: Retrieving pixel data from GPU (glGetTexImage()) not supported on OpenGL ES 2.0 +//void *rlglReadTexturePixels(Texture2D texture) // Required to know texture size! It could not be retrieved on OpenGL ES 2.0 void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) { void *pixels = NULL; @@ -2108,14 +2141,32 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) #endif #if defined(GRAPHICS_API_OPENGL_ES2) - // TODO: Look for some way to retrieve texture width and height from id + // TODO: Look for some way to retrieve texture width and height from id -> NO WAY AVAILABLE int width = 1024; int height = 1024; FBO fbo = rlglLoadFBO(width, height); - // NOTE: Altenatively we can bind texture to color fbo and glReadPixels() + // NOTE: Two possible Options: + // 1 - Bind texture to color fbo attachment and glReadPixels() + // 2 - Create an fbo, activate it, render quad with texture, glReadPixels() + +#define GET_TEXTURE_FBO_OPTION_1 + +#if defined(GET_TEXTURE_FBO_OPTION_1) + glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); + + // Attach color texture and depth renderbuffer to FBO + // NOTE: texture must RGB + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0); + + pixels = (unsigned char *)malloc(width*height*3*sizeof(unsigned char)); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + +#elif defined(GET_TEXTURE_FBO_OPTION_2) // Render texture to fbo glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); glClearColor(0.0, 0.0, 0.0, 0.0); @@ -2131,8 +2182,12 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) //glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); - //Model quad = GenModelQuad(width, height); - //DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE); + Model quad; + //quad.mesh = GenMeshQuad(width, height); + quad.transform = MatrixIdentity(); + quad.shader = simpleShader; + + DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE); pixels = (unsigned char *)malloc(width*height*4*sizeof(unsigned char)); @@ -2140,7 +2195,8 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) // Bind framebuffer 0, which means render to back buffer glBindFramebuffer(GL_FRAMEBUFFER, 0); - +#endif // GET_TEXTURE_FBO_OPTION + // Clean up temporal fbo rlglUnloadFBO(fbo); #endif -- cgit v1.2.3 From 5208d57f1e0180ea095cecec64d3db7703ec63c9 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 5 Nov 2015 09:46:18 +0100 Subject: Corrected alpha issue on screenshots taken --- src/rlgl.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 0befad3f..6df49846 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1610,7 +1610,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height) // NOTE: Don't confuse glViewport with the transformation matrix // NOTE: glViewport just defines the area of the context that you will actually draw to. - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color (black) + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set clear color (black) //glClearDepth(1.0f); // Clear depth buffer (default) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear used buffers, depth buffer is used for 3D @@ -2063,11 +2063,16 @@ unsigned char *rlglReadScreenPixels(int width, int height) // Flip image vertically! unsigned char *imgData = (unsigned char *)malloc(width*height*sizeof(unsigned char)*4); - for (int y = height-1; y >= 0; y--) + for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < (width*4); x++) { - imgData[x + (height - y - 1)*width*4] = screenData[x + (y*width*4)]; + // Flip line + imgData[((height - 1) - y)*width*4 + x] = screenData[(y*width*4) + x]; + + // Set alpha component value to 255 (no trasparent image retrieval) + // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it! + if (((x + 1)%4) == 0) imgData[((height - 1) - y)*width*4 + x] = 255; } } -- cgit v1.2.3 From 88e1fd9530100311071352f71999cca08854a3a2 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 5 Nov 2015 12:32:47 +0100 Subject: Added texture retrieval support on OpenGL ES 2.0 Updated functions: Image GetTextureData(Texture2D texture); void *rlglReadTexturePixels(Texture2D texture); --- src/rlgl.c | 74 ++++++++++++++++++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 41 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 6df49846..766a834d 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1029,7 +1029,7 @@ void rlglInit(void) else TraceLog(WARNING, "[EXTENSION] VAO extension not found, VAO usage not supported"); if (npotSupported) TraceLog(INFO, "[EXTENSION] NPOT textures extension detected, full NPOT textures supported"); - else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, NPOT textures support is limited (no-mipmaps, no-repeat"); + else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, NPOT textures support is limited (no-mipmaps, no-repeat)"); #endif if (texCompDXTSupported) TraceLog(INFO, "[EXTENSION] DXT compressed textures supported"); @@ -2051,8 +2051,6 @@ Model rlglLoadModel(VertexData mesh) } // Read screen pixel data (color buffer) -// ISSUE: Non pre-multiplied alpha when reading from backbuffer! -// TODO: Multiply alpha unsigned char *rlglReadScreenPixels(int width, int height) { unsigned char *screenData = (unsigned char *)malloc(width*height*sizeof(unsigned char)*4); @@ -2082,28 +2080,30 @@ unsigned char *rlglReadScreenPixels(int width, int height) } // Read texture pixel data -// NOTE: Retrieving pixel data from GPU (glGetTexImage()) not supported on OpenGL ES 2.0 -//void *rlglReadTexturePixels(Texture2D texture) // Required to know texture size! It could not be retrieved on OpenGL ES 2.0 -void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) +// NOTE: glGetTexImage() is not available on OpenGL ES 2.0 +// Texture2D width and height are required on OpenGL ES 2.0. There is no way to get it from texture id. +void *rlglReadTexturePixels(Texture2D texture) { void *pixels = NULL; #if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33) - int width, height; - - glBindTexture(GL_TEXTURE_2D, textureId); + glBindTexture(GL_TEXTURE_2D, texture.id); + // NOTE: Using texture.id, we can retrieve some texture info (but not on OpenGL ES 2.0) + /* + int width, height, format; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); - //glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); - //GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); + // Other texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE + */ int glFormat = 0, glType = 0; - unsigned int size = width*height; + unsigned int size = texture.width*texture.height; // NOTE: GL_LUMINANCE and GL_LUMINANCE_ALPHA are removed since OpenGL 3.1 - // Must be replaced by GL_RED and GL_RG on Core OpenGL 3.3 and data must be swizzled + // Must be replaced by GL_RED and GL_RG on Core OpenGL 3.3 switch (format) { @@ -2111,27 +2111,15 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_LUMINANCE; glType = GL_UNSIGNED_BYTE; break; // 8 bit per pixel (no alpha) case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_LUMINANCE_ALPHA; glType = GL_UNSIGNED_BYTE; break; // 16 bpp (2 channels) #elif defined(GRAPHICS_API_OPENGL_33) - case UNCOMPRESSED_GRAYSCALE: // 8 bit per pixel (no alpha) - { - pixels = (unsigned char *)malloc(size); glFormat = GL_RED; glType = GL_UNSIGNED_BYTE; - - GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } break; - case UNCOMPRESSED_GRAY_ALPHA: // 16 bpp (2 channels) - { - pixels = (unsigned char *)malloc(size*2); glFormat = GL_RG; glType = GL_UNSIGNED_BYTE; - - GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); - } break; + case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_RED; glType = GL_UNSIGNED_BYTE; break; + case UNCOMPRESSED_GRAY_ALPHA: pixels = (unsigned char *)malloc(size*2); glFormat = GL_RG; glType = GL_UNSIGNED_BYTE; break; #endif case UNCOMPRESSED_R5G6B5: pixels = (unsigned short *)malloc(size); glFormat = GL_RGB; glType = GL_UNSIGNED_SHORT_5_6_5; break; // 16 bpp case UNCOMPRESSED_R8G8B8: pixels = (unsigned char *)malloc(size*3); glFormat = GL_RGB; glType = GL_UNSIGNED_BYTE; break; // 24 bpp case UNCOMPRESSED_R5G5B5A1: pixels = (unsigned short *)malloc(size); glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_5_5_5_1; break; // 16 bpp (1 bit alpha) case UNCOMPRESSED_R4G4B4A4: pixels = (unsigned short *)malloc(size); glFormat = GL_RGBA; glType = GL_UNSIGNED_SHORT_4_4_4_4; break; // 16 bpp (4 bit alpha) case UNCOMPRESSED_R8G8B8A8: pixels = (unsigned char *)malloc(size*4); glFormat = GL_RGBA; glType = GL_UNSIGNED_BYTE; break; // 32 bpp - default: TraceLog(WARNING, "Texture format not suported"); break; + default: TraceLog(WARNING, "Texture data retrieval, format not suported"); break; } // NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding. @@ -2146,34 +2134,36 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) #endif #if defined(GRAPHICS_API_OPENGL_ES2) - // TODO: Look for some way to retrieve texture width and height from id -> NO WAY AVAILABLE - int width = 1024; - int height = 1024; - - FBO fbo = rlglLoadFBO(width, height); + FBO fbo = rlglLoadFBO(texture.width, texture.height); // NOTE: Two possible Options: // 1 - Bind texture to color fbo attachment and glReadPixels() // 2 - Create an fbo, activate it, render quad with texture, glReadPixels() -#define GET_TEXTURE_FBO_OPTION_1 +#define GET_TEXTURE_FBO_OPTION_1 // It works #if defined(GET_TEXTURE_FBO_OPTION_1) glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); + glBindTexture(GL_TEXTURE_2D, 0); - // Attach color texture and depth renderbuffer to FBO - // NOTE: texture must RGB - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0); + // Attach our texture to FBO -> Texture must be RGB + // NOTE: Previoust attached texture is automatically detached + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id, 0); - pixels = (unsigned char *)malloc(width*height*3*sizeof(unsigned char)); + pixels = (unsigned char *)malloc(texture.width*texture.height*4*sizeof(unsigned char)); - glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + // NOTE: Despite FBO color texture is RGB, we read data as RGBA... reading as RGB doesn't work... o__O + glReadPixels(0, 0, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + // Re-attach internal FBO color texture before deleting it + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo.colorTextureId, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); #elif defined(GET_TEXTURE_FBO_OPTION_2) // Render texture to fbo glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); + glClearColor(0.0, 0.0, 0.0, 0.0); glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -2194,12 +2184,14 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format) DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE); - pixels = (unsigned char *)malloc(width*height*4*sizeof(unsigned char)); + pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char)); - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glReadPixels(0, 0, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, pixels); // Bind framebuffer 0, which means render to back buffer glBindFramebuffer(GL_FRAMEBUFFER, 0); + + UnloadModel(quad); #endif // GET_TEXTURE_FBO_OPTION // Clean up temporal fbo -- cgit v1.2.3 From a6f5a0339a00840c62c0cb0519d0f8482114bd54 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 9 Nov 2015 13:13:26 +0100 Subject: Corrected bug --- src/rlgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 766a834d..3862ac74 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -2105,7 +2105,7 @@ void *rlglReadTexturePixels(Texture2D texture) // NOTE: GL_LUMINANCE and GL_LUMINANCE_ALPHA are removed since OpenGL 3.1 // Must be replaced by GL_RED and GL_RG on Core OpenGL 3.3 - switch (format) + switch (texture.format) { #if defined(GRAPHICS_API_OPENGL_11) case UNCOMPRESSED_GRAYSCALE: pixels = (unsigned char *)malloc(size); glFormat = GL_LUMINANCE; glType = GL_UNSIGNED_BYTE; break; // 8 bit per pixel (no alpha) -- cgit v1.2.3 From 4db2da91850fcc55ec08df253e533e236eb91451 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 21 Dec 2015 16:42:13 +0100 Subject: Added new matrix location points and extra functions - New model and view transformation matrix added, useful for shaders. Modelview matrix not deleted to keep opengl 1.1 pipeline compatibility. - New extra function added DrawModelWiresEx() to set a rotation and scale transformations to a wire model drawing. - Other writing and little audio.c bug fixed. --- src/rlgl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 3862ac74..f9108342 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1498,6 +1498,8 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r glUseProgram(model.shader.id); // Apply transformation provided in model.transform matrix + // TODO: review if at this point the modelview matrix just contains view matrix values + Matrix viewworld = modelview; // Store view matrix before applying model transformations Matrix modelviewworld = MatrixMultiply(model.transform, modelview); // World-space transformation // Apply transformations provided in function @@ -1513,6 +1515,8 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r // NOTE: Drawing in OpenGL 3.3+, transform is passed to shader glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(projection)); + glUniformMatrix4fv(model.shader.modelLoc, 1, false, GetMatrixVector(transform)); + glUniformMatrix4fv(model.shader.viewLoc, 1, false, GetMatrixVector(viewworld)); glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(modelviewworld)); // Apply color tinting to model @@ -2242,6 +2246,8 @@ Shader LoadShader(char *vsFileName, char *fsFileName) // Get handles to GLSL uniform locations (vertex shader) shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); + shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) @@ -2781,6 +2787,8 @@ static Shader LoadDefaultShader(void) // Get handles to GLSL uniform locations (vertex shader) shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); + shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) @@ -2861,6 +2869,8 @@ static Shader LoadSimpleShader(void) // Get handles to GLSL uniform locations (vertex shader) shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); + shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) -- cgit v1.2.3 From 1bcb5ddd505e5c4bdac6f254e931e9c3145be88d Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 21 Dec 2015 17:25:22 +0100 Subject: Added lighting engine module - New lighting engine module which contains new data types Light and Material. These data types and functions facilitates making a basic 3D iluminated program with a light and a model. - Added lighting engine module example (currently included in raylib.h; it might be compiled by separate and include lighting.h in game source C file). - Corrected some opengl defines control structures and added some TODO to fix raylib-opengl 1.1 source build (note: now source can be compiled without errors, but rlglReadPixels() won't work properly). Note: most of functions of phong version 330 shader are not in v100 shaders, so I couldn't write a version 100 phong shader. These functions are included from version 150. --- src/rlgl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index f9108342..8a0440e0 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1094,6 +1094,7 @@ void rlglInit(void) // Modifies global variables: postproFbo, postproQuad void rlglInitPostpro(void) { +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) postproFbo = rlglLoadFBO(screenWidth, screenHeight); if (postproFbo.id > 0) @@ -1120,6 +1121,7 @@ void rlglInitPostpro(void) // NOTE: postproFbo.colorTextureId must be assigned to postproQuad model shader } +#endif } // Load a framebuffer object @@ -1195,11 +1197,13 @@ FBO rlglLoadFBO(int width, int height) // Unload framebuffer object void rlglUnloadFBO(FBO fbo) { +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) glDeleteFramebuffers(1, &fbo.id); glDeleteTextures(1, &fbo.colorTextureId); glDeleteTextures(1, &fbo.depthTextureId); TraceLog(INFO, "[FBO ID %i] Unloaded framebuffer object successfully", fbo.id); +#endif } // Vertex Buffer Object deinitialization (memory free) @@ -1939,7 +1943,8 @@ void rlglGenerateMipmaps(unsigned int textureId) { #if defined(GRAPHICS_API_OPENGL_11) // Compute required mipmaps - void *data = rlglReadTexturePixels(textureId, UNCOMPRESSED_R8G8B8A8); // TODO: Detect internal format + // TODO: rlglReadTexturePixels() needs Texture2D type parameter, not unsigned int parameter + void *data; // = rlglReadTexturePixels(textureId, UNCOMPRESSED_R8G8B8A8); // TODO: Detect internal format // NOTE: data size is reallocated to fit mipmaps data int mipmapCount = GenerateMipmaps(data, width, height); -- cgit v1.2.3 From 95da97fa744766fb46b912dcae504cd858fd2377 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 4 Jan 2016 15:09:44 +0100 Subject: Fixed bug: rlglGenerateMipmaps() --- src/rlgl.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 8a0440e0..504381b2 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1921,40 +1921,31 @@ void rlglUpdateTexture(unsigned int id, int width, int height, int format, void } // Generate mipmap data for selected texture -void rlglGenerateMipmaps(unsigned int textureId) +void rlglGenerateMipmaps(Texture2D texture) { - glBindTexture(GL_TEXTURE_2D, textureId); + glBindTexture(GL_TEXTURE_2D, texture.id); // Check if texture is power-of-two (POT) bool texIsPOT = false; - // NOTE: In OpenGL ES 2.0 we have no way to retrieve texture size from id - -#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33) - int width, height; - - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); - - if (((width > 0) && ((width & (width - 1)) == 0)) && ((height > 0) && ((height & (height - 1)) == 0))) texIsPOT = true; -#endif + if (((texture.width > 0) && ((texture.width & (texture.width - 1)) == 0)) && + ((texture.height > 0) && ((texture.height & (texture.height - 1)) == 0))) texIsPOT = true; if ((texIsPOT) || (npotSupported)) { #if defined(GRAPHICS_API_OPENGL_11) // Compute required mipmaps - // TODO: rlglReadTexturePixels() needs Texture2D type parameter, not unsigned int parameter - void *data; // = rlglReadTexturePixels(textureId, UNCOMPRESSED_R8G8B8A8); // TODO: Detect internal format + void *data = rlglReadTexturePixels(texture); // NOTE: data size is reallocated to fit mipmaps data - int mipmapCount = GenerateMipmaps(data, width, height); + int mipmapCount = GenerateMipmaps(data, texture.width, texture.height); // TODO: Adjust mipmap size depending on texture format! - int size = width*height*4; + int size = texture.width*texture.height*4; int offset = size; - int mipWidth = width/2; - int mipHeight = height/2; + int mipWidth = texture.width/2; + int mipHeight = texture.height/2; // Load the mipmaps for (int level = 1; level < mipmapCount; level++) @@ -1968,17 +1959,17 @@ void rlglGenerateMipmaps(unsigned int textureId) mipHeight /= 2; } - TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", textureId); + TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture.id); #elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically - TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", textureId); + TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", texture.id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps (must be available) #endif } - else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", textureId); + else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", texture.id); glBindTexture(GL_TEXTURE_2D, 0); } -- cgit v1.2.3 From 891c4a458a2fb03737c75def69dd6b0d67d38ad5 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 4 Jan 2016 20:02:57 +0100 Subject: Matrix variables renaming --- src/rlgl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 504381b2..4531f2d8 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -397,33 +397,33 @@ void rlLoadIdentity(void) // Multiply the current matrix by a translation matrix void rlTranslatef(float x, float y, float z) { - Matrix mat = MatrixTranslate(x, y, z); - MatrixTranspose(&mat); + Matrix matTranslation = MatrixTranslate(x, y, z); + MatrixTranspose(&matTranslation); - *currentMatrix = MatrixMultiply(*currentMatrix, mat); + *currentMatrix = MatrixMultiply(*currentMatrix, matTranslation); } // Multiply the current matrix by a rotation matrix void rlRotatef(float angleDeg, float x, float y, float z) { - Matrix rotation = MatrixIdentity(); + Matrix matRotation = MatrixIdentity(); Vector3 axis = (Vector3){ x, y, z }; VectorNormalize(&axis); - rotation = MatrixRotate(angleDeg*DEG2RAD, axis); + matRotation = MatrixRotate(angleDeg*DEG2RAD, axis); - MatrixTranspose(&rotation); + MatrixTranspose(&matRotation); - *currentMatrix = MatrixMultiply(*currentMatrix, rotation); + *currentMatrix = MatrixMultiply(*currentMatrix, matRotation); } // Multiply the current matrix by a scaling matrix void rlScalef(float x, float y, float z) { - Matrix mat = MatrixScale(x, y, z); - MatrixTranspose(&mat); + Matrix matScale = MatrixScale(x, y, z); + MatrixTranspose(&matScale); - *currentMatrix = MatrixMultiply(*currentMatrix, mat); + *currentMatrix = MatrixMultiply(*currentMatrix, matScale); } // Multiply the current matrix by another matrix -- cgit v1.2.3 From 7f2e67e924ae9f3f4c1172d14d25fc6212618339 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 6 Jan 2016 17:22:24 +0100 Subject: Simplified MatrixMultiply() function --- src/rlgl.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 4531f2d8..c44372f5 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1500,28 +1500,34 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) glUseProgram(model.shader.id); - - // Apply transformation provided in model.transform matrix - // TODO: review if at this point the modelview matrix just contains view matrix values - Matrix viewworld = modelview; // Store view matrix before applying model transformations - Matrix modelviewworld = MatrixMultiply(model.transform, modelview); // World-space transformation - - // Apply transformations provided in function + + // At this point the modelview matrix just contains the view matrix (camera) + // That's because Begin3dMode() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix() + Matrix matView = modelview; // View matrix (camera) + Matrix matProjection = projection; // Projection matrix (perspective) + + // Calculate transformation matrix from function parameters // Get transform matrix (rotation -> scale -> translation) - Matrix rotation = MatrixRotate(rotationAngle*DEG2RAD, rotationAxis); + Matrix matRotation = MatrixRotate(rotationAngle*DEG2RAD, rotationAxis); Matrix matScale = MatrixScale(scale.x, scale.y, scale.z); - Matrix translation = MatrixTranslate(position.x, position.y, position.z); - - Matrix transform = MatrixMultiply(MatrixMultiply(rotation, matScale), translation); // Object-space transformation matrix - modelviewworld = MatrixMultiply(transform, modelview); // World-space transformation + Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z); + Matrix matTransform = MatrixMultiply(MatrixMultiply(matRotation, matScale), matTranslation); + + // Combine model internal transformation matrix (model.transform) with matrix generated by function parameters (matTransform) + Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates + + // Calculate model-view matrix combining matModel and matView + Matrix matModelView = MatrixMultiply(matModel, matView); // Transform to camera-space coordinates - // Projection: Screen-space transformation + // Calculate model-view-projection matrix (MVP) + //Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates - // NOTE: Drawing in OpenGL 3.3+, transform is passed to shader - glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(projection)); - glUniformMatrix4fv(model.shader.modelLoc, 1, false, GetMatrixVector(transform)); - glUniformMatrix4fv(model.shader.viewLoc, 1, false, GetMatrixVector(viewworld)); - glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(modelviewworld)); + // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader + // TODO: Reduce number of matrices passed to shaders, use only matMVP + glUniformMatrix4fv(model.shader.modelLoc, 1, false, GetMatrixVector(matModel)); + glUniformMatrix4fv(model.shader.viewLoc, 1, false, GetMatrixVector(matView)); + glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(matProjection)); + glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(matModelView)); // Apply color tinting to model // NOTE: Just update one uniform on fragment shader -- cgit v1.2.3 From e5a56fa98515337c805e5a641cd3787cb6898596 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 11 Jan 2016 11:59:15 +0100 Subject: Change drawing order to avoid artifacts with... ... transparent elements --- src/rlgl.c | 58 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index c44372f5..e8b1ec47 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1301,7 +1301,35 @@ void rlglDraw(void) glUniform1i(currentShader.mapDiffuseLoc, 0); } - // NOTE: We draw in this order: triangle shapes, textured quads and lines + // NOTE: We draw in this order: lines, triangles, quads + + if (lines.vCounter > 0) + { + glBindTexture(GL_TEXTURE_2D, whiteTexture); + + if (vaoSupported) + { + glBindVertexArray(vaoLines); + } + else + { + glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]); + glVertexAttribPointer(currentShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0); + glEnableVertexAttribArray(currentShader.vertexLoc); + + if (currentShader.colorLoc != -1) + { + glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]); + glVertexAttribPointer(currentShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0); + glEnableVertexAttribArray(currentShader.colorLoc); + } + } + + glDrawArrays(GL_LINES, 0, lines.vCounter); + + if (!vaoSupported) glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0); + } if (triangles.vCounter > 0) { @@ -1394,34 +1422,6 @@ void rlglDraw(void) glBindTexture(GL_TEXTURE_2D, 0); // Unbind textures } - if (lines.vCounter > 0) - { - glBindTexture(GL_TEXTURE_2D, whiteTexture); - - if (vaoSupported) - { - glBindVertexArray(vaoLines); - } - else - { - glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]); - glVertexAttribPointer(currentShader.vertexLoc, 3, GL_FLOAT, 0, 0, 0); - glEnableVertexAttribArray(currentShader.vertexLoc); - - if (currentShader.colorLoc != -1) - { - glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]); - glVertexAttribPointer(currentShader.colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0); - glEnableVertexAttribArray(currentShader.colorLoc); - } - } - - glDrawArrays(GL_LINES, 0, lines.vCounter); - - if (!vaoSupported) glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindTexture(GL_TEXTURE_2D, 0); - } - if (vaoSupported) glBindVertexArray(0); // Unbind VAO glUseProgram(0); // Unbind shader program -- cgit v1.2.3 From 5e7686695fcfe32bbf956990ced0a02b7c881af1 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 11 Jan 2016 13:29:55 +0100 Subject: Review Light/Material system Simplified for the user (more intuitive and clear) Removed lighting module dependency --- src/rlgl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index e8b1ec47..2f525f47 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1296,8 +1296,8 @@ void rlglDraw(void) { glUseProgram(currentShader.id); - glUniformMatrix4fv(currentShader.projectionLoc, 1, false, GetMatrixVector(projection)); - glUniformMatrix4fv(currentShader.modelviewLoc, 1, false, GetMatrixVector(modelview)); + glUniformMatrix4fv(currentShader.projectionLoc, 1, false, MatrixToFloat(projection)); + glUniformMatrix4fv(currentShader.modelviewLoc, 1, false, MatrixToFloat(modelview)); glUniform1i(currentShader.mapDiffuseLoc, 0); } @@ -1524,10 +1524,10 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader // TODO: Reduce number of matrices passed to shaders, use only matMVP - glUniformMatrix4fv(model.shader.modelLoc, 1, false, GetMatrixVector(matModel)); - glUniformMatrix4fv(model.shader.viewLoc, 1, false, GetMatrixVector(matView)); - glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(matProjection)); - glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(matModelView)); + glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel)); + glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView)); + glUniformMatrix4fv(model.shader.projectionLoc, 1, false, MatrixToFloat(matProjection)); + glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, MatrixToFloat(matModelView)); // Apply color tinting to model // NOTE: Just update one uniform on fragment shader -- cgit v1.2.3 From fb6ef2c2f4fe22552908d339cda541453e43faec Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 13 Jan 2016 17:13:28 +0100 Subject: Vertex shaders optimization --- src/rlgl.c | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 2f525f47..e3c763be 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1295,9 +1295,10 @@ void rlglDraw(void) if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0)) { glUseProgram(currentShader.id); + + Matrix matMVP = MatrixMultiply(modelview, projection); // Create modelview-projection matrix - glUniformMatrix4fv(currentShader.projectionLoc, 1, false, MatrixToFloat(projection)); - glUniformMatrix4fv(currentShader.modelviewLoc, 1, false, MatrixToFloat(modelview)); + glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP)); glUniform1i(currentShader.mapDiffuseLoc, 0); } @@ -1520,14 +1521,14 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r Matrix matModelView = MatrixMultiply(matModel, matView); // Transform to camera-space coordinates // Calculate model-view-projection matrix (MVP) - //Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates + Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader // TODO: Reduce number of matrices passed to shaders, use only matMVP glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel)); glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView)); - glUniformMatrix4fv(model.shader.projectionLoc, 1, false, MatrixToFloat(matProjection)); - glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, MatrixToFloat(matModelView)); + + glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP)); // Apply color tinting to model // NOTE: Just update one uniform on fragment shader @@ -2247,13 +2248,13 @@ Shader LoadShader(char *vsFileName, char *fsFileName) shader.colorLoc = -1; // Get handles to GLSL uniform locations (vertex shader) - shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); - shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) - shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor"); + shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor"); shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0"); shader.mapNormalLoc = -1; // It can be set later shader.mapSpecularLoc = -1; // It can be set later @@ -2738,40 +2739,39 @@ static Shader LoadDefaultShader(void) "in vec2 vertexTexCoord; \n" "in vec4 vertexColor; \n" "out vec2 fragTexCoord; \n" - "out vec4 tintColor; \n" + "out vec4 fragTintColor; \n" #elif defined(GRAPHICS_API_OPENGL_ES2) char vShaderStr[] = "#version 100 \n" "attribute vec3 vertexPosition; \n" "attribute vec2 vertexTexCoord; \n" "attribute vec4 vertexColor; \n" "varying vec2 fragTexCoord; \n" - "varying vec4 tintColor; \n" + "varying vec4 fragTintColor; \n" #endif - "uniform mat4 projectionMatrix; \n" - "uniform mat4 modelviewMatrix; \n" + "uniform mat4 mvpMatrix; \n" "void main() \n" "{ \n" " fragTexCoord = vertexTexCoord; \n" - " tintColor = vertexColor; \n" - " gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n" + " fragTintColor = vertexColor; \n" + " gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n" "} \n"; // Fragment shader directly defined, no external file required #if defined(GRAPHICS_API_OPENGL_33) char fShaderStr[] = "#version 330 \n" "in vec2 fragTexCoord; \n" - "in vec4 tintColor; \n" + "in vec4 fragTintColor; \n" #elif defined(GRAPHICS_API_OPENGL_ES2) char fShaderStr[] = "#version 100 \n" "precision mediump float; \n" // precision required for OpenGL ES2 (WebGL) "varying vec2 fragTexCoord; \n" - "varying vec4 tintColor; \n" + "varying vec4 fragTintColor; \n" #endif "uniform sampler2D texture0; \n" "void main() \n" "{ \n" " vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead - " gl_FragColor = texelColor*tintColor; \n" + " gl_FragColor = texelColor*fragTintColor; \n" "} \n"; shader.id = LoadShaderProgram(vShaderStr, fShaderStr); @@ -2788,10 +2788,10 @@ static Shader LoadDefaultShader(void) shader.normalLoc = -1; // Get handles to GLSL uniform locations (vertex shader) - shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); - shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) shader.tintColorLoc = -1; @@ -2831,12 +2831,11 @@ static Shader LoadSimpleShader(void) "attribute vec3 vertexNormal; \n" "varying vec2 fragTexCoord; \n" #endif - "uniform mat4 projectionMatrix; \n" - "uniform mat4 modelviewMatrix; \n" + "uniform mat4 mvpMatrix; \n" "void main() \n" "{ \n" " fragTexCoord = vertexTexCoord; \n" - " gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n" + " gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n" "} \n"; // Fragment shader directly defined, no external file required @@ -2849,11 +2848,11 @@ static Shader LoadSimpleShader(void) "varying vec2 fragTexCoord; \n" #endif "uniform sampler2D texture0; \n" - "uniform vec4 tintColor; \n" + "uniform vec4 fragTintColor; \n" "void main() \n" "{ \n" " vec4 texelColor = texture2D(texture0, fragTexCoord); \n" // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead - " gl_FragColor = texelColor*tintColor; \n" + " gl_FragColor = texelColor*fragTintColor; \n" "} \n"; shader.id = LoadShaderProgram(vShaderStr, fShaderStr); @@ -2870,13 +2869,13 @@ static Shader LoadSimpleShader(void) shader.colorLoc = -1; // Get handles to GLSL uniform locations (vertex shader) - shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix"); + shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); + shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); - shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix"); // Get handles to GLSL uniform locations (fragment shader) - shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor"); + shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor"); shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0"); shader.mapNormalLoc = -1; // It can be set later shader.mapSpecularLoc = -1; // It can be set later -- cgit v1.2.3 From 3b4d8442e049f969c737722cb72f1c8ad66621a7 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 13 Jan 2016 19:30:35 +0100 Subject: Corrected some float values --- src/rlgl.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index e3c763be..7afa374e 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -821,10 +821,10 @@ void rlDeleteBuffers(unsigned int id) void rlClearColor(byte r, byte g, byte b, byte a) { // Color values clamp to 0.0f(0) and 1.0f(255) - float cr = (float)r / 255; - float cg = (float)g / 255; - float cb = (float)b / 255; - float ca = (float)a / 255; + float cr = (float)r/255; + float cg = (float)g/255; + float cb = (float)b/255; + float ca = (float)a/255; glClearColor(cr, cg, cb, ca); } @@ -1104,12 +1104,12 @@ void rlglInitPostpro(void) quadData.vertexCount = 6; - float w = screenWidth; - float h = screenHeight; + float w = (float)screenWidth; + float h = (float)screenHeight; - float quadPositions[6*3] = { w, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, h, 0.0, 0, h, 0.0, w, h, 0.0, w, 0.0, 0.0 }; - float quadTexcoords[6*2] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0 }; - float quadNormals[6*3] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; + float quadPositions[6*3] = { w, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, h, 0.0f, 0.0f, h, 0.0f, w, h, 0.0f, w, 0.0f, 0.0f }; + float quadTexcoords[6*2] = { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f }; + float quadNormals[6*3] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; unsigned char quadColors[6*4] = { 255 }; quadData.vertices = quadPositions; @@ -1667,7 +1667,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height) // NOTE: Using global variables: screenWidth, screenHeight Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view) { - Vector3 result = { 0, 0, 0 }; // Object coordinates + Vector3 result = { 0.0f, 0.0f, 0.0f }; // Object coordinates //GLint viewport[4]; //glGetIntegerv(GL_VIEWPORT, viewport); // Not available on OpenGL ES 2.0 @@ -1698,11 +1698,11 @@ Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view) quat.x = ((source.x - (float)x)/(float)width)*2.0f - 1.0f; quat.y = ((source.y - (float)y)/(float)height)*2.0f - 1.0f; quat.z = source.z*2.0f - 1.0f; - quat.w = 1.0; + quat.w = 1.0f; QuaternionTransform(&quat, modelviewprojection); - if (quat.w != 0.0) + if (quat.w != 0.0f) { quat.x /= quat.w; quat.y /= quat.w; @@ -2171,7 +2171,7 @@ void *rlglReadTexturePixels(Texture2D texture) // Render texture to fbo glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); - glClearColor(0.0, 0.0, 0.0, 0.0); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); @@ -2189,7 +2189,7 @@ void *rlglReadTexturePixels(Texture2D texture) quad.transform = MatrixIdentity(); quad.shader = simpleShader; - DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE); + DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE); pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char)); @@ -3239,19 +3239,19 @@ static pixel *GenNextMipmap(pixel *srcData, int srcWidth, int srcHeight) int x2, y2; pixel prow, pcol; - int width = srcWidth / 2; - int height = srcHeight / 2; + int width = srcWidth/2; + int height = srcHeight/2; pixel *mipmap = (pixel *)malloc(width*height*sizeof(pixel)); // Scaling algorithm works perfectly (box-filter) for (int y = 0; y < height; y++) { - y2 = 2 * y; + y2 = 2*y; for (int x = 0; x < width; x++) { - x2 = 2 * x; + x2 = 2*x; prow.r = (srcData[y2*srcWidth + x2].r + srcData[y2*srcWidth + x2 + 1].r)/2; prow.g = (srcData[y2*srcWidth + x2].g + srcData[y2*srcWidth + x2 + 1].g)/2; -- cgit v1.2.3 From fd05d3e3531964a38ea84df920264a1ed14bb777 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 18 Jan 2016 13:36:18 +0100 Subject: Rename VertexData struct to Mesh Reviewed vertex type variables --- src/rlgl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 7afa374e..ca08e1a2 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1100,9 +1100,9 @@ void rlglInitPostpro(void) if (postproFbo.id > 0) { // Create a simple quad model to render fbo texture - VertexData quadData; + Mesh quad; - quadData.vertexCount = 6; + quad.vertexCount = 6; float w = (float)screenWidth; float h = (float)screenHeight; @@ -1112,12 +1112,12 @@ void rlglInitPostpro(void) float quadNormals[6*3] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; unsigned char quadColors[6*4] = { 255 }; - quadData.vertices = quadPositions; - quadData.texcoords = quadTexcoords; - quadData.normals = quadNormals; - quadData.colors = quadColors; + quad.vertices = quadPositions; + quad.texcoords = quadTexcoords; + quad.normals = quadNormals; + quad.colors = quadColors; - postproQuad = rlglLoadModel(quadData); + postproQuad = rlglLoadModel(quad); // NOTE: postproFbo.colorTextureId must be assigned to postproQuad model shader } @@ -1982,7 +1982,7 @@ void rlglGenerateMipmaps(Texture2D texture) } // Load vertex data into a VAO (if supported) and VBO -Model rlglLoadModel(VertexData mesh) +Model rlglLoadModel(Mesh mesh) { Model model; -- cgit v1.2.3 From efa1c96d19095c801a01dbf9b0214a82b7ae8c11 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 20 Jan 2016 18:20:05 +0100 Subject: Adapted raymath as single header library Added support for single header implementation and also inline functions support --- src/rlgl.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index ca08e1a2..dbcbc35f 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -32,6 +32,8 @@ #include // Declares malloc() and free() for memory management, rand() #include // Declares strcmp(), strlen(), strtok() +#include "raymath.h" // Required for Vector3 and Matrix functions + #if defined(GRAPHICS_API_OPENGL_11) #ifdef __APPLE__ // OpenGL include for OSX #include -- cgit v1.2.3 From 23d66e9b6f4ae26cded37878da37aabcb29e48ad Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 21 Jan 2016 12:24:35 +0100 Subject: Move extensions loading to core module --- src/rlgl.c | 61 +++++-------------------------------------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index dbcbc35f..35aa5a5f 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -43,13 +43,11 @@ #endif #if defined(GRAPHICS_API_OPENGL_33) - #define GLEW_STATIC #ifdef __APPLE__ // OpenGL include for OSX #include #else - #include // GLEW extensions loading lib - //#include "glad.h" // glad extensions loading lib: ERRORS: windows.h - //#include "gl_core_3_3.h" // glLoadGen extension loading lib: ERRORS: windows.h + #include // GLEW header, includes OpenGL headers + //#include "glad.h" // glad header, includes OpenGL headers #endif #endif @@ -896,59 +894,10 @@ void rlglInit(void) #if defined(GRAPHICS_API_OPENGL_33) -#define GLEW_EXTENSIONS_LOADER -#if defined(GLEW_EXTENSIONS_LOADER) - // Initialize extensions using GLEW - glewExperimental = 1; // Needed for core profile - GLenum error = glewInit(); - - if (error != GLEW_OK) TraceLog(ERROR, "Failed to initialize GLEW - Error Code: %s\n", glewGetErrorString(error)); - - if (glewIsSupported("GL_VERSION_3_3")) - { - TraceLog(INFO, "OpenGL 3.3 Core profile supported"); - - vaoSupported = true; - npotSupported = true; - } - else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported"); - - // With GLEW, we can check if an extension has been loaded in two ways: - //if (GLEW_ARB_vertex_array_object) { } - //if (glewIsSupported("GL_ARB_vertex_array_object")) { } - - // NOTE: GLEW is a big library that loads ALL extensions, we can use some alternative to load only required ones - // Alternatives: glLoadGen, glad, libepoxy - -#elif defined(GLAD_EXTENSIONS_LOADER) - // NOTE: glad is generated and contains only required OpenGL version and core extensions - //if (!gladLoadGL()) TraceLog(ERROR, "Failed to initialize glad\n"); - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) TraceLog(ERROR, "Failed to initialize glad\n"); // No GLFW3 in this module... - - if (GLAD_GL_VERSION_3_3) - { - TraceLog(INFO, "OpenGL 3.3 Core profile supported"); - - vaoSupported = true; - npotSupported = true; - } - else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported"); - - // With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans - //if (GLAD_GL_ARB_vertex_array_object) // Use GL_ARB_vertex_array_object + // NOTE: On OpenGL 3.3 VAO and NPOT are supported by default + vaoSupported = true; + npotSupported = true; -#elif defined(GLLOADGEN_EXTENSIONS_LOADER) - // NOTE: glLoadGen already generates a header with required OpenGL version and core extensions - if (ogl_LoadFunctions() != ogl_LOAD_FAILED) - { - TraceLog(INFO, "OpenGL 3.3 Core profile supported"); - - vaoSupported = true; - npotSupported = true; - } - else TraceLog(ERROR, "OpenGL 3.3 Core profile not supported"); -#endif - // NOTE: We don't need to check again supported extensions but we do (in case GLEW is replaced sometime) // We get a list of available extensions and we check for some of them (compressed textures) glGetIntegerv(GL_NUM_EXTENSIONS, &numExt); -- cgit v1.2.3 From 4e57bd1f18996990546920f2242a58894c6cec81 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 22 Jan 2016 01:22:45 +0100 Subject: Replaced GLEW by GLAD Removed GLEW external dependency, now it works with GLAD Kept GLEW path, just in case... detected weird behaviour when testing with gDEBugger --- src/rlgl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 35aa5a5f..ec909385 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -46,8 +46,9 @@ #ifdef __APPLE__ // OpenGL include for OSX #include #else - #include // GLEW header, includes OpenGL headers - //#include "glad.h" // glad header, includes OpenGL headers + //#define GLEW_STATIC + //#include // GLEW header, includes OpenGL headers + #include "glad.h" // glad header, includes OpenGL headers #endif #endif -- cgit v1.2.3 From 99f99bea470ace9577950db8976aa092a678635d Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 25 Jan 2016 13:54:09 +0100 Subject: Simplified shader matrix uniforms --- src/rlgl.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index ec909385..49300054 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1477,8 +1477,8 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader // TODO: Reduce number of matrices passed to shaders, use only matMVP - glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel)); - glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView)); + //glUniformMatrix4fv(model.material.shader.modelLoc, 1, false, MatrixToFloat(matModel)); + //glUniformMatrix4fv(model.material.shader.viewLoc, 1, false, MatrixToFloat(matView)); glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP)); @@ -2201,9 +2201,6 @@ Shader LoadShader(char *vsFileName, char *fsFileName) // Get handles to GLSL uniform locations (vertex shader) shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); - - shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); - shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); // Get handles to GLSL uniform locations (fragment shader) shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor"); @@ -2503,6 +2500,18 @@ void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size) #endif } +// Set shader uniform value (matrix 4x4) +void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat) +{ +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) + glUseProgram(shader.id); + + glUniformMatrix4fv(uniformLoc, 1, false, MatrixToFloat(mat)); + + glUseProgram(0); +#endif +} + // Default diffuse shader map texture assignment void SetShaderMapDiffuse(Shader *shader, Texture2D texture) { @@ -2741,9 +2750,6 @@ static Shader LoadDefaultShader(void) // Get handles to GLSL uniform locations (vertex shader) shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); - - shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); - shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); // Get handles to GLSL uniform locations (fragment shader) shader.tintColorLoc = -1; @@ -2822,9 +2828,6 @@ static Shader LoadSimpleShader(void) // Get handles to GLSL uniform locations (vertex shader) shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix"); - - shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix"); - shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix"); // Get handles to GLSL uniform locations (fragment shader) shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor"); -- cgit v1.2.3 From df5c64d0beee06df8c87a43e5341b6b98f82839f Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 2 Feb 2016 18:41:01 +0100 Subject: Functions parameters reorganize: Axis and Angle sin(), cos() functions cached and replaced by float c99 versions sinf(), cos() --- src/rlgl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 49300054..48e6ac1b 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -411,7 +411,7 @@ void rlRotatef(float angleDeg, float x, float y, float z) Vector3 axis = (Vector3){ x, y, z }; VectorNormalize(&axis); - matRotation = MatrixRotate(angleDeg*DEG2RAD, axis); + matRotation = MatrixRotate(axis, angleDeg*DEG2RAD); MatrixTranspose(&matRotation); @@ -1406,13 +1406,13 @@ void rlglDrawPostpro(void) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) glBindFramebuffer(GL_FRAMEBUFFER, 0); - rlglDrawModel(postproQuad, (Vector3){0,0,0}, 0.0f, (Vector3){0,0,0}, (Vector3){1.0f, 1.0f, 1.0f}, (Color){ 255, 255, 255, 255 }, false); + rlglDrawModel(postproQuad, (Vector3){0,0,0}, (Vector3){0,0,0}, 0.0f, (Vector3){1.0f, 1.0f, 1.0f}, (Color){ 255, 255, 255, 255 }, false); #endif } // Draw a 3d model // NOTE: Model transform can come within model struct -void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 rotationAxis, Vector3 scale, Color color, bool wires) +void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color color, bool wires) { #if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33) // NOTE: glPolygonMode() not available on OpenGL ES @@ -1461,7 +1461,7 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r // Calculate transformation matrix from function parameters // Get transform matrix (rotation -> scale -> translation) - Matrix matRotation = MatrixRotate(rotationAngle*DEG2RAD, rotationAxis); + Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD); Matrix matScale = MatrixScale(scale.x, scale.y, scale.z); Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z); Matrix matTransform = MatrixMultiply(MatrixMultiply(matRotation, matScale), matTranslation); -- cgit v1.2.3 From 646f1c3f716dd817ff717d35480a744a8be46ead Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Feb 2016 17:45:28 +0100 Subject: Some formating tweaks --- src/rlgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 48e6ac1b..6810cb4b 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1406,7 +1406,7 @@ void rlglDrawPostpro(void) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) glBindFramebuffer(GL_FRAMEBUFFER, 0); - rlglDrawModel(postproQuad, (Vector3){0,0,0}, (Vector3){0,0,0}, 0.0f, (Vector3){1.0f, 1.0f, 1.0f}, (Color){ 255, 255, 255, 255 }, false); + rlglDrawModel(postproQuad, (Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, 0.0f, 0.0f }, 0.0f, (Vector3){1.0f, 1.0f, 1.0f}, (Color){ 255, 255, 255, 255 }, false); #endif } -- cgit v1.2.3 From 2ef9552454db2119e1e6df0999d77525dbc31609 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 Feb 2016 19:01:16 +0100 Subject: WARNING message shortened --- src/rlgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 6810cb4b..421dda02 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -981,7 +981,7 @@ void rlglInit(void) else TraceLog(WARNING, "[EXTENSION] VAO extension not found, VAO usage not supported"); if (npotSupported) TraceLog(INFO, "[EXTENSION] NPOT textures extension detected, full NPOT textures supported"); - else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, NPOT textures support is limited (no-mipmaps, no-repeat)"); + else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, limited NPOT support (no-mipmaps, no-repeat)"); #endif if (texCompDXTSupported) TraceLog(INFO, "[EXTENSION] DXT compressed textures supported"); -- cgit v1.2.3 From fca83c9ff8a808194cd74821640ed3f17a90010e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 11 Feb 2016 14:27:18 +0100 Subject: Solve bug on matrix multiply order for scale and rotation --- src/rlgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 421dda02..2ea06e1c 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -1464,7 +1464,7 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD); Matrix matScale = MatrixScale(scale.x, scale.y, scale.z); Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z); - Matrix matTransform = MatrixMultiply(MatrixMultiply(matRotation, matScale), matTranslation); + Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation); // Combine model internal transformation matrix (model.transform) with matrix generated by function parameters (matTransform) Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates -- cgit v1.2.3 From 823abf666e09e96ccbf5230c96f2d3a61ff60895 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 12 Feb 2016 12:22:56 +0100 Subject: Reviewed code TODOs --- src/rlgl.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/rlgl.c') diff --git a/src/rlgl.c b/src/rlgl.c index 2ea06e1c..5f8a5ea1 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -171,7 +171,7 @@ typedef struct { typedef struct { GLuint textureId; int vertexCount; - // TODO: DrawState state -> Blending mode, shader + // TODO: Store draw state -> blending mode, shader } DrawCall; // pixel type (same as Color type) @@ -1475,11 +1475,7 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotationAxis, float ro // Calculate model-view-projection matrix (MVP) Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates - // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader - // TODO: Reduce number of matrices passed to shaders, use only matMVP - //glUniformMatrix4fv(model.material.shader.modelLoc, 1, false, MatrixToFloat(matModel)); - //glUniformMatrix4fv(model.material.shader.viewLoc, 1, false, MatrixToFloat(matView)); - + // Send combined model-view-projection matrix to shader glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP)); // Apply color tinting to model @@ -1900,7 +1896,7 @@ void rlglGenerateMipmaps(Texture2D texture) int mipmapCount = GenerateMipmaps(data, texture.width, texture.height); // TODO: Adjust mipmap size depending on texture format! - int size = texture.width*texture.height*4; + int size = texture.width*texture.height*4; // RGBA 32bit only int offset = size; int mipWidth = texture.width/2; -- cgit v1.2.3