diff options
Diffstat (limited to 'src/ral/backends/opengl')
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 26 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.h | 2 | ||||
-rw-r--r-- | src/ral/backends/opengl/opengl_helpers.h | 11 |
3 files changed, 33 insertions, 6 deletions
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index cf3a4e5..4316e75 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -233,10 +233,23 @@ TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void* glGenTextures(1, &gl_texture_id); texture->id = gl_texture_id; - glBindTexture(GL_TEXTURE_2D, gl_texture_id); + GLenum gl_tex_type = opengl_tex_type(desc.tex_type); + texture->type = desc.tex_type; + printf("Creating texture of type %s\n", texture_type_names[desc.tex_type]); + glBindTexture(gl_tex_type, gl_texture_id); - GLint internal_format = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT : GL_RGB; - GLenum format = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT : GL_RGBA; + GLint internal_format; + if (desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT) { + internal_format = GL_DEPTH_COMPONENT; + } else if (desc.format == TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM) { + internal_format = GL_RGBA; + } else { + internal_format = GL_RGB; + } + + GLint format = internal_format; + // FIXME: GLint format = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_DEPTH_COMPONENT : + // GL_RGBA; GLenum data_type = desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT ? GL_FLOAT : GL_UNSIGNED_BYTE; if (desc.format == TEXTURE_FORMAT_DEPTH_DEFAULT) { @@ -257,7 +270,9 @@ TextureHandle GPU_TextureCreate(TextureDesc desc, bool create_view, const void* if (data) { glTexImage2D(GL_TEXTURE_2D, 0, internal_format, desc.extents.x, desc.extents.y, 0, format, data_type, data); - glGenerateMipmap(GL_TEXTURE_2D); + if (desc.tex_type == TEXTURE_TYPE_2D) { + glGenerateMipmap(GL_TEXTURE_2D); + } } else { WARN("No image data provided"); glTexImage2D(GL_TEXTURE_2D, 0, internal_format, desc.extents.x, desc.extents.y, 0, format, @@ -340,7 +355,8 @@ PUB void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData } glUniform1i(tex_slot, i); glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(GL_TEXTURE_CUBE_MAP, tex->id); + GLenum gl_tex_type = opengl_tex_type(tex->type); + glBindTexture(gl_tex_type, tex->id); } } } diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h index fd50830..98ffe95 100644 --- a/src/ral/backends/opengl/backend_opengl.h +++ b/src/ral/backends/opengl/backend_opengl.h @@ -60,7 +60,7 @@ typedef struct GPU_Buffer { typedef struct GPU_Texture { u32 id; - void *pad; + GPU_TextureType type; } GPU_Texture; typedef struct opengl_support { diff --git a/src/ral/backends/opengl/opengl_helpers.h b/src/ral/backends/opengl/opengl_helpers.h index f3059ac..f240050 100644 --- a/src/ral/backends/opengl/opengl_helpers.h +++ b/src/ral/backends/opengl/opengl_helpers.h @@ -127,4 +127,15 @@ static u32 shader_create_separate(const char* vert_shader, const char* frag_shad return shader_prog; } +static GLenum opengl_tex_type(GPU_TextureType tex_type) { + switch (tex_type) { + case TEXTURE_TYPE_2D: + return GL_TEXTURE_2D; + case TEXTURE_TYPE_CUBE_MAP: + return GL_TEXTURE_CUBE_MAP; + default: + return GL_TEXTURE_2D; + } +} + #endif |