Merge pull request #978 from aftersomemath:depth-precision-in-place
PiperOrigin-RevId: 572961667 Change-Id: I69011ddf835ae286e30e7f84cca67867cfe94fa4
This commit is contained in:
@@ -1062,7 +1062,7 @@ static void makeShadow(const mjModel* m, mjrContext* con) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
|
||||
@@ -1126,11 +1126,14 @@ static void makeOff(mjrContext* con) {
|
||||
mju_error("Could not allocate offscreen depth and stencil buffer");
|
||||
}
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil);
|
||||
|
||||
GLenum depth_buffer_format =
|
||||
mjGLAD_GL_ARB_depth_buffer_float ? GL_DEPTH32F_STENCIL8 : GL_DEPTH24_STENCIL8;
|
||||
if (con->offSamples) {
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH24_STENCIL8,
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, depth_buffer_format,
|
||||
con->offWidth, con->offHeight);
|
||||
} else {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, con->offWidth, con->offHeight);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, depth_buffer_format, con->offWidth, con->offHeight);
|
||||
}
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, con->offDepthStencil);
|
||||
@@ -1169,7 +1172,7 @@ static void makeOff(mjrContext* con) {
|
||||
mju_error("Could not allocate offscreen depth and stencil buffer_r");
|
||||
}
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil_r);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, con->offWidth, con->offHeight);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, depth_buffer_format, con->offWidth, con->offHeight);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
|
||||
GL_RENDERBUFFER, con->offDepthStencil_r);
|
||||
|
||||
@@ -1535,7 +1538,6 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
// free previous context
|
||||
mjr_freeContext(con);
|
||||
|
||||
// no model: offscreen and font only
|
||||
@@ -1607,6 +1609,9 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
|
||||
|
||||
// set default color pixel format for mjr_readPixels
|
||||
con->readPixelFormat = GL_RGB;
|
||||
|
||||
// set default depth mapping for mjr_readPixels
|
||||
con->readDepthMap = mjDEPTH_ZERONEAR;
|
||||
}
|
||||
|
||||
|
||||
@@ -1830,10 +1835,10 @@ MJAPI void mjr_resizeOffscreen(int width, int height, mjrContext* con) {
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil);
|
||||
if (con->offSamples) {
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH24_STENCIL8,
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, con->offSamples, GL_DEPTH32F_STENCIL8,
|
||||
con->offWidth, con->offHeight);
|
||||
} else {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, con->offWidth, con->offHeight);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH32F_STENCIL8, con->offWidth, con->offHeight);
|
||||
}
|
||||
|
||||
if (con->offSamples) {
|
||||
@@ -1841,6 +1846,6 @@ MJAPI void mjr_resizeOffscreen(int width, int height, mjrContext* con) {
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, con->offWidth, con->offHeight);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, con->offDepthStencil_r);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, con->offWidth, con->offHeight);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH32F_STENCIL8, con->offWidth, con->offHeight);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user