Support float texture data on OpenGL ES 2.0
This commit is contained in:
parent
35a6e9a074
commit
7b8965eb38
7 changed files with 23 additions and 14 deletions
|
@ -21,7 +21,7 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
|
||||||
|
|
||||||
// Load skybox model
|
// Load skybox model
|
||||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
in vec3 fragPos;
|
in vec3 fragPosition;
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform sampler2D equirectangularMap;
|
uniform sampler2D equirectangularMap;
|
||||||
|
@ -28,7 +28,7 @@ vec2 SampleSphericalMap(vec3 v)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Normalize local position
|
// Normalize local position
|
||||||
vec2 uv = SampleSphericalMap(normalize(fragPos));
|
vec2 uv = SampleSphericalMap(normalize(fragPosition));
|
||||||
|
|
||||||
// Fetch color from texture map
|
// Fetch color from texture map
|
||||||
vec3 color = texture(equirectangularMap, uv).rgb;
|
vec3 color = texture(equirectangularMap, uv).rgb;
|
||||||
|
|
|
@ -16,12 +16,12 @@ uniform mat4 projection;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
|
|
||||||
// Output vertex attributes (to fragment shader)
|
// Output vertex attributes (to fragment shader)
|
||||||
out vec3 fragPos;
|
out vec3 fragPosition;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Calculate fragment position based on model transformations
|
// Calculate fragment position based on model transformations
|
||||||
fragPos = vertexPosition;
|
fragPosition = vertexPosition;
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = projection*view*vec4(vertexPosition, 1.0);
|
gl_Position = projection*view*vec4(vertexPosition, 1.0);
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
in vec3 fragPos;
|
in vec3 fragPosition;
|
||||||
|
|
||||||
// Input uniform values
|
// Input uniform values
|
||||||
uniform samplerCube environmentMap;
|
uniform samplerCube environmentMap;
|
||||||
|
@ -20,7 +20,7 @@ out vec4 finalColor;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Fetch color from texture map
|
// Fetch color from texture map
|
||||||
vec3 color = texture(environmentMap, fragPos).rgb;
|
vec3 color = texture(environmentMap, fragPosition).rgb;
|
||||||
|
|
||||||
// Apply gamma correction
|
// Apply gamma correction
|
||||||
color = color/(color + vec3(1.0));
|
color = color/(color + vec3(1.0));
|
||||||
|
|
|
@ -16,12 +16,12 @@ uniform mat4 projection;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
|
|
||||||
// Output vertex attributes (to fragment shader)
|
// Output vertex attributes (to fragment shader)
|
||||||
out vec3 fragPos;
|
out vec3 fragPosition;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Calculate fragment position based on model transformations
|
// Calculate fragment position based on model transformations
|
||||||
fragPos = vertexPosition;
|
fragPosition = vertexPosition;
|
||||||
|
|
||||||
// Remove translation from the view matrix
|
// Remove translation from the view matrix
|
||||||
mat4 rotView = mat4(mat3(view));
|
mat4 rotView = mat4(mat3(view));
|
||||||
|
|
|
@ -70,7 +70,7 @@ int main(void)
|
||||||
SetMusicVolume(music, 1.0f);
|
SetMusicVolume(music, 1.0f);
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
|
|
||||||
fontMission = LoadFontEx("resources/fonts/traveling_typewriter.ttf", 64, 250, 0);
|
fontMission = LoadFontEx("resources/fonts/traveling_typewriter.ttf", 64, 0, 250);
|
||||||
texButton = LoadTexture("resources/textures/title_ribbon.png");
|
texButton = LoadTexture("resources/textures/title_ribbon.png");
|
||||||
|
|
||||||
// UI BUTTON
|
// UI BUTTON
|
||||||
|
|
17
src/rlgl.h
17
src/rlgl.h
|
@ -2968,7 +2968,7 @@ Matrix GetMatrixModelview()
|
||||||
Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size)
|
Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size)
|
||||||
{
|
{
|
||||||
Texture2D cubemap = { 0 };
|
Texture2D cubemap = { 0 };
|
||||||
#if defined(GRAPHICS_API_OPENGL_33) // || defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader
|
// NOTE: SetShaderDefaultLocations() already setups locations for projection and view Matrix in shader
|
||||||
// Other locations should be setup externally in shader before calling the function
|
// Other locations should be setup externally in shader before calling the function
|
||||||
|
|
||||||
|
@ -2978,22 +2978,31 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size)
|
||||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // Flag not supported on OpenGL ES 2.0
|
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // Flag not supported on OpenGL ES 2.0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Setup framebuffer
|
// Setup framebuffer
|
||||||
unsigned int fbo, rbo;
|
unsigned int fbo, rbo;
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glGenRenderbuffers(1, &rbo);
|
glGenRenderbuffers(1, &rbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33)
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size);
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, size, size);
|
||||||
|
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size, size);
|
||||||
|
#endif
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
||||||
|
|
||||||
// Set up cubemap to render and attach to framebuffer
|
// Set up cubemap to render and attach to framebuffer
|
||||||
// NOTE: faces are stored with 16 bit floating point values
|
// NOTE: faces are stored with 16 bit floating point values
|
||||||
glGenTextures(1, &cubemap.id);
|
glGenTextures(1, &cubemap.id);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id);
|
||||||
for (unsigned int i = 0; i < 6; i++)
|
for (unsigned int i = 0; i < 6; i++)
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL);
|
{
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_33)
|
||||||
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB32F, size, size, 0, GL_RGB, GL_FLOAT, NULL);
|
||||||
|
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
if (texFloatSupported) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, size, size, 0, GL_RGB, GL_FLOAT, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
#if defined(GRAPHICS_API_OPENGL_33)
|
#if defined(GRAPHICS_API_OPENGL_33)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue