rlgl functions renaming

Keep working on PBR
This commit is contained in:
Ray 2017-07-09 01:32:29 +02:00
parent a7c1850af1
commit 007cbf85b0
7 changed files with 130 additions and 154 deletions

View File

@ -809,7 +809,7 @@ void EndDrawing(void)
{ {
// Get image data for the current frame (from backbuffer) // Get image data for the current frame (from backbuffer)
// NOTE: This process is very slow... :( // NOTE: This process is very slow... :(
unsigned char *screenData = rlglReadScreenPixels(screenWidth, screenHeight); unsigned char *screenData = rlReadScreenPixels(screenWidth, screenHeight);
GifWriteFrame(screenData, screenWidth, screenHeight, 10, 8, false); GifWriteFrame(screenData, screenWidth, screenHeight, 10, 8, false);
free(screenData); // Free image data free(screenData); // Free image data
@ -994,10 +994,10 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera)
MatrixTranspose(&matView); MatrixTranspose(&matView);
//#define USE_RLGL_UNPROJECT //#define USE_RLGL_UNPROJECT
#if defined(USE_RLGL_UNPROJECT) // OPTION 1: Use rlglUnproject() #if defined(USE_RLGL_UNPROJECT) // OPTION 1: Use rlUnproject()
Vector3 nearPoint = rlglUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView); Vector3 nearPoint = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView);
Vector3 farPoint = rlglUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView); Vector3 farPoint = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView);
#else // OPTION 2: Compute unprojection directly here #else // OPTION 2: Compute unprojection directly here
@ -1201,7 +1201,7 @@ void SetConfigFlags(char flags)
void TakeScreenshot(const char *fileName) void TakeScreenshot(const char *fileName)
{ {
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
unsigned char *imgData = rlglReadScreenPixels(renderWidth, renderHeight); unsigned char *imgData = rlReadScreenPixels(renderWidth, renderHeight);
SavePNG(fileName, imgData, renderWidth, renderHeight, 4); // Save image as PNG SavePNG(fileName, imgData, renderWidth, renderHeight, 4); // Save image as PNG
free(imgData); free(imgData);

View File

@ -620,7 +620,7 @@ Mesh LoadMesh(const char *fileName)
#endif #endif
if (mesh.vertexCount == 0) TraceLog(WARNING, "Mesh could not be loaded"); if (mesh.vertexCount == 0) TraceLog(WARNING, "Mesh could not be loaded");
else rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh) else rlLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh)
// TODO: Initialize default mesh data in case loading fails, maybe a cube? // TODO: Initialize default mesh data in case loading fails, maybe a cube?
@ -644,7 +644,7 @@ Mesh LoadMeshEx(int vertexCount, float *vData, float *vtData, float *vnData, Col
mesh.colors = (unsigned char *)cData; mesh.colors = (unsigned char *)cData;
mesh.indices = NULL; mesh.indices = NULL;
rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh) rlLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh)
return mesh; return mesh;
} }
@ -656,7 +656,7 @@ Mesh LoadMeshHeightmap(Image heightmap, Vector3 size)
{ {
Mesh mesh = GenMeshHeightmap(heightmap, size); Mesh mesh = GenMeshHeightmap(heightmap, size);
rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static model) rlLoadMesh(&mesh, false); // Upload vertex data to GPU (static model)
return mesh; return mesh;
} }
@ -666,7 +666,7 @@ Mesh LoadMeshCubicmap(Image cubicmap)
{ {
Mesh mesh = GenMeshCubicmap(cubicmap, (Vector3){ 1.0f, 1.5f, 1.0f }); Mesh mesh = GenMeshCubicmap(cubicmap, (Vector3){ 1.0f, 1.5f, 1.0f });
rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static model) rlLoadMesh(&mesh, false); // Upload vertex data to GPU (static model)
return mesh; return mesh;
} }
@ -674,7 +674,7 @@ Mesh LoadMeshCubicmap(Image cubicmap)
// Unload mesh from memory (RAM and/or VRAM) // Unload mesh from memory (RAM and/or VRAM)
void UnloadMesh(Mesh *mesh) void UnloadMesh(Mesh *mesh)
{ {
rlglUnloadMesh(mesh); rlUnloadMesh(mesh);
} }
// Load material data (from file) // Load material data (from file)
@ -696,8 +696,8 @@ Material LoadMaterialDefault(void)
{ {
Material material = { 0 }; Material material = { 0 };
material.shader = GetDefaultShader(); material.shader = GetShaderDefault();
material.maps[TEXMAP_DIFFUSE].tex = GetDefaultTexture(); // White texture (1x1 pixel) material.maps[TEXMAP_DIFFUSE].tex = GetTextureDefault(); // White texture (1x1 pixel)
//material.maps[TEXMAP_NORMAL].tex; // NOTE: By default, not set //material.maps[TEXMAP_NORMAL].tex; // NOTE: By default, not set
//material.maps[TEXMAP_SPECULAR].tex; // NOTE: By default, not set //material.maps[TEXMAP_SPECULAR].tex; // NOTE: By default, not set
@ -747,10 +747,10 @@ Material LoadMaterialPBR(Texture2D cubemap, Color albedo, int metalness, int rou
mat.maps[TEXMAP_HEIGHT].value = 0.0f; //(Color){ 0, 0, 0, 0 }; mat.maps[TEXMAP_HEIGHT].value = 0.0f; //(Color){ 0, 0, 0, 0 };
// Set up environment materials cubemap // Set up environment materials cubemap
mat.maps[TEXMAP_CUBEMAP].tex = cubemap; mat.maps[TEXMAP_CUBEMAP].tex = cubemap; // Texture2D rlGenMapCubemap(Shader shader, Texture2D cubemap, int size);
//mat.maps[TEXMAP_IRRADIANCE] = env.maps[TEXMAP_IRRADIANCE]; //mat.maps[TEXMAP_IRRADIANCE] = env.maps[TEXMAP_IRRADIANCE]; // Texture2D GenMapIrradiance(Texture2D cubemap, int size);
//mat.maps[TEXMAP_PREFILTER] = env.maps[TEXMAP_PREFILTER]; //mat.maps[TEXMAP_PREFILTER] = env.maps[TEXMAP_PREFILTER]; // Texture2D GenMapPrefilter(Texture2D cubemap, int size);
//mat.maps[TEXMAP_BRDF] = env.maps[TEXMAP_BRDF]; //mat.maps[TEXMAP_BRDF] = env.maps[TEXMAP_BRDF]; // Texture2D GenMapBRDF(Texture2D cubemap, int size);
// NOTE: All maps textures are set to { 0 } // NOTE: All maps textures are set to { 0 }
@ -785,6 +785,9 @@ Material LoadMaterialEnv(const char *filename, int cubemapSize, int irradianceSi
// Set up shaders constant values // Set up shaders constant values
SetShaderValuei(env.shader, GetShaderLocation(env.shader, "cubeMap"), (int[1]){ 0 }, 1); SetShaderValuei(env.shader, GetShaderLocation(env.shader, "cubeMap"), (int[1]){ 0 }, 1);
// Load HDR environment texture
Texture2D skyTex = LoadTexture(filename);
// Generate texture: CUBEMAP // Generate texture: CUBEMAP
//---------------------------------------- //----------------------------------------
@ -803,11 +806,9 @@ Material LoadMaterialEnv(const char *filename, int cubemapSize, int irradianceSi
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glLineWidth(2); glLineWidth(2);
// Load HDR environment texture
Texture2D skyTex = LoadTexture(filename);
// Set up framebuffer for skybox // Set up framebuffer for skybox
unsigned int captureFBO, captureRBO; unsigned int captureFBO, captureRBO;
glGenFramebuffers(1, &captureFBO); glGenFramebuffers(1, &captureFBO);
glGenRenderbuffers(1, &captureRBO); glGenRenderbuffers(1, &captureRBO);
glBindFramebuffer(GL_FRAMEBUFFER, captureFBO); glBindFramebuffer(GL_FRAMEBUFFER, captureFBO);
@ -981,7 +982,7 @@ Material LoadMaterialEnv(const char *filename, int cubemapSize, int irradianceSi
// Generate texture: BRDF // Generate texture: BRDF
//---------------------------------------- //----------------------------------------
Shader brdfShader = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS); Shader brdfShader = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS);
/*
RenderTexture2D brdfMap = LoadRenderTexture(brdfSize, brdfSize); RenderTexture2D brdfMap = LoadRenderTexture(brdfSize, brdfSize);
BeginDrawing(); BeginDrawing();
@ -996,6 +997,7 @@ Material LoadMaterialEnv(const char *filename, int cubemapSize, int irradianceSi
EndDrawing(); EndDrawing();
UnloadRenderTexture(brdfMap); UnloadRenderTexture(brdfMap);
*/
/* /*
// Generate BRDF convolution texture // Generate BRDF convolution texture
glGenTextures(1, &env.maps[TEXMAP_BRDF].tex.id); glGenTextures(1, &env.maps[TEXMAP_BRDF].tex.id);
@ -1553,7 +1555,7 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota
model.transform = MatrixMultiply(model.transform, matTransform); model.transform = MatrixMultiply(model.transform, matTransform);
model.material.maps[TEXMAP_DIFFUSE].color = tint; // TODO: Multiply tint color by diffuse color? model.material.maps[TEXMAP_DIFFUSE].color = tint; // TODO: Multiply tint color by diffuse color?
rlglDrawMesh(model.mesh, model.material, model.transform); rlDrawMesh(model.mesh, model.material, model.transform);
} }
// Draw a model wires (with texture if set) // Draw a model wires (with texture if set)

View File

@ -1028,8 +1028,8 @@ RLAPI char *LoadText(const char *fileName); // Loa
RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load shader from files and bind default locations RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load shader from files and bind default locations
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM) RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
RLAPI Shader GetDefaultShader(void); // Get default shader RLAPI Shader GetShaderDefault(void); // Get default shader
RLAPI Texture2D GetDefaultTexture(void); // Get default texture RLAPI Texture2D GetTextureDefault(void); // Get default texture
// Shader configuration functions // Shader configuration functions
RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location RLAPI int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location

View File

@ -1183,7 +1183,7 @@ void rlglInit(int width, int height)
// Init default white texture // Init default white texture
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes) unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
whiteTexture = rlglLoadTexture(pixels, 1, 1, UNCOMPRESSED_R8G8B8A8, 1); whiteTexture = rlLoadTexture(pixels, 1, 1, UNCOMPRESSED_R8G8B8A8, 1);
if (whiteTexture != 0) TraceLog(INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture); if (whiteTexture != 0) TraceLog(INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture);
else TraceLog(WARNING, "Base white texture could not be loaded"); else TraceLog(WARNING, "Base white texture could not be loaded");
@ -1277,7 +1277,7 @@ void rlglDraw(void)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: In a future version, models could be stored in a stack... // NOTE: In a future version, models could be stored in a stack...
//for (int i = 0; i < modelsCount; i++) rlglDrawMesh(models[i]->mesh, models[i]->material, models[i]->transform); //for (int i = 0; i < modelsCount; i++) rlDrawMesh(models[i]->mesh, models[i]->material, models[i]->transform);
// NOTE: Default buffers upload and draw // NOTE: Default buffers upload and draw
UpdateDefaultBuffers(); UpdateDefaultBuffers();
@ -1309,7 +1309,7 @@ void rlglLoadExtensions(void *loader)
} }
// Get world coordinates from screen coordinates // Get world coordinates from screen coordinates
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view) Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view)
{ {
Vector3 result = { 0.0f, 0.0f, 0.0f }; Vector3 result = { 0.0f, 0.0f, 0.0f };
@ -1332,7 +1332,7 @@ Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view)
} }
// Convert image data to OpenGL texture (returns OpenGL valid Id) // Convert image data to OpenGL texture (returns OpenGL valid Id)
unsigned int rlglLoadTexture(void *data, int width, int height, int format, int mipmapCount) unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
{ {
glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding
@ -1515,7 +1515,7 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int format, int
} }
// Load a texture to be used for rendering (fbo with color and depth attachments) // Load a texture to be used for rendering (fbo with color and depth attachments)
RenderTexture2D rlglLoadRenderTexture(int width, int height) RenderTexture2D rlLoadRenderTexture(int width, int height)
{ {
RenderTexture2D target; RenderTexture2D target;
@ -1610,7 +1610,7 @@ RenderTexture2D rlglLoadRenderTexture(int width, int height)
} }
// Update already loaded texture in GPU with new data // Update already loaded texture in GPU with new data
void rlglUpdateTexture(unsigned int id, int width, int height, int format, const void *data) void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data)
{ {
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
@ -1642,8 +1642,14 @@ void rlglUpdateTexture(unsigned int id, int width, int height, int format, const
#endif #endif
} }
// Unload texture from GPU memory
void rlUnloadTexture(unsigned int id)
{
if (id > 0) glDeleteTextures(1, &id);
}
// Generate mipmap data for selected texture // Generate mipmap data for selected texture
void rlglGenerateMipmaps(Texture2D *texture) void rlGenerateMipmaps(Texture2D *texture)
{ {
glBindTexture(GL_TEXTURE_2D, texture->id); glBindTexture(GL_TEXTURE_2D, texture->id);
@ -1657,7 +1663,7 @@ void rlglGenerateMipmaps(Texture2D *texture)
{ {
#if defined(GRAPHICS_API_OPENGL_11) #if defined(GRAPHICS_API_OPENGL_11)
// Compute required mipmaps // Compute required mipmaps
void *data = rlglReadTexturePixels(*texture); void *data = rlReadTexturePixels(*texture);
// NOTE: data size is reallocated to fit mipmaps data // NOTE: data size is reallocated to fit mipmaps data
// NOTE: CPU mipmap generation only supports RGBA 32bit data // NOTE: CPU mipmap generation only supports RGBA 32bit data
@ -1709,7 +1715,7 @@ void rlglGenerateMipmaps(Texture2D *texture)
} }
// Upload vertex data into a VAO (if supported) and VBO // Upload vertex data into a VAO (if supported) and VBO
void rlglLoadMesh(Mesh *mesh, bool dynamic) void rlLoadMesh(Mesh *mesh, bool dynamic)
{ {
mesh->vaoId = 0; // Vertex Array Object mesh->vaoId = 0; // Vertex Array Object
mesh->vboId[0] = 0; // Vertex positions VBO mesh->vboId[0] = 0; // Vertex positions VBO
@ -1846,7 +1852,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
} }
// Update vertex data on GPU (upload new data to one buffer) // Update vertex data on GPU (upload new data to one buffer)
void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex) void rlUpdateMesh(Mesh mesh, int buffer, int numVertex)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Activate mesh VAO // Activate mesh VAO
@ -1908,7 +1914,7 @@ void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
} }
// Draw a 3d mesh with material and transform // Draw a 3d mesh with material and transform
void rlglDrawMesh(Mesh mesh, Material material, Matrix transform) void rlDrawMesh(Mesh mesh, Material material, Matrix transform)
{ {
#if defined(GRAPHICS_API_OPENGL_11) #if defined(GRAPHICS_API_OPENGL_11)
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@ -1943,7 +1949,16 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
#endif #endif
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
glUseProgram(material.shader.id); glUseProgram(material.shader.id); // Bind shader program
/*
// Calculate and send to shader model matrix
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
Matrix transform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
SetShaderValueMatrix(mat.shader, GetShaderLocation(mat.shader, "mMatrix"), transform);
*/
// Upload to shader material.colDiffuse // Upload to shader material.colDiffuse
glUniform4f(material.shader.locs[LOC_TEXTURE_COLOR01], (float)material.maps[TEXMAP_DIFFUSE].color.r/255, (float)material.maps[TEXMAP_DIFFUSE].color.g/255, (float)material.maps[TEXMAP_DIFFUSE].color.b/255, (float)material.maps[TEXMAP_DIFFUSE].color.a/255); glUniform4f(material.shader.locs[LOC_TEXTURE_COLOR01], (float)material.maps[TEXMAP_DIFFUSE].color.r/255, (float)material.maps[TEXMAP_DIFFUSE].color.g/255, (float)material.maps[TEXMAP_DIFFUSE].color.b/255, (float)material.maps[TEXMAP_DIFFUSE].color.a/255);
@ -1962,56 +1977,20 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
// Calculate model-view matrix combining matModel and matView // Calculate model-view matrix combining matModel and matView
Matrix matModelView = MatrixMultiply(transform, matView); // Transform to camera-space coordinates Matrix matModelView = MatrixMultiply(transform, matView); // Transform to camera-space coordinates
// If not using default shader, we check for some additional location points
// NOTE: This method is quite inefficient... it's a temporal solution while looking for a better one // Active required texture maps if available
if (material.shader.id != defaultShader.id) for (int i = 0; i < MAX_MATERIAL_TEXTURE_MAPS; i++)
{ {
// Check if model matrix is located in shader and upload value if (material.maps[i].tex.id > 0)
int modelMatrixLoc = glGetUniformLocation(material.shader.id, "modelMatrix");
if (modelMatrixLoc != -1)
{ {
// Transpose and inverse model transformations matrix for fragment normal calculations glActiveTexture(GL_TEXTURE0 + i);
Matrix transInvTransform = transform; if ((i == TEXMAP_IRRADIANCE) || (i == TEXMAP_PREFILTER) || (i == TEXMAP_CUBEMAP))
MatrixTranspose(&transInvTransform); {
MatrixInvert(&transInvTransform); glBindTexture(GL_TEXTURE_CUBE_MAP, material.maps[i].tex.id);
}
// Send model transformations matrix to shader else glBindTexture(GL_TEXTURE_2D, material.maps[i].tex.id);
glUniformMatrix4fv(modelMatrixLoc, 1, false, MatrixToFloat(transInvTransform)); glUniform1i(material.shader.locs[LOC_TEXTURE_MAP01 + i], i);
} }
// Check if view direction is located in shader and upload value
// NOTE: View matrix values m8, m9 and m10 are view direction vector axis (target - position)
int viewDirLoc = glGetUniformLocation(material.shader.id, "viewDir");
if (viewDirLoc != -1) glUniform3f(viewDirLoc, matView.m8, matView.m9, matView.m10);
// TODO: Check if glossiness is located in shader and upload value
int glossinessLoc = glGetUniformLocation(material.shader.id, "glossiness");
//if (glossinessLoc != -1) glUniform1f(glossinessLoc, material.glossiness);
}
// Set shader textures (diffuse, normal, specular)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, material.maps[TEXMAP_DIFFUSE].tex.id);
glUniform1i(material.shader.locs[LOC_TEXTURE_MAP01], 0); // Diffuse texture fits in active texture unit 0
if ((material.maps[TEXMAP_NORMAL].tex.id != 0) && (material.shader.locs[LOC_TEXTURE_MAP01] != -1))
{
// Upload to shader specular map flag
glUniform1i(glGetUniformLocation(material.shader.id, "useNormal"), 1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, material.maps[TEXMAP_NORMAL].tex.id);
glUniform1i(material.shader.locs[LOC_TEXTURE_MAP01], 1); // Normal texture fits in active texture unit 1
}
if ((material.maps[TEXMAP_SPECULAR].tex.id != 0) && (material.shader.locs[LOC_TEXTURE_MAP02] != -1))
{
// Upload to shader specular map flag
glUniform1i(glGetUniformLocation(material.shader.id, "useSpecular"), 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, material.maps[TEXMAP_SPECULAR].tex.id);
glUniform1i(material.shader.locs[LOC_TEXTURE_MAP02], 2); // Specular texture fits in active texture unit 2
} }
if (vaoSupported) if (vaoSupported)
@ -2020,6 +1999,8 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
} }
else else
{ {
// TODO: Simplify VBO binding into a for loop
// Bind mesh VBO data: vertex position (shader-location = 0) // Bind mesh VBO data: vertex position (shader-location = 0)
glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]); glBindBuffer(GL_ARRAY_BUFFER, mesh.vboId[0]);
glVertexAttribPointer(material.shader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0); glVertexAttribPointer(material.shader.locs[LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
@ -2098,25 +2079,21 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
else glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount); else glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);
} }
if (material.maps[TEXMAP_NORMAL].tex.id != 0) // Unbind all binded texture maps
for (int i = 0; i < MAX_MATERIAL_TEXTURE_MAPS; i++)
{ {
glActiveTexture(GL_TEXTURE1); if (material.maps[i].tex.id > 0)
glBindTexture(GL_TEXTURE_2D, 0); {
glActiveTexture(GL_TEXTURE0 + i); // Set shader active texture
if ((i == TEXMAP_IRRADIANCE) || (i == TEXMAP_PREFILTER) || (i == TEXMAP_CUBEMAP)) glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
else glBindTexture(GL_TEXTURE_2D, 0); // Unbind current active texture
}
} }
if (material.maps[TEXMAP_SPECULAR].tex.id != 0) if (vaoSupported) glBindVertexArray(0); // Unbind VAO
{
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, 0);
}
glActiveTexture(GL_TEXTURE0); // Set shader active texture to default 0
glBindTexture(GL_TEXTURE_2D, 0); // Unbind textures
if (vaoSupported) glBindVertexArray(0); // Unbind VAO
else else
{ {
glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind VBOs glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind VBOs
if (mesh.indices != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if (mesh.indices != NULL) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
} }
@ -2129,7 +2106,7 @@ void rlglDrawMesh(Mesh mesh, Material material, Matrix transform)
} }
// Unload mesh data from CPU and GPU // Unload mesh data from CPU and GPU
void rlglUnloadMesh(Mesh *mesh) void rlUnloadMesh(Mesh *mesh)
{ {
if (mesh->vertices != NULL) free(mesh->vertices); if (mesh->vertices != NULL) free(mesh->vertices);
if (mesh->texcoords != NULL) free(mesh->texcoords); if (mesh->texcoords != NULL) free(mesh->texcoords);
@ -2151,7 +2128,7 @@ void rlglUnloadMesh(Mesh *mesh)
} }
// Read screen pixel data (color buffer) // Read screen pixel data (color buffer)
unsigned char *rlglReadScreenPixels(int width, int height) unsigned char *rlReadScreenPixels(int width, int height)
{ {
unsigned char *screenData = (unsigned char *)calloc(width*height*4, sizeof(unsigned char)); unsigned char *screenData = (unsigned char *)calloc(width*height*4, sizeof(unsigned char));
@ -2182,7 +2159,7 @@ unsigned char *rlglReadScreenPixels(int width, int height)
// Read texture pixel data // Read texture pixel data
// NOTE: glGetTexImage() is not available on OpenGL ES 2.0 // 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. // 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 *rlReadTexturePixels(Texture2D texture)
{ {
void *pixels = NULL; void *pixels = NULL;
@ -2235,7 +2212,7 @@ void *rlglReadTexturePixels(Texture2D texture)
#if defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_ES2)
RenderTexture2D fbo = rlglLoadRenderTexture(texture.width, texture.height); RenderTexture2D fbo = rlLoadRenderTexture(texture.width, texture.height);
// NOTE: Two possible Options: // NOTE: Two possible Options:
// 1 - Bind texture to color fbo attachment and glReadPixels() // 1 - Bind texture to color fbo attachment and glReadPixels()
@ -2328,7 +2305,7 @@ void rlglRecordDraw(void)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Get default internal texture (white texture) // Get default internal texture (white texture)
Texture2D GetDefaultTexture(void) Texture2D GetTextureDefault(void)
{ {
Texture2D texture; Texture2D texture;
@ -2438,7 +2415,7 @@ void EndShaderMode(void)
} }
// Get default shader // Get default shader
Shader GetDefaultShader(void) Shader GetShaderDefault(void)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
return defaultShader; return defaultShader;
@ -2609,7 +2586,7 @@ void InitVrSimulator(int vrDevice)
// Initialize framebuffer and textures for stereo rendering // Initialize framebuffer and textures for stereo rendering
// NOTE: screen size should match HMD aspect ratio // NOTE: screen size should match HMD aspect ratio
vrConfig.stereoFbo = rlglLoadRenderTexture(screenWidth, screenHeight); vrConfig.stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight);
#if defined(SUPPORT_DISTORTION_SHADER) #if defined(SUPPORT_DISTORTION_SHADER)
// Load distortion shader (initialized by default with Oculus Rift CV1 parameters) // Load distortion shader (initialized by default with Oculus Rift CV1 parameters)
@ -2727,7 +2704,7 @@ void EndVrDrawing(void)
// Draw RenderTexture (stereoFbo) using distortion shader // Draw RenderTexture (stereoFbo) using distortion shader
currentShader = vrConfig.distortionShader; currentShader = vrConfig.distortionShader;
#else #else
currentShader = GetDefaultShader(); currentShader = GetShaderDefault();
#endif #endif
rlEnableTexture(vrConfig.stereoFbo.texture.id); rlEnableTexture(vrConfig.stereoFbo.texture.id);

View File

@ -400,24 +400,22 @@ void rlglClose(void); // De-init rlgl
void rlglDraw(void); // Draw VAO/VBO void rlglDraw(void); // Draw VAO/VBO
void rlglLoadExtensions(void *loader); // Load OpenGL extensions void rlglLoadExtensions(void *loader); // Load OpenGL extensions
unsigned int rlglLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU // Textures data management
RenderTexture2D rlglLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments) unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
void rlglUpdateTexture(unsigned int id, int width, int height, int format, const void *data); // Update GPU texture with new data void rlUpdateTexture(unsigned int id, int width, int height, int format, const void *data); // Update GPU texture with new data
void rlglGenerateMipmaps(Texture2D *texture); // Generate mipmap data for selected texture void rlUnloadTexture(unsigned int id);
void rlGenerateMipmaps(Texture2D *texture); // Generate mipmap data for selected texture
void *rlReadTexturePixels(Texture2D texture); // Read texture pixel data
unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
RenderTexture2D rlLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments)
void rlglLoadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids // Vertex data management
void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update vertex data on GPU (upload new data to one buffer) void rlLoadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids
void rlglDrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform void rlUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update vertex data on GPU (upload new data to one buffer)
void rlglUnloadMesh(Mesh *mesh); // Unload mesh data from CPU and GPU void rlDrawMesh(Mesh mesh, Material material, Matrix transform); // Draw a 3d mesh with material and transform
void rlUnloadMesh(Mesh *mesh); // Unload mesh data from CPU and GPU
Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
unsigned char *rlglReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
void *rlglReadTexturePixels(Texture2D texture); // Read texture pixel data
// VR functions exposed to core module but not to raylib users
void BeginVrDrawing(void); // Begin VR drawing configuration
void EndVrDrawing(void); // End VR drawing process (and desktop mirror)
// NOTE: There is a set of shader related functions that are available to end user, // NOTE: There is a set of shader related functions that are available to end user,
// to avoid creating function wrappers through core module, they have been directly declared in raylib.h // to avoid creating function wrappers through core module, they have been directly declared in raylib.h
@ -427,35 +425,34 @@ void EndVrDrawing(void); // End VR drawing process (and deskt
// Shaders System Functions (Module: rlgl) // Shaders System Functions (Module: rlgl)
// NOTE: This functions are useless when using OpenGL 1.1 // NOTE: This functions are useless when using OpenGL 1.1
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations Shader LoadShader(char *vsFileName, char *fsFileName); // Load a custom shader and bind default locations
void UnloadShader(Shader shader); // Unload a custom shader from memory void UnloadShader(Shader shader); // Unload a custom shader from memory
Shader GetDefaultShader(void); // Get default shader Shader GetShaderDefault(void); // Get default shader
Shader GetStandardShader(void); // Get default shader Texture2D GetTextureDefault(void); // Get default texture
Texture2D GetDefaultTexture(void); // Get default texture
int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location int GetShaderLocation(Shader shader, const char *uniformName); // Get shader uniform location
void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float) void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // Set shader uniform value (float)
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int) void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4) void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix) void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix) void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
void BeginShaderMode(Shader shader); // Begin custom shader drawing void BeginShaderMode(Shader shader); // Begin custom shader drawing
void EndShaderMode(void); // End custom shader drawing (use default shader) void EndShaderMode(void); // End custom shader drawing (use default shader)
void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied) void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
void EndBlendMode(void); // End blending mode (reset to default: alpha blending) void EndBlendMode(void); // End blending mode (reset to default: alpha blending)
void TraceLog(int msgType, const char *text, ...); void InitVrSimulator(int vrDevice); // Init VR simulator for selected device
float *MatrixToFloat(Matrix mat); void CloseVrSimulator(void); // Close VR simulator for current device
void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
void BeginVrDrawing(void); // Begin VR stereo rendering
void EndVrDrawing(void); // End VR stereo rendering
void InitVrSimulator(int vrDevice); // Init VR simulator for selected device void TraceLog(int msgType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
void CloseVrSimulator(void); // Close VR simulator for current device float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
void UpdateVrTracking(Camera *camera); // Update VR tracking (position and orientation) and camera
void ToggleVrMode(void); // Enable/Disable VR experience (device or simulator)
void BeginVrDrawing(void); // Begin VR stereo rendering
void EndVrDrawing(void); // End VR stereo rendering
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -119,7 +119,7 @@ void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
float d = sqrtf(dx*dx + dy*dy); float d = sqrtf(dx*dx + dy*dy);
float angle = asinf(dy/d); float angle = asinf(dy/d);
rlEnableTexture(GetDefaultTexture().id); rlEnableTexture(GetTextureDefault().id);
rlPushMatrix(); rlPushMatrix();
rlTranslatef((float)startPos.x, (float)startPos.y, 0); rlTranslatef((float)startPos.x, (float)startPos.y, 0);
@ -203,7 +203,7 @@ void DrawCircleV(Vector2 center, float radius, Color color)
} }
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20)) else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{ {
rlEnableTexture(GetDefaultTexture().id); // Default white texture rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
for (int i = 0; i < 360; i += 20) for (int i = 0; i < 360; i += 20)
@ -253,7 +253,7 @@ void DrawRectangleRec(Rectangle rec, Color color)
void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color) void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color)
{ {
rlEnableTexture(GetDefaultTexture().id); rlEnableTexture(GetTextureDefault().id);
rlPushMatrix(); rlPushMatrix();
rlTranslatef((float)rec.x, (float)rec.y, 0); rlTranslatef((float)rec.x, (float)rec.y, 0);
@ -309,7 +309,7 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
} }
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20)) else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{ {
rlEnableTexture(GetDefaultTexture().id); // Default white texture rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
@ -376,7 +376,7 @@ void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
} }
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20)) else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{ {
rlEnableTexture(GetDefaultTexture().id); // Default white texture rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);

View File

@ -63,8 +63,8 @@
#include <string.h> // Required for: strcmp(), strrchr(), strncmp() #include <string.h> // Required for: strcmp(), strrchr(), strncmp()
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2 #include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3 or ES2
// Required for: rlglLoadTexture() rlDeleteTextures(), // Required for: rlLoadTexture() rlDeleteTextures(),
// rlglGenerateMipmaps(), some funcs for DrawTexturePro() // rlGenerateMipmaps(), some funcs for DrawTexturePro()
#include "utils.h" // Required for: fopen() Android mapping #include "utils.h" // Required for: fopen() Android mapping
@ -381,7 +381,7 @@ Texture2D LoadTextureFromImage(Image image)
{ {
Texture2D texture = { 0 }; Texture2D texture = { 0 };
texture.id = rlglLoadTexture(image.data, image.width, image.height, image.format, image.mipmaps); texture.id = rlLoadTexture(image.data, image.width, image.height, image.format, image.mipmaps);
texture.width = image.width; texture.width = image.width;
texture.height = image.height; texture.height = image.height;
@ -396,7 +396,7 @@ Texture2D LoadTextureFromImage(Image image)
// Load texture for rendering (framebuffer) // Load texture for rendering (framebuffer)
RenderTexture2D LoadRenderTexture(int width, int height) RenderTexture2D LoadRenderTexture(int width, int height)
{ {
RenderTexture2D target = rlglLoadRenderTexture(width, height); RenderTexture2D target = rlLoadRenderTexture(width, height);
return target; return target;
} }
@ -522,7 +522,7 @@ Image GetTextureData(Texture2D texture)
if (texture.format < 8) if (texture.format < 8)
{ {
image.data = rlglReadTexturePixels(texture); image.data = rlReadTexturePixels(texture);
if (image.data != NULL) if (image.data != NULL)
{ {
@ -550,7 +550,7 @@ Image GetTextureData(Texture2D texture)
// NOTE: pixels data must match texture.format // NOTE: pixels data must match texture.format
void UpdateTexture(Texture2D texture, const void *pixels) void UpdateTexture(Texture2D texture, const void *pixels)
{ {
rlglUpdateTexture(texture.id, texture.width, texture.height, texture.format, pixels); rlUpdateTexture(texture.id, texture.width, texture.height, texture.format, pixels);
} }
// Convert image data to desired format // Convert image data to desired format
@ -1444,9 +1444,9 @@ void GenTextureMipmaps(Texture2D *texture)
{ {
TraceLog(WARNING, "Limited NPOT support, no mipmaps available for NPOT textures"); TraceLog(WARNING, "Limited NPOT support, no mipmaps available for NPOT textures");
} }
else rlglGenerateMipmaps(texture); else rlGenerateMipmaps(texture);
#else #else
rlglGenerateMipmaps(texture); rlGenerateMipmaps(texture);
#endif #endif
} }