2018-08-14 08:49:31 +00:00
|
|
|
#include <stddef.h>
|
2018-05-11 14:39:28 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "private.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
static PolyContext GL_CONTEXT;
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
PolyContext *_glGetPVRContext() {
|
2018-05-11 14:39:28 +00:00
|
|
|
return &GL_CONTEXT;
|
|
|
|
}
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
/* We can't just use the GL_CONTEXT for this state as the two
|
|
|
|
* GL states are combined, so we store them separately and then
|
|
|
|
* calculate the appropriate PVR state from them. */
|
|
|
|
static GLenum CULL_FACE = GL_BACK;
|
|
|
|
static GLenum FRONT_FACE = GL_CCW;
|
|
|
|
static GLboolean CULLING_ENABLED = GL_FALSE;
|
2018-08-22 08:24:49 +00:00
|
|
|
static GLboolean COLOR_MATERIAL_ENABLED = GL_FALSE;
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-09-12 14:04:52 +00:00
|
|
|
GLboolean LIGHTING_ENABLED = GL_FALSE;
|
2020-05-08 06:19:56 +00:00
|
|
|
|
2019-02-21 21:58:31 +00:00
|
|
|
/* Is the shared texture palette enabled? */
|
|
|
|
static GLboolean SHARED_PALETTE_ENABLED = GL_FALSE;
|
|
|
|
|
2021-05-08 13:38:55 +00:00
|
|
|
GLboolean ALPHA_TEST_ENABLED = GL_FALSE;
|
2019-03-10 17:53:58 +00:00
|
|
|
|
2020-03-05 20:04:44 +00:00
|
|
|
static GLboolean POLYGON_OFFSET_ENABLED = GL_FALSE;
|
|
|
|
|
2019-11-18 17:39:09 +00:00
|
|
|
static GLboolean NORMALIZE_ENABLED = GL_FALSE;
|
2019-03-10 17:53:58 +00:00
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
static struct {
|
|
|
|
GLint x;
|
|
|
|
GLint y;
|
|
|
|
GLsizei width;
|
|
|
|
GLsizei height;
|
|
|
|
GLboolean applied;
|
|
|
|
} SCISSOR_RECT = {
|
|
|
|
0, 0, 640, 480, false
|
|
|
|
};
|
|
|
|
|
2019-02-21 21:58:31 +00:00
|
|
|
GLboolean _glIsSharedTexturePaletteEnabled() {
|
|
|
|
return SHARED_PALETTE_ENABLED;
|
|
|
|
}
|
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
void _glApplyScissor(bool force);
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
static int _calc_pvr_face_culling() {
|
|
|
|
if(!CULLING_ENABLED) {
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_CULLING_NONE;
|
2018-05-05 19:38:55 +00:00
|
|
|
} else {
|
|
|
|
if(CULL_FACE == GL_BACK) {
|
2021-04-09 15:24:47 +00:00
|
|
|
return (FRONT_FACE == GL_CW) ? GPU_CULLING_CCW : GPU_CULLING_CW;
|
2018-05-05 19:38:55 +00:00
|
|
|
} else {
|
2021-04-09 15:24:47 +00:00
|
|
|
return (FRONT_FACE == GL_CCW) ? GPU_CULLING_CCW : GPU_CULLING_CW;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum DEPTH_FUNC = GL_LESS;
|
|
|
|
static GLboolean DEPTH_TEST_ENABLED = GL_FALSE;
|
|
|
|
|
|
|
|
static int _calc_pvr_depth_test() {
|
|
|
|
if(!DEPTH_TEST_ENABLED) {
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_ALWAYS;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
switch(DEPTH_FUNC) {
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_NEVER:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_NEVER;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_LESS:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_GREATER;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_EQUAL:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_EQUAL;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_LEQUAL:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_GEQUAL;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_GREATER:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_LESS;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_NOTEQUAL:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_NOTEQUAL;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_GEQUAL:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_LEQUAL;
|
2018-05-05 19:38:55 +00:00
|
|
|
break;
|
|
|
|
case GL_ALWAYS:
|
|
|
|
default:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_DEPTHCMP_ALWAYS;
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLenum BLEND_SFACTOR = GL_ONE;
|
|
|
|
static GLenum BLEND_DFACTOR = GL_ZERO;
|
2021-05-08 13:38:55 +00:00
|
|
|
GLboolean BLEND_ENABLED = GL_FALSE;
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2020-03-05 20:04:44 +00:00
|
|
|
static GLfloat OFFSET_FACTOR = 0.0f;
|
|
|
|
static GLfloat OFFSET_UNITS = 0.0f;
|
|
|
|
|
2019-11-18 17:39:09 +00:00
|
|
|
GLboolean _glIsNormalizeEnabled() {
|
|
|
|
return NORMALIZE_ENABLED;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
static int _calcPVRBlendFactor(GLenum factor) {
|
|
|
|
switch(factor) {
|
|
|
|
case GL_ZERO:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_ZERO;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_SRC_ALPHA:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_SRCALPHA;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_DST_COLOR:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_DESTCOLOR;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_DST_ALPHA:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_DESTALPHA;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_ONE_MINUS_DST_COLOR:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_INVDESTCOLOR;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_ONE_MINUS_SRC_ALPHA:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_INVSRCALPHA;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_ONE_MINUS_DST_ALPHA:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_INVDESTALPHA;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_ONE:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_ONE;
|
2018-05-11 14:39:28 +00:00
|
|
|
default:
|
2019-03-13 15:14:09 +00:00
|
|
|
fprintf(stderr, "Invalid blend mode: %u\n", (unsigned int) factor);
|
2021-04-09 15:24:47 +00:00
|
|
|
return GPU_BLEND_ONE;
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
static void _updatePVRBlend(PolyContext* context) {
|
2020-05-10 12:49:45 +00:00
|
|
|
if(BLEND_ENABLED || ALPHA_TEST_ENABLED) {
|
2021-04-09 15:24:47 +00:00
|
|
|
context->gen.alpha = GPU_ALPHA_ENABLE;
|
2018-05-11 14:39:28 +00:00
|
|
|
} else {
|
2021-04-09 15:24:47 +00:00
|
|
|
context->gen.alpha = GPU_ALPHA_DISABLE;
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
2019-09-06 08:35:57 +00:00
|
|
|
|
|
|
|
context->blend.src = _calcPVRBlendFactor(BLEND_SFACTOR);
|
|
|
|
context->blend.dst = _calcPVRBlendFactor(BLEND_DFACTOR);
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 15:14:09 +00:00
|
|
|
GLboolean _glCheckValidEnum(GLint param, GLint* values, const char* func) {
|
2018-08-22 08:24:49 +00:00
|
|
|
GLubyte found = 0;
|
|
|
|
while(*values != 0) {
|
|
|
|
if(*values == param) {
|
|
|
|
found++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
values++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!found) {
|
|
|
|
_glKosThrowError(GL_INVALID_ENUM, func);
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-05 20:04:44 +00:00
|
|
|
GLboolean TEXTURES_ENABLED [] = {GL_FALSE, GL_FALSE};
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
void _glUpdatePVRTextureContext(PolyContext *context, GLshort textureUnit) {
|
2019-03-03 19:06:01 +00:00
|
|
|
const TextureObject *tx1 = (textureUnit == 0) ? _glGetTexture0() : _glGetTexture1();
|
2018-08-14 08:49:31 +00:00
|
|
|
|
2019-09-06 08:35:57 +00:00
|
|
|
/* Disable all texturing to start with */
|
2021-04-09 15:24:47 +00:00
|
|
|
context->txr.enable = GPU_TEXTURE_DISABLE;
|
|
|
|
context->txr2.enable = GPU_TEXTURE_DISABLE;
|
|
|
|
context->txr2.alpha = GPU_TXRALPHA_DISABLE;
|
2019-09-06 08:35:57 +00:00
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
if(!TEXTURES_ENABLED[textureUnit] || !tx1) {
|
2018-05-11 14:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
context->txr.alpha = (BLEND_ENABLED || ALPHA_TEST_ENABLED) ? GPU_TXRALPHA_ENABLE : GPU_TXRALPHA_DISABLE;
|
2019-11-30 10:07:04 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
GLuint filter = GPU_FILTER_NEAREST;
|
2018-08-09 08:32:29 +00:00
|
|
|
GLboolean enableMipmaps = GL_FALSE;
|
|
|
|
|
|
|
|
switch(tx1->minFilter) {
|
|
|
|
case GL_NEAREST_MIPMAP_LINEAR:
|
|
|
|
case GL_NEAREST_MIPMAP_NEAREST:
|
|
|
|
case GL_LINEAR_MIPMAP_LINEAR:
|
|
|
|
case GL_LINEAR_MIPMAP_NEAREST:
|
|
|
|
enableMipmaps = GL_TRUE;
|
|
|
|
break;
|
2018-08-14 08:49:31 +00:00
|
|
|
default:
|
|
|
|
enableMipmaps = GL_FALSE;
|
|
|
|
break;
|
2018-08-09 08:32:29 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 07:34:54 +00:00
|
|
|
/* FIXME: If you disable mipmaps on a compressed mipmapped texture
|
|
|
|
* you get corruption and I don't know why, so we force mipmapping for now */
|
|
|
|
if(tx1->isCompressed && _glIsMipmapComplete(tx1)) {
|
|
|
|
enableMipmaps = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-05 20:04:44 +00:00
|
|
|
if(tx1->height != tx1->width){
|
|
|
|
enableMipmaps = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2018-08-09 08:32:29 +00:00
|
|
|
if(enableMipmaps) {
|
2021-10-25 18:04:58 +00:00
|
|
|
// FIXME: This is probably the wrong filter for this
|
|
|
|
// GL mode, but I'm not sure what's correct...
|
|
|
|
if(tx1->minFilter == GL_NEAREST_MIPMAP_LINEAR) {
|
2021-04-09 15:24:47 +00:00
|
|
|
filter = GPU_FILTER_TRILINEAR1;
|
2018-08-09 08:32:29 +00:00
|
|
|
} else if(tx1->minFilter == GL_LINEAR_MIPMAP_LINEAR) {
|
2021-04-09 15:24:47 +00:00
|
|
|
filter = GPU_FILTER_TRILINEAR2;
|
2021-10-25 18:04:58 +00:00
|
|
|
} else if(tx1->minFilter == GL_LINEAR_MIPMAP_NEAREST) {
|
2021-04-09 15:24:47 +00:00
|
|
|
filter = GPU_FILTER_BILINEAR;
|
2018-08-09 08:32:29 +00:00
|
|
|
} else {
|
2021-04-09 15:24:47 +00:00
|
|
|
filter = GPU_FILTER_NEAREST;
|
2018-08-09 08:32:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(tx1->minFilter == GL_LINEAR && tx1->magFilter == GL_LINEAR) {
|
2021-04-09 15:24:47 +00:00
|
|
|
filter = GPU_FILTER_BILINEAR;
|
2018-08-09 08:32:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
/* 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) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tx1->data) {
|
2021-04-09 15:24:47 +00:00
|
|
|
context->txr.enable = GPU_TEXTURE_ENABLE;
|
2018-08-09 08:32:29 +00:00
|
|
|
context->txr.filter = filter;
|
2018-05-11 14:39:28 +00:00
|
|
|
context->txr.width = tx1->width;
|
|
|
|
context->txr.height = tx1->height;
|
2020-03-05 20:04:44 +00:00
|
|
|
context->txr.mipmap = enableMipmaps;
|
|
|
|
context->txr.mipmap_bias = tx1->mipmap_bias;
|
2019-09-24 14:47:23 +00:00
|
|
|
|
|
|
|
if(enableMipmaps) {
|
|
|
|
context->txr.base = tx1->data;
|
|
|
|
} else {
|
|
|
|
context->txr.base = tx1->data + tx1->baseDataOffset;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
context->txr.format = tx1->color;
|
2019-03-10 11:18:56 +00:00
|
|
|
|
|
|
|
if(tx1->isPaletted) {
|
|
|
|
if(_glIsSharedTexturePaletteEnabled()) {
|
2019-03-10 20:18:11 +00:00
|
|
|
TexturePalette* palette = _glGetSharedPalette(tx1->shared_bank);
|
2021-04-09 15:24:47 +00:00
|
|
|
context->txr.format |= GPUPaletteSelect8BPP(palette->bank);
|
2019-03-10 11:18:56 +00:00
|
|
|
} else {
|
2021-04-09 15:24:47 +00:00
|
|
|
context->txr.format |= GPUPaletteSelect8BPP((tx1->palette) ? tx1->palette->bank : 0);
|
2019-03-10 11:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
context->txr.env = tx1->env;
|
2021-04-09 15:24:47 +00:00
|
|
|
context->txr.uv_flip = GPU_UVFLIP_NONE;
|
2018-05-11 14:39:28 +00:00
|
|
|
context->txr.uv_clamp = tx1->uv_clamp;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
GLboolean _glIsLightingEnabled() {
|
2018-05-12 13:05:54 +00:00
|
|
|
return LIGHTING_ENABLED;
|
|
|
|
}
|
|
|
|
|
2018-08-22 08:24:49 +00:00
|
|
|
GLboolean _glIsColorMaterialEnabled() {
|
|
|
|
return COLOR_MATERIAL_ENABLED;
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
static GLfloat CLEAR_COLOUR[3];
|
|
|
|
|
2018-09-15 10:45:38 +00:00
|
|
|
void _glInitContext() {
|
2021-04-09 15:24:47 +00:00
|
|
|
memset(&GL_CONTEXT, 0, sizeof(PolyContext));
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.list_type = GPU_LIST_OP_POLY;
|
|
|
|
GL_CONTEXT.fmt.color = GPU_CLRFMT_ARGBPACKED;
|
|
|
|
GL_CONTEXT.fmt.uv = GPU_UVFMT_32BIT;
|
|
|
|
GL_CONTEXT.gen.color_clamp = GPU_CLRCLAMP_DISABLE;
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
const VideoMode* mode = GetVideoMode();
|
|
|
|
|
|
|
|
SCISSOR_RECT.x = 0;
|
|
|
|
SCISSOR_RECT.y = 0;
|
|
|
|
SCISSOR_RECT.width = mode->width;
|
|
|
|
SCISSOR_RECT.height = mode->height;
|
|
|
|
|
2020-03-24 13:58:44 +00:00
|
|
|
glClearDepth(1.0f);
|
2018-05-05 19:38:55 +00:00
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
glDepthMask(GL_TRUE);
|
2022-01-18 21:28:07 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2018-05-11 14:39:28 +00:00
|
|
|
glFrontFace(GL_CCW);
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glClearColor(0, 0, 0, 0);
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
2018-05-20 15:37:45 +00:00
|
|
|
glDisable(GL_FOG);
|
2018-05-12 13:05:54 +00:00
|
|
|
glDisable(GL_LIGHTING);
|
2018-05-20 15:37:45 +00:00
|
|
|
|
2018-05-14 16:10:53 +00:00
|
|
|
GLubyte i;
|
|
|
|
for(i = 0; i < MAX_LIGHTS; ++i) {
|
2018-05-12 13:05:54 +00:00
|
|
|
glDisable(GL_LIGHT0 + i);
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glEnable(GLenum cap) {
|
|
|
|
switch(cap) {
|
|
|
|
case GL_TEXTURE_2D:
|
2018-08-14 08:49:31 +00:00
|
|
|
TEXTURES_ENABLED[_glGetActiveTexture()] = GL_TRUE;
|
2018-05-05 19:38:55 +00:00
|
|
|
break;
|
|
|
|
case GL_CULL_FACE: {
|
|
|
|
CULLING_ENABLED = GL_TRUE;
|
|
|
|
GL_CONTEXT.gen.culling = _calc_pvr_face_culling();
|
|
|
|
} break;
|
|
|
|
case GL_DEPTH_TEST: {
|
|
|
|
DEPTH_TEST_ENABLED = GL_TRUE;
|
|
|
|
GL_CONTEXT.depth.comparison = _calc_pvr_depth_test();
|
|
|
|
} break;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_BLEND: {
|
|
|
|
BLEND_ENABLED = GL_TRUE;
|
|
|
|
_updatePVRBlend(&GL_CONTEXT);
|
|
|
|
} break;
|
|
|
|
case GL_SCISSOR_TEST: {
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.gen.clip_mode = GPU_USERCLIP_INSIDE;
|
2021-04-14 20:38:33 +00:00
|
|
|
_glApplyScissor(false);
|
2018-05-11 14:39:28 +00:00
|
|
|
} break;
|
2018-05-12 13:05:54 +00:00
|
|
|
case GL_LIGHTING: {
|
|
|
|
LIGHTING_ENABLED = GL_TRUE;
|
|
|
|
} break;
|
2018-05-20 15:37:45 +00:00
|
|
|
case GL_FOG:
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.gen.fog_type = GPU_FOG_TABLE;
|
2018-05-20 15:37:45 +00:00
|
|
|
break;
|
2018-08-22 08:24:49 +00:00
|
|
|
case GL_COLOR_MATERIAL:
|
|
|
|
COLOR_MATERIAL_ENABLED = GL_TRUE;
|
|
|
|
break;
|
2019-03-03 18:54:25 +00:00
|
|
|
case GL_SHARED_TEXTURE_PALETTE_EXT: {
|
2019-02-21 21:58:31 +00:00
|
|
|
SHARED_PALETTE_ENABLED = GL_TRUE;
|
2019-03-03 18:54:25 +00:00
|
|
|
}
|
2019-02-21 21:58:31 +00:00
|
|
|
break;
|
2019-03-10 17:53:58 +00:00
|
|
|
case GL_ALPHA_TEST: {
|
|
|
|
ALPHA_TEST_ENABLED = GL_TRUE;
|
2020-05-10 12:49:45 +00:00
|
|
|
_updatePVRBlend(&GL_CONTEXT);
|
2019-03-10 17:53:58 +00:00
|
|
|
} break;
|
2018-05-12 13:05:54 +00:00
|
|
|
case GL_LIGHT0:
|
|
|
|
case GL_LIGHT1:
|
|
|
|
case GL_LIGHT2:
|
|
|
|
case GL_LIGHT3:
|
|
|
|
case GL_LIGHT4:
|
|
|
|
case GL_LIGHT5:
|
|
|
|
case GL_LIGHT6:
|
|
|
|
case GL_LIGHT7:
|
2020-05-08 06:19:56 +00:00
|
|
|
_glEnableLight(cap & 0xF, GL_TRUE);
|
2018-05-12 13:05:54 +00:00
|
|
|
break;
|
2018-08-01 10:32:07 +00:00
|
|
|
case GL_NEARZ_CLIPPING_KOS:
|
2019-03-03 19:06:01 +00:00
|
|
|
_glEnableClipping(GL_TRUE);
|
2018-08-01 10:32:07 +00:00
|
|
|
break;
|
2020-03-05 20:04:44 +00:00
|
|
|
case GL_POLYGON_OFFSET_POINT:
|
|
|
|
case GL_POLYGON_OFFSET_LINE:
|
|
|
|
case GL_POLYGON_OFFSET_FILL:
|
|
|
|
POLYGON_OFFSET_ENABLED = GL_TRUE;
|
|
|
|
break;
|
2019-11-18 17:39:09 +00:00
|
|
|
case GL_NORMALIZE:
|
|
|
|
NORMALIZE_ENABLED = GL_TRUE;
|
|
|
|
break;
|
2018-05-11 14:39:28 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glDisable(GLenum cap) {
|
|
|
|
switch(cap) {
|
|
|
|
case GL_TEXTURE_2D: {
|
2018-08-14 08:49:31 +00:00
|
|
|
TEXTURES_ENABLED[_glGetActiveTexture()] = GL_FALSE;
|
2018-05-05 19:38:55 +00:00
|
|
|
} break;
|
|
|
|
case GL_CULL_FACE: {
|
|
|
|
CULLING_ENABLED = GL_FALSE;
|
|
|
|
GL_CONTEXT.gen.culling = _calc_pvr_face_culling();
|
|
|
|
} break;
|
|
|
|
case GL_DEPTH_TEST: {
|
|
|
|
DEPTH_TEST_ENABLED = GL_FALSE;
|
|
|
|
GL_CONTEXT.depth.comparison = _calc_pvr_depth_test();
|
|
|
|
} break;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_BLEND:
|
|
|
|
BLEND_ENABLED = GL_FALSE;
|
|
|
|
_updatePVRBlend(&GL_CONTEXT);
|
|
|
|
break;
|
|
|
|
case GL_SCISSOR_TEST: {
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.gen.clip_mode = GPU_USERCLIP_DISABLE;
|
2018-05-11 14:39:28 +00:00
|
|
|
} break;
|
2018-05-12 13:05:54 +00:00
|
|
|
case GL_LIGHTING: {
|
|
|
|
LIGHTING_ENABLED = GL_FALSE;
|
|
|
|
} break;
|
2018-05-20 15:37:45 +00:00
|
|
|
case GL_FOG:
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.gen.fog_type = GPU_FOG_DISABLE;
|
2018-05-20 15:37:45 +00:00
|
|
|
break;
|
2018-08-22 08:24:49 +00:00
|
|
|
case GL_COLOR_MATERIAL:
|
|
|
|
COLOR_MATERIAL_ENABLED = GL_FALSE;
|
|
|
|
break;
|
2019-03-03 18:54:25 +00:00
|
|
|
case GL_SHARED_TEXTURE_PALETTE_EXT: {
|
2019-02-21 21:58:31 +00:00
|
|
|
SHARED_PALETTE_ENABLED = GL_FALSE;
|
2019-03-03 18:54:25 +00:00
|
|
|
}
|
2019-02-21 21:58:31 +00:00
|
|
|
break;
|
2019-03-10 17:53:58 +00:00
|
|
|
case GL_ALPHA_TEST: {
|
|
|
|
ALPHA_TEST_ENABLED = GL_FALSE;
|
|
|
|
} break;
|
2018-05-12 13:05:54 +00:00
|
|
|
case GL_LIGHT0:
|
|
|
|
case GL_LIGHT1:
|
|
|
|
case GL_LIGHT2:
|
|
|
|
case GL_LIGHT3:
|
|
|
|
case GL_LIGHT4:
|
|
|
|
case GL_LIGHT5:
|
|
|
|
case GL_LIGHT6:
|
|
|
|
case GL_LIGHT7:
|
2020-05-08 06:19:56 +00:00
|
|
|
_glEnableLight(cap & 0xF, GL_FALSE);
|
2018-05-12 13:05:54 +00:00
|
|
|
break;
|
2018-08-01 10:32:07 +00:00
|
|
|
case GL_NEARZ_CLIPPING_KOS:
|
2019-03-03 19:06:01 +00:00
|
|
|
_glEnableClipping(GL_FALSE);
|
2018-08-01 10:32:07 +00:00
|
|
|
break;
|
2020-03-05 20:04:44 +00:00
|
|
|
case GL_POLYGON_OFFSET_POINT:
|
|
|
|
case GL_POLYGON_OFFSET_LINE:
|
|
|
|
case GL_POLYGON_OFFSET_FILL:
|
|
|
|
POLYGON_OFFSET_ENABLED = GL_FALSE;
|
|
|
|
break;
|
2019-11-18 17:39:09 +00:00
|
|
|
case GL_NORMALIZE:
|
|
|
|
NORMALIZE_ENABLED = GL_FALSE;
|
|
|
|
break;
|
2018-05-11 14:39:28 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear Caps */
|
|
|
|
GLAPI void APIENTRY glClear(GLuint mode) {
|
2018-05-11 14:39:28 +00:00
|
|
|
if(mode & GL_COLOR_BUFFER_BIT) {
|
2021-04-09 15:24:47 +00:00
|
|
|
GPUSetBackgroundColour(CLEAR_COLOUR[0], CLEAR_COLOUR[1], CLEAR_COLOUR[2]);
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glClearColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
2018-05-11 14:39:28 +00:00
|
|
|
if(r > 1) r = 1;
|
|
|
|
if(g > 1) g = 1;
|
|
|
|
if(b > 1) b = 1;
|
|
|
|
if(a > 1) a = 1;
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
/* FIXME: The background-poly doesn't take an alpha value */
|
|
|
|
_GL_UNUSED(a);
|
|
|
|
|
|
|
|
CLEAR_COLOUR[0] = r;
|
|
|
|
CLEAR_COLOUR[1] = g;
|
|
|
|
CLEAR_COLOUR[2] = b;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Depth Testing */
|
|
|
|
GLAPI void APIENTRY glClearDepthf(GLfloat depth) {
|
2020-03-24 13:58:44 +00:00
|
|
|
glClearDepth(depth);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glClearDepth(GLfloat depth) {
|
2020-03-24 13:58:44 +00:00
|
|
|
/* We reverse because using invW means that farther Z == lower number */
|
2021-04-19 19:51:22 +00:00
|
|
|
GPUSetClearDepth(MIN(1.0f - depth, PVR_MIN_Z));
|
2019-03-10 12:19:41 +00:00
|
|
|
}
|
|
|
|
|
2019-03-10 20:05:40 +00:00
|
|
|
GLAPI void APIENTRY glDrawBuffer(GLenum mode) {
|
2020-03-05 20:04:44 +00:00
|
|
|
_GL_UNUSED(mode);
|
2019-03-10 20:05:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-10 12:19:41 +00:00
|
|
|
GLAPI void APIENTRY glReadBuffer(GLenum mode) {
|
2020-03-05 20:04:44 +00:00
|
|
|
_GL_UNUSED(mode);
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glDepthMask(GLboolean flag) {
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.depth.write = (flag == GL_TRUE) ? GPU_DEPTHWRITE_ENABLE : GPU_DEPTHWRITE_DISABLE;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glDepthFunc(GLenum func) {
|
|
|
|
DEPTH_FUNC = func;
|
|
|
|
GL_CONTEXT.depth.comparison = _calc_pvr_depth_test();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hints */
|
|
|
|
/* Currently Supported Capabilities:
|
2018-05-20 15:16:53 +00:00
|
|
|
GL_PERSPECTIVE_CORRECTION_HINT - This will Enable on the PVR */
|
2018-05-05 19:38:55 +00:00
|
|
|
GLAPI void APIENTRY glHint(GLenum target, GLenum mode) {
|
2018-05-20 15:16:53 +00:00
|
|
|
if(target == GL_PERSPECTIVE_CORRECTION_HINT && mode == GL_NICEST) {
|
|
|
|
// FIXME: enable supersampling
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 21:28:07 +00:00
|
|
|
/* Polygon Rasterization Mode */
|
|
|
|
GLAPI void APIENTRY glPolygonMode(GLenum face, GLenum mode) {
|
|
|
|
_GL_UNUSED(face);
|
|
|
|
_GL_UNUSED(mode);
|
|
|
|
}
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
/* Culling */
|
|
|
|
GLAPI void APIENTRY glFrontFace(GLenum mode) {
|
|
|
|
FRONT_FACE = mode;
|
2018-05-11 14:39:28 +00:00
|
|
|
GL_CONTEXT.gen.culling = _calc_pvr_face_culling();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glCullFace(GLenum mode) {
|
|
|
|
CULL_FACE = mode;
|
2018-05-11 14:39:28 +00:00
|
|
|
GL_CONTEXT.gen.culling = _calc_pvr_face_culling();
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-09-08 19:53:28 +00:00
|
|
|
GLenum _glGetShadeModel() {
|
2021-04-09 15:24:47 +00:00
|
|
|
return (GL_CONTEXT.gen.shading == GPU_SHADE_FLAT) ? GL_FLAT : GL_SMOOTH;
|
2018-09-08 19:53:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
/* Shading - Flat or Goraud */
|
|
|
|
GLAPI void APIENTRY glShadeModel(GLenum mode) {
|
2021-04-09 15:24:47 +00:00
|
|
|
GL_CONTEXT.gen.shading = (mode == GL_SMOOTH) ? GPU_SHADE_GOURAUD : GPU_SHADE_FLAT;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Blending */
|
|
|
|
GLAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor) {
|
2018-05-11 14:39:28 +00:00
|
|
|
BLEND_SFACTOR = sfactor;
|
|
|
|
BLEND_DFACTOR = dfactor;
|
|
|
|
_updatePVRBlend(&GL_CONTEXT);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-10 17:53:58 +00:00
|
|
|
|
|
|
|
GLAPI void APIENTRY glAlphaFunc(GLenum func, GLclampf ref) {
|
2019-03-13 15:14:09 +00:00
|
|
|
GLint validFuncs[] = {
|
2019-03-10 17:53:58 +00:00
|
|
|
GL_GREATER,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
if(_glCheckValidEnum(func, validFuncs, __func__) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLubyte val = (GLubyte)(ref * 255.0f);
|
2021-04-09 15:24:47 +00:00
|
|
|
GPUSetAlphaCutOff(val);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void glLineWidth(GLfloat width) {
|
2020-03-05 20:04:44 +00:00
|
|
|
_GL_UNUSED(width);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void glPolygonOffset(GLfloat factor, GLfloat units) {
|
2020-03-05 20:04:44 +00:00
|
|
|
OFFSET_FACTOR = factor;
|
|
|
|
OFFSET_UNITS = units;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:38:14 +00:00
|
|
|
void glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params) {
|
|
|
|
_GL_UNUSED(target);
|
|
|
|
_GL_UNUSED(pname);
|
|
|
|
_GL_UNUSED(params);
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void glGetTexParameteriv(GLenum target, GLenum pname, GLint *params) {
|
2020-03-05 20:04:44 +00:00
|
|
|
_GL_UNUSED(target);
|
|
|
|
_GL_UNUSED(pname);
|
|
|
|
_GL_UNUSED(params);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
|
2020-03-05 20:04:44 +00:00
|
|
|
_GL_UNUSED(red);
|
|
|
|
_GL_UNUSED(green);
|
|
|
|
_GL_UNUSED(blue);
|
|
|
|
_GL_UNUSED(alpha);
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
void glPixelStorei(GLenum pname, GLint param) {
|
2020-03-05 20:04:44 +00:00
|
|
|
_GL_UNUSED(pname);
|
|
|
|
_GL_UNUSED(param);
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2018-08-22 08:24:49 +00:00
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
|
|
|
|
if(SCISSOR_RECT.x == x &&
|
|
|
|
SCISSOR_RECT.y == y &&
|
|
|
|
SCISSOR_RECT.width == width &&
|
|
|
|
SCISSOR_RECT.height == height) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCISSOR_RECT.x = x;
|
|
|
|
SCISSOR_RECT.y = y;
|
|
|
|
SCISSOR_RECT.width = width;
|
|
|
|
SCISSOR_RECT.height = height;
|
|
|
|
SCISSOR_RECT.applied = false;
|
|
|
|
|
|
|
|
_glApplyScissor(false);
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
/* Setup the hardware user clip rectangle.
|
|
|
|
|
|
|
|
The minimum clip rectangle is a 32x32 area which is dependent on the tile
|
|
|
|
size use by the tile accelerator. The PVR swithes off rendering to tiles
|
|
|
|
outside or inside the defined rectangle dependant upon the 'clipmode'
|
|
|
|
bits in the polygon header.
|
|
|
|
|
|
|
|
Clip rectangles therefore must have a size that is some multiple of 32.
|
|
|
|
|
|
|
|
glScissor(0, 0, 32, 32) allows only the 'tile' in the lower left
|
|
|
|
hand corner of the screen to be modified and glScissor(0, 0, 0, 0)
|
|
|
|
disallows modification to all 'tiles' on the screen.
|
2021-04-14 20:38:33 +00:00
|
|
|
|
|
|
|
We call this in the following situations:
|
|
|
|
|
|
|
|
- glEnable(GL_SCISSOR_TEST) is called
|
|
|
|
- glScissor() is called
|
|
|
|
- After glKosSwapBuffers()
|
|
|
|
|
|
|
|
This ensures that a clip command is added to every vertex list
|
|
|
|
at the right place, either when enabling the scissor test, or
|
|
|
|
when the scissor test changes.
|
2018-05-11 14:39:28 +00:00
|
|
|
*/
|
2021-04-14 20:38:33 +00:00
|
|
|
void _glApplyScissor(bool force) {
|
|
|
|
/* Don't do anyting if clipping is disabled */
|
|
|
|
if(GL_CONTEXT.gen.clip_mode == GPU_USERCLIP_DISABLE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't apply if we already applied - nothing changed */
|
|
|
|
if(SCISSOR_RECT.applied && !force) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PVRTileClipCommand c;
|
2018-05-11 14:39:28 +00:00
|
|
|
|
|
|
|
GLint miny, maxx, maxy;
|
2021-04-09 15:24:47 +00:00
|
|
|
|
|
|
|
const VideoMode* vid_mode = GetVideoMode();
|
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
GLsizei scissor_width = MAX(MIN(SCISSOR_RECT.width, vid_mode->width), 0);
|
|
|
|
GLsizei scissor_height = MAX(MIN(SCISSOR_RECT.height, vid_mode->height), 0);
|
2018-05-11 14:39:28 +00:00
|
|
|
|
|
|
|
/* force the origin to the lower left-hand corner of the screen */
|
2021-04-14 20:38:33 +00:00
|
|
|
miny = (vid_mode->height - scissor_height) - SCISSOR_RECT.y;
|
|
|
|
maxx = (scissor_width + SCISSOR_RECT.x);
|
|
|
|
maxy = (scissor_height + miny);
|
2018-05-11 14:39:28 +00:00
|
|
|
|
|
|
|
/* load command structure while mapping screen coords to TA tiles */
|
2021-04-14 20:38:33 +00:00
|
|
|
c.flags = GPU_CMD_USERCLIP;
|
|
|
|
c.d1 = c.d2 = c.d3 = 0;
|
|
|
|
c.sx = CLAMP(SCISSOR_RECT.x / 32, 0, vid_mode->width / 32);
|
|
|
|
c.sy = CLAMP(miny / 32, 0, vid_mode->height / 32);
|
|
|
|
c.ex = CLAMP((maxx / 32) - 1, 0, vid_mode->width / 32);
|
|
|
|
c.ey = CLAMP((maxy / 32) - 1, 0, vid_mode->height / 32);
|
|
|
|
|
|
|
|
aligned_vector_push_back(&_glOpaquePolyList()->vector, &c, 1);
|
|
|
|
aligned_vector_push_back(&_glPunchThruPolyList()->vector, &c, 1);
|
|
|
|
aligned_vector_push_back(&_glTransparentPolyList()->vector, &c, 1);
|
|
|
|
|
|
|
|
SCISSOR_RECT.applied = true;
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2022-01-18 20:29:27 +00:00
|
|
|
void glStencilFunc(GLenum func, GLint ref, GLuint mask) {
|
|
|
|
_GL_UNUSED(func);
|
|
|
|
_GL_UNUSED(ref);
|
|
|
|
_GL_UNUSED(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void glStencilOp(GLenum sfail, GLenum dpfail, GLenum dppass) {
|
|
|
|
_GL_UNUSED(sfail);
|
|
|
|
_GL_UNUSED(dpfail);
|
|
|
|
_GL_UNUSED(dppass);
|
|
|
|
}
|
|
|
|
|
2018-05-12 13:39:20 +00:00
|
|
|
GLboolean APIENTRY glIsEnabled(GLenum cap) {
|
|
|
|
switch(cap) {
|
|
|
|
case GL_DEPTH_TEST:
|
|
|
|
return DEPTH_TEST_ENABLED;
|
|
|
|
case GL_SCISSOR_TEST:
|
2021-04-09 15:24:47 +00:00
|
|
|
return GL_CONTEXT.gen.clip_mode == GPU_USERCLIP_INSIDE;
|
2018-05-12 13:39:20 +00:00
|
|
|
case GL_CULL_FACE:
|
|
|
|
return CULLING_ENABLED;
|
|
|
|
case GL_LIGHTING:
|
|
|
|
return LIGHTING_ENABLED;
|
|
|
|
case GL_BLEND:
|
|
|
|
return BLEND_ENABLED;
|
2020-03-05 20:04:44 +00:00
|
|
|
case GL_POLYGON_OFFSET_POINT:
|
|
|
|
case GL_POLYGON_OFFSET_LINE:
|
|
|
|
case GL_POLYGON_OFFSET_FILL:
|
|
|
|
return POLYGON_OFFSET_ENABLED;
|
2018-05-12 13:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2018-08-07 19:46:26 +00:00
|
|
|
static GLenum COMPRESSED_FORMATS [] = {
|
|
|
|
GL_COMPRESSED_ARGB_1555_VQ_KOS,
|
|
|
|
GL_COMPRESSED_ARGB_1555_VQ_TWID_KOS,
|
|
|
|
GL_COMPRESSED_ARGB_4444_VQ_KOS,
|
|
|
|
GL_COMPRESSED_ARGB_4444_VQ_TWID_KOS,
|
|
|
|
GL_COMPRESSED_RGB_565_VQ_KOS,
|
|
|
|
GL_COMPRESSED_RGB_565_VQ_TWID_KOS
|
|
|
|
};
|
|
|
|
|
2020-03-05 20:04:44 +00:00
|
|
|
static GLuint NUM_COMPRESSED_FORMATS = sizeof(COMPRESSED_FORMATS) / sizeof(GLenum);
|
2018-08-07 19:46:26 +00:00
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
void APIENTRY glGetBooleanv(GLenum pname, GLboolean* params) {
|
2019-03-29 08:47:55 +00:00
|
|
|
GLuint enabledAttrs = *_glGetEnabledAttributes();
|
2018-08-21 15:08:06 +00:00
|
|
|
GLuint activeClientTexture = _glGetActiveClientTexture();
|
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
switch(pname) {
|
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
*params = TEXTURES_ENABLED[_glGetActiveTexture()];
|
|
|
|
break;
|
2018-08-21 15:08:06 +00:00
|
|
|
case GL_VERTEX_ARRAY:
|
|
|
|
*params = (enabledAttrs & VERTEX_ENABLED_FLAG) == VERTEX_ENABLED_FLAG;
|
|
|
|
break;
|
|
|
|
case GL_COLOR_ARRAY:
|
|
|
|
*params = (enabledAttrs & DIFFUSE_ENABLED_FLAG) == DIFFUSE_ENABLED_FLAG;
|
|
|
|
break;
|
|
|
|
case GL_NORMAL_ARRAY:
|
|
|
|
*params = (enabledAttrs & NORMAL_ENABLED_FLAG) == NORMAL_ENABLED_FLAG;
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_COORD_ARRAY: {
|
|
|
|
if(activeClientTexture == 0) {
|
|
|
|
*params = (enabledAttrs & UV_ENABLED_FLAG) == UV_ENABLED_FLAG;
|
|
|
|
} else {
|
|
|
|
*params = (enabledAttrs & ST_ENABLED_FLAG) == ST_ENABLED_FLAG;
|
|
|
|
}
|
|
|
|
} break;
|
2018-08-14 08:49:31 +00:00
|
|
|
default:
|
|
|
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-28 08:46:13 +00:00
|
|
|
void APIENTRY glGetFloatv(GLenum pname, GLfloat* params) {
|
|
|
|
switch(pname) {
|
|
|
|
case GL_PROJECTION_MATRIX:
|
2021-04-15 20:31:29 +00:00
|
|
|
MEMCPY4(params, _glGetProjectionMatrix(), sizeof(float) * 16);
|
2019-02-28 08:46:13 +00:00
|
|
|
break;
|
2019-03-10 12:30:39 +00:00
|
|
|
case GL_MODELVIEW_MATRIX:
|
2021-04-15 20:31:29 +00:00
|
|
|
MEMCPY4(params, _glGetModelViewMatrix(), sizeof(float) * 16);
|
2020-03-05 20:04:44 +00:00
|
|
|
break;
|
|
|
|
case GL_POLYGON_OFFSET_FACTOR:
|
|
|
|
*params = OFFSET_FACTOR;
|
|
|
|
break;
|
|
|
|
case GL_POLYGON_OFFSET_UNITS:
|
|
|
|
*params = OFFSET_UNITS;
|
2019-03-10 12:30:39 +00:00
|
|
|
break;
|
2019-02-28 08:46:13 +00:00
|
|
|
default:
|
2020-03-05 20:04:44 +00:00
|
|
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
2019-02-28 08:46:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 13:39:20 +00:00
|
|
|
void APIENTRY glGetIntegerv(GLenum pname, GLint *params) {
|
|
|
|
switch(pname) {
|
|
|
|
case GL_MAX_LIGHTS:
|
|
|
|
*params = MAX_LIGHTS;
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_BINDING_2D:
|
2020-02-29 09:47:58 +00:00
|
|
|
*params = (_glGetBoundTexture()) ? _glGetBoundTexture()->index : 0;
|
2018-05-12 13:39:20 +00:00
|
|
|
break;
|
2018-08-04 20:00:26 +00:00
|
|
|
case GL_DEPTH_FUNC:
|
|
|
|
*params = DEPTH_FUNC;
|
|
|
|
break;
|
|
|
|
case GL_BLEND_SRC:
|
|
|
|
*params = BLEND_SFACTOR;
|
|
|
|
break;
|
|
|
|
case GL_BLEND_DST:
|
|
|
|
*params = BLEND_DFACTOR;
|
|
|
|
break;
|
2018-08-07 07:45:24 +00:00
|
|
|
case GL_MAX_TEXTURE_SIZE:
|
|
|
|
*params = MAX_TEXTURE_SIZE;
|
|
|
|
break;
|
2018-08-07 19:46:26 +00:00
|
|
|
case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
|
|
|
|
*params = NUM_COMPRESSED_FORMATS;
|
|
|
|
break;
|
2018-08-19 20:10:42 +00:00
|
|
|
case GL_ACTIVE_TEXTURE:
|
|
|
|
*params = GL_TEXTURE0 + _glGetActiveTexture();
|
|
|
|
break;
|
2018-08-21 14:50:59 +00:00
|
|
|
case GL_CLIENT_ACTIVE_TEXTURE:
|
|
|
|
*params = GL_TEXTURE0 + _glGetActiveClientTexture();
|
|
|
|
break;
|
2018-08-07 19:46:26 +00:00
|
|
|
case GL_COMPRESSED_TEXTURE_FORMATS_ARB: {
|
|
|
|
GLuint i = 0;
|
|
|
|
for(; i < NUM_COMPRESSED_FORMATS; ++i) {
|
|
|
|
params[i] = COMPRESSED_FORMATS[i];
|
|
|
|
}
|
|
|
|
} break;
|
2021-02-20 15:10:35 +00:00
|
|
|
case GL_TEXTURE_FREE_MEMORY_ATI:
|
2021-02-19 21:28:31 +00:00
|
|
|
case GL_FREE_TEXTURE_MEMORY_KOS:
|
|
|
|
*params = _glFreeTextureMemory();
|
|
|
|
break;
|
|
|
|
case GL_USED_TEXTURE_MEMORY_KOS:
|
|
|
|
*params = _glUsedTextureMemory();
|
|
|
|
break;
|
|
|
|
case GL_FREE_CONTIGUOUS_TEXTURE_MEMORY_KOS:
|
|
|
|
*params = _glFreeContiguousTextureMemory();
|
|
|
|
break;
|
2018-05-12 13:39:20 +00:00
|
|
|
default:
|
2020-03-05 20:04:44 +00:00
|
|
|
_glKosThrowError(GL_INVALID_ENUM, __func__);
|
2018-05-12 13:39:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-19 12:43:22 +00:00
|
|
|
|
2019-03-13 15:14:09 +00:00
|
|
|
const GLubyte *glGetString(GLenum name) {
|
2018-05-19 12:43:22 +00:00
|
|
|
switch(name) {
|
|
|
|
case GL_VENDOR:
|
2019-03-13 15:14:09 +00:00
|
|
|
return (const GLubyte*) "KallistiOS / Kazade";
|
2018-05-19 12:43:22 +00:00
|
|
|
|
|
|
|
case GL_RENDERER:
|
2019-03-13 15:14:09 +00:00
|
|
|
return (const GLubyte*) "PowerVR2 CLX2 100mHz";
|
2018-05-19 12:43:22 +00:00
|
|
|
|
|
|
|
case GL_VERSION:
|
2019-03-30 07:15:50 +00:00
|
|
|
return (const GLubyte*) "1.2 (partial) - GLdc 1.1";
|
2018-05-19 12:43:22 +00:00
|
|
|
|
|
|
|
case GL_EXTENSIONS:
|
2021-02-20 15:10:35 +00:00
|
|
|
return (const GLubyte*) "GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_EXT_paletted_texture, GL_EXT_shared_texture_palette, GL_KOS_multiple_shared_palette, GL_ARB_vertex_array_bgra, GL_ARB_vertex_type_2_10_10_10_rev, GL_KOS_texture_memory_management, GL_ATI_meminfo";
|
2018-05-19 12:43:22 +00:00
|
|
|
}
|
|
|
|
|
2019-03-13 15:14:09 +00:00
|
|
|
return (const GLubyte*) "GL_KOS_ERROR: ENUM Unsupported\n";
|
2018-05-19 12:43:22 +00:00
|
|
|
}
|