Fix a number of issues with texture loading
This commit is contained in:
parent
dca991ffe3
commit
021237f258
18
GL/draw.c
18
GL/draw.c
|
@ -435,7 +435,7 @@ typedef struct {
|
||||||
|
|
||||||
#define MAX_LISTS 5
|
#define MAX_LISTS 5
|
||||||
|
|
||||||
static void push(const AlignedVector* vertices, PolyList* activePolyList, TextureObject* textureObject) {
|
static void push(const AlignedVector* vertices, PolyList* activePolyList, GLshort textureUnit) {
|
||||||
/* Copy the vertices to the active poly list */
|
/* Copy the vertices to the active poly list */
|
||||||
|
|
||||||
static GLuint LIST_COUNTER = 0;
|
static GLuint LIST_COUNTER = 0;
|
||||||
|
@ -455,7 +455,7 @@ static void push(const AlignedVector* vertices, PolyList* activePolyList, Textur
|
||||||
pvr_poly_cxt_t cxt = *getPVRContext();
|
pvr_poly_cxt_t cxt = *getPVRContext();
|
||||||
cxt.list_type = activePolyList->list_type;
|
cxt.list_type = activePolyList->list_type;
|
||||||
|
|
||||||
updatePVRTextureContext(&cxt, textureObject);
|
_glUpdatePVRTextureContext(&cxt, textureUnit);
|
||||||
|
|
||||||
pvr_poly_compile(hdr, &cxt);
|
pvr_poly_compile(hdr, &cxt);
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ
|
||||||
}
|
}
|
||||||
|
|
||||||
divide(buffer);
|
divide(buffer);
|
||||||
push(buffer, activePolyList(), getTexture0());
|
push(buffer, activePolyList(), 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Now, if multitexturing is enabled, we want to send exactly the same vertices again, except:
|
Now, if multitexturing is enabled, we want to send exactly the same vertices again, except:
|
||||||
|
@ -577,10 +577,18 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ
|
||||||
- We want to set the uv coordinates to the passed st ones
|
- We want to set the uv coordinates to the passed st ones
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
GLboolean doMultitexture;
|
||||||
|
glGetBooleanv(GL_TEXTURE_2D, &doMultitexture);
|
||||||
|
|
||||||
|
if(!doMultitexture) {
|
||||||
|
/* Multitexture actively disabled */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TextureObject* texture1 = getTexture1();
|
TextureObject* texture1 = getTexture1();
|
||||||
|
|
||||||
if(!texture1 || ((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG)) {
|
if(!texture1 || ((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG) != ST_ENABLED_FLAG)) {
|
||||||
/* Multitexture disabled */
|
/* Multitexture implicitly disabled */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,7 +615,7 @@ static void submitVertices(GLenum mode, GLsizei first, GLsizei count, GLenum typ
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
/* Send the buffer again to the transparent list */
|
/* Send the buffer again to the transparent list */
|
||||||
push(buffer, transparentPolyList(), texture1);
|
push(buffer, transparentPolyList(), 1);
|
||||||
|
|
||||||
/* Reset state */
|
/* Reset state */
|
||||||
glDepthFunc(depthFunc);
|
glDepthFunc(depthFunc);
|
||||||
|
|
|
@ -88,12 +88,16 @@ GLubyte checkImmediateModeInactive(const char* func);
|
||||||
|
|
||||||
pvr_poly_cxt_t* getPVRContext();
|
pvr_poly_cxt_t* getPVRContext();
|
||||||
GLubyte _glKosInitTextures();
|
GLubyte _glKosInitTextures();
|
||||||
void updatePVRTextureContext(pvr_poly_cxt_t* context, TextureObject* tx1);
|
|
||||||
|
void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit);
|
||||||
|
|
||||||
TextureObject* getTexture0();
|
TextureObject* getTexture0();
|
||||||
TextureObject* getTexture1();
|
TextureObject* getTexture1();
|
||||||
TextureObject* getBoundTexture();
|
TextureObject* getBoundTexture();
|
||||||
|
GLubyte _glGetActiveTexture();
|
||||||
|
|
||||||
GLboolean isBlendingEnabled();
|
GLboolean isBlendingEnabled();
|
||||||
GLboolean _glIsMipmapComplete(TextureObject* obj);
|
GLboolean _glIsMipmapComplete(const TextureObject* obj);
|
||||||
GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level);
|
GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level);
|
||||||
GLuint _glGetMipmapLevelCount(TextureObject* obj);
|
GLuint _glGetMipmapLevelCount(TextureObject* obj);
|
||||||
|
|
||||||
|
|
43
GL/state.c
43
GL/state.c
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -115,11 +116,15 @@ static void _updatePVRBlend(pvr_poly_cxt_t* context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLboolean TEXTURES_ENABLED = GL_FALSE;
|
static GLboolean TEXTURES_ENABLED [] = {GL_FALSE, GL_FALSE};
|
||||||
|
|
||||||
void updatePVRTextureContext(pvr_poly_cxt_t* context, TextureObject *tx1) {
|
void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit) {
|
||||||
if(!TEXTURES_ENABLED) {
|
const TextureObject *tx1 = (textureUnit == 0) ? getTexture0() : getTexture1();
|
||||||
context->txr2.enable = context->txr.enable = PVR_TEXTURE_DISABLE;
|
|
||||||
|
if(!TEXTURES_ENABLED[textureUnit] || !tx1) {
|
||||||
|
context->txr.enable = PVR_TEXTURE_DISABLE;
|
||||||
|
context->txr.base = 0;
|
||||||
|
context->txr.format = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +141,9 @@ void updatePVRTextureContext(pvr_poly_cxt_t* context, TextureObject *tx1) {
|
||||||
case GL_LINEAR_MIPMAP_NEAREST:
|
case GL_LINEAR_MIPMAP_NEAREST:
|
||||||
enableMipmaps = GL_TRUE;
|
enableMipmaps = GL_TRUE;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
enableMipmaps = GL_FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(enableMipmaps) {
|
if(enableMipmaps) {
|
||||||
|
@ -154,7 +162,17 @@ void updatePVRTextureContext(pvr_poly_cxt_t* context, TextureObject *tx1) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tx1) {
|
/* If we don't have complete mipmaps, and yet mipmapping was enabled, we disable texturing.
|
||||||
|
* This is effectively what standard GL does (it renders a white texture)
|
||||||
|
*/
|
||||||
|
if(!_glIsMipmapComplete(tx1) && enableMipmaps) {
|
||||||
|
context->txr.enable = PVR_TEXTURE_DISABLE;
|
||||||
|
context->txr.base = 0;
|
||||||
|
context->txr.format = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tx1->data) {
|
||||||
context->txr.enable = PVR_TEXTURE_ENABLE;
|
context->txr.enable = PVR_TEXTURE_ENABLE;
|
||||||
context->txr.filter = filter;
|
context->txr.filter = filter;
|
||||||
context->txr.mipmap = (enableMipmaps) ? PVR_MIPMAP_ENABLE : PVR_MIPMAP_DISABLE;
|
context->txr.mipmap = (enableMipmaps) ? PVR_MIPMAP_ENABLE : PVR_MIPMAP_DISABLE;
|
||||||
|
@ -217,7 +235,7 @@ void initContext() {
|
||||||
GLAPI void APIENTRY glEnable(GLenum cap) {
|
GLAPI void APIENTRY glEnable(GLenum cap) {
|
||||||
switch(cap) {
|
switch(cap) {
|
||||||
case GL_TEXTURE_2D:
|
case GL_TEXTURE_2D:
|
||||||
TEXTURES_ENABLED = GL_TRUE;
|
TEXTURES_ENABLED[_glGetActiveTexture()] = GL_TRUE;
|
||||||
break;
|
break;
|
||||||
case GL_CULL_FACE: {
|
case GL_CULL_FACE: {
|
||||||
CULLING_ENABLED = GL_TRUE;
|
CULLING_ENABLED = GL_TRUE;
|
||||||
|
@ -261,7 +279,7 @@ GLAPI void APIENTRY glEnable(GLenum cap) {
|
||||||
GLAPI void APIENTRY glDisable(GLenum cap) {
|
GLAPI void APIENTRY glDisable(GLenum cap) {
|
||||||
switch(cap) {
|
switch(cap) {
|
||||||
case GL_TEXTURE_2D: {
|
case GL_TEXTURE_2D: {
|
||||||
TEXTURES_ENABLED = GL_FALSE;
|
TEXTURES_ENABLED[_glGetActiveTexture()] = GL_FALSE;
|
||||||
} break;
|
} break;
|
||||||
case GL_CULL_FACE: {
|
case GL_CULL_FACE: {
|
||||||
CULLING_ENABLED = GL_FALSE;
|
CULLING_ENABLED = GL_FALSE;
|
||||||
|
@ -458,6 +476,17 @@ static GLenum COMPRESSED_FORMATS [] = {
|
||||||
|
|
||||||
static GLint NUM_COMPRESSED_FORMATS = sizeof(COMPRESSED_FORMATS) / sizeof(GLenum);
|
static GLint NUM_COMPRESSED_FORMATS = sizeof(COMPRESSED_FORMATS) / sizeof(GLenum);
|
||||||
|
|
||||||
|
void APIENTRY glGetBooleanv(GLenum pname, GLboolean* params) {
|
||||||
|
switch(pname) {
|
||||||
|
case GL_TEXTURE_2D:
|
||||||
|
*params = TEXTURES_ENABLED[_glGetActiveTexture()];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
||||||
|
_glKosPrintError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void APIENTRY glGetIntegerv(GLenum pname, GLint *params) {
|
void APIENTRY glGetIntegerv(GLenum pname, GLint *params) {
|
||||||
switch(pname) {
|
switch(pname) {
|
||||||
case GL_MAX_LIGHTS:
|
case GL_MAX_LIGHTS:
|
||||||
|
|
12
GL/texture.c
12
GL/texture.c
|
@ -1,5 +1,6 @@
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "../include/glext.h"
|
#include "../include/glext.h"
|
||||||
|
@ -16,6 +17,10 @@ static GLubyte ACTIVE_TEXTURE = 0;
|
||||||
|
|
||||||
static GLuint _determinePVRFormat(GLint internalFormat, GLenum type);
|
static GLuint _determinePVRFormat(GLint internalFormat, GLenum type);
|
||||||
|
|
||||||
|
GLubyte _glGetActiveTexture() {
|
||||||
|
return ACTIVE_TEXTURE;
|
||||||
|
}
|
||||||
|
|
||||||
static GLint _determineStride(GLenum format, GLenum type) {
|
static GLint _determineStride(GLenum format, GLenum type) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case GL_BYTE:
|
case GL_BYTE:
|
||||||
|
@ -178,6 +183,7 @@ void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) {
|
||||||
|
|
||||||
if(txr->data) {
|
if(txr->data) {
|
||||||
pvr_mem_free(txr->data);
|
pvr_mem_free(txr->data);
|
||||||
|
txr->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
named_array_release(&TEXTURE_OBJECTS, *textures++);
|
named_array_release(&TEXTURE_OBJECTS, *textures++);
|
||||||
|
@ -532,7 +538,7 @@ static GLboolean _isSupportedFormat(GLenum format) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLboolean _glIsMipmapComplete(TextureObject* obj) {
|
GLboolean _glIsMipmapComplete(const TextureObject* obj) {
|
||||||
if(!obj->mipmap || !obj->mipmapCount) {
|
if(!obj->mipmap || !obj->mipmapCount) {
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -628,8 +634,10 @@ void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalFormat,
|
||||||
active->color = pvr_format;
|
active->color = pvr_format;
|
||||||
/* Set the required mipmap count */
|
/* Set the required mipmap count */
|
||||||
active->mipmapCount = _glGetMipmapLevelCount(active);
|
active->mipmapCount = _glGetMipmapLevelCount(active);
|
||||||
active->data = pvr_mem_malloc(_glGetMipmapDataSize(active));
|
|
||||||
active->dataStride = sizeof(GLshort);
|
active->dataStride = sizeof(GLshort);
|
||||||
|
|
||||||
|
GLuint size = _glGetMipmapDataSize(active);
|
||||||
|
active->data = pvr_mem_malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark this level as set in the mipmap bitmask */
|
/* Mark this level as set in the mipmap bitmask */
|
||||||
|
|
|
@ -596,6 +596,7 @@ GLAPI void APIENTRY glMaterialfv(GLenum face, GLenum pname, const GLfloat *param
|
||||||
GLAPI GLuint APIENTRY glKosMipMapTexSize(GLuint width, GLuint height);
|
GLAPI GLuint APIENTRY glKosMipMapTexSize(GLuint width, GLuint height);
|
||||||
|
|
||||||
/* glGet Functions */
|
/* glGet Functions */
|
||||||
|
GLAPI void APIENTRY glGetBooleanv(GLenum pname, GLboolean* params);
|
||||||
GLAPI void APIENTRY glGetIntegerv(GLenum pname, GLint *params);
|
GLAPI void APIENTRY glGetIntegerv(GLenum pname, GLint *params);
|
||||||
GLAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat *params);
|
GLAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat *params);
|
||||||
GLAPI GLboolean APIENTRY glIsEnabled(GLenum cap);
|
GLAPI GLboolean APIENTRY glIsEnabled(GLenum cap);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user