<div dir="ltr"><div>Looks good AFAICS.  Just cosmetic requests.</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 10, 2015 at 11:14 PM, Rob Clark <span dir="ltr"><<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If we have the NV_read_depth_stencil extension, we can actually read<br>
depth/stencil.  Takes a bit of gymnastics to actually figure out that<br>
it is a depth/stencil buffer in the first place.<br>
<br>
TODO: this still seems to fall over w/ z24_s8, somehow ends up<br>
attempting to glReadPixels() with GL_FLOAT type.  Still trying to<br>
untangle all the logic here... gles really doesn't make it easy.<br>
<br>
Signed-off-by: Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>><br>
---<br>
Re-sending this and following patch to apitrace list (already sent to<br>
mesa list).  The corresponding mesa patches to implement the extensions<br>
used were sent earlier today.<br>
<br>
 retrace/glstate.cpp          |  3 ++<br>
 retrace/glstate_images.cpp   | 69 ++++++++++++++++++++++++++++++--------------<br>
 retrace/glstate_internal.hpp |  1 +<br>
 3 files changed, 52 insertions(+), 21 deletions(-)<br>
<br>
diff --git a/retrace/glstate.cpp b/retrace/glstate.cpp<br>
index 3d3c026..4386e08 100644<br>
--- a/retrace/glstate.cpp<br>
+++ b/retrace/glstate.cpp<br>
@@ -59,6 +59,9 @@ Context::Context(void) {<br>
     ARB_get_program_binary = ext.has("GL_ARB_get_program_binary");<br>
     KHR_debug = !ES && ext.has("GL_KHR_debug");<br>
     EXT_debug_label = ext.has("GL_EXT_debug_label");<br>
+<br>
+    if (ES)<br>
+        NV_read_depth_stencil = ext.has("GL_NV_read_depth_stencil");<br>
 }<br>
<br>
 PixelPackState::PixelPackState(const Context &context) {<br>
diff --git a/retrace/glstate_images.cpp b/retrace/glstate_images.cpp<br>
index c111efa..90ae3e0 100644<br>
--- a/retrace/glstate_images.cpp<br>
+++ b/retrace/glstate_images.cpp<br>
@@ -102,11 +102,11 @@ struct ImageDesc<br>
  * call.<br>
  */<br>
 static bool<br>
-probeTextureLevelSizeOES(GLenum target, GLint level, const GLint size[3]) {<br>
+probeTextureLevelSizeOES(GLenum target, GLint level, const GLint size[3],<br>
+                         GLenum internalFormat, GLenum type)<br>
+{<br>
     flushErrors();<br>
<br>
-    GLenum internalFormat = GL_RGBA;<br>
-    GLenum type = GL_UNSIGNED_BYTE;<br>
     GLint dummy = 0;<br>
<br>
     switch (target) {<br>
@@ -150,7 +150,9 @@ probeTextureLevelSizeOES(GLenum target, GLint level, const GLint size[3]) {<br>
  * It is assumed that the texture exists.<br>
  */<br>
 static GLint<br>
-bisectTextureLevelSizeOES(GLenum target, GLint level, GLint axis, GLint max) {<br>
+bisectTextureLevelSizeOES(GLenum target, GLint level, GLint axis, GLint max,<br>
+                          GLenum internalFormat, GLenum type)<br>
+{<br>
     GLint size[3] = {0, 0, 0};<br>
<br>
     assert(axis < 3);<br>
@@ -165,7 +167,7 @@ bisectTextureLevelSizeOES(GLenum target, GLint level, GLint axis, GLint max) {<br>
<br>
         size[axis] = test;<br>
<br>
-        if (probeTextureLevelSizeOES(target, level, size)) {<br>
+        if (probeTextureLevelSizeOES(target, level, size, internalFormat, type)) {<br>
             min = test;<br>
         } else {<br>
             max = test;<br>
@@ -186,20 +188,43 @@ getActiveTextureLevelDescOES(Context &context, GLenum target, GLint level, Image<br>
         return false;<br>
     }<br>
<br>
-    const GLint size[3] = {1, 1, 1};<br>
-    if (!probeTextureLevelSizeOES(target, level, size)) {<br>
+    GLenum formatAndTypes[] = {<br>
+        /* internalFormat */      /* type */<br>
+        GL_RGBA,                  GL_UNSIGNED_BYTE,<br>
+        GL_DEPTH_STENCIL,         GL_FLOAT_32_UNSIGNED_INT_24_8_REV,<br>
+        GL_DEPTH_STENCIL,         GL_UNSIGNED_INT_24_8,<br>
+        GL_DEPTH_COMPONENT,       GL_FLOAT,<br>
+        GL_DEPTH_COMPONENT,       GL_UNSIGNED_INT,<br>
+        GL_STENCIL_INDEX,         GL_UNSIGNED_BYTE,<br>
+        /* others? */<br>
+        0,<br>
+    };<br></blockquote><div><br></div><div>Please use a structure here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    const GLint size[3] = {1, 1, 1};<br>
+    GLenum internalFormat = GL_NONE;<br>
+    GLenum type;<br>
+<br>
+    for (int i = 0; formatAndTypes[i]; i += 2) {<br>
+        if (probeTextureLevelSizeOES(target, level, size,<br>
+                                     formatAndTypes[i],<br>
+                                     formatAndTypes[i+1])) {<br>
+            internalFormat = formatAndTypes[i];<br>
+            type = formatAndTypes[i+1];<br>
+            break;<br>
+        }<br>
+    }<br>
+<br></blockquote><div><br></div><div>Please put this new code in a new probeTextureFormatOES function.</div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    if (internalFormat == GL_NONE) {<br>
         return false;<br>
     }<br>
<br>
-    // XXX: mere guess<br>
-    desc.internalFormat = GL_RGBA;<br>
+    desc.internalFormat = internalFormat;<br>
<br>
     GLint maxSize = 0;<br>
     switch (target) {<br>
     case GL_TEXTURE_2D:<br>
         glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);<br>
-        desc.width = bisectTextureLevelSizeOES(target, level, 0, maxSize);<br>
-        desc.height = bisectTextureLevelSizeOES(target, level, 1, maxSize);<br>
+        desc.width = bisectTextureLevelSizeOES(target, level, 0, maxSize, internalFormat, type);<br>
+        desc.height = bisectTextureLevelSizeOES(target, level, 1, maxSize, internalFormat, type);<br>
         desc.depth = 1;<br>
         break;<br>
     case GL_TEXTURE_CUBE_MAP:<br>
@@ -210,15 +235,15 @@ getActiveTextureLevelDescOES(Context &context, GLenum target, GLint level, Image<br>
     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:<br>
     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:<br>
         glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxSize);<br>
-        desc.width = bisectTextureLevelSizeOES(target, level, 0, maxSize);<br>
+        desc.width = bisectTextureLevelSizeOES(target, level, 0, maxSize, internalFormat, type);<br>
         desc.height = desc.width;<br>
         desc.depth = 1;<br>
         break;<br>
     case GL_TEXTURE_3D_OES:<br>
         glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_OES, &maxSize);<br>
-        desc.width = bisectTextureLevelSizeOES(target, level, 0, maxSize);<br>
-        desc.width = bisectTextureLevelSizeOES(target, level, 1, maxSize);<br>
-        desc.depth = bisectTextureLevelSizeOES(target, level, 2, maxSize);<br>
+        desc.width = bisectTextureLevelSizeOES(target, level, 0, maxSize, internalFormat, type);<br>
+        desc.width = bisectTextureLevelSizeOES(target, level, 1, maxSize, internalFormat, type);<br>
+        desc.depth = bisectTextureLevelSizeOES(target, level, 2, maxSize, internalFormat, type);<br>
         break;<br>
     default:<br>
         return false;<br>
@@ -376,7 +401,8 @@ getTextureBinding(GLenum target)<br>
  * texture to a framebuffer.<br>
  */<br>
 static inline void<br>
-getTexImageOES(GLenum target, GLint level, ImageDesc &desc, GLubyte *pixels)<br>
+getTexImageOES(GLenum target, GLint level, GLenum format, GLenum type,<br>
+               ImageDesc &desc, GLubyte *pixels)<br>
 {<br>
     memset(pixels, 0x80, desc.height * desc.width * 4);<br>
<br>
@@ -412,12 +438,13 @@ getTexImageOES(GLenum target, GLint level, ImageDesc &desc, GLubyte *pixels)<br>
         if (status != GL_FRAMEBUFFER_COMPLETE) {<br>
             std::cerr << __FUNCTION__ << ": " << enumToString(status) << "\n";<br>
         }<br>
-        glReadPixels(0, 0, desc.width, desc.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);<br>
+<br>
+        glReadPixels(0, 0, desc.width, desc.height, format, type, pixels);<br>
         break;<br>
     case GL_TEXTURE_3D_OES:<br>
         for (int i = 0; i < desc.depth; i++) {<br>
             glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, texture, level, i);<br>
-            glReadPixels(0, 0, desc.width, desc.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels + 4 * i * desc.width * desc.height);<br>
+            glReadPixels(0, 0, desc.width, desc.height, format, type, pixels + 4 * i * desc.width * desc.height);<br>
         }<br>
         break;<br>
     }<br>
@@ -498,7 +525,7 @@ dumpActiveTextureLevel(StateWriter &writer, Context &context,<br>
         }<br>
     } else {<br>
         if (context.ES) {<br>
-            getTexImageOES(target, level, desc, image->pixels);<br>
+            getTexImageOES(target, level, format, type, desc, image->pixels);<br>
         } else {<br>
             glGetTexImage(target, level, format, type, image->pixels);<br>
         }<br>
@@ -1005,7 +1032,7 @@ dumpReadBufferImage(StateWriter &writer,<br>
     }<br>
<br>
     // On GLES glReadPixels only supports GL_RGBA and GL_UNSIGNED_BYTE combination<br>
-    if (context.ES) {<br>
+    if (context.ES && !context.NV_read_depth_stencil) {<br>
         format = GL_RGBA;<br>
         type = GL_UNSIGNED_BYTE;<br>
     }<br>
@@ -1366,7 +1393,7 @@ dumpFramebufferAttachments(StateWriter &writer, Context &context, GLenum target)<br>
<br>
     glReadBuffer(read_buffer);<br>
<br>
-    if (!context.ES) {<br>
+    if ((!context.ES) || context.NV_read_depth_stencil) {<br>
         dumpFramebufferAttachment(writer, context, target, GL_DEPTH_ATTACHMENT);<br>
         dumpFramebufferAttachment(writer, context, target, GL_STENCIL_ATTACHMENT);<br>
     }<br>
diff --git a/retrace/glstate_internal.hpp b/retrace/glstate_internal.hpp<br>
index 6f9086e..c180890 100644<br>
--- a/retrace/glstate_internal.hpp<br>
+++ b/retrace/glstate_internal.hpp<br>
@@ -49,6 +49,7 @@ struct Context<br>
     unsigned ARB_get_program_binary:1;<br>
     unsigned KHR_debug:1;<br>
     unsigned EXT_debug_label:1;<br>
+    unsigned NV_read_depth_stencil:1;  /* ES only */<br>
<br>
     Context(void);<br>
 };<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.4.3<br></font></span></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Jose</div></div>