Skip to content

Commit

Permalink
sokol_gfx.h gl: explicitely set GL_TEXTURE_MAX_LEVEL, and more detail…
Browse files Browse the repository at this point in the history
…ed framebuffer status logging (fixes #923)
  • Loading branch information
floooh committed Oct 25, 2023
1 parent 4eb208b commit 2bbba59
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3213,8 +3213,12 @@ typedef struct sg_frame_stats {
_SG_LOGITEM_XMACRO(GL_SHADER_LINKING_FAILED, "shader linking failed (gl)") \
_SG_LOGITEM_XMACRO(GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER, "vertex attribute not found in shader (gl)") \
_SG_LOGITEM_XMACRO(GL_TEXTURE_NAME_NOT_FOUND_IN_SHADER, "texture name not found in shader (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_INCOMPLETE, "framebuffer completeness check failed (gl)") \
_SG_LOGITEM_XMACRO(GL_MSAA_FRAMEBUFFER_INCOMPLETE, "completeness check failed for msaa resolve framebuffer (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNDEFINED, "framebuffer completeness check failed with GL_FRAMEBUFFER_UNDEFINED (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_ATTACHMENT, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MISSING_ATTACHMENT, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNSUPPORTED, "framebuffer completeness check failed with GL_FRAMEBUFFER_UNSUPPORTED (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE, "framebuffer completeness check failed with GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE (gl)") \
_SG_LOGITEM_XMACRO(GL_FRAMEBUFFER_STATUS_UNKNOWN, "framebuffer completeness check failed (unknown reason) (gl)") \
_SG_LOGITEM_XMACRO(D3D11_CREATE_BUFFER_FAILED, "CreateBuffer() failed (d3d11)") \
_SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_TEXTURE_UNSUPPORTED_PIXEL_FORMAT, "pixel format not supported for depth-stencil texture (d3d11)") \
_SG_LOGITEM_XMACRO(D3D11_CREATE_DEPTH_TEXTURE_FAILED, "CreateTexture2D() failed for depth-stencil texture (d3d11)") \
Expand Down Expand Up @@ -4304,6 +4308,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
#define GL_TEXTURE_COMPARE_FUNC 0x884D
#define GL_COMPARE_REF_TO_TEXTURE 0x884E
#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
#define GL_TEXTURE_MAX_LEVEL 0x813D
#endif

#ifndef GL_UNSIGNED_INT_2_10_10_10_REV
Expand Down Expand Up @@ -7689,6 +7694,7 @@ _SOKOL_PRIVATE sg_resource_state _sg_gl_create_image(_sg_image_t* img, const sg_
SOKOL_ASSERT(img->gl.tex[slot]);
_sg_gl_cache_store_texture_sampler_binding(0);
_sg_gl_cache_bind_texture_sampler(0, img->gl.target, img->gl.tex[slot], 0);
glTexParameteri(img->gl.target, GL_TEXTURE_MAX_LEVEL, img->cmn.num_mipmaps - 1);
const int num_faces = img->cmn.type == SG_IMAGETYPE_CUBE ? 6 : 1;
int data_index = 0;
for (int face_index = 0; face_index < num_faces; face_index++) {
Expand Down Expand Up @@ -8127,9 +8133,31 @@ _SOKOL_PRIVATE sg_resource_state _sg_gl_create_pass(_sg_pass_t* pass, _sg_image_
}

// check if framebuffer is complete
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
_SG_ERROR(GL_FRAMEBUFFER_INCOMPLETE);
return SG_RESOURCESTATE_FAILED;
{
const GLenum fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fb_status != GL_FRAMEBUFFER_COMPLETE) {
switch (fb_status) {
case GL_FRAMEBUFFER_UNDEFINED:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_UNDEFINED);
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_ATTACHMENT);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MISSING_ATTACHMENT);
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_UNSUPPORTED);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE);
break;
default:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_UNKNOWN);
break;
}
return SG_RESOURCESTATE_FAILED;
}
}

// setup color attachments for the framebuffer
Expand All @@ -8151,8 +8179,28 @@ _SOKOL_PRIVATE sg_resource_state _sg_gl_create_pass(_sg_pass_t* pass, _sg_image_
glBindFramebuffer(GL_FRAMEBUFFER, pass->gl.msaa_resolve_framebuffer[i]);
_sg_gl_fb_attach_texture(gl_resolve_att, cmn_resolve_att, GL_COLOR_ATTACHMENT0);
// check if framebuffer is complete
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
_SG_ERROR(GL_MSAA_FRAMEBUFFER_INCOMPLETE);
const GLenum fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fb_status != GL_FRAMEBUFFER_COMPLETE) {
switch (fb_status) {
case GL_FRAMEBUFFER_UNDEFINED:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_UNDEFINED);
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_ATTACHMENT);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MISSING_ATTACHMENT);
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_UNSUPPORTED);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE);
break;
default:
_SG_ERROR(GL_FRAMEBUFFER_STATUS_UNKNOWN);
break;
}
return SG_RESOURCESTATE_FAILED;
}
// setup color attachments for the framebuffer
Expand Down

0 comments on commit 2bbba59

Please sign in to comment.