ReactOS 0.4.15-dev-7788-g1ad9096
texobj.h File Reference
#include "types.h"
Include dependency graph for texobj.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct gl_texture_objectgl_alloc_texture_object (struct gl_shared_state *shared, GLuint name, GLuint dimensions)
 
void gl_free_texture_object (struct gl_shared_state *shared, struct gl_texture_object *t)
 
void gl_test_texture_object_completeness (struct gl_texture_object *t)
 
void gl_GenTextures (GLcontext *ctx, GLsizei n, GLuint *textures)
 
void gl_DeleteTextures (GLcontext *ctx, GLsizei n, const GLuint *textures)
 
void gl_BindTexture (GLcontext *ctx, GLenum target, GLuint texture)
 
void gl_PrioritizeTextures (GLcontext *ctx, GLsizei n, const GLuint *textures, const GLclampf *priorities)
 
GLboolean gl_AreTexturesResident (GLcontext *ctx, GLsizei n, const GLuint *textures, GLboolean *residences)
 
GLboolean gl_IsTexture (GLcontext *ctx, GLuint texture)
 

Function Documentation

◆ gl_alloc_texture_object()

struct gl_texture_object * gl_alloc_texture_object ( struct gl_shared_state shared,
GLuint  name,
GLuint  dimensions 
)

Definition at line 118 of file texobj.c.

120{
121 struct gl_texture_object *obj;
122
123 assert(dimensions >= 0 && dimensions <= 2);
124
125 obj = (struct gl_texture_object *)
126 calloc(1,sizeof(struct gl_texture_object));
127 if (obj) {
128 /* init the non-zero fields */
129 obj->Name = name;
130 obj->Dimensions = dimensions;
131 obj->WrapS = GL_REPEAT;
132 obj->WrapT = GL_REPEAT;
133 obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR;
134 obj->MagFilter = GL_LINEAR;
135 obj->MinMagThresh = 0.0F;
136 obj->Palette[0] = 255;
137 obj->Palette[1] = 255;
138 obj->Palette[2] = 255;
139 obj->Palette[3] = 255;
140 obj->PaletteSize = 1;
141 obj->PaletteIntFormat = GL_RGBA;
142 obj->PaletteFormat = GL_RGBA;
143
144 /* insert into linked list */
145 if (shared) {
146 obj->Next = shared->TexObjectList;
147 shared->TexObjectList = obj;
148 }
149
150 if (name > 0) {
151 /* insert into hash table */
152 HashInsert(shared->TexObjects, name, obj);
153 }
154 }
155 return obj;
156}
void HashInsert(struct HashTable *table, GLuint key, void *data)
Definition: hash.c:138
#define assert(x)
Definition: debug.h:53
#define GL_LINEAR
Definition: gl.h:421
#define GL_NEAREST_MIPMAP_LINEAR
Definition: gl.h:668
#define GL_RGBA
Definition: gl.h:503
#define GL_REPEAT
Definition: gl.h:679
#define calloc
Definition: rosglue.h:14
struct HashTable * TexObjects
Definition: types.h:1125
struct gl_texture_object * TexObjectList
Definition: types.h:1126
Definition: name.c:39

Referenced by alloc_proxy_textures(), alloc_shared_state(), gl_BindTexture(), and gl_GenTextures().

◆ gl_AreTexturesResident()

GLboolean gl_AreTexturesResident ( GLcontext ctx,
GLsizei  n,
const GLuint textures,
GLboolean residences 
)

Definition at line 543 of file texobj.c.

