Skip to content

Commit 589eb75

Browse files
authored
Merge pull request #1195 from asarium/opengl/moreObjectLabels
Assign OpenGL labels to more objects
2 parents fbe9cc1 + 084d237 commit 589eb75

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

code/graphics/opengl/ShaderProgram.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ GLenum get_gl_shader_stage(opengl::ShaderStage stage) {
143143
}
144144
}
145145

146-
opengl::ShaderProgram::ShaderProgram() : _program_id(0), Uniforms(this) {
146+
opengl::ShaderProgram::ShaderProgram(const SCP_string& program_name) : _program_id(0), Uniforms(this) {
147147
_program_id = glCreateProgram();
148+
opengl_set_object_label(GL_PROGRAM, _program_id, program_name);
148149
}
149150
opengl::ShaderProgram::~ShaderProgram() {
150151
freeCompiledShaders();
@@ -172,8 +173,9 @@ void opengl::ShaderProgram::use() {
172173
GLuint opengl::ShaderProgram::getShaderHandle() {
173174
return _program_id;
174175
}
175-
void opengl::ShaderProgram::addShaderCode(opengl::ShaderStage stage, const SCP_vector<SCP_string>& codeParts) {
176+
void opengl::ShaderProgram::addShaderCode(opengl::ShaderStage stage, const SCP_string& name, const SCP_vector<SCP_string>& codeParts) {
176177
auto shader_obj = compile_shader_object(codeParts, get_gl_shader_stage(stage));
178+
opengl_set_object_label(GL_SHADER, shader_obj, name);
177179
_compiled_shaders.push_back(shader_obj);
178180
glAttachShader(_program_id, shader_obj);
179181
}

code/graphics/opengl/ShaderProgram.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ShaderProgram {
8484

8585
void freeCompiledShaders();
8686
public:
87-
ShaderProgram();
87+
explicit ShaderProgram(const SCP_string& program_name);
8888
~ShaderProgram();
8989

9090
ShaderUniforms Uniforms;
@@ -97,7 +97,7 @@ class ShaderProgram {
9797

9898
void use();
9999

100-
void addShaderCode(ShaderStage stage, const SCP_vector<SCP_string>& codeParts);
100+
void addShaderCode(ShaderStage stage, const SCP_string& name, const SCP_vector<SCP_string>& codeParts);
101101

102102
void linkProgram();
103103

code/graphics/opengl/gropengl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,11 +1656,13 @@ void gr_opengl_pop_debug_group() {
16561656
glPopDebugGroup();
16571657
}
16581658
}
1659+
#if !defined(NDEBUG) || defined(FS_OPENGL_DEBUG) || defined(DOXYGEN)
16591660
void opengl_set_object_label(GLenum type, GLuint handle, const SCP_string& name) {
16601661
if (GLAD_GL_KHR_debug) {
16611662
glObjectLabel(type, handle, (GLsizei) name.size(), name.c_str());
16621663
}
16631664
}
1665+
#endif
16641666

16651667
uint opengl_data_type_size(GLenum data_type)
16661668
{

code/graphics/opengl/gropengl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ void gr_opengl_pop_debug_group();
3333
* @param handle The handle of the object
3434
* @param name The name of the object
3535
*/
36+
#if !defined(NDEBUG) || defined(FS_OPENGL_DEBUG) || defined(DOXYGEN)
3637
void opengl_set_object_label(GLenum type, GLuint handle, const SCP_string& name);
38+
#else
39+
// Remove this definition
40+
inline void opengl_set_object_label(GLenum, GLuint, const SCP_string&) {}
41+
#endif
3742

3843
uint opengl_data_type_size(GLenum data_type);
3944

code/graphics/opengl/gropenglshader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,15 @@ int opengl_compile_shader(shader_type sdr, uint flags)
566566
}
567567

568568
auto shader_hash = get_shader_hash(vert_content, geom_content, frag_content);
569-
std::unique_ptr<opengl::ShaderProgram> program(new opengl::ShaderProgram());
569+
std::unique_ptr<opengl::ShaderProgram> program(new opengl::ShaderProgram(sdr_info->description));
570570

571571
if (!load_cached_shader_binary(program.get(), shader_hash)) {
572572
GR_DEBUG_SCOPE("Compiling shader code");
573573
try {
574-
program->addShaderCode(opengl::STAGE_VERTEX, vert_content);
575-
program->addShaderCode(opengl::STAGE_FRAGMENT, frag_content);
574+
program->addShaderCode(opengl::STAGE_VERTEX, sdr_info->vert, vert_content);
575+
program->addShaderCode(opengl::STAGE_FRAGMENT, sdr_info->frag, frag_content);
576576
if (use_geo_sdr) {
577-
program->addShaderCode(opengl::STAGE_GEOMETRY, geom_content);
577+
program->addShaderCode(opengl::STAGE_GEOMETRY, sdr_info->geo, geom_content);
578578
}
579579

580580
for (int i = 0; i < opengl_vert_attrib::NUM_ATTRIBS; ++i) {

code/graphics/opengl/gropengltexture.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ int opengl_create_texture_sub(int bitmap_handle, int bitmap_type, int bmap_w, in
425425

426426
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
427427
glBindTexture(t->texture_target, t->texture_id);
428+
if (!reload) {
429+
opengl_set_object_label(GL_TEXTURE, t->texture_id, bm_get_filename(bitmap_handle));
430+
}
428431

429432
GLenum min_filter = GL_LINEAR;
430433

0 commit comments

Comments
 (0)