Skip to content

Commit

Permalink
[OpenGL] Create default depth texture
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 17, 2023
1 parent 69e0f3f commit 4e48fab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,12 +2494,14 @@ void gl_context::bind_textures(const std::vector<gfx_api::texture_input>& textur
{
switch (desc.target)
{
case gfx_api::pixel_format_target::texture_2d:
pTextureToBind = pDefaultTexture;
break;
case gfx_api::pixel_format_target::texture_2d_array:
case gfx_api::pixel_format_target::depth_map:
pTextureToBind = pDefaultArrayTexture;
break;
case gfx_api::pixel_format_target::texture_2d:
pTextureToBind = pDefaultTexture;
case gfx_api::pixel_format_target::depth_map:
pTextureToBind = pDefaultDepthTexture;
break;
}
}
Expand Down Expand Up @@ -3073,6 +3075,11 @@ bool gl_context::_initialize(const gfx_api::backend_Impl_Factory& impl, int32_t
const size_t defaultTexture_height = 2;
pDefaultTexture = dynamic_cast<gl_texture*>(create_texture(1, defaultTexture_width, defaultTexture_height, gfx_api::pixel_format::FORMAT_RGBA8_UNORM_PACK8, "<default_texture>"));
pDefaultArrayTexture = dynamic_cast<gl_texture_array*>(create_texture_array(1, 1, defaultTexture_width, defaultTexture_height, gfx_api::pixel_format::FORMAT_RGBA8_UNORM_PACK8, "<default_array_texture>"));
pDefaultDepthTexture = create_depthmap_texture(1, 2, 2, "<default_depth_map>");
if (!pDefaultDepthTexture)
{
debug(LOG_INFO, "Failed to create default depth texture??");
}

iV_Image defaultTexture;
defaultTexture.allocate(defaultTexture_width, defaultTexture_height, 4, true);
Expand Down Expand Up @@ -3899,6 +3906,12 @@ void gl_context::shutdown()
pDefaultArrayTexture = nullptr;
}

if (pDefaultDepthTexture)
{
delete pDefaultDepthTexture;
pDefaultDepthTexture = nullptr;
}

if (glDeleteBuffers) // glDeleteBuffers might be NULL (if initializing the OpenGL loader library fails)
{
glDeleteBuffers(1, &scratchbuffer);
Expand Down
1 change: 1 addition & 0 deletions lib/ivis_opengl/gfx_api_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ struct gl_context final : public gfx_api::context

gl_texture *pDefaultTexture = nullptr;
gl_texture_array *pDefaultArrayTexture = nullptr;
gl_gpurendered_texture *pDefaultDepthTexture = nullptr;

gl_gpurendered_texture* depthTexture = nullptr;
std::vector<GLuint> depthFBO;
Expand Down

0 comments on commit 4e48fab

Please sign in to comment.