Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / mesa / state_tracker / st_cb_get.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * glGet functions
31 *
32 * \author Brian Paul
33 */
34
35 #include "main/imports.h"
36 #include "main/context.h"
37
38 #include "pipe/p_defines.h"
39
40 #include "st_cb_fbo.h"
41 #include "st_cb_get.h"
42
43
44
45 /**
46 * Examine the current color read buffer format to determine
47 * which GL pixel format/type combo is the best match.
48 */
49 static void
50 get_preferred_read_format_type(GLcontext *ctx, GLint *format, GLint *type)
51 {
52 struct gl_framebuffer *fb = ctx->ReadBuffer;
53 struct st_renderbuffer *strb = st_renderbuffer(fb->_ColorReadBuffer);
54
55 /* defaults */
56 *format = ctx->Const.ColorReadFormat;
57 *type = ctx->Const.ColorReadType;
58
59 if (strb) {
60 /* XXX could add more cases here... */
61 if (strb->format == PIPE_FORMAT_A8R8G8B8_UNORM) {
62 *format = GL_BGRA;
63 if (_mesa_little_endian())
64 *type = GL_UNSIGNED_INT_8_8_8_8_REV;
65 else
66 *type = GL_UNSIGNED_INT_8_8_8_8;
67 }
68 }
69 }
70
71
72 /**
73 * We only intercept the OES preferred ReadPixels format/type.
74 * Everything else goes to the default _mesa_GetIntegerv.
75 */
76 static GLboolean
77 st_GetIntegerv(GLcontext *ctx, GLenum pname, GLint *params)
78 {
79 GLint dummy;
80
81 switch (pname) {
82 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
83 get_preferred_read_format_type(ctx, &dummy, params);
84 return GL_TRUE;
85 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
86 get_preferred_read_format_type(ctx, params, &dummy);
87 return GL_TRUE;
88 default:
89 return GL_FALSE;
90 }
91 }
92
93
94 void st_init_get_functions(struct dd_function_table *functions)
95 {
96 functions->GetIntegerv = st_GetIntegerv;
97 }