546{
547 GLboolean resident = GL_TRUE;
548 GLuint i;
549
550 if (INSIDE_BEGIN_END(ctx)) {
551 gl_error( ctx, GL_INVALID_OPERATION, "glAreTexturesResident" );
552 return GL_FALSE;
553 }
554 if (n<0) {
555 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)" );
556 return GL_FALSE;
557 }
558
559 for (i=0;i<n;i++) {
560 struct gl_texture_object *t;
561 if (texName[i]==0) {
562 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)" );
563 return GL_FALSE;
564 }
565 t = (struct gl_texture_object *)
566 HashLookup(ctx->Shared->TexObjects, texName[i]);
567 if (t) {
568 /* we consider all valid texture objects to be resident */
570 }
571 else {
572 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)" );
573 return GL_FALSE;
574 }
575 }
576 return resident;
577}
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
void * HashLookup(const struct HashTable *table, GLuint key)
Definition: hash.c:110
#define GL_TRUE
Definition: gl.h:174
#define GL_INVALID_VALUE
Definition: gl.h:695
#define GL_INVALID_OPERATION
Definition: gl.h:696
unsigned int GLuint
Definition: gl.h:159
#define GL_FALSE
Definition: gl.h:173
GLdouble GLdouble t
Definition: gl.h:2047
unsigned char GLboolean
Definition: gl.h:151
GLdouble n
Definition: glext.h:7729
const GLuint GLboolean * residences
Definition: glext.h:8098
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
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135

Referenced by init_dlist_pointers(), and init_exec_pointers().

◆ gl_BindTexture()

void gl_BindTexture ( GLcontext ctx,
GLenum  target,
GLuint  texture 
)

Definition at line 402 of file texobj.c.

403{
404 struct gl_texture_object *oldTexObj;
405 struct gl_texture_object *newTexObj;
406 struct gl_texture_object **targetPointer;
407 GLuint targetDimensions;
408
409 if (INSIDE_BEGIN_END(ctx)) {
410 gl_error( ctx, GL_INVALID_OPERATION, "glAreTexturesResident" );
411 return;
412 }
413 switch (target) {
414 case GL_TEXTURE_1D:
415 oldTexObj = ctx->Texture.Current1D;
416 targetPointer = &ctx->Texture.Current1D;
417 targetDimensions = 1;
418 break;
419 case GL_TEXTURE_2D:
420 oldTexObj = ctx->Texture.Current2D;
421 targetPointer = &ctx->Texture.Current2D;
422 targetDimensions = 2;
423 break;
424 default:
425 gl_error( ctx, GL_INVALID_ENUM, "glBindTexture" );
426 return;
427 }
428
429 if (texName==0) {
430 /* use default n-D texture */
431 switch (target) {
432 case GL_TEXTURE_1D:
433 newTexObj = ctx->Shared->Default1D;
434 break;
435 case GL_TEXTURE_2D:
436 newTexObj = ctx->Shared->Default2D;
437 break;
438 default:
439 gl_problem(ctx, "Bad target in gl_BindTexture");
440 return;
441 }
442 }
443 else {
444 newTexObj = (struct gl_texture_object *)
445 HashLookup(ctx->Shared->TexObjects, texName);
446 if (newTexObj) {
447 if (newTexObj->Dimensions == 0) {
448 /* first time bound */
449 newTexObj->Dimensions = targetDimensions;
450 }
451 else if (newTexObj->Dimensions != targetDimensions) {
452 /* wrong dimensionality */
453 gl_error( ctx, GL_INVALID_OPERATION, "glBindTextureEXT" );
454 return;
455 }
456 }
457 else {
458 /* create new texture object */
459 newTexObj = gl_alloc_texture_object(ctx->Shared, texName,
460 targetDimensions);
461 }
462 }
463
464 /* Update the Texture.Current[123]D pointer */
465 *targetPointer = newTexObj;
466
467 /* Tidy up reference counting */
468 if (*targetPointer != oldTexObj && oldTexObj->Name>0) {
469 /* decrement reference count of the prev texture object */
470 oldTexObj->RefCount--;
471 assert( oldTexObj->RefCount >= 0 );
472 }
473
474 if (newTexObj->Name>0) {
475 newTexObj->RefCount++;
476 }
477
478 /* Check if we may have to use a new triangle rasterizer */
479 if ( oldTexObj->WrapS != newTexObj->WrapS
480 || oldTexObj->WrapT != newTexObj->WrapT
481 || oldTexObj->WrapR != newTexObj->WrapR
482 || oldTexObj->MinFilter != newTexObj->MinFilter
483 || oldTexObj->MagFilter != newTexObj->MagFilter
484 || (oldTexObj->Image[0] && newTexObj->Image[0] &&
485 (oldTexObj->Image[0]->Format!=newTexObj->Image[0]->Format))
486 || !newTexObj->Complete) {
487 ctx->NewState |= NEW_RASTER_OPS;
488 }
489
490 /* If we've changed the Current[123]D texture object then update the
491 * ctx->Texture.Current pointer to point to the new texture object.
492 */
493 if (oldTexObj==ctx->Texture.Current) {
494 ctx->Texture.Current = newTexObj;
495 }
496
497 /* The current n-D texture object can never be NULL! */
498 assert(*targetPointer);
499
500 /* Pass BindTexture call to device driver */
501 if (ctx->Driver.BindTexture) {
502 (*ctx->Driver.BindTexture)( ctx, target, newTexObj );
503 }
504}
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
#define NEW_RASTER_OPS
Definition: types.h:1233
#define GL_TEXTURE_2D
Definition: gl.h:645
#define GL_TEXTURE_1D
Definition: gl.h:644
#define GL_INVALID_ENUM
Definition: gl.h:694
GLenum target
Definition: glext.h:7315
GLenum WrapS
Definition: types.h:1094
struct gl_texture_image * Image[MAX_TEXTURE_LEVELS]
Definition: types.h:1100
GLenum WrapT
Definition: types.h:1095
GLenum MinFilter
Definition: types.h:1097
GLint RefCount
Definition: types.h:1089
GLenum WrapR
Definition: types.h:1096
GLuint Dimensions
Definition: types.h:1091
GLboolean Complete
Definition: types.h:1112
GLenum MagFilter
Definition: types.h:1098
struct gl_texture_object * gl_alloc_texture_object(struct gl_shared_state *shared, GLuint name, GLuint dimensions)
Definition: texobj.c:118

