[Mesa-users] glGetTexImage with GL_TEXTURE_3D
Markus Müller
mueller at imfusion.de
Mon Aug 29 07:43:41 UTC 2016
Hello,
I'm using the Gallium llvmpipe software renderer on Windows and have the
problem that when downloading 3D textures with glGetTexImage, only the
first slice is copied to the provided buffer. I attached a small example
that works with the default nvidia driver and Mesa 10.3.1 but fails with
Mesa 10.6.9 (also 11 and 12).
The following patch seems to fix this but I'm not sure if it breaks
something else:
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index f97d0ef..83bf122 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -509,14 +509,16 @@ get_tex_rgba_uncompressed(struct gl_context *ctx,
GLuint dimensions,
*/
if (format == rgba_format) {
rgba = dest;
- } else if (rgba == NULL) { /* Allocate the RGBA buffer only
once */
+ } else {
need_convert = true;
- rgba = malloc(height * rgba_stride);
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
- ctx->Driver.UnmapTextureImage(ctx, texImage, img);
- return;
- }
+ if (rgba == NULL) { /* Allocate the RGBA buffer
only once */
+ rgba = malloc(height * rgba_stride);
+ if (!rgba) {
+ _mesa_error(ctx,
GL_OUT_OF_MEMORY, "glGetTexImage()");
+ ctx->Driver.UnmapTextureImage(ctx, texImage, img);
+ return;
+ }
+ }
}
_mesa_format_convert(rgba, rgba_format, rgba_stride,
Regards,
Markus
-------------- next part --------------
#include "glew/include/GL/glew.h"
#include "glfw/include/GLFW/glfw3.h"
#include "assert.h"
#include "string.h"
#include "stdio.h"
int main(void)
{
GLFWwindow* window;
if (!glfwInit())
return -1;
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK)
return -1;
int size = 64;
unsigned short* pixelsIn = new unsigned short[size*size*size];
memset(pixelsIn, 0xAA, size*size*size*sizeof(unsigned short));
GLuint tex = -1;
glGenTextures(1, &tex);
assert(tex >= 0);
glBindTexture(GL_TEXTURE_3D, tex);
glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY16, size, size, size, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixelsIn);
assert(glGetError() == GL_NO_ERROR);
unsigned short* pixelsOut = new unsigned short[size*size*size];
memset(pixelsOut, 0x00, size*size*size*sizeof(unsigned short));
glPixelStorei(GL_PACK_ALIGNMENT, 8);
glGetTexImage(GL_TEXTURE_3D, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, pixelsOut);
assert(glGetError() == GL_NO_ERROR);
int same = memcmp(pixelsIn, pixelsOut, size*size*size*sizeof(unsigned short));
assert(same == 0);
glfwTerminate();
delete[] pixelsIn;
delete[] pixelsOut;
return 0;
}
More information about the mesa-users
mailing list