Add flag for depth rendering.
PiperOrigin-RevId: 846203691 Change-Id: I5ec494446bcfc1f7c81536a87dd24f9967973563
This commit is contained in:
committed by
Copybara-Service
parent
47e35e632f
commit
7190bd4912
+49
-1
@@ -1019,7 +1019,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
//---------------------------------- reflection rendering
|
||||
|
||||
// plane and box reflection rendering
|
||||
if (scn->flags[mjRND_REFLECTION]) {
|
||||
if (scn->flags[mjRND_REFLECTION] && !scn->flags[mjRND_DEPTH]) {
|
||||
for (int i=0; i < ngeom; i++) {
|
||||
// get geom pointer
|
||||
thisgeom = scn->geoms + i;
|
||||
@@ -1481,6 +1481,54 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
if (scn->flags[mjRND_DEPTH]) {
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT |
|
||||
GL_LIGHTING_BIT | GL_POLYGON_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 1, 0, 1, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
void* depth_buf = mju_malloc(sizeof(float) * viewport.width * viewport.height);
|
||||
glReadPixels(0, 0, viewport.width, viewport.height, GL_DEPTH_COMPONENT, GL_FLOAT, depth_buf);
|
||||
|
||||
GLuint depth_tex;
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glGenTextures(1, &depth_tex);
|
||||
glBindTexture(GL_TEXTURE_2D, depth_tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, viewport.width, viewport.height,
|
||||
0, GL_LUMINANCE, GL_FLOAT, depth_buf);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); glVertex2f(0, 0);
|
||||
glTexCoord2f(1, 0); glVertex2f(1, 0);
|
||||
glTexCoord2f(1, 1); glVertex2f(1, 1);
|
||||
glTexCoord2f(0, 1); glVertex2f(0, 1);
|
||||
glEnd();
|
||||
|
||||
glDeleteTextures(1, &depth_tex);
|
||||
mju_free(depth_buf);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
}
|
||||
|
||||
// restore currentBuffer
|
||||
mjr_restoreBuffer(con);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user