Referenced by execute_list(), and init_exec_pointers().

◆ gl_DeleteTextures()

void gl_DeleteTextures ( GLcontext ctx,
GLsizei  n,
const GLuint textures 
)

Definition at line 356 of file texobj.c.

357{
358 GLuint i;
359
360 if (INSIDE_BEGIN_END(ctx)) {
361 gl_error( ctx, GL_INVALID_OPERATION, "glAreTexturesResident" );
362 return;
363 }
364
365 for (i=0;i<n;i++) {
366 struct gl_texture_object *t;
367 if (texName[i]>0) {
368 t = (struct gl_texture_object *)
369 HashLookup(ctx->Shared->TexObjects, texName[i]);
370 if (t) {
371 if (ctx->Texture.Current1D==t) {
372 /* revert to default 1-D texture */
373 ctx->Texture.Current1D = ctx->Shared->Default1D;
374 t->RefCount--;
375 assert( t->RefCount >= 0 );
376 }
377 else if (ctx->Texture.Current2D==t) {
378 /* revert to default 2-D texture */
379 ctx->Texture.Current2D = ctx->Shared->Default2D;
380 t->RefCount--;
381 assert( t->RefCount >= 0 );
382 }
383
384 /* tell device driver to delete texture */
385 if (ctx->Driver.DeleteTexture) {
386 (*ctx->Driver.DeleteTexture)( ctx, t );
387 }
388
389 if (t->RefCount==0) {
390 gl_free_texture_object(ctx->Shared, t);
391 }
392 }
393 }
394 }
395}
void gl_free_texture_object(struct gl_shared_state *shared, struct gl_texture_object *t)
Definition: texobj.c:165

Referenced by init_dlist_pointers(), and init_exec_pointers().

