Browse Source

REVIEWED: rlgl_standalone usage

Ray 4 years ago
parent
commit
6f5a4a9351
2 changed files with 27 additions and 17 deletions
  1. 17 8
      examples/others/rlgl_standalone.c
  2. 10 9
      src/rlgl.h

+ 17 - 8
examples/others/rlgl_standalone.c

@@ -65,6 +65,15 @@
 #define RAYWHITE   (Color){ 245, 245, 245, 255 }   // My own White (raylib logo)
 #define DARKGRAY   (Color){ 80, 80, 80, 255 }      // Dark Gray
 
+// Camera type, defines a camera position/orientation in 3d space
+typedef struct Camera {
+    Vector3 position;       // Camera position
+    Vector3 target;         // Camera target it looks-at
+    Vector3 up;             // Camera up vector (rotation over its axis)
+    float fovy;             // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
+    int projection;         // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
+} Camera;
+
 //----------------------------------------------------------------------------------
 // Module specific Functions Declaration
 //----------------------------------------------------------------------------------
@@ -170,15 +179,15 @@ int main(void)
             Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)screenWidth/(double)screenHeight, 0.01, 1000.0);
             Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
 
-            SetMatrixModelview(matView);    // Set internal modelview matrix (default shader)
-            SetMatrixProjection(matProj);   // Set internal projection matrix (default shader)
+            rlSetMatrixModelview(matView);    // Set internal modelview matrix (default shader)
+            rlSetMatrixProjection(matProj);   // Set internal projection matrix (default shader)
 
             DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
             DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, RAYWHITE);
             DrawGrid(10, 1.0f);
 
-            // NOTE: Internal buffers drawing (3D data)
-            rlglDraw();
+            // Draw internal render batch buffers (3D data)
+            rlDrawRenderBatchActive();
             //-----------------------------------------------
             
             // Draw '2D' elements in the scene (GUI)
@@ -188,8 +197,8 @@ int main(void)
             matProj = MatrixOrtho(0.0, screenWidth, screenHeight, 0.0, 0.0, 1.0);
             matView = MatrixIdentity();
             
-            SetMatrixModelview(matView);    // Set internal modelview matrix (default shader)
-            SetMatrixProjection(matProj);   // Set internal projection matrix (default shader)
+            rlSetMatrixModelview(matView);    // Set internal modelview matrix (default shader)
+            rlSetMatrixProjection(matProj);   // Set internal projection matrix (default shader)
 
 #else   // Let rlgl generate and multiply matrix internally
 
@@ -201,8 +210,8 @@ int main(void)
 #endif
             DrawRectangleV((Vector2){ 10.0f, 10.0f }, (Vector2){ 780.0f, 20.0f }, DARKGRAY);
 
-            // NOTE: Internal buffers drawing (2D data)
-            rlglDraw();
+            // Draw internal render batch buffers (3D data)
+            rlDrawRenderBatchActive();
             //-----------------------------------------------
             
         glfwSwapBuffers(window);

+ 10 - 9
src/rlgl.h

@@ -3248,12 +3248,12 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
 
 #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
     // Bind shader program
-    glUseProgram(material.shader.id);
+    rlEnableShader(material.shader.id);
 
     // Matrices and other values required by shader
     //-----------------------------------------------------
-    // Calculate and send to shader model matrix (used by PBR shader)
-    if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[SHADER_LOC_MATRIX_MODEL], transform);
+    // Calculate and send to shader model matrix
+    if (material.shader.locs[SHADER_LOC_MATRIX_MODEL] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_MODEL], transform);
 
     // Upload to shader material.colDiffuse
     if (material.shader.locs[SHADER_LOC_COLOR_DIFFUSE] != -1)
@@ -3269,8 +3269,8 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
                                                                (float)material.maps[MATERIAL_MAP_SPECULAR].color.b/255.0f,
                                                                (float)material.maps[MATERIAL_MAP_SPECULAR].color.a/255.0f);
 
-    if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[SHADER_LOC_MATRIX_VIEW], RLGL.State.modelview);
-    if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) SetShaderValueMatrix(material.shader, material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], RLGL.State.projection);
+    if (material.shader.locs[SHADER_LOC_MATRIX_VIEW] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_VIEW], RLGL.State.modelview);
+    if (material.shader.locs[SHADER_LOC_MATRIX_PROJECTION] != -1) rlSetUniformMatrix(material.shader.locs[SHADER_LOC_MATRIX_PROJECTION], RLGL.State.projection);
 
     // At this point the modelview matrix just contains the view matrix (camera)
     // That's because BeginMode3D() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
@@ -4036,7 +4036,8 @@ TextureCubemap rlGenTexturePrefilter(Shader shader, TextureCubemap cubemap, int
 
     // Define projection matrix and send it to shader
     Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
-    SetShaderValueMatrix(shader, shader.locs[SHADER_LOC_MATRIX_PROJECTION], fboProjection);
+    rlEnableShader(shader.id);
+    rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_PROJECTION], fboProjection);
 
     // Define view matrix for every side of the cubemap
     Matrix fboViews[6] = {
@@ -4048,12 +4049,11 @@ TextureCubemap rlGenTexturePrefilter(Shader shader, TextureCubemap cubemap, int
         MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){  0.0f,  0.0f, -1.0f }, (Vector3){ 0.0f, -1.0f,  0.0f })
     };
 
-    rlEnableShader(shader.id);
     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
 
     // TODO: Locations should be taken out of this function... too shader dependant...
-    int roughnessLoc = GetShaderLocation(shader, "roughness");
+    int roughnessLoc = rlGetLocationUniform(shader.id, "roughness");
 
     rlEnableFramebuffer(fbo);
 
@@ -4075,7 +4075,8 @@ TextureCubemap rlGenTexturePrefilter(Shader shader, TextureCubemap cubemap, int
 
         for (int i = 0; i < 6; i++)
         {
-            SetShaderValueMatrix(shader, shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
+            //rlEnableShader(shader.id);
+            rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
             glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, prefilter.id, mip);
             //rlFramebufferAttach(fbo, irradiance.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i);  // TODO: Support mip levels?