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
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
|
|
|
|
static struct {
|
|
|
|
GLboolean is_dirty;
|
|
|
|
|
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. */
|
2023-03-07 10:19:09 +00:00
|
|
|
GLenum depth_func;
|
|
|
|
GLboolean depth_test_enabled;
|
|
|
|
GLenum cull_face;
|
|
|
|
GLenum front_face;
|
|
|
|
GLboolean culling_enabled;
|
|
|
|
GLboolean color_material_enabled;
|
|
|
|
GLboolean znear_clipping_enabled;
|
|
|
|
GLboolean lighting_enabled;
|
|
|
|
GLboolean shared_palette_enabled;
|
|
|
|
GLboolean alpha_test_enabled;
|
|
|
|
GLboolean polygon_offset_enabled;
|
2023-03-07 21:27:48 +00:00
|
|
|
GLboolean normalize_enabled;
|
|
|
|
GLboolean scissor_test_enabled;
|
|
|
|
GLboolean fog_enabled;
|
|
|
|
GLboolean depth_mask_enabled;
|
2023-03-07 10:19:09 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
GLint x;
|
|
|
|
GLint y;
|
|
|
|
GLsizei width;
|
|
|
|
GLsizei height;
|
|
|
|
GLboolean applied;
|
|
|
|
} scissor_rect;
|
|
|
|
|
|
|
|
GLenum blend_sfactor;
|
|
|
|
GLenum blend_dfactor;
|
|
|
|
GLboolean blend_enabled;
|
|
|
|
GLfloat offset_factor;
|
|
|
|
GLfloat offset_units;
|
|
|
|
|
|
|
|
GLfloat scene_ambient[4];
|
|
|
|
GLboolean viewer_in_eye_coords;
|
|
|
|
GLenum color_control;
|
|
|
|
GLenum color_material_mode;
|
|
|
|
GLenum color_material_mask;
|
|
|
|
|
|
|
|
LightSource lights[MAX_GLDC_LIGHTS];
|
|
|
|
GLuint enabled_light_count;
|
|
|
|
Material material;
|
2023-03-07 21:27:48 +00:00
|
|
|
|
|
|
|
GLenum shade_model;
|
2023-03-07 10:19:09 +00:00
|
|
|
} GPUState = {
|
2023-03-07 21:27:48 +00:00
|
|
|
.is_dirty = GL_TRUE,
|
|
|
|
.depth_func = GL_LESS,
|
|
|
|
.depth_test_enabled = GL_FALSE,
|
|
|
|
.cull_face = GL_BACK,
|
|
|
|
.front_face = GL_CCW,
|
|
|
|
.culling_enabled = GL_FALSE,
|
|
|
|
.color_material_enabled = GL_FALSE,
|
|
|
|
.znear_clipping_enabled = GL_TRUE,
|
|
|
|
.lighting_enabled = GL_FALSE,
|
|
|
|
.shared_palette_enabled = GL_FALSE,
|
|
|
|
.alpha_test_enabled = GL_FALSE,
|
|
|
|
.polygon_offset_enabled = GL_FALSE,
|
|
|
|
.normalize_enabled = GL_FALSE,
|
|
|
|
.scissor_test_enabled = GL_FALSE,
|
|
|
|
.fog_enabled = GL_FALSE,
|
|
|
|
.depth_mask_enabled = GL_FALSE,
|
|
|
|
.scissor_rect = {0, 0, 640, 480, false},
|
|
|
|
.blend_sfactor = GL_ONE,
|
|
|
|
.blend_dfactor = GL_ZERO,
|
|
|
|
.blend_enabled = GL_FALSE,
|
|
|
|
.offset_factor = 0.0f,
|
|
|
|
.offset_units = 0.0f,
|
|
|
|
.scene_ambient = {0.2f, 0.2f, 0.2f, 1.0f},
|
|
|
|
.viewer_in_eye_coords = GL_TRUE,
|
|
|
|
.color_control = GL_SINGLE_COLOR,
|
|
|
|
.color_material_mode = GL_AMBIENT_AND_DIFFUSE,
|
|
|
|
.color_material_mask = AMBIENT_MASK | DIFFUSE_MASK,
|
|
|
|
.lights = {0},
|
|
|
|
.enabled_light_count = 0,
|
|
|
|
.material = {0},
|
|
|
|
.shade_model = GL_SMOOTH
|
2023-03-07 10:19:09 +00:00
|
|
|
};
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
void _glGPUStateMarkClean() {
|
|
|
|
GPUState.is_dirty = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2023-03-17 20:40:45 +00:00
|
|
|
void _glGPUStateMarkDirty() {
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
GLboolean _glGPUStateIsDirty() {
|
|
|
|
return GPUState.is_dirty;
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
Material* _glActiveMaterial() {
|
|
|
|
return &GPUState.material;
|
|
|
|
}
|
2022-06-13 19:16:37 +00:00
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
LightSource* _glLightAt(GLuint i) {
|
|
|
|
assert(i < MAX_GLDC_LIGHTS);
|
|
|
|
return &GPUState.lights[i];
|
|
|
|
}
|
2020-05-08 06:19:56 +00:00
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
void _glEnableLight(GLubyte light, GLboolean value) {
|
|
|
|
GPUState.lights[light].isEnabled = value;
|
|
|
|
}
|
2019-02-21 21:58:31 +00:00
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
GLboolean _glIsDepthTestEnabled() {
|
|
|
|
return GPUState.depth_test_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _glGetDepthFunc() {
|
|
|
|
return GPUState.depth_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean _glIsDepthWriteEnabled() {
|
|
|
|
return GPUState.depth_mask_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _glGetShadeModel() {
|
|
|
|
return GPUState.shade_model;
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GLuint _glEnabledLightCount() {
|
|
|
|
return GPUState.enabled_light_count;
|
|
|
|
}
|
2019-03-10 17:53:58 +00:00
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GLfloat* _glLightModelSceneAmbient() {
|
|
|
|
return GPUState.scene_ambient;
|
|
|
|
}
|
2020-03-05 20:04:44 +00:00
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GLboolean _glIsBlendingEnabled() {
|
|
|
|
return GPUState.blend_enabled;
|
|
|
|
}
|
2019-03-10 17:53:58 +00:00
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GLboolean _glIsAlphaTestEnabled() {
|
|
|
|
return GPUState.alpha_test_enabled;
|
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
GLboolean _glIsCullingEnabled() {
|
|
|
|
return GPUState.culling_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _glGetCullFace() {
|
|
|
|
return GPUState.cull_face;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _glGetFrontFace() {
|
|
|
|
return GPUState.front_face;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean _glIsFogEnabled() {
|
|
|
|
return GPUState.fog_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean _glIsScissorTestEnabled() {
|
|
|
|
return GPUState.scissor_test_enabled;
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
void _glRecalcEnabledLights() {
|
|
|
|
GPUState.enabled_light_count = 0;
|
2023-03-17 20:40:45 +00:00
|
|
|
for(GLubyte i = 0; i < MAX_GLDC_LIGHTS; ++i) {
|
2023-03-07 10:19:09 +00:00
|
|
|
if(_glLightAt(i)->isEnabled) {
|
|
|
|
GPUState.enabled_light_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glSetLightModelViewerInEyeCoordinates(GLboolean v) {
|
|
|
|
GPUState.viewer_in_eye_coords = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glSetLightModelSceneAmbient(const GLfloat* v) {
|
|
|
|
vec4cpy(GPUState.scene_ambient, v);
|
|
|
|
}
|
|
|
|
|
2023-03-23 20:01:41 +00:00
|
|
|
GLfloat* _glGetLightModelSceneAmbient() {
|
|
|
|
return GPUState.scene_ambient;
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
void _glSetLightModelColorControl(GLint v) {
|
|
|
|
GPUState.color_control = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _glColorMaterialMask() {
|
|
|
|
return GPUState.color_material_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glSetColorMaterialMask(GLenum mask) {
|
|
|
|
GPUState.color_material_mask = mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glSetColorMaterialMode(GLenum mode) {
|
|
|
|
GPUState.color_material_mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _glColorMaterialMode() {
|
|
|
|
return GPUState.color_material_mode;
|
|
|
|
}
|
2021-04-14 20:38:33 +00:00
|
|
|
|
2019-02-21 21:58:31 +00:00
|
|
|
GLboolean _glIsSharedTexturePaletteEnabled() {
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.shared_palette_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean _glNearZClippingEnabled() {
|
|
|
|
return GPUState.znear_clipping_enabled;
|
2019-02-21 21:58:31 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
void _glApplyScissor(bool force);
|
|
|
|
|
2019-11-18 17:39:09 +00:00
|
|
|
GLboolean _glIsNormalizeEnabled() {
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.normalize_enabled;
|
2019-11-18 17:39:09 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
GLenum _glGetBlendSourceFactor() {
|
|
|
|
return GPUState.blend_sfactor;
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +00:00
|
|
|
GLenum _glGetBlendDestFactor() {
|
|
|
|
return GPUState.blend_dfactor;
|
2018-05-11 14:39:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 21:27:48 +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
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
if(!TEXTURES_ENABLED[textureUnit] || !tx1 || !tx1->data) {
|
|
|
|
context->txr.base = NULL;
|
2018-05-11 14:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
context->txr.alpha = (GPUState.blend_enabled || GPUState.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-12-03 07:32:53 +00:00
|
|
|
if (palette->size != 16){
|
|
|
|
context->txr.format |= GPUPaletteSelect8BPP(palette->bank);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
context->txr.format |= GPUPaletteSelect4BPP(palette->bank);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-11-18 10:04:46 +00:00
|
|
|
if (tx1->palette->size != 16){
|
|
|
|
context->txr.format |= GPUPaletteSelect8BPP((tx1->palette) ? tx1->palette->bank : 0);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
context->txr.format |= GPUPaletteSelect4BPP((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() {
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.lighting_enabled;
|
2018-05-12 13:05:54 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 08:24:49 +00:00
|
|
|
GLboolean _glIsColorMaterialEnabled() {
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.color_material_enabled;
|
2018-08-22 08:24:49 +00:00
|
|
|
}
|
|
|
|
|
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-14 20:38:33 +00:00
|
|
|
const VideoMode* mode = GetVideoMode();
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GPUState.scissor_rect.x = 0;
|
|
|
|
GPUState.scissor_rect.y = 0;
|
|
|
|
GPUState.scissor_rect.width = mode->width;
|
|
|
|
GPUState.scissor_rect.height = mode->height;
|
2021-04-14 20:38:33 +00:00
|
|
|
|
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;
|
2021-12-03 07:32:53 +00:00
|
|
|
for(i = 0; i < MAX_GLDC_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:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(TEXTURES_ENABLED[_glGetActiveTexture()] != GL_TRUE) {
|
|
|
|
TEXTURES_ENABLED[_glGetActiveTexture()] = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
break;
|
|
|
|
case GL_CULL_FACE: {
|
2023-04-28 18:48:56 +00:00
|
|
|
if(GPUState.culling_enabled != GL_TRUE) {
|
|
|
|
GPUState.culling_enabled = GL_TRUE;
|
2023-03-17 20:40:45 +00:00
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
} break;
|
|
|
|
case GL_DEPTH_TEST: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.depth_test_enabled != GL_TRUE) {
|
|
|
|
GPUState.depth_test_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
} break;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_BLEND: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.blend_enabled != GL_TRUE) {
|
|
|
|
GPUState.blend_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
} break;
|
|
|
|
case GL_SCISSOR_TEST: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.scissor_test_enabled != GL_TRUE) {
|
|
|
|
GPUState.scissor_test_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
} break;
|
2018-05-12 13:05:54 +00:00
|
|
|
case GL_LIGHTING: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.lighting_enabled != GL_TRUE) {
|
|
|
|
GPUState.lighting_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-12 13:05:54 +00:00
|
|
|
} break;
|
2018-05-20 15:37:45 +00:00
|
|
|
case GL_FOG:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.fog_enabled != GL_TRUE) {
|
|
|
|
GPUState.fog_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-20 15:37:45 +00:00
|
|
|
break;
|
2018-08-22 08:24:49 +00:00
|
|
|
case GL_COLOR_MATERIAL:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.color_material_enabled != GL_TRUE) {
|
|
|
|
GPUState.color_material_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-08-22 08:24:49 +00:00
|
|
|
break;
|
2019-03-03 18:54:25 +00:00
|
|
|
case GL_SHARED_TEXTURE_PALETTE_EXT: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.shared_palette_enabled != GL_TRUE) {
|
|
|
|
GPUState.shared_palette_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = 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: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.alpha_test_enabled != GL_TRUE) {
|
|
|
|
GPUState.alpha_test_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
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:
|
2023-03-17 20:40:45 +00:00
|
|
|
case GL_LIGHT7: {
|
|
|
|
LightSource* ptr = _glLightAt(cap & 0xF);
|
|
|
|
if(ptr->isEnabled != GL_TRUE) {
|
|
|
|
ptr->isEnabled = GL_TRUE;
|
|
|
|
_glRecalcEnabledLights();
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 13:05:54 +00:00
|
|
|
break;
|
2018-08-01 10:32:07 +00:00
|
|
|
case GL_NEARZ_CLIPPING_KOS:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.znear_clipping_enabled != GL_TRUE) {
|
|
|
|
GPUState.znear_clipping_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = 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:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.polygon_offset_enabled != GL_TRUE) {
|
|
|
|
GPUState.polygon_offset_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2020-03-05 20:04:44 +00:00
|
|
|
break;
|
2019-11-18 17:39:09 +00:00
|
|
|
case GL_NORMALIZE:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.normalize_enabled != GL_TRUE) {
|
|
|
|
GPUState.normalize_enabled = GL_TRUE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2019-11-18 17:39:09 +00:00
|
|
|
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) {
|
2023-03-17 20:40:45 +00:00
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
if(TEXTURES_ENABLED[_glGetActiveTexture()] != GL_FALSE) {
|
|
|
|
TEXTURES_ENABLED[_glGetActiveTexture()] = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2018-05-05 19:38:55 +00:00
|
|
|
case GL_CULL_FACE: {
|
2023-04-28 18:48:56 +00:00
|
|
|
if(GPUState.culling_enabled != GL_FALSE) {
|
|
|
|
GPUState.culling_enabled = GL_FALSE;
|
2023-03-17 20:40:45 +00:00
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
} break;
|
|
|
|
case GL_DEPTH_TEST: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.depth_test_enabled != GL_FALSE) {
|
|
|
|
GPUState.depth_test_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case GL_BLEND: {
|
|
|
|
if(GPUState.blend_enabled != GL_FALSE) {
|
|
|
|
GPUState.blend_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
} break;
|
2018-05-11 14:39:28 +00:00
|
|
|
case GL_SCISSOR_TEST: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.scissor_test_enabled != GL_FALSE) {
|
|
|
|
GPUState.scissor_test_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-11 14:39:28 +00:00
|
|
|
} break;
|
2018-05-12 13:05:54 +00:00
|
|
|
case GL_LIGHTING: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.lighting_enabled != GL_FALSE) {
|
|
|
|
GPUState.lighting_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-12 13:05:54 +00:00
|
|
|
} break;
|
2018-05-20 15:37:45 +00:00
|
|
|
case GL_FOG:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.fog_enabled != GL_FALSE) {
|
|
|
|
GPUState.fog_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-20 15:37:45 +00:00
|
|
|
break;
|
2018-08-22 08:24:49 +00:00
|
|
|
case GL_COLOR_MATERIAL:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.color_material_enabled != GL_FALSE) {
|
|
|
|
GPUState.color_material_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-08-22 08:24:49 +00:00
|
|
|
break;
|
2019-03-03 18:54:25 +00:00
|
|
|
case GL_SHARED_TEXTURE_PALETTE_EXT: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.shared_palette_enabled != GL_FALSE) {
|
|
|
|
GPUState.shared_palette_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = 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: {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.alpha_test_enabled != GL_FALSE) {
|
|
|
|
GPUState.alpha_test_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
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:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.lights[cap & 0xF].isEnabled) {
|
|
|
|
_glEnableLight(cap & 0xF, GL_FALSE);
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-12 13:05:54 +00:00
|
|
|
break;
|
2018-08-01 10:32:07 +00:00
|
|
|
case GL_NEARZ_CLIPPING_KOS:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.znear_clipping_enabled != GL_FALSE) {
|
|
|
|
GPUState.znear_clipping_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = 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:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.polygon_offset_enabled != GL_FALSE) {
|
|
|
|
GPUState.polygon_offset_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2020-03-05 20:04:44 +00:00
|
|
|
break;
|
2019-11-18 17:39:09 +00:00
|
|
|
case GL_NORMALIZE:
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.normalize_enabled != GL_FALSE) {
|
|
|
|
GPUState.normalize_enabled = GL_FALSE;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2019-11-18 17:39:09 +00:00
|
|
|
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) {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.depth_mask_enabled != flag) {
|
|
|
|
GPUState.depth_mask_enabled = flag;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glDepthFunc(GLenum func) {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.depth_func != func) {
|
|
|
|
GPUState.depth_func = func;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.front_face != mode) {
|
|
|
|
GPUState.front_face = mode;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLAPI void APIENTRY glCullFace(GLenum mode) {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.cull_face != mode) {
|
|
|
|
GPUState.cull_face = mode;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
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) {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.shade_model != mode) {
|
|
|
|
GPUState.shade_model = mode;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
2018-05-05 19:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Blending */
|
|
|
|
GLAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor) {
|
2023-03-17 20:40:45 +00:00
|
|
|
if(GPUState.blend_dfactor != dfactor || GPUState.blend_sfactor != sfactor) {
|
|
|
|
GPUState.blend_sfactor = sfactor;
|
|
|
|
GPUState.blend_dfactor = dfactor;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
|
|
|
}
|
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) {
|
2023-03-07 10:19:09 +00:00
|
|
|
GPUState.offset_factor = factor;
|
|
|
|
GPUState.offset_units = units;
|
|
|
|
GPUState.is_dirty = GL_TRUE;
|
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) {
|
2023-03-07 10:19:09 +00:00
|
|
|
|
|
|
|
if(GPUState.scissor_rect.x == x &&
|
|
|
|
GPUState.scissor_rect.y == y &&
|
|
|
|
GPUState.scissor_rect.width == width &&
|
|
|
|
GPUState.scissor_rect.height == height) {
|
2021-04-14 20:38:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GPUState.scissor_rect.x = x;
|
|
|
|
GPUState.scissor_rect.y = y;
|
|
|
|
GPUState.scissor_rect.width = width;
|
|
|
|
GPUState.scissor_rect.height = height;
|
|
|
|
GPUState.scissor_rect.applied = false;
|
|
|
|
GPUState.is_dirty = GL_TRUE; // FIXME: do we need this?
|
2021-04-14 20:38:33 +00:00
|
|
|
|
|
|
|
_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 */
|
2023-03-07 21:27:48 +00:00
|
|
|
if(!GPUState.scissor_test_enabled) {
|
2021-04-14 20:38:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't apply if we already applied - nothing changed */
|
2023-03-07 10:19:09 +00:00
|
|
|
if(GPUState.scissor_rect.applied && !force) {
|
2021-04-14 20:38:33 +00:00
|
|
|
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();
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GLsizei scissor_width = MAX(MIN(GPUState.scissor_rect.width, vid_mode->width), 0);
|
|
|
|
GLsizei scissor_height = MAX(MIN(GPUState.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 */
|
2023-03-07 10:19:09 +00:00
|
|
|
miny = (vid_mode->height - scissor_height) - GPUState.scissor_rect.y;
|
|
|
|
maxx = (scissor_width + GPUState.scissor_rect.x);
|
2021-04-14 20:38:33 +00:00
|
|
|
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;
|
2023-03-07 10:19:09 +00:00
|
|
|
|
|
|
|
uint16_t vw = vid_mode->width >> 5;
|
|
|
|
uint16_t vh = vid_mode->height >> 5;
|
|
|
|
|
|
|
|
c.sx = CLAMP(GPUState.scissor_rect.x >> 5, 0, vw);
|
|
|
|
c.sy = CLAMP(miny >> 5, 0, vh);
|
|
|
|
c.ex = CLAMP((maxx >> 5) - 1, 0, vw);
|
|
|
|
c.ey = CLAMP((maxy >> 5) - 1, 0, vh);
|
2021-04-14 20:38:33 +00:00
|
|
|
|
|
|
|
aligned_vector_push_back(&_glOpaquePolyList()->vector, &c, 1);
|
|
|
|
aligned_vector_push_back(&_glPunchThruPolyList()->vector, &c, 1);
|
|
|
|
aligned_vector_push_back(&_glTransparentPolyList()->vector, &c, 1);
|
|
|
|
|
2023-03-07 10:19:09 +00:00
|
|
|
GPUState.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:
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.depth_test_enabled;
|
2018-05-12 13:39:20 +00:00
|
|
|
case GL_SCISSOR_TEST:
|
2023-03-07 21:27:48 +00:00
|
|
|
return GPUState.scissor_test_enabled;
|
2018-05-12 13:39:20 +00:00
|
|
|
case GL_CULL_FACE:
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.culling_enabled;
|
2018-05-12 13:39:20 +00:00
|
|
|
case GL_LIGHTING:
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.lighting_enabled;
|
2018-05-12 13:39:20 +00:00
|
|
|
case GL_BLEND:
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.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:
|
2023-03-07 10:19:09 +00:00
|
|
|
return GPUState.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:
|
2023-03-07 10:19:09 +00:00
|
|
|
*params = GPUState.offset_factor;
|
2020-03-05 20:04:44 +00:00
|
|
|
break;
|
|
|
|
case GL_POLYGON_OFFSET_UNITS:
|
2023-03-07 10:19:09 +00:00
|
|
|
*params = GPUState.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:
|
2021-12-03 07:32:53 +00:00
|
|
|
*params = MAX_GLDC_LIGHTS;
|
2018-05-12 13:39:20 +00:00
|
|
|
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:
|
2023-03-07 10:19:09 +00:00
|
|
|
*params = GPUState.depth_func;
|
2018-08-04 20:00:26 +00:00
|
|
|
break;
|
|
|
|
case GL_BLEND_SRC:
|
2023-03-07 10:19:09 +00:00
|
|
|
*params = GPUState.blend_sfactor;
|
2018-08-04 20:00:26 +00:00
|
|
|
break;
|
|
|
|
case GL_BLEND_DST:
|
2023-03-07 10:19:09 +00:00
|
|
|
*params = GPUState.blend_dfactor;
|
2018-08-04 20:00:26 +00:00
|
|
|
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:
|
2022-05-04 19:45:21 +00:00
|
|
|
return (const GLubyte*)"GL_ARB_framebuffer_object, GL_ARB_multitexture, GL_ARB_texture_rg, GL_OES_compressed_paletted_texture, 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
|
|
|
}
|