Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/render/render_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ static void makeShadow(const mjModel* m, mjrContext* con) {
mju_error("Could not allocate shadow framebuffer");
}
glBindFramebuffer(GL_FRAMEBUFFER, con->shadowFBO);
glObjectLabel(GL_FRAMEBUFFER, con->shadowFBO, -1, "mjr_shadow_fbo");

// Create a shadow depth texture in TEXTURE1 and explicitly select an int24
// depth buffer. A depth stencil format is used because that appears to be
Expand All @@ -1059,6 +1060,7 @@ static void makeShadow(const mjModel* m, mjrContext* con) {
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, con->shadowTex);
glObjectLabel(GL_TEXTURE, con->shadowTex, -1, "mjr_shadow_texture");
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8,
con->shadowSize, con->shadowSize, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Expand Down Expand Up @@ -1102,6 +1104,7 @@ static void makeOff(mjrContext* con) {
mju_error("Could not allocate offscreen framebuffer");
}
glBindFramebuffer(GL_FRAMEBUFFER, con->offFBO);
glObjectLabel(GL_FRAMEBUFFER, con->offFBO, -1, "mjr_offscreen_fbo");

// clamp samples request
int sMax = 0;
Expand All @@ -1116,6 +1119,8 @@ static void makeOff(mjrContext* con) {
mju_error("Could not allocate offscreen color buffer");
}
glBindRenderbuffer(GL_RENDERBUFFER, con->offColor);
glObjectLabel(GL_RENDERBUFFER, con->offColor, -1, "mjr_rb_offscreen_color");

if (con->offSamples) {
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_RGBA8,
con->offWidth, con->offHeight);
Expand All @@ -1130,6 +1135,7 @@ static void makeOff(mjrContext* con) {
mju_error("Could not allocate offscreen depth and stencil buffer");
}
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil);
glObjectLabel(GL_RENDERBUFFER, con->offDepthStencil, -1, "mjr_rb_offscreen_depth_stencil");

GLenum depth_buffer_format =
mjGLAD_GL_ARB_depth_buffer_float ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8;
Expand Down Expand Up @@ -1166,6 +1172,9 @@ static void makeOff(mjrContext* con) {
mju_error("Could not allocate offscreen color buffer_r");
}
glBindRenderbuffer(GL_RENDERBUFFER, con->offColor_r);
// store an object name for nsight UI
glObjectLabel(GL_RENDERBUFFER, con->offColor_r, -1, "mjr_rb_offscreen_color_r");

glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, con->offWidth, con->offHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, con->offColor_r);
Expand All @@ -1176,6 +1185,8 @@ static void makeOff(mjrContext* con) {
mju_error("Could not allocate offscreen depth and stencil buffer_r");
}
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil_r);
glObjectLabel(GL_RENDERBUFFER, con->offDepthStencil_r, -1, "mjr_rb_offscreen_depth_stencil_r");

glRenderbufferStorage(GL_RENDERBUFFER, depth_buffer_format, con->offWidth, con->offHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, con->offDepthStencil_r);
Expand Down Expand Up @@ -1370,6 +1381,8 @@ void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid) {
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, con->texture[texid]);
glObjectLabel(GL_TEXTURE, con->texture[texid], -1, m->names + m->name_texadr[texid]);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Expand Down Expand Up @@ -1411,6 +1424,8 @@ void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid) {
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, con->texture[texid]);
glObjectLabel(GL_TEXTURE, con->texture[texid], -1, m->names + m->name_texadr[texid]);

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_R, GL_CLAMP_TO_EDGE);
Expand Down Expand Up @@ -1507,7 +1522,11 @@ void GLAPIENTRY debugCallback(GLenum source,
GLsizei length,
const GLchar* message,
const void* userParam) {
printf("GL DEBUG: source = 0x%x, type = 0x%x, severity = 0x%x, id = 0x%x\nmessage = %s\n\n",
// (33385/33386 ) supress warnings about ogl debug group push/pop
if ( type == 33385 || type == 33386) {
return;
}
printf("GL DEBUG: source = 0x%x, type = 0x%x, severity = 0x%x, id = 0x%x\nmessage = %s\n\n",
source, type, severity, id, message);
}

Expand Down Expand Up @@ -1760,13 +1779,16 @@ void mjr_addAux(int index, int width, int height, int samples, mjrContext* con)
mju_error("Could not allocate auxiliary framebuffer");
}
glBindFramebuffer(GL_FRAMEBUFFER, con->auxFBO[index]);
glObjectLabel(GL_FRAMEBUFFER, con->auxFBO[index], -1, "mjr_fb_aux");

// create color buffer with multisamples
glGenRenderbuffers(1, con->auxColor + index);
if (!con->auxColor[index]) {
mju_error("Could not allocate auxiliary color buffer");
}
glBindRenderbuffer(GL_RENDERBUFFER, con->auxColor[index]);
glObjectLabel(GL_RENDERBUFFER, con->auxColor[index], -1, "mjr_rb_aux_color");

glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->auxSamples[index], GL_RGBA8,
con->auxWidth[index], con->auxHeight[index]);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
Expand All @@ -1784,13 +1806,16 @@ void mjr_addAux(int index, int width, int height, int samples, mjrContext* con)
mju_error("Could not allocate auxiliary resolve framebuffer");
}
glBindFramebuffer(GL_FRAMEBUFFER, con->auxFBO_r[index]);
glObjectLabel(GL_FRAMEBUFFER, con->auxFBO_r[index], -1, "mjr_fb_aux_resolve");

// create color buffer for resolving multisamples
glGenRenderbuffers(1, con->auxColor_r + index);
if (!con->auxColor_r[index]) {
mju_error("Could not allocate auxiliary color resolve buffer");
}
glBindRenderbuffer(GL_RENDERBUFFER, con->auxColor_r[index]);
glObjectLabel(GL_RENDERBUFFER, con->auxColor_r[index], -1, "mjr_fb_aux_color_r");

glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8,
con->auxWidth[index], con->auxHeight[index]);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
Expand Down
35 changes: 29 additions & 6 deletions src/render/render_gl3.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
if (mode == mjrRND_SHADOWCAST && (geom->type == mjGEOM_LINE || geom->category == mjCAT_DECOR)) {
return;
}

glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "renderGeom");
// make transformation matrix
float mat[16] = {
geom->mat[0], geom->mat[3], geom->mat[6], 0.0f,
Expand Down Expand Up @@ -582,6 +582,8 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
(mode == mjrRND_NORMAL || mode == mjrRND_SHADOWMAP)) {
settexture(mjtexREGULAR, 0, con, geom);
}
glPopDebugGroup();

}


Expand Down Expand Up @@ -859,6 +861,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
}
}

glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "render");

// upload dynamic skin data to GPU
for (int i=0; i < scn->nskin; i++) {
// upload positions to VBO
Expand Down Expand Up @@ -962,6 +966,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {

// render with stereo
for (int view = (stereo ? 0 : -1); view < (stereo ? 2 : 0); view++) {
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "view render pass");
// change drawbuffer for QUADBUFFERED stereo
if (stereo == mjSTEREO_QUADBUFFERED) {
if (con->windowDoublebuffer) {
Expand Down Expand Up @@ -1012,6 +1017,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
}

// skip the remaining passes
glPopDebugGroup(); // end regular rendering early
continue;
}

Expand Down Expand Up @@ -1045,6 +1051,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
}

// prepare to render plane in stencil buffer
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "stencil buffer");
glDisable(GL_DEPTH_TEST);
glColorMask(0, 0, 0, 0);
glEnable(GL_STENCIL_TEST);
Expand Down Expand Up @@ -1085,6 +1092,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glEnable(GL_LIGHT0+j);
}

glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "reflected objects");
// render reflected non-transparent geoms, except for thisgeom
for (int j=0; j < ngeom; j++) {
if (!scn->geoms[j].transparent && i != j) {
Expand Down Expand Up @@ -1125,12 +1133,15 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glDisable(GL_CLIP_PLANE0);
glPopMatrix();
glFrontFace(GL_CCW);
glPopDebugGroup(); // "reflected objects"
glPopDebugGroup(); // "stencil buffer"

}
}
}

//---------------------------------- regular rendering

glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "regular rendering");
// set light position and direction, enable non-shadow lights
for (int i=0; i < nlight; i++) {
// set light
Expand Down Expand Up @@ -1164,7 +1175,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
for (int i=0; i < nlight; i++) {
glDisable(GL_LIGHT0+i);
}

glPopDebugGroup(); // end regular rendering

//------------------------------------ shadow rendering

// black fog, to avoid glow
Expand All @@ -1173,6 +1185,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {

// shadow map rendering
if (scn->flags[mjRND_SHADOW] && con->shadowFBO) {
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "shadow rendering");
for (int i=0; i < nlight; i++) {
// get pointer
thislight = scn->lights + i;
Expand Down Expand Up @@ -1300,6 +1313,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
settexture(mjtexSHADOW, 0, con, 0);
}
}
glPopDebugGroup(); // end shadow rendering
}

// restore fog color
Expand All @@ -1308,6 +1322,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
//------------------------------------ skybox rendering

if (scn->flags[mjRND_SKYBOX]) {
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "skybox");
// skybox always filled
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

Expand Down Expand Up @@ -1392,12 +1407,14 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
}
}

glPopDebugGroup(); // end skybox
// wireframe or filled depending on flag
glPolygonMode(GL_FRONT_AND_BACK, scn->flags[mjRND_WIREFRAME] ? GL_LINE : GL_FILL);
}

//------------------------------------ transparent regular rendering

glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "transparent regular rendering");

// enable lights
for (int i=0; i < nlight; i++) {
glEnable(GL_LIGHT0+i);
Expand Down Expand Up @@ -1432,9 +1449,11 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
for (int i=0; i < nlight; i++) {
glDisable(GL_LIGHT0+i);
}

glPopDebugGroup(); // end transparent regular rendering

//------------------------------------ label rendering

glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "label rendering");

// render text labels if present
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
Expand All @@ -1448,6 +1467,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
}
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glPopDebugGroup(); // end label rendering
glPopDebugGroup(); // end view
}

// frame
Expand Down Expand Up @@ -1482,6 +1503,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {

// restore currentBuffer
mjr_restoreBuffer(con);
glPopDebugGroup(); // end rendering

}


Expand Down