◆ gl_free_texture_object()

void gl_free_texture_object ( struct gl_shared_state shared,
struct gl_texture_object t 
)

Definition at line 165 of file texobj.c.

167{
168 struct gl_texture_object *tprev, *tcurr;
169
170 assert(t);
171
172 /* unlink t from the linked list */
173 if (shared) {
174 tprev = NULL;
175 tcurr = shared->TexObjectList;
176 while (tcurr) {
177 if (tcurr==t) {
178 if (tprev) {
179 tprev->Next = t->Next;
180 }
181 else {
182 shared->TexObjectList = t->Next;
183 }
184 break;
185 }
186 tprev = tcurr;
187 tcurr = tcurr->Next;
188 }
189 }
190
191 if (t->Name) {
192 /* remove from hash table */
193 HashRemove(shared->TexObjects, t->Name);
194 }
195
196 /* free texture image */
197 {
198 GLuint i;
199 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
200 if (t->Image[i]) {
201 gl_free_texture_image( t->Image[i] );
202 }
203 }
204 }
205 /* free this object */
206 free( t );
207}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define MAX_TEXTURE_LEVELS
Definition: config.h:90
void HashRemove(struct HashTable *table, GLuint key)
Definition: hash.c:176
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
struct gl_texture_object * Next
Definition: types.h:1114
void gl_free_texture_image(struct gl_texture_image *teximage)
Definition: teximage.c:338

Referenced by alloc_proxy_textures(), alloc_shared_state(), free_shared_state(), gl_DeleteTextures(), and gl_destroy_context().

◆ gl_GenTextures()

void gl_GenTextures ( GLcontext ctx,
GLsizei  n,
GLuint textures 
)

Definition at line 322 of file texobj.c.

323{
324 GLuint first, i;
325
326 if (INSIDE_BEGIN_END(ctx)) {
327 gl_error( ctx, GL_INVALID_OPERATION, "glGenTextures" );
328 return;
329 }
330 if (n<0) {
331 gl_error( ctx, GL_INVALID_VALUE, "glGenTextures" );
332 return;
333 }
334
335 first = HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
336
337 /* Return the texture names */
338 for (i=0;i<n;i++) {
339 texName[i] = first + i;
340 }
341
342 /* Allocate new, empty texture objects */
343 for (i=0;i<n;i++) {
344 GLuint name = first + i;
345 GLuint dims = 0;
346 struct gl_texture_object *newTexObj = gl_alloc_texture_object(ctx->Shared, name, dims);
347 (void)newTexObj;
348 }
349}
GLuint HashFindFreeKeyBlock(const struct HashTable *table, GLuint numKeys)
Definition: hash.c:248
const GLint * first
Definition: glext.h:5794

Referenced by init_dlist_pointers(), and init_exec_pointers().

◆ gl_IsTexture()

GLboolean gl_IsTexture ( GLcontext ctx,
GLuint  texture 
)

Definition at line 584 of file texobj.c.

585{
586 if (INSIDE_BEGIN_END(ctx)) {
587 gl_error( ctx, GL_INVALID_OPERATION, "glIsTextures" );
588 return GL_FALSE;
589 }
590 if (texture>0 && HashLookup(ctx->Shared->TexObjects, texture)) {
591 return GL_TRUE;
592 }
593 else {
594 return GL_FALSE;
595 }
596}
GLenum GLuint texture
Definition: glext.h:6295

Referenced by init_dlist_pointers(), and init_exec_pointers().

◆ gl_PrioritizeTextures()

void gl_PrioritizeTextures ( GLcontext ctx,
GLsizei  n,
const GLuint textures,
const GLclampf priorities 
)

Definition at line 511 of file texobj.c.

514{
515 GLuint i;
516
517 if (INSIDE_BEGIN_END(ctx)) {
518 gl_error( ctx, GL_INVALID_OPERATION, "glAreTexturesResident" );
519 return;
520 }
521 if (n<0) {
522 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)" );
523 return;
524 }
525
526 for (i=0;i<n;i++) {
527 struct gl_texture_object *t;
528 if (texName[i]>0) {
529 t = (struct gl_texture_object *)
530 HashLookup(ctx->Shared->TexObjects, texName[i]);
531 if (t) {
532 t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
533 }
534 }
535 }
536}
const GLuint const GLclampf * priorities
Definition: glext.h:8103
#define CLAMP(f, min, max)
Definition: tif_color.c:177

Referenced by execute_list(), and init_exec_pointers().

◆ gl_test_texture_object_completeness()

void gl_test_texture_object_completeness ( struct gl_texture_object t)

Definition at line 215 of file texobj.c.

216{
217 t->Complete = GL_TRUE; /* be optimistic */
218
219 /* Always need level zero image */
220 if (!t->Image[0] || !t->Image[0]->Data) {
221 t->Complete = GL_FALSE;
222 return;
223 }
224
225 if (t->MinFilter!=GL_NEAREST && t->MinFilter!=GL_LINEAR) {
226 /*
227 * Mipmapping: determine if we have a complete set of mipmaps
228 */
229 int i;
230
231 /* Test dimension-independent attributes */
232 for (i=1; i<MAX_TEXTURE_LEVELS; i++) {
233 if (t->Image[i]) {
234 if (!t->Image[i]->Data) {
235 t->Complete = GL_FALSE;
236 return;
237 }
238 if (t->Image[i]->Format != t->Image[0]->Format) {
239 t->Complete = GL_FALSE;
240 return;
241 }
242 if (t->Image[i]->Border != t->Image[0]->Border) {
243 t->Complete = GL_FALSE;
244 return;
245 }
246 }
247 }
248
249 /* Test things which depend on number of texture image dimensions */
250 if (t->Dimensions==1) {
251 /* Test 1-D mipmaps */
252 GLuint width = t->Image[0]->Width2;
253 for (i=1; i<MAX_TEXTURE_LEVELS; i++) {
254 if (width>1) {
255 width /= 2;
256 }
257 if (!t->Image[i]) {
258 t->Complete = GL_FALSE;
259 return;
260 }
261 if (!t->Image[i]->Data) {
262 t->Complete = GL_FALSE;
263 return;
264 }
265 if (t->Image[i]->Format != t->Image[0]->Format) {
266 t->Complete = GL_FALSE;
267 return;
268 }
269 if (t->Image[i]->Border != t->Image[0]->Border) {
270 t->Complete = GL_FALSE;
271 return;
272 }
273 if (t->Image[i]->Width2 != width ) {
274 t->Complete = GL_FALSE;
275 return;
276 }
277 if (width==1) {
278 return; /* found smallest needed mipmap, all done! */
279 }
280 }
281 }
282 else if (t->Dimensions==2) {
283 /* Test 2-D mipmaps */
284 GLuint width = t->Image[0]->Width2;
285 GLuint height = t->Image[0]->Height2;
286 for (i=1; i<MAX_TEXTURE_LEVELS; i++) {
287 if (width>1) {
288 width /= 2;
289 }
290 if (height>1) {
291 height /= 2;
292 }
293 if (!t->Image[i]) {
294 t->Complete = GL_FALSE;
295 return;
296 }
297 if (t->Image[i]->Width2 != width) {
298 t->Complete = GL_FALSE;
299 return;
300 }
301 if (t->Image[i]->Height2 != height) {
302 t->Complete = GL_FALSE;
303 return;
304 }
305 if (width==1 && height==1) {
306 return; /* found smallest needed mipmap, all done! */
307 }
308 }
309 }
310 else {
311 /* Dimensions = ??? */
312 gl_problem(NULL, "Bug in gl_test_texture_object_completeness\n");
313 }
314 }
315}
#define GL_NEAREST
Definition: gl.h:678
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546

Referenced by gl_update_texture_state().