-/* $Id: texobj.c,v 1.16 2000/03/27 17:55:19 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "all.h"
#else
#include "glheader.h"
+#include "colortab.h"
#include "context.h"
#include "enums.h"
#include "hash.h"
* table.
* Input: shared - the shared GL state structure to contain the texture object
* name - integer name for the texture object
- * dimensions - either 1, 2 or 3
+ * dimensions - either 1, 2, 3 or 6 (cube map)
* Return: pointer to new texture object
*/
struct gl_texture_object *
{
struct gl_texture_object *obj;
- ASSERT(dimensions <= 3);
+ ASSERT(dimensions <= 3 || dimensions == 6);
obj = CALLOC_STRUCT(gl_texture_object);
obj->BaseLevel = 0;
obj->MaxLevel = 1000;
obj->MinMagThresh = 0.0F;
- obj->Palette.Table[0] = 255;
- obj->Palette.Table[1] = 255;
- obj->Palette.Table[2] = 255;
- obj->Palette.Table[3] = 255;
- obj->Palette.Size = 1;
- obj->Palette.IntFormat = GL_RGBA;
- obj->Palette.Format = GL_RGBA;
+ _mesa_init_colortable(&obj->Palette);
/* insert into linked list */
if (shared) {
_mesa_HashRemove(shared->TexObjects, t->Name);
}
- /* free texture image */
+ _mesa_free_colortable_data(&t->Palette);
+
+ /* free texture images */
{
GLuint i;
for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
* Examine a texture object to determine if it is complete or not.
* The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly.
*/
-void gl_test_texture_object_completeness( const GLcontext *ctx, struct gl_texture_object *t )
+void
+_mesa_test_texobj_completeness( const GLcontext *ctx,
+ struct gl_texture_object *t )
{
t->Complete = GL_TRUE; /* be optimistic */
/* Always need level zero image */
- if (!t->Image[0] || !t->Image[0]->Data) {
+ if (!t->Image[0]) {
t->Complete = GL_FALSE;
return;
}
if (t->Dimensions==1) {
t->P = t->Image[0]->WidthLog2;
}
- else if (t->Dimensions==2) {
+ else if (t->Dimensions == 2 || t->Dimensions == 6) {
t->P = MAX2(t->Image[0]->WidthLog2, t->Image[0]->HeightLog2);
}
else if (t->Dimensions==3) {
/* Test dimension-independent attributes */
for (i = minLevel; i <= maxLevel; i++) {
if (t->Image[i]) {
- if (!t->Image[i]->Data) {
- t->Complete = GL_FALSE;
- return;
- }
if (t->Image[i]->Format != t->Image[0]->Format) {
t->Complete = GL_FALSE;
return;
t->Complete = GL_FALSE;
return;
}
- if (!t->Image[i]->Data) {
- t->Complete = GL_FALSE;
- return;
- }
if (t->Image[i]->Width2 != width ) {
t->Complete = GL_FALSE;
return;
switch (target) {
case GL_TEXTURE_1D:
dim = 1;
+ oldTexObj = texUnit->CurrentD[1];
break;
case GL_TEXTURE_2D:
dim = 2;
+ oldTexObj = texUnit->CurrentD[2];
break;
case GL_TEXTURE_3D:
dim = 3;
+ oldTexObj = texUnit->CurrentD[3];
break;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ if (ctx->Extensions.HaveTextureCubeMap) {
+ dim = 6;
+ oldTexObj = texUnit->CurrentCubeMap;
+ break;
+ }
+ /* fallthrough */
default:
gl_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
return;
}
- oldTexObj = texUnit->CurrentD[dim];
-
if (oldTexObj->Name == texName)
return;
- if (texName == 0)
- newTexObj = ctx->Shared->DefaultD[dim];
+ if (texName == 0) {
+ if (target == GL_TEXTURE_CUBE_MAP_ARB)
+ newTexObj = ctx->Shared->DefaultCubeMap;
+ else
+ newTexObj = ctx->Shared->DefaultD[dim];
+ }
else {
struct _mesa_HashTable *hash = ctx->Shared->TexObjects;
newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName);
newTexObj->RefCount++;
- texUnit->CurrentD[dim] = newTexObj;
+ switch (target) {
+ case GL_TEXTURE_1D:
+ texUnit->CurrentD[1] = newTexObj;
+ break;
+ case GL_TEXTURE_2D:
+ texUnit->CurrentD[2] = newTexObj;
+ break;
+ case GL_TEXTURE_3D:
+ texUnit->CurrentD[3] = newTexObj;
+ break;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ texUnit->CurrentCubeMap = newTexObj;
+ break;
+ default:
+ gl_problem(ctx, "bad target in BindTexture");
+ }
/* If we've changed the CurrentD[123] texture object then update the
* ctx->Texture.Current pointer to point to the new texture object.