ReactOS  0.4.13-dev-259-g5ca9c9c
colortab.c
Go to the documentation of this file.
1 /* $Id: colortab.c,v 1.6 1997/10/16 02:26:18 brianp Exp $ */
2 
3 /*
4  * Mesa 3-D graphics library
5  * Version: 2.5
6  * Copyright (C) 1995-1997 Brian Paul
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 
23 
24 /*
25  * $Log: colortab.c,v $
26  * Revision 1.6 1997/10/16 02:26:18 brianp
27  * call Driver.UpdateTexturePalette(ctx,NULL) when shared palette changed
28  *
29  * Revision 1.5 1997/10/16 01:59:08 brianp
30  * added GL_EXT_shared_texture_palette extension
31  *
32  * Revision 1.4 1997/10/15 23:37:05 brianp
33  * removed dirty flag stuff
34  *
35  * Revision 1.3 1997/10/13 23:50:03 brianp
36  * added call to Driver.UpdateTexturePalette
37  *
38  * Revision 1.2 1997/09/29 23:27:44 brianp
39  * updated for new device driver texture functions
40  *
41  * Revision 1.1 1997/09/27 00:12:46 brianp
42  * Initial revision
43  *
44  */
45 
46 
47 #ifdef PC_HEADER
48 #include "all.h"
49 #else
50 #include "colortab.h"
51 #include "context.h"
52 #include "macros.h"
53 #endif
54 
55 
56 
57 /*
58  * Return GL_TRUE if k is a power of two, else return GL_FALSE.
59  */
61 {
62  GLint i, m = 1;
63  for (i=0; i<32; i++) {
64  if (k == m)
65  return GL_TRUE;
66  m = m << 1;
67  }
68  return GL_FALSE;
69 }
70 
71 
73 {
74  switch (format) {
75  case GL_ALPHA:
76  case GL_ALPHA4:
77  case GL_ALPHA8:
78  case GL_ALPHA12:
79  case GL_ALPHA16:
80  return GL_ALPHA;
81  case 1:
82  case GL_LUMINANCE:
83  case GL_LUMINANCE4:
84  case GL_LUMINANCE8:
85  case GL_LUMINANCE12:
86  case GL_LUMINANCE16:
87  return GL_LUMINANCE;
88  case 2:
89  case GL_LUMINANCE_ALPHA:
96  return GL_LUMINANCE_ALPHA;
97  case GL_INTENSITY:
98  case GL_INTENSITY4:
99  case GL_INTENSITY8:
100  case GL_INTENSITY12:
101  case GL_INTENSITY16:
102  return GL_INTENSITY;
103  case 3:
104  case GL_RGB:
105  case GL_R3_G3_B2:
106  case GL_RGB4:
107  case GL_RGB5:
108  case GL_RGB8:
109  case GL_RGB10:
110  case GL_RGB12:
111  case GL_RGB16:
112  return GL_RGB;
113  case 4:
114  case GL_RGBA:
115  case GL_RGBA2:
116  case GL_RGBA4:
117  case GL_RGB5_A1:
118  case GL_RGBA8:
119  case GL_RGB10_A2:
120  case GL_RGBA12:
121  case GL_RGBA16:
122  return GL_RGBA;
123  default:
124  return -1; /* error */
125  }
126 }
127 
128 
131 {
132  struct gl_texture_object *texObj;
134 
135  if (INSIDE_BEGIN_END(ctx)) {
136  gl_error( ctx, GL_INVALID_OPERATION, "glGetBooleanv" );
137  return;
138  }
139 
140  switch (target) {
141  case GL_TEXTURE_1D:
142  texObj = ctx->Texture.Current1D;
143  break;
144  case GL_TEXTURE_2D:
145  texObj = ctx->Texture.Current2D;
146  break;
147  case GL_PROXY_TEXTURE_1D:
148  texObj = ctx->Texture.Proxy1D;
149  proxy = GL_TRUE;
150  break;
151  case GL_PROXY_TEXTURE_2D:
152  texObj = ctx->Texture.Proxy2D;
153  proxy = GL_TRUE;
154  break;
155  default:
156  gl_error(ctx, GL_INVALID_ENUM, "glColorTableEXT(target)");
157  return;
158  }
159 
160  /* internalformat = just like glTexImage */
161 
162  if (table->Width < 1 || table->Width > MAX_TEXTURE_PALETTE_SIZE
163  || !power_of_two(table->Width)) {
164  gl_error(ctx, GL_INVALID_VALUE, "glColorTableEXT(width)");
165  if (proxy) {
166  texObj->PaletteSize = 0;
167  texObj->PaletteIntFormat = 0;
168  texObj->PaletteFormat = 0;
169  }
170  return;
171  }
172 
173  /* per-texture object palette */
174  texObj->PaletteSize = table->Width;
177  if (!proxy) {
178  MEMCPY(texObj->Palette, table->Data, table->Width*table->Components);
179  if (ctx->Driver.UpdateTexturePalette) {
180  (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
181  }
182  }
183 }
184 
185 
186 
188  GLsizei start, struct gl_image *data )
189 {
190  /* XXX TODO */
191  gl_problem(ctx, "glColorSubTableEXT not implemented");
192 }
193 
194 
195 
197  GLenum type, GLvoid *table )
198 {
199  if (INSIDE_BEGIN_END(ctx)) {
200  gl_error( ctx, GL_INVALID_OPERATION, "glGetBooleanv" );
201  return;
202  }
203 
204  switch (target) {
205  case GL_TEXTURE_1D:
206  break;
207  case GL_TEXTURE_2D:
208  break;
209  case GL_TEXTURE_3D_EXT:
210  break;
211  default:
212  gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableEXT(target)");
213  return;
214  }
215 
216  gl_problem(ctx, "glGetColorTableEXT not implemented!");
217 }
218 
219 
220 
223 {
224  GLint iparams[10];
225 
226  gl_GetColorTableParameteriv( ctx, target, pname, iparams );
227  *params = (GLfloat) iparams[0];
228 }
229 
230 
231 
234 {
235  struct gl_texture_object *texObj;
236 
237  if (INSIDE_BEGIN_END(ctx)) {
238  gl_error( ctx, GL_INVALID_OPERATION, "glGetColorTableParameter" );
239  return;
240  }
241 
242  switch (target) {
243  case GL_TEXTURE_1D:
244  texObj = ctx->Texture.Current1D;
245  break;
246  case GL_TEXTURE_2D:
247  texObj = ctx->Texture.Current2D;
248  break;
249  default:
250  gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
251  return;
252  }
253 
254  switch (pname) {
256  if (texObj)
257  *params = texObj->PaletteIntFormat;
258  break;
260  if (texObj)
261  *params = texObj->PaletteSize;
262  break;
264  *params = 8;
265  break;
267  *params = 8;
268  break;
270  *params = 8;
271  break;
273  *params = 8;
274  break;
276  *params = 8;
277  break;
279  *params = 8;
280  break;
281  default:
282  gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter" );
283  return;
284  }
285 }
286 
287 
#define GL_INTENSITY8
Definition: gl.h:749
void gl_GetColorTable(GLcontext *ctx, GLenum target, GLenum format, GLenum type, GLvoid *table)
Definition: colortab.c:196
#define GL_LUMINANCE12_ALPHA4
Definition: gl.h:744
#define GL_TEXTURE_3D_EXT
Definition: glext.h:2471
GLubyte Palette[MAX_TEXTURE_PALETTE_SIZE *4]
Definition: types.h:1103
int proxy
Definition: main.c:67
#define GL_PROXY_TEXTURE_2D
Definition: gl.h:727
#define GL_INTENSITY4
Definition: gl.h:748
#define MAX_TEXTURE_PALETTE_SIZE
Definition: config.h:122
#define GL_FALSE
Definition: gl.h:173
#define GL_ALPHA
Definition: gl.h:483
void gl_ColorTable(GLcontext *ctx, GLenum target, GLenum internalFormat, struct gl_image *table)
Definition: colortab.c:129
#define GL_RGB8
Definition: gl.h:755
#define GL_LUMINANCE4_ALPHA4
Definition: gl.h:741
#define GL_RGB16
Definition: gl.h:758
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define GL_ALPHA4
Definition: gl.h:733
#define GL_RGB5
Definition: gl.h:754
#define GL_LUMINANCE6_ALPHA2
Definition: gl.h:742
#define GL_COLOR_TABLE_RED_SIZE_EXT
Definition: colortab.h:40
#define GL_RGBA4
Definition: gl.h:760
#define GL_RGB12
Definition: gl.h:757
static GLint decode_internal_format(GLint format)
Definition: colortab.c:72
const GLfloat * m
Definition: glext.h:10848
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define GL_RGB4
Definition: gl.h:753
#define GL_ALPHA12
Definition: gl.h:735
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
#define GL_INTENSITY16
Definition: gl.h:751
GLenum pname
Definition: glext.h:5645
#define GL_LUMINANCE4
Definition: gl.h:737
struct dd_function_table Driver
Definition: types.h:1276
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static GLboolean power_of_two(GLint k)
Definition: colortab.c:60
GLenum const GLfloat * params
Definition: glext.h:5645
#define GL_TEXTURE_1D
Definition: gl.h:644
int GLsizei
Definition: gl.h:160
unsigned char GLboolean
Definition: gl.h:151
#define GL_LUMINANCE8_ALPHA8
Definition: gl.h:743
#define GL_COLOR_TABLE_BLUE_SIZE_EXT
Definition: colortab.h:42
#define GL_LUMINANCE8
Definition: gl.h:738
#define GL_LUMINANCE16_ALPHA16
Definition: gl.h:746
GLenum internalFormat
Definition: glext.h:8404
struct gl_texture_attrib Texture
Definition: types.h:1334
void gl_GetColorTableParameteriv(GLcontext *ctx, GLenum target, GLenum pname, GLint *params)
Definition: colortab.c:232
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
#define GL_PROXY_TEXTURE_1D
Definition: gl.h:726
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
#define GL_RGB10
Definition: gl.h:756
#define GL_COLOR_TABLE_WIDTH_EXT
Definition: colortab.h:39
GLenum PaletteFormat
Definition: types.h:1106
GLenum PaletteIntFormat
Definition: types.h:1105
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define GL_RGB
Definition: gl.h:502
#define GL_RGBA8
Definition: gl.h:762
#define GL_INVALID_VALUE
Definition: gl.h:695
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_LUMINANCE12_ALPHA12
Definition: gl.h:745
void gl_ColorSubTable(GLcontext *ctx, GLenum target, GLsizei start, struct gl_image *data)
Definition: colortab.c:187
unsigned int GLenum
Definition: gl.h:150
#define GL_LUMINANCE12
Definition: gl.h:739
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
#define GL_RGB10_A2
Definition: gl.h:763
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
#define GL_LUMINANCE
Definition: gl.h:484
#define GL_COLOR_TABLE_GREEN_SIZE_EXT
Definition: colortab.h:41
GLuint start
Definition: gl.h:1545
#define GL_TRUE
Definition: gl.h:174
#define GL_COLOR_TABLE_ALPHA_SIZE_EXT
Definition: colortab.h:43
#define GL_R3_G3_B2
Definition: gl.h:752
#define GL_INVALID_ENUM
Definition: gl.h:694
#define GL_TEXTURE_2D
Definition: gl.h:645
#define GL_LUMINANCE16
Definition: gl.h:740
float GLfloat
Definition: gl.h:161
void gl_GetColorTableParameterfv(GLcontext *ctx, GLenum target, GLenum pname, GLfloat *params)
Definition: colortab.c:221
GLenum target
Definition: glext.h:7315
int GLint
Definition: gl.h:156
#define GL_COLOR_TABLE_FORMAT_EXT
Definition: colortab.h:38
#define GL_RGBA
Definition: gl.h:503
#define GL_INTENSITY12
Definition: gl.h:750
#define GL_RGBA12
Definition: gl.h:764
#define GL_ALPHA16
Definition: gl.h:736
#define GL_RGBA2
Definition: gl.h:759
#define GL_INTENSITY
Definition: gl.h:747
int k
Definition: mpi.c:3369
#define GL_RGBA16
Definition: gl.h:765
GLuint PaletteSize
Definition: types.h:1104
#define GL_COLOR_TABLE_INTENSITY_SIZE_EXT
Definition: colortab.h:45
#define GL_ALPHA8
Definition: gl.h:734
#define GL_RGB5_A1
Definition: gl.h:761
#define GL_COLOR_TABLE_LUMINANCE_SIZE_EXT
Definition: colortab.h:44