Support instancing in OpenGL ES 2.0 if available
Checking for extension and enabling it if available
This commit is contained in:
parent
3c76b5cc8e
commit
aba69146f2
1 changed files with 111 additions and 96 deletions
47
src/rlgl.h
47
src/rlgl.h
|
@ -892,11 +892,12 @@ typedef struct rlglData {
|
||||||
|
|
||||||
} State; // Renderer state
|
} State; // Renderer state
|
||||||
struct {
|
struct {
|
||||||
bool vao; // VAO support (OpenGL ES2 could not support VAO extension)
|
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
||||||
bool texNPOT; // NPOT textures full support
|
bool instancing; // Instancing supported
|
||||||
bool texDepth; // Depth textures supported
|
bool texNPOT; // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
|
||||||
bool texFloat32; // float textures support (32 bit per channel)
|
bool texDepth; // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture)
|
||||||
bool texCompDXT; // DDS texture compression support
|
bool texFloat32; // float textures support (32 bit per channel) (GL_OES_texture_float)
|
||||||
|
bool texCompDXT; // DDS texture compression support (GL_EXT_texture_compression_s3tc)
|
||||||
bool texCompETC1; // ETC1 texture compression support
|
bool texCompETC1; // ETC1 texture compression support
|
||||||
bool texCompETC2; // ETC2/EAC texture compression support
|
bool texCompETC2; // ETC2/EAC texture compression support
|
||||||
bool texCompPVRT; // PVR texture compression support
|
bool texCompPVRT; // PVR texture compression support
|
||||||
|
@ -930,9 +931,14 @@ static rlglData RLGL = { 0 };
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// NOTE: VAO functionality is exposed through extensions (OES)
|
// NOTE: VAO functionality is exposed through extensions (OES)
|
||||||
static PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays; // Entry point pointer to function glGenVertexArrays()
|
static PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays = NULL;
|
||||||
static PFNGLBINDVERTEXARRAYOESPROC glBindVertexArray; // Entry point pointer to function glBindVertexArray()
|
static PFNGLBINDVERTEXARRAYOESPROC glBindVertexArray = NULL;
|
||||||
static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays; // Entry point pointer to function glDeleteVertexArrays()
|
static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays = NULL;
|
||||||
|
|
||||||
|
// NOTE: Instancing functionality could also be available through extension
|
||||||
|
static PFNGLDRAWARRAYSINSTANCEDEXTPROC glDrawArraysInstanced = NULL;
|
||||||
|
static PFNGLDRAWELEMENTSINSTANCEDEXTPROC glDrawElementsInstanced = NULL;
|
||||||
|
static PFNGLVERTEXATTRIBDIVISOREXTPROC glVertexAttribDivisor = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -1617,10 +1623,9 @@ void rlglInit(int width, int height)
|
||||||
GLint numExt = 0;
|
GLint numExt = 0;
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_21)
|
#if defined(GRAPHICS_API_OPENGL_33) && !defined(GRAPHICS_API_OPENGL_21)
|
||||||
// NOTE: On OpenGL 3.3 VAO and NPOT are supported by default
|
// OpenGL 3.3 extensions supported by default (core)
|
||||||
RLGL.ExtSupported.vao = true;
|
RLGL.ExtSupported.vao = true;
|
||||||
|
RLGL.ExtSupported.instancing = true;
|
||||||
// Multiple texture extensions supported by default
|
|
||||||
RLGL.ExtSupported.texNPOT = true;
|
RLGL.ExtSupported.texNPOT = true;
|
||||||
RLGL.ExtSupported.texFloat32 = true;
|
RLGL.ExtSupported.texFloat32 = true;
|
||||||
RLGL.ExtSupported.texDepth = true;
|
RLGL.ExtSupported.texDepth = true;
|
||||||
|
@ -1686,6 +1691,16 @@ void rlglInit(int width, int height)
|
||||||
if ((glGenVertexArrays != NULL) && (glBindVertexArray != NULL) && (glDeleteVertexArrays != NULL)) RLGL.ExtSupported.vao = true;
|
if ((glGenVertexArrays != NULL) && (glBindVertexArray != NULL) && (glDeleteVertexArrays != NULL)) RLGL.ExtSupported.vao = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check instanced rendering support
|
||||||
|
if (strcmp(extList[i], (const char *)"GL_ANGLE_instanced_arrays") == 0)
|
||||||
|
{
|
||||||
|
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)eglGetProcAddress("glDrawArraysInstancedANGLE");
|
||||||
|
glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)eglGetProcAddress("glDrawElementsInstancedANGLE");
|
||||||
|
glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISOREXTPROC)eglGetProcAddress("glVertexAttribDivisorANGLE");
|
||||||
|
|
||||||
|
if ((glDrawArraysInstanced != NULL) && (glDrawElementsInstanced != NULL) && (glVertexAttribDivisor != NULL)) RLGL.ExtSupported.instancing = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check NPOT textures support
|
// Check NPOT textures support
|
||||||
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
|
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
|
||||||
if (strcmp(extList[i], (const char *)"GL_OES_texture_npot") == 0) RLGL.ExtSupported.texNPOT = true;
|
if (strcmp(extList[i], (const char *)"GL_OES_texture_npot") == 0) RLGL.ExtSupported.texNPOT = true;
|
||||||
|
@ -2925,7 +2940,9 @@ void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
|
||||||
// Draw a 3d mesh with material and transform
|
// Draw a 3d mesh with material and transform
|
||||||
void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int count)
|
void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int count)
|
||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_33)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
if (RLGL.ExtSupported.instancing)
|
||||||
|
{
|
||||||
// Bind shader program
|
// Bind shader program
|
||||||
glUseProgram(material.shader.id);
|
glUseProgram(material.shader.id);
|
||||||
|
|
||||||
|
@ -2991,7 +3008,7 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
// Draw call!
|
// Draw instanced
|
||||||
if (mesh.indices != NULL) glDrawElementsInstanced(GL_TRIANGLES, mesh.triangleCount*3, GL_UNSIGNED_SHORT, 0, count);
|
if (mesh.indices != NULL) glDrawElementsInstanced(GL_TRIANGLES, mesh.triangleCount*3, GL_UNSIGNED_SHORT, 0, count);
|
||||||
else glDrawArraysInstanced(GL_TRIANGLES, 0, mesh.vertexCount, count);
|
else glDrawArraysInstanced(GL_TRIANGLES, 0, mesh.vertexCount, count);
|
||||||
|
|
||||||
|
@ -3011,9 +3028,7 @@ void rlDrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int c
|
||||||
|
|
||||||
// Unbind shader program
|
// Unbind shader program
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
|
}
|
||||||
#else
|
|
||||||
TRACELOG(LOG_WARNING, "VAO: Instanced rendering requires GRAPHICS_API_OPENGL_33");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue