Review some comments

This commit is contained in:
Ray 2020-10-26 20:11:58 +01:00
parent 482b8a5e7e
commit d9e591f235

View file

@ -812,12 +812,12 @@ typedef struct DrawCall {
int mode; // Drawing mode: LINES, TRIANGLES, QUADS int mode; // Drawing mode: LINES, TRIANGLES, QUADS
int vertexCount; // Number of vertex of the draw int vertexCount; // Number of vertex of the draw
int vertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES) int vertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES)
//unsigned int vaoId; // Vertex array id to be used on the draw //unsigned int vaoId; // Vertex array id to be used on the draw -> Using RLGL.currentBatch->vertexBuffer.vaoId
//unsigned int shaderId; // Shader id to be used on the draw //unsigned int shaderId; // Shader id to be used on the draw -> Using RLGL.currentShader.id
unsigned int textureId; // Texture id to be used on the draw 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 //Matrix projection; // Projection matrix for this draw -> Using RLGL.projection
//Matrix modelview; // Modelview matrix for this draw //Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview
} DrawCall; } DrawCall;
// RenderBatch type // RenderBatch type
@ -826,7 +826,7 @@ typedef struct RenderBatch {
int currentBuffer; // Current buffer tracking in case of multi-buffering int currentBuffer; // Current buffer tracking in case of multi-buffering
VertexBuffer *vertexBuffer; // Dynamic buffer(s) for vertex data VertexBuffer *vertexBuffer; // Dynamic buffer(s) for vertex data
DrawCall *draws; // Draw calls array DrawCall *draws; // Draw calls array, depends on textureId
int drawsCounter; // Draw calls counter int drawsCounter; // Draw calls counter
float currentDepth; // Current depth value for next draw float currentDepth; // Current depth value for next draw
} RenderBatch; } RenderBatch;
@ -857,7 +857,7 @@ typedef struct rlglData {
Matrix stack[MAX_MATRIX_STACK_SIZE];// Matrix stack for push/pop Matrix stack[MAX_MATRIX_STACK_SIZE];// Matrix stack for push/pop
int stackCounter; // Matrix stack counter int stackCounter; // Matrix stack counter
Texture2D shapesTexture; // Texture used on shapes drawing (usually a white) Texture2D shapesTexture; // Texture used on shapes drawing (usually a white pixel)
Rectangle shapesTextureRec; // Texture source rectangle used on shapes drawing Rectangle shapesTextureRec; // Texture source rectangle used on shapes drawing
unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader) unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader)
unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program) unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program)
@ -4421,16 +4421,14 @@ static void DrawRenderBatch(RenderBatch *batch)
#if defined(SUPPORT_VR_SIMULATOR) #if defined(SUPPORT_VR_SIMULATOR)
if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView); if (eyesCount == 2) SetStereoView(eye, matProjection, matModelView);
#endif #endif
// Draw buffers // Draw buffers
if (batch->vertexBuffer[batch->currentBuffer].vCounter > 0) if (batch->vertexBuffer[batch->currentBuffer].vCounter > 0)
{ {
// Set current shader and upload current MVP matrix // Set current shader and upload current MVP matrix
glUseProgram(RLGL.State.currentShader.id); glUseProgram(RLGL.State.currentShader.id);
// Create modelview-projection matrix // Create modelview-projection matrix and upload to shader
Matrix matMVP = MatrixMultiply(RLGL.State.modelview, RLGL.State.projection); Matrix matMVP = MatrixMultiply(RLGL.State.modelview, RLGL.State.projection);
glUniformMatrix4fv(RLGL.State.currentShader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP)); glUniformMatrix4fv(RLGL.State.currentShader.locs[LOC_MATRIX_MVP], 1, false, MatrixToFloat(matMVP));
glUniform4f(RLGL.State.currentShader.locs[LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f); glUniform4f(RLGL.State.currentShader.locs[LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f);
glUniform1i(RLGL.State.currentShader.locs[LOC_MAP_DIFFUSE], 0); // Provided value refers to the texture unit (active) glUniform1i(RLGL.State.currentShader.locs[LOC_MAP_DIFFUSE], 0); // Provided value refers to the texture unit (active)
@ -4441,8 +4439,6 @@ static void DrawRenderBatch(RenderBatch *batch)
// NOTE: Right now additional map textures not considered for default buffers drawing // NOTE: Right now additional map textures not considered for default buffers drawing
int vertexOffset = 0;
if (RLGL.ExtSupported.vao) glBindVertexArray(batch->vertexBuffer[batch->currentBuffer].vaoId); if (RLGL.ExtSupported.vao) glBindVertexArray(batch->vertexBuffer[batch->currentBuffer].vaoId);
else else
{ {
@ -4470,9 +4466,10 @@ static void DrawRenderBatch(RenderBatch *batch)
{ {
glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId); glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId);
// TODO: Find some way to bind additional textures --> Use global texture IDs? Register them on draw[i]? for (int i = 0, vertexOffset = 0; i < batch->drawsCounter; i++)
//if (RLGL.State.currentShader->locs[LOC_MAP_SPECULAR] > 0) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textureUnit1_id); } {
//if (RLGL.State.currentShader->locs[LOC_MAP_SPECULAR] > 0) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textureUnit2_id); } // Texture 0 is always active by default, bind the texture for current draw call
glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId);
if ((batch->draws[i].mode == RL_LINES) || (batch->draws[i].mode == RL_TRIANGLES)) glDrawArrays(batch->draws[i].mode, vertexOffset, batch->draws[i].vertexCount); if ((batch->draws[i].mode == RL_LINES) || (batch->draws[i].mode == RL_TRIANGLES)) glDrawArrays(batch->draws[i].mode, vertexOffset, batch->draws[i].vertexCount);
else else