[Mesa-dev] [PATCH 16/29] mesa: use master conversion function to implement get_tex_rgba_uncompressed()

2014-11-18 Thread Iago Toral Quiroga
From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This covers glGetTexImage for uncompressed color formats.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
Signed-off-by: Eduardo Lima Mitev el...@igalia.com
---
 src/mesa/main/texgetimage.c | 170 ++--
 1 file changed, 117 insertions(+), 53 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index cb5f793..84cd53e 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -45,7 +45,8 @@
 #include texgetimage.h
 #include teximage.h
 #include texstore.h
-
+#include format_utils.h
+#include pixeltransfer.h
 
 
 /**
@@ -380,20 +381,10 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
GLenum rebaseFormat = GL_NONE;
GLuint height = texImage-Height;
GLuint depth = texImage-Depth;
-   GLuint img, row;
-   GLfloat (*rgba)[4];
-   GLuint (*rgba_uint)[4];
-   GLboolean tex_is_integer = 
_mesa_is_format_integer_color(texImage-TexFormat);
-   GLboolean tex_is_uint = _mesa_is_format_unsigned(texImage-TexFormat);
+   GLuint img;
GLenum texBaseFormat = _mesa_get_format_base_format(texImage-TexFormat);
 
-   /* Allocate buffer for one row of texels */
-   rgba = malloc(4 * width * sizeof(GLfloat));
-   rgba_uint = (GLuint (*)[4]) rgba;
-   if (!rgba) {
-  _mesa_error(ctx, GL_OUT_OF_MEMORY, glGetTexImage());
-  return;
-   }
+   assert (depth = 1 || dimensions  2);
 
if (texImage-TexObject-Target == GL_TEXTURE_1D_ARRAY) {
   depth = height;
@@ -413,9 +404,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
  texImage-_BaseFormat == GL_RGB ||
  texImage-_BaseFormat == GL_RG) 
 (destBaseFormat == GL_LUMINANCE ||
- destBaseFormat == GL_LUMINANCE_ALPHA ||
- destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
- destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
+ destBaseFormat == GL_LUMINANCE_ALPHA)) {
   /* If we're reading back an RGB(A) texture as luminance then we need
* to return L=tex(R).  Note, that's different from glReadPixels which
* returns L=R+G+B.
@@ -467,6 +456,22 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
   }
}
 
+   /* Describe the dst format */
+   GLboolean dst_is_integer = _mesa_is_enum_format_integer(format);
+   uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
+   int dst_stride = _mesa_image_row_stride(ctx-Pack, width, format, type);
+
+   /* Since _mesa_format_convert does not handle transferOps we need to handle
+* them before we call the function. This requires to convert to RGBA float
+* first so we can call _mesa_apply_rgba_transfer_ops. If the dst format is
+* integer we can ignore transferOps.
+*
+* Some source formats (Luminance) will also require to be rebased to obtain
+* the expected results and this also requires to convert to RGBA first.
+*/
+   assert(!transferOps || (transferOps  !dst_is_integer));
+   bool needs_rgba = (transferOps || rebaseFormat != GL_NONE);
+
for (img = 0; img  depth; img++) {
   GLubyte *srcMap;
   GLint rowstride;
@@ -475,46 +480,105 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
   ctx-Driver.MapTextureImage(ctx, texImage, img,
   0, 0, width, height, GL_MAP_READ_BIT,
   srcMap, rowstride);
-  if (srcMap) {
- for (row = 0; row  height; row++) {
-const GLubyte *src = srcMap + row * rowstride;
-void *dest = _mesa_image_address(dimensions, ctx-Pack, pixels,
- width, height, format, type,
- img, row, 0);
-
-   if (tex_is_integer) {
-  _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
-   if (tex_is_uint) {
-  _mesa_pack_rgba_span_from_uints(ctx, width,
-  (GLuint (*)[4]) rgba_uint,
-  format, type, dest);
-   } else {
-  _mesa_pack_rgba_span_from_ints(ctx, width,
- (GLint (*)[4]) rgba_uint,
- format, type, dest);
-   }
-   } else {
-  _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_float(width, rgba, rebaseFormat);
-  _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
- format, type, dest,
- ctx-Pack, transferOps);
-   }
-}

Re: [Mesa-dev] [PATCH 16/29] mesa: use master conversion function to implement get_tex_rgba_uncompressed()

2014-11-18 Thread Brian Paul

On 11/18/2014 02:23 AM, Iago Toral Quiroga wrote:

From: Samuel Iglesias Gonsalvez sigles...@igalia.com

This covers glGetTexImage for uncompressed color formats.

Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
Signed-off-by: Eduardo Lima Mitev el...@igalia.com
---
  src/mesa/main/texgetimage.c | 170 ++--
  1 file changed, 117 insertions(+), 53 deletions(-)

diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index cb5f793..84cd53e 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -45,7 +45,8 @@
  #include texgetimage.h
  #include teximage.h
  #include texstore.h
-
+#include format_utils.h
+#include pixeltransfer.h


  /**
@@ -380,20 +381,10 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
 GLenum rebaseFormat = GL_NONE;
 GLuint height = texImage-Height;
 GLuint depth = texImage-Depth;
-   GLuint img, row;
-   GLfloat (*rgba)[4];
-   GLuint (*rgba_uint)[4];
-   GLboolean tex_is_integer = 
_mesa_is_format_integer_color(texImage-TexFormat);
-   GLboolean tex_is_uint = _mesa_is_format_unsigned(texImage-TexFormat);
+   GLuint img;
 GLenum texBaseFormat = _mesa_get_format_base_format(texImage-TexFormat);

-   /* Allocate buffer for one row of texels */
-   rgba = malloc(4 * width * sizeof(GLfloat));
-   rgba_uint = (GLuint (*)[4]) rgba;
-   if (!rgba) {
-  _mesa_error(ctx, GL_OUT_OF_MEMORY, glGetTexImage());
-  return;
-   }
+   assert (depth = 1 || dimensions  2);

 if (texImage-TexObject-Target == GL_TEXTURE_1D_ARRAY) {
depth = height;
@@ -413,9 +404,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
   texImage-_BaseFormat == GL_RGB ||
   texImage-_BaseFormat == GL_RG) 
  (destBaseFormat == GL_LUMINANCE ||
- destBaseFormat == GL_LUMINANCE_ALPHA ||
- destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
- destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
+ destBaseFormat == GL_LUMINANCE_ALPHA)) {
/* If we're reading back an RGB(A) texture as luminance then we need
 * to return L=tex(R).  Note, that's different from glReadPixels which
 * returns L=R+G+B.
@@ -467,6 +456,22 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
}
 }

+   /* Describe the dst format */
+   GLboolean dst_is_integer = _mesa_is_enum_format_integer(format);
+   uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
+   int dst_stride = _mesa_image_row_stride(ctx-Pack, width, format, type);


This won't build with MSVC.  Declarations cannot follow code.




+
+   /* Since _mesa_format_convert does not handle transferOps we need to handle
+* them before we call the function. This requires to convert to RGBA float
+* first so we can call _mesa_apply_rgba_transfer_ops. If the dst format is
+* integer we can ignore transferOps.
+*
+* Some source formats (Luminance) will also require to be rebased to obtain
+* the expected results and this also requires to convert to RGBA first.
+*/
+   assert(!transferOps || (transferOps  !dst_is_integer));
+   bool needs_rgba = (transferOps || rebaseFormat != GL_NONE);
+
 for (img = 0; img  depth; img++) {
GLubyte *srcMap;
GLint rowstride;
@@ -475,46 +480,105 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint 
dimensions,
ctx-Driver.MapTextureImage(ctx, texImage, img,
0, 0, width, height, GL_MAP_READ_BIT,
srcMap, rowstride);
-  if (srcMap) {
- for (row = 0; row  height; row++) {
-const GLubyte *src = srcMap + row * rowstride;
-void *dest = _mesa_image_address(dimensions, ctx-Pack, pixels,
- width, height, format, type,
- img, row, 0);
-
-   if (tex_is_integer) {
-  _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
-   if (tex_is_uint) {
-  _mesa_pack_rgba_span_from_uints(ctx, width,
-  (GLuint (*)[4]) rgba_uint,
-  format, type, dest);
-   } else {
-  _mesa_pack_rgba_span_from_ints(ctx, width,
- (GLint (*)[4]) rgba_uint,
- format, type, dest);
-   }
-   } else {
-  _mesa_unpack_rgba_row(texFormat, width, src, rgba);
-   if (rebaseFormat)
-  _mesa_rebase_rgba_float(width, rgba, rebaseFormat);
-  _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
-   

Re: [Mesa-dev] [PATCH 16/29] mesa: use master conversion function to implement get_tex_rgba_uncompressed()

2014-11-18 Thread Iago Toral
On Tue, 2014-11-18 at 08:00 -0700, Brian Paul wrote:
 On 11/18/2014 02:23 AM, Iago Toral Quiroga wrote:
  From: Samuel Iglesias Gonsalvez sigles...@igalia.com
 
  This covers glGetTexImage for uncompressed color formats.
 
  Signed-off-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
  Signed-off-by: Eduardo Lima Mitev el...@igalia.com
  ---
src/mesa/main/texgetimage.c | 170 
  ++--
1 file changed, 117 insertions(+), 53 deletions(-)
 
  diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
  index cb5f793..84cd53e 100644
  --- a/src/mesa/main/texgetimage.c
  +++ b/src/mesa/main/texgetimage.c
  @@ -45,7 +45,8 @@
#include texgetimage.h
#include teximage.h
#include texstore.h
  -
  +#include format_utils.h
  +#include pixeltransfer.h
 
 
/**
  @@ -380,20 +381,10 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, 
  GLuint dimensions,
   GLenum rebaseFormat = GL_NONE;
   GLuint height = texImage-Height;
   GLuint depth = texImage-Depth;
  -   GLuint img, row;
  -   GLfloat (*rgba)[4];
  -   GLuint (*rgba_uint)[4];
  -   GLboolean tex_is_integer = 
  _mesa_is_format_integer_color(texImage-TexFormat);
  -   GLboolean tex_is_uint = _mesa_is_format_unsigned(texImage-TexFormat);
  +   GLuint img;
   GLenum texBaseFormat = 
  _mesa_get_format_base_format(texImage-TexFormat);
 
  -   /* Allocate buffer for one row of texels */
  -   rgba = malloc(4 * width * sizeof(GLfloat));
  -   rgba_uint = (GLuint (*)[4]) rgba;
  -   if (!rgba) {
  -  _mesa_error(ctx, GL_OUT_OF_MEMORY, glGetTexImage());
  -  return;
  -   }
  +   assert (depth = 1 || dimensions  2);
 
   if (texImage-TexObject-Target == GL_TEXTURE_1D_ARRAY) {
  depth = height;
  @@ -413,9 +404,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, 
  GLuint dimensions,
 texImage-_BaseFormat == GL_RGB ||
 texImage-_BaseFormat == GL_RG) 
(destBaseFormat == GL_LUMINANCE ||
  - destBaseFormat == GL_LUMINANCE_ALPHA ||
  - destBaseFormat == GL_LUMINANCE_INTEGER_EXT ||
  - destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) {
  + destBaseFormat == GL_LUMINANCE_ALPHA)) {
  /* If we're reading back an RGB(A) texture as luminance then we need
   * to return L=tex(R).  Note, that's different from glReadPixels 
  which
   * returns L=R+G+B.
  @@ -467,6 +456,22 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, 
  GLuint dimensions,
  }
   }
 
  +   /* Describe the dst format */
  +   GLboolean dst_is_integer = _mesa_is_enum_format_integer(format);
  +   uint32_t dst_format = _mesa_format_from_format_and_type(format, type);
  +   int dst_stride = _mesa_image_row_stride(ctx-Pack, width, format, 
  type);
 
 This won't build with MSVC.  Declarations cannot follow code.

Ooops! I think I have done this in a number of patches..
Noted, I'll clean these up. thanks!

 
 
  +
  +   /* Since _mesa_format_convert does not handle transferOps we need to 
  handle
  +* them before we call the function. This requires to convert to RGBA 
  float
  +* first so we can call _mesa_apply_rgba_transfer_ops. If the dst 
  format is
  +* integer we can ignore transferOps.
  +*
  +* Some source formats (Luminance) will also require to be rebased to 
  obtain
  +* the expected results and this also requires to convert to RGBA first.
  +*/
  +   assert(!transferOps || (transferOps  !dst_is_integer));
  +   bool needs_rgba = (transferOps || rebaseFormat != GL_NONE);
  +
   for (img = 0; img  depth; img++) {
  GLubyte *srcMap;
  GLint rowstride;
  @@ -475,46 +480,105 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, 
  GLuint dimensions,
  ctx-Driver.MapTextureImage(ctx, texImage, img,
  0, 0, width, height, GL_MAP_READ_BIT,
  srcMap, rowstride);
  -  if (srcMap) {
  - for (row = 0; row  height; row++) {
  -const GLubyte *src = srcMap + row * rowstride;
  -void *dest = _mesa_image_address(dimensions, ctx-Pack, 
  pixels,
  - width, height, format, type,
  - img, row, 0);
  -
  -   if (tex_is_integer) {
  -  _mesa_unpack_uint_rgba_row(texFormat, width, src, rgba_uint);
  -   if (rebaseFormat)
  -  _mesa_rebase_rgba_uint(width, rgba_uint, rebaseFormat);
  -   if (tex_is_uint) {
  -  _mesa_pack_rgba_span_from_uints(ctx, width,
  -  (GLuint (*)[4]) 
  rgba_uint,
  -  format, type, dest);
  -   } else {
  -  _mesa_pack_rgba_span_from_ints(ctx, width,
  - (GLint (*)[4])