Handle calling glBindTexture on an unknown name
This commit is contained in:
parent
e34f7e6368
commit
111d4ca83e
35
GL/texture.c
35
GL/texture.c
|
@ -170,24 +170,28 @@ GLboolean APIENTRY glIsTexture(GLuint texture) {
|
||||||
return (named_array_used(&TEXTURE_OBJECTS, texture)) ? GL_TRUE : GL_FALSE;
|
return (named_array_used(&TEXTURE_OBJECTS, texture)) ? GL_TRUE : GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _glInitializeTextureObject(TextureObject* txr, unsigned int id) {
|
||||||
|
txr->index = id;
|
||||||
|
txr->width = txr->height = 0;
|
||||||
|
txr->mipmap = 0;
|
||||||
|
txr->uv_clamp = 0;
|
||||||
|
txr->env = PVR_TXRENV_MODULATEALPHA;
|
||||||
|
txr->data = NULL;
|
||||||
|
txr->mipmapCount = 0;
|
||||||
|
txr->minFilter = GL_NEAREST;
|
||||||
|
txr->magFilter = GL_NEAREST;
|
||||||
|
txr->palette = NULL;
|
||||||
|
txr->isCompressed = GL_FALSE;
|
||||||
|
txr->isPaletted = GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
|
void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
|
||||||
TRACE();
|
TRACE();
|
||||||
|
|
||||||
while(n--) {
|
while(n--) {
|
||||||
GLuint id = 0;
|
GLuint id = 0;
|
||||||
TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id);
|
TextureObject* txr = (TextureObject*) named_array_alloc(&TEXTURE_OBJECTS, &id);
|
||||||
txr->index = id;
|
_glInitializeTextureObject(txr, id);
|
||||||
txr->width = txr->height = 0;
|
|
||||||
txr->mipmap = 0;
|
|
||||||
txr->uv_clamp = 0;
|
|
||||||
txr->env = PVR_TXRENV_MODULATEALPHA;
|
|
||||||
txr->data = NULL;
|
|
||||||
txr->mipmapCount = 0;
|
|
||||||
txr->minFilter = GL_NEAREST;
|
|
||||||
txr->magFilter = GL_NEAREST;
|
|
||||||
txr->palette = NULL;
|
|
||||||
txr->isCompressed = GL_FALSE;
|
|
||||||
txr->isPaletted = GL_FALSE;
|
|
||||||
|
|
||||||
*textures = id;
|
*textures = id;
|
||||||
|
|
||||||
|
@ -236,6 +240,13 @@ void APIENTRY glBindTexture(GLenum target, GLuint texture) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If this didn't come from glGenTextures, then we should initialize the
|
||||||
|
* texture the first time it's bound */
|
||||||
|
if(!named_array_used(&TEXTURE_OBJECTS, texture)) {
|
||||||
|
TextureObject* txr = named_array_reserve(&TEXTURE_OBJECTS, texture);
|
||||||
|
_glInitializeTextureObject(txr, texture);
|
||||||
|
}
|
||||||
|
|
||||||
if(texture) {
|
if(texture) {
|
||||||
TEXTURE_UNITS[ACTIVE_TEXTURE] = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture);
|
TEXTURE_UNITS[ACTIVE_TEXTURE] = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, texture);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
@ -57,6 +58,23 @@ void* named_array_alloc(NamedArray* array, unsigned int* new_id) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* named_array_reserve(NamedArray* array, unsigned int id) {
|
||||||
|
if(!named_array_used(array, id)) {
|
||||||
|
unsigned int j = id % 8;
|
||||||
|
unsigned int i = (id - j) / 8;
|
||||||
|
|
||||||
|
assert(!named_array_used(array, id));
|
||||||
|
array->used_markers[i] |= (unsigned char) 1 << j;
|
||||||
|
assert(named_array_used(array, id));
|
||||||
|
|
||||||
|
unsigned char* ptr = &array->elements[(id - 1) * array->element_size];
|
||||||
|
memset(ptr, 0, array->element_size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return named_array_get(array, id);
|
||||||
|
}
|
||||||
|
|
||||||
void named_array_release(NamedArray* array, unsigned int new_id) {
|
void named_array_release(NamedArray* array, unsigned int new_id) {
|
||||||
new_id--;
|
new_id--;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,10 @@ typedef struct {
|
||||||
|
|
||||||
void named_array_init(NamedArray* array, unsigned int element_size, unsigned int max_elements);
|
void named_array_init(NamedArray* array, unsigned int element_size, unsigned int max_elements);
|
||||||
char named_array_used(NamedArray* array, unsigned int id);
|
char named_array_used(NamedArray* array, unsigned int id);
|
||||||
|
|
||||||
void* named_array_alloc(NamedArray* array, unsigned int* new_id);
|
void* named_array_alloc(NamedArray* array, unsigned int* new_id);
|
||||||
|
void* named_array_reserve(NamedArray* array, unsigned int id);
|
||||||
|
|
||||||
void named_array_release(NamedArray* array, unsigned int new_id);
|
void named_array_release(NamedArray* array, unsigned int new_id);
|
||||||
void* named_array_get(NamedArray* array, unsigned int id);
|
void* named_array_get(NamedArray* array, unsigned int id);
|
||||||
void named_array_cleanup(NamedArray* array);
|
void named_array_cleanup(NamedArray* array);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user