[rlgl] Update function rlUpdateMeshAt
This commit is contained in:
parent
40d70bf1a6
commit
c9541abc4c
92
src/rlgl.h
92
src/rlgl.h
|
|
@ -2513,72 +2513,7 @@ unsigned int rlLoadAttribBuffer(unsigned int vaoId, int shaderLoc, void *buffer,
|
||||||
// Update vertex or index data on GPU (upload new data to one buffer)
|
// Update vertex or index data on GPU (upload new data to one buffer)
|
||||||
void rlUpdateMesh(Mesh mesh, int buffer, int num)
|
void rlUpdateMesh(Mesh mesh, int buffer, int num)
|
||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
rlUpdateMeshAt(mesh, buffer, num, 0);
|
||||||
// Activate mesh VAO
|
|
||||||
if (vaoSupported) glBindVertexArray(mesh.vaoId);
|
|
||||||
|
|
||||||
switch (buffer)
|
|
||||||
{
|
|
||||||
case 0: // Update vertices (vertex position)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
|
|
||||||
if (num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num, mesh.vertices, GL_DYNAMIC_DRAW);
|
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*num, mesh.vertices);
|
|
||||||
|
|
||||||
} break;
|
|
||||||
case 1: // Update texcoords (vertex texture coordinates)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[1]);
|
|
||||||
if (num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*num, mesh.texcoords, GL_DYNAMIC_DRAW);
|
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*num, mesh.texcoords);
|
|
||||||
|
|
||||||
} break;
|
|
||||||
case 2: // Update normals (vertex normals)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[2]);
|
|
||||||
if (num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num, mesh.normals, GL_DYNAMIC_DRAW);
|
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*num, mesh.normals);
|
|
||||||
|
|
||||||
} break;
|
|
||||||
case 3: // Update colors (vertex colors)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[3]);
|
|
||||||
if (num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*num, mesh.colors, GL_DYNAMIC_DRAW);
|
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*num, mesh.colors);
|
|
||||||
|
|
||||||
} break;
|
|
||||||
case 4: // Update tangents (vertex tangents)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[4]);
|
|
||||||
if (num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*num, mesh.tangents, GL_DYNAMIC_DRAW);
|
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*4*num, mesh.tangents);
|
|
||||||
} break;
|
|
||||||
case 5: // Update texcoords2 (vertex second texture coordinates)
|
|
||||||
{
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[5]);
|
|
||||||
if (num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*num, mesh.texcoords2, GL_DYNAMIC_DRAW);
|
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*num, mesh.texcoords2);
|
|
||||||
} break;
|
|
||||||
case 6: // Update indices (triangle index buffer)
|
|
||||||
{
|
|
||||||
unsigned short *indices = mesh.indices;
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.vboId[6]);
|
|
||||||
if (num >= mesh.triangleCount*3) // 3 indices per triangle
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(*indices)*num, indices, GL_DYNAMIC_DRAW);
|
|
||||||
else
|
|
||||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(*indices)*num, indices);
|
|
||||||
} break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unbind the current VAO
|
|
||||||
if (vaoSupported) glBindVertexArray(0);
|
|
||||||
|
|
||||||
// Another option would be using buffer mapping...
|
|
||||||
//mesh.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
|
||||||
// Now we can modify vertices
|
|
||||||
//glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update vertex or index data on GPU, at index
|
// Update vertex or index data on GPU, at index
|
||||||
|
|
@ -2595,51 +2530,60 @@ void rlUpdateMeshAt(Mesh mesh, int buffer, int num, int index)
|
||||||
case 0: // Update vertices (vertex position)
|
case 0: // Update vertices (vertex position)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
|
||||||
if (index + num >= mesh.vertexCount) break;
|
if (index == 0 && num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num, mesh.vertices, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.vertexCount) break;
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*3*index, sizeof(float)*3*num, mesh.vertices);
|
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*3*index, sizeof(float)*3*num, mesh.vertices);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 1: // Update texcoords (vertex texture coordinates)
|
case 1: // Update texcoords (vertex texture coordinates)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[1]);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[1]);
|
||||||
if (index + num >= mesh.vertexCount) break;
|
if (index == 0 && num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*num, mesh.texcoords, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.vertexCount) break;
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*2*index, sizeof(float)*2*num, mesh.texcoords);
|
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*2*index, sizeof(float)*2*num, mesh.texcoords);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 2: // Update normals (vertex normals)
|
case 2: // Update normals (vertex normals)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[2]);
|
||||||
if (index + num >= mesh.vertexCount) break;
|
if (index == 0 && num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*num, mesh.normals, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.vertexCount) break;
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*3*index, sizeof(float)*3*num, mesh.normals);
|
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*3*index, sizeof(float)*3*num, mesh.normals);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 3: // Update colors (vertex colors)
|
case 3: // Update colors (vertex colors)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[3]);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[3]);
|
||||||
if (index + num >= mesh.vertexCount) break;
|
if (index == 0 && num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*num, mesh.colors, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.vertexCount) break;
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*index, sizeof(unsigned char)*4*num, mesh.colors);
|
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*index, sizeof(unsigned char)*4*num, mesh.colors);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 4: // Update tangents (vertex tangents)
|
case 4: // Update tangents (vertex tangents)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[4]);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[4]);
|
||||||
if (index + num >= mesh.vertexCount) break;
|
if (index == 0 && num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*num, mesh.tangents, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.vertexCount) break;
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*4*index, sizeof(float)*4*num, mesh.tangents);
|
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*4*index, sizeof(float)*4*num, mesh.tangents);
|
||||||
} break;
|
} break;
|
||||||
case 5: // Update texcoords2 (vertex second texture coordinates)
|
case 5: // Update texcoords2 (vertex second texture coordinates)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[5]);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[5]);
|
||||||
if (index + num >= mesh.vertexCount) break;
|
if (index == 0 && num >= mesh.vertexCount) glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*num, mesh.texcoords2, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.vertexCount) break;
|
||||||
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*2*index, sizeof(float)*2*num, mesh.texcoords2);
|
else glBufferSubData(GL_ARRAY_BUFFER, sizeof(float)*2*index, sizeof(float)*2*num, mesh.texcoords2);
|
||||||
} break;
|
} break;
|
||||||
case 6: // Update indices (triangle index buffer)
|
case 6: // Update indices (triangle index buffer)
|
||||||
{
|
{
|
||||||
|
// the * 3 is because each triangle has 3 indices
|
||||||
unsigned short *indices = mesh.indices;
|
unsigned short *indices = mesh.indices;
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.vboId[6]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.vboId[6]);
|
||||||
if (index + num >= mesh.triangleCount*3) // 3 indices per triangle
|
if (index == 0 && num >= mesh.triangleCount)
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(*indices)*num*3, indices, GL_DYNAMIC_DRAW);
|
||||||
|
else if (index + num >= mesh.triangleCount)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeof(*indices)*index, sizeof(*indices)*num, indices);
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeof(*indices)*index*3, sizeof(*indices)*num*3, indices);
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user