2018-05-05 19:38:55 +00:00
|
|
|
#ifndef PRIVATE_H
|
|
|
|
#define PRIVATE_H
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
#include <stdint.h>
|
2021-04-09 15:24:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "platform.h"
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "../include/GL/gl.h"
|
|
|
|
#include "../include/GL/glext.h"
|
|
|
|
#include "../include/GL/glkos.h"
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
#include "../containers/aligned_vector.h"
|
|
|
|
#include "../containers/named_array.h"
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2021-12-03 07:32:53 +00:00
|
|
|
#define MAX_GLDC_4BPP_PALETTE_SLOTS 16
|
|
|
|
#define MAX_GLDC_PALETTE_SLOTS 4
|
|
|
|
#define MAX_GLDC_SHARED_PALETTES (MAX_GLDC_PALETTE_SLOTS*MAX_GLDC_4BPP_PALETTE_SLOTS)
|
|
|
|
|
|
|
|
|
2020-03-05 19:57:30 +00:00
|
|
|
extern void* memcpy4 (void *dest, const void *src, size_t count);
|
|
|
|
|
|
|
|
#define GL_NO_INSTRUMENT inline __attribute__((no_instrument_function))
|
|
|
|
#define GL_INLINE_DEBUG GL_NO_INSTRUMENT __attribute__((always_inline))
|
|
|
|
#define GL_FORCE_INLINE static GL_INLINE_DEBUG
|
|
|
|
#define _GL_UNUSED(x) (void)(x)
|
2020-02-16 20:22:13 +00:00
|
|
|
|
2019-09-24 20:26:17 +00:00
|
|
|
#define _PACK4(v) ((v * 0xF) / 0xFF)
|
|
|
|
#define PACK_ARGB4444(a,r,g,b) (_PACK4(a) << 12) | (_PACK4(r) << 8) | (_PACK4(g) << 4) | (_PACK4(b))
|
|
|
|
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )
|
2019-09-25 12:10:34 +00:00
|
|
|
#define PACK_ARGB1555(a,r,g,b) \
|
|
|
|
(((GLushort)(a > 0) << 15) | (((GLushort) r >> 3) << 10) | (((GLushort)g >> 3) << 5) | ((GLushort)b >> 3))
|
|
|
|
|
2019-09-24 20:26:17 +00:00
|
|
|
#define PACK_RGB565(r,g,b) \
|
2019-09-25 12:45:08 +00:00
|
|
|
((((GLushort)r & 0xf8) << 8) | (((GLushort) g & 0xfc) << 3) | ((GLushort) b >> 3))
|
2019-09-24 20:26:17 +00:00
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
#define TRACE_ENABLED 0
|
2020-02-29 13:25:30 +00:00
|
|
|
#define TRACE() if(TRACE_ENABLED) {fprintf(stderr, "%s\n", __func__);} (void) 0
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2018-08-21 15:08:06 +00:00
|
|
|
#define VERTEX_ENABLED_FLAG (1 << 0)
|
|
|
|
#define UV_ENABLED_FLAG (1 << 1)
|
|
|
|
#define ST_ENABLED_FLAG (1 << 2)
|
|
|
|
#define DIFFUSE_ENABLED_FLAG (1 << 3)
|
|
|
|
#define NORMAL_ENABLED_FLAG (1 << 4)
|
|
|
|
|
2018-08-07 07:45:24 +00:00
|
|
|
#define MAX_TEXTURE_SIZE 1024
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2019-09-14 19:51:47 +00:00
|
|
|
|
|
|
|
/* This gives us an easy way to switch
|
|
|
|
* internal matrix order if necessary */
|
|
|
|
|
|
|
|
#define TRANSPOSE 0
|
|
|
|
|
|
|
|
#if TRANSPOSE
|
|
|
|
#define M0 0
|
|
|
|
#define M1 4
|
|
|
|
#define M2 8
|
|
|
|
#define M3 12
|
|
|
|
#define M4 1
|
|
|
|
#define M5 5
|
|
|
|
#define M6 9
|
|
|
|
#define M7 13
|
|
|
|
#define M8 2
|
|
|
|
#define M9 6
|
|
|
|
#define M10 10
|
|
|
|
#define M11 14
|
|
|
|
#define M12 3
|
|
|
|
#define M13 7
|
|
|
|
#define M14 11
|
|
|
|
#define M15 15
|
|
|
|
#else
|
|
|
|
#define M0 0
|
|
|
|
#define M1 1
|
|
|
|
#define M2 2
|
|
|
|
#define M3 3
|
|
|
|
#define M4 4
|
|
|
|
#define M5 5
|
|
|
|
#define M6 6
|
|
|
|
#define M7 7
|
|
|
|
#define M8 8
|
|
|
|
#define M9 9
|
|
|
|
#define M10 10
|
|
|
|
#define M11 11
|
|
|
|
#define M12 12
|
|
|
|
#define M13 13
|
|
|
|
#define M14 14
|
|
|
|
#define M15 15
|
|
|
|
#endif
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int flags; /* Constant PVR_CMD_USERCLIP */
|
|
|
|
unsigned int d1, d2, d3; /* Ignored for this type */
|
|
|
|
unsigned int sx, /* Start x */
|
|
|
|
sy, /* Start y */
|
|
|
|
ex, /* End x */
|
|
|
|
ey; /* End y */
|
|
|
|
} PVRTileClipCommand; /* Tile Clip command for the pvr */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int list_type;
|
|
|
|
AlignedVector vector;
|
|
|
|
} PolyList;
|
|
|
|
|
2021-04-25 12:05:56 +00:00
|
|
|
typedef struct {
|
|
|
|
GLint x;
|
|
|
|
GLint y;
|
|
|
|
GLint width;
|
|
|
|
GLint height;
|
|
|
|
|
|
|
|
float x_plus_hwidth;
|
|
|
|
float y_plus_hheight;
|
|
|
|
float hwidth; /* width * 0.5f */
|
|
|
|
float hheight; /* height * 0.5f */
|
|
|
|
} Viewport;
|
|
|
|
|
|
|
|
extern Viewport VIEWPORT;
|
|
|
|
|
2018-09-20 14:01:13 +00:00
|
|
|
typedef struct {
|
|
|
|
/* Palette data is always stored in RAM as RGBA8888 and packed as ARGB8888
|
|
|
|
* when uploaded to the PVR */
|
|
|
|
GLubyte* data;
|
2019-03-09 14:32:50 +00:00
|
|
|
GLushort width; /* The user specified width */
|
|
|
|
GLushort size; /* The size of the bank (16 or 256) */
|
2018-09-20 14:01:13 +00:00
|
|
|
GLenum format;
|
2019-03-09 14:32:50 +00:00
|
|
|
GLshort bank;
|
2018-09-20 14:01:13 +00:00
|
|
|
} TexturePalette;
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
typedef struct {
|
2020-03-05 19:57:30 +00:00
|
|
|
//0
|
|
|
|
GLuint index;
|
|
|
|
GLuint color; /* This is the PVR texture format */
|
|
|
|
//8
|
|
|
|
GLenum minFilter;
|
|
|
|
GLenum magFilter;
|
|
|
|
//16
|
|
|
|
GLvoid *data;
|
|
|
|
TexturePalette* palette;
|
|
|
|
//24
|
2018-05-11 14:39:28 +00:00
|
|
|
GLushort width;
|
|
|
|
GLushort height;
|
2020-03-05 19:57:30 +00:00
|
|
|
//28
|
2018-08-08 08:50:57 +00:00
|
|
|
GLushort mipmap; /* Bitmask of supplied mipmap levels */
|
2020-03-05 19:57:30 +00:00
|
|
|
/* When using the shared palette, this is the bank (0-3) */
|
|
|
|
GLushort shared_bank;
|
|
|
|
//32
|
|
|
|
GLuint dataStride;
|
|
|
|
//36
|
|
|
|
GLubyte mipmap_bias;
|
|
|
|
GLubyte env;
|
2018-08-08 08:50:57 +00:00
|
|
|
GLubyte mipmapCount; /* The number of mipmap levels */
|
2018-05-11 14:39:28 +00:00
|
|
|
GLubyte uv_clamp;
|
2020-03-05 19:57:30 +00:00
|
|
|
//40
|
2019-09-24 14:47:23 +00:00
|
|
|
/* Mipmap textures have a different
|
|
|
|
* offset for the base level when supplying the data, this
|
|
|
|
* keeps track of that. baseDataOffset == 0
|
|
|
|
* means that the texture has no mipmaps
|
|
|
|
*/
|
|
|
|
GLuint baseDataOffset;
|
2020-03-05 19:57:30 +00:00
|
|
|
GLuint baseDataSize; /* The data size of mipmap level 0 */
|
|
|
|
//48
|
|
|
|
GLboolean isCompressed;
|
|
|
|
GLboolean isPaletted;
|
|
|
|
//50
|
2018-05-11 14:39:28 +00:00
|
|
|
} TextureObject;
|
|
|
|
|
2018-05-12 13:05:54 +00:00
|
|
|
typedef struct {
|
2018-05-19 08:17:24 +00:00
|
|
|
GLfloat emissive[4];
|
2018-05-12 13:05:54 +00:00
|
|
|
GLfloat ambient[4];
|
|
|
|
GLfloat diffuse[4];
|
2018-08-01 10:32:07 +00:00
|
|
|
GLfloat specular[4];
|
2020-02-16 20:22:13 +00:00
|
|
|
|
|
|
|
/* Valid values are 0-128 */
|
2020-02-17 20:29:12 +00:00
|
|
|
GLfloat exponent;
|
2020-05-07 19:58:24 +00:00
|
|
|
|
|
|
|
/* Base ambient + emission colour for
|
|
|
|
* the current material + light */
|
2020-05-11 19:34:09 +00:00
|
|
|
GLfloat baseColour[4];
|
2018-05-12 13:05:54 +00:00
|
|
|
} Material;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GLfloat position[4];
|
|
|
|
GLfloat spot_direction[3];
|
|
|
|
GLfloat spot_cutoff;
|
|
|
|
GLfloat constant_attenuation;
|
|
|
|
GLfloat linear_attenuation;
|
|
|
|
GLfloat quadratic_attenuation;
|
2018-05-19 08:17:24 +00:00
|
|
|
GLfloat spot_exponent;
|
|
|
|
GLfloat diffuse[4];
|
|
|
|
GLfloat specular[4];
|
|
|
|
GLfloat ambient[4];
|
2020-05-07 19:58:24 +00:00
|
|
|
|
|
|
|
GLboolean isDirectional;
|
2020-05-08 06:19:56 +00:00
|
|
|
GLboolean isEnabled;
|
2020-05-07 19:58:24 +00:00
|
|
|
|
|
|
|
/* We set these when the material changes
|
|
|
|
* so we don't calculate them per-vertex. They are
|
|
|
|
* light_value * materia_value */
|
|
|
|
GLfloat ambientMaterial[4];
|
|
|
|
GLfloat diffuseMaterial[4];
|
|
|
|
GLfloat specularMaterial[4];
|
2018-05-12 13:05:54 +00:00
|
|
|
} LightSource;
|
|
|
|
|
2020-05-08 08:49:01 +00:00
|
|
|
|
2020-05-11 19:34:09 +00:00
|
|
|
#define argbcpy(dst, src) \
|
2021-04-20 15:08:58 +00:00
|
|
|
*((GLuint*) dst) = *((const GLuint*) src) \
|
2020-05-08 08:49:01 +00:00
|
|
|
|
|
|
|
|
2020-05-11 19:34:09 +00:00
|
|
|
typedef struct {
|
|
|
|
float xy[2];
|
|
|
|
} _glvec2;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float xyz[3];
|
|
|
|
} _glvec3;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float xyzw[4];
|
|
|
|
} _glvec4;
|
|
|
|
|
|
|
|
#define vec2cpy(dst, src) \
|
|
|
|
*((_glvec2*) dst) = *((_glvec2*) src)
|
|
|
|
|
|
|
|
#define vec3cpy(dst, src) \
|
|
|
|
*((_glvec3*) dst) = *((_glvec3*) src)
|
|
|
|
|
|
|
|
#define vec4cpy(dst, src) \
|
|
|
|
*((_glvec4*) dst) = *((_glvec4*) src)
|
2020-05-08 08:49:01 +00:00
|
|
|
|
2020-05-11 19:34:09 +00:00
|
|
|
GL_FORCE_INLINE float clamp(float d, float min, float max) {
|
|
|
|
return (d < min) ? min : (d > max) ? max : d;
|
|
|
|
}
|
2020-05-08 08:49:01 +00:00
|
|
|
|
2019-03-25 19:04:50 +00:00
|
|
|
#define swapVertex(a, b) \
|
|
|
|
do { \
|
2019-11-30 10:07:23 +00:00
|
|
|
Vertex c = *a; \
|
|
|
|
*a = *b; \
|
|
|
|
*b = c; \
|
2019-03-25 19:04:50 +00:00
|
|
|
} while(0)
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
/* ClipVertex doesn't have room for these, so we need to parse them
|
|
|
|
* out separately. Potentially 'w' will be housed here if we support oargb */
|
|
|
|
typedef struct {
|
|
|
|
float nxyz[3];
|
|
|
|
float st[2];
|
|
|
|
} VertexExtra;
|
|
|
|
|
|
|
|
/* Generating PVR vertices from the user-submitted data gets complicated, particularly
|
|
|
|
* when a realloc could invalidate pointers. This structure holds all the information
|
|
|
|
* we need on the target vertex array to allow passing around to the various stages (e.g. generate/clip etc.)
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
PolyList* output;
|
|
|
|
uint32_t header_offset; // The offset of the header in the output list
|
|
|
|
uint32_t start_offset; // The offset into the output list
|
|
|
|
uint32_t count; // The number of vertices in this output
|
|
|
|
|
|
|
|
/* Pointer to count * VertexExtra; */
|
|
|
|
AlignedVector* extras;
|
|
|
|
} SubmissionTarget;
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
Vertex* _glSubmissionTargetStart(SubmissionTarget* target);
|
|
|
|
Vertex* _glSubmissionTargetEnd(SubmissionTarget* target);
|
2019-03-24 08:09:02 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CLIP_RESULT_ALL_IN_FRONT,
|
|
|
|
CLIP_RESULT_ALL_BEHIND,
|
|
|
|
CLIP_RESULT_ALL_ON_PLANE,
|
|
|
|
CLIP_RESULT_FRONT_TO_BACK,
|
|
|
|
CLIP_RESULT_BACK_TO_FRONT
|
|
|
|
} ClipResult;
|
|
|
|
|
|
|
|
|
|
|
|
#define A8IDX 3
|
|
|
|
#define R8IDX 2
|
|
|
|
#define G8IDX 1
|
|
|
|
#define B8IDX 0
|
|
|
|
|
|
|
|
struct SubmissionTarget;
|
|
|
|
|
2020-04-03 19:12:42 +00:00
|
|
|
float _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout);
|
2019-03-24 08:09:02 +00:00
|
|
|
void _glClipTriangleStrip(SubmissionTarget* target, uint8_t fladeShade);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
PolyList* _glOpaquePolyList();
|
|
|
|
PolyList* _glPunchThruPolyList();
|
2019-03-03 19:02:25 +00:00
|
|
|
PolyList *_glTransparentPolyList();
|
2018-05-05 19:38:55 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
void _glInitAttributePointers();
|
2018-09-15 10:45:38 +00:00
|
|
|
void _glInitContext();
|
|
|
|
void _glInitLights();
|
2019-03-13 15:43:50 +00:00
|
|
|
void _glInitImmediateMode(GLuint initial_size);
|
2019-03-03 19:02:25 +00:00
|
|
|
void _glInitMatrices();
|
|
|
|
void _glInitFramebuffers();
|
2018-05-16 20:00:41 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
void _glMatrixLoadNormal();
|
|
|
|
void _glMatrixLoadModelView();
|
2021-04-25 12:05:56 +00:00
|
|
|
void _glMatrixLoadProjection();
|
2019-03-03 19:02:25 +00:00
|
|
|
void _glMatrixLoadTexture();
|
2021-04-25 12:05:56 +00:00
|
|
|
void _glMatrixLoadModelViewProjection();
|
2018-05-16 20:00:41 +00:00
|
|
|
|
2019-09-08 16:27:56 +00:00
|
|
|
extern GLfloat DEPTH_RANGE_MULTIPLIER_L;
|
|
|
|
extern GLfloat DEPTH_RANGE_MULTIPLIER_H;
|
|
|
|
|
2019-09-14 19:51:47 +00:00
|
|
|
Matrix4x4* _glGetProjectionMatrix();
|
|
|
|
Matrix4x4* _glGetModelViewMatrix();
|
2019-02-28 08:46:13 +00:00
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
void _glWipeTextureOnFramebuffers(GLuint texture);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
PolyContext* _glGetPVRContext();
|
2019-03-03 19:02:25 +00:00
|
|
|
GLubyte _glInitTextures();
|
2018-08-14 08:49:31 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
void _glUpdatePVRTextureContext(PolyContext* context, GLshort textureUnit);
|
2019-04-17 13:55:30 +00:00
|
|
|
void _glAllocateSpaceForMipmaps(TextureObject* active);
|
2018-08-14 08:49:31 +00:00
|
|
|
|
2018-08-21 15:15:43 +00:00
|
|
|
typedef struct {
|
2021-09-13 09:29:04 +00:00
|
|
|
const void* ptr; // 4
|
|
|
|
GLenum type; // 4
|
|
|
|
GLsizei stride; // 4
|
|
|
|
GLint size; // 4
|
2018-08-21 15:15:43 +00:00
|
|
|
} AttribPointer;
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
typedef struct {
|
|
|
|
AttribPointer vertex; // 16
|
|
|
|
AttribPointer colour; // 32
|
|
|
|
AttribPointer uv; // 48
|
|
|
|
AttribPointer st; // 64
|
|
|
|
AttribPointer normal; // 80
|
|
|
|
AttribPointer padding; // 96
|
|
|
|
} AttribPointerList;
|
|
|
|
|
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
|
|
|
|
2019-03-29 08:47:55 +00:00
|
|
|
GLuint* _glGetEnabledAttributes();
|
2018-08-21 15:15:43 +00:00
|
|
|
AttribPointer* _glGetVertexAttribPointer();
|
|
|
|
AttribPointer* _glGetDiffuseAttribPointer();
|
|
|
|
AttribPointer* _glGetNormalAttribPointer();
|
|
|
|
AttribPointer* _glGetUVAttribPointer();
|
|
|
|
AttribPointer* _glGetSTAttribPointer();
|
2018-09-08 19:53:28 +00:00
|
|
|
GLenum _glGetShadeModel();
|
2018-08-21 15:08:06 +00:00
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
TextureObject* _glGetTexture0();
|
|
|
|
TextureObject* _glGetTexture1();
|
|
|
|
TextureObject* _glGetBoundTexture();
|
2021-09-12 14:04:52 +00:00
|
|
|
|
|
|
|
extern GLubyte ACTIVE_TEXTURE;
|
|
|
|
extern GLboolean TEXTURES_ENABLED[];
|
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
GLubyte _glGetActiveTexture();
|
2021-09-12 14:04:52 +00:00
|
|
|
|
2018-08-21 14:50:59 +00:00
|
|
|
GLuint _glGetActiveClientTexture();
|
2019-03-10 11:18:56 +00:00
|
|
|
TexturePalette* _glGetSharedPalette(GLshort bank);
|
2019-03-11 19:07:59 +00:00
|
|
|
void _glSetInternalPaletteFormat(GLenum val);
|
2018-08-14 08:49:31 +00:00
|
|
|
|
2019-02-21 21:58:31 +00:00
|
|
|
GLboolean _glIsSharedTexturePaletteEnabled();
|
2019-03-10 11:18:56 +00:00
|
|
|
void _glApplyColorTable(TexturePalette *palette);
|
2019-02-21 21:58:31 +00:00
|
|
|
|
2021-05-08 13:38:55 +00:00
|
|
|
extern GLboolean BLEND_ENABLED;
|
|
|
|
extern GLboolean ALPHA_TEST_ENABLED;
|
2021-05-23 12:19:54 +00:00
|
|
|
extern GLboolean AUTOSORT_ENABLED;
|
2021-05-08 13:38:55 +00:00
|
|
|
|
|
|
|
GL_FORCE_INLINE GLboolean _glIsBlendingEnabled() {
|
|
|
|
return BLEND_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_FORCE_INLINE GLboolean _glIsAlphaTestEnabled() {
|
|
|
|
return ALPHA_TEST_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern PolyList OP_LIST;
|
|
|
|
extern PolyList PT_LIST;
|
|
|
|
extern PolyList TR_LIST;
|
|
|
|
|
|
|
|
GL_FORCE_INLINE PolyList* _glActivePolyList() {
|
|
|
|
if(BLEND_ENABLED) {
|
|
|
|
return &TR_LIST;
|
|
|
|
} else if(ALPHA_TEST_ENABLED) {
|
|
|
|
return &PT_LIST;
|
|
|
|
} else {
|
|
|
|
return &OP_LIST;
|
|
|
|
}
|
|
|
|
}
|
2019-03-10 17:53:58 +00:00
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
GLboolean _glIsMipmapComplete(const TextureObject* obj);
|
2020-03-05 19:57:30 +00:00
|
|
|
GLubyte* _glGetMipmapLocation(const TextureObject* obj, GLuint level);
|
|
|
|
GLuint _glGetMipmapLevelCount(const TextureObject* obj);
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2021-09-12 14:04:52 +00:00
|
|
|
extern GLboolean LIGHTING_ENABLED;
|
2019-03-03 19:06:01 +00:00
|
|
|
GLboolean _glIsLightingEnabled();
|
2021-09-12 14:04:52 +00:00
|
|
|
|
2020-05-08 06:19:56 +00:00
|
|
|
void _glEnableLight(GLubyte light, unsigned char value);
|
2018-08-22 08:24:49 +00:00
|
|
|
GLboolean _glIsColorMaterialEnabled();
|
2019-08-01 19:21:03 +00:00
|
|
|
|
2019-11-18 17:39:09 +00:00
|
|
|
GLboolean _glIsNormalizeEnabled();
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
extern AttribPointerList ATTRIB_POINTERS;
|
|
|
|
|
2021-09-12 14:04:52 +00:00
|
|
|
extern GLuint ENABLED_VERTEX_ATTRIBUTES;
|
2021-09-13 11:57:52 +00:00
|
|
|
extern GLuint FAST_PATH_ENABLED;
|
2021-09-12 14:04:52 +00:00
|
|
|
|
2021-09-13 11:57:52 +00:00
|
|
|
GL_FORCE_INLINE GLuint _glIsVertexDataFastPathCompatible() {
|
2021-09-12 14:04:52 +00:00
|
|
|
/* The fast path is enabled when all enabled elements of the vertex
|
|
|
|
* match the output format. This means:
|
|
|
|
*
|
|
|
|
* xyz == 3f
|
|
|
|
* uv == 2f
|
|
|
|
* rgba == argb4444
|
|
|
|
* st == 2f
|
|
|
|
* normal == 3f
|
|
|
|
*
|
|
|
|
* When this happens we do inline straight copies of the enabled data
|
|
|
|
* and transforms for positions and normals happen while copying.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & VERTEX_ENABLED_FLAG)) {
|
2021-09-13 09:29:04 +00:00
|
|
|
if(ATTRIB_POINTERS.vertex.size != 3 || ATTRIB_POINTERS.vertex.type != GL_FLOAT) {
|
2021-09-12 14:04:52 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG)) {
|
2021-09-13 09:29:04 +00:00
|
|
|
if(ATTRIB_POINTERS.uv.size != 2 || ATTRIB_POINTERS.uv.type != GL_FLOAT) {
|
2021-09-12 14:04:52 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & DIFFUSE_ENABLED_FLAG)) {
|
|
|
|
/* FIXME: Shouldn't this be a reversed format? */
|
2021-09-13 09:29:04 +00:00
|
|
|
if(ATTRIB_POINTERS.colour.size != GL_BGRA || ATTRIB_POINTERS.colour.type != GL_UNSIGNED_BYTE) {
|
2021-09-12 14:04:52 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & ST_ENABLED_FLAG)) {
|
2021-09-13 09:29:04 +00:00
|
|
|
if(ATTRIB_POINTERS.st.size != 2 || ATTRIB_POINTERS.st.type != GL_FLOAT) {
|
2021-09-12 14:04:52 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ENABLED_VERTEX_ATTRIBUTES & NORMAL_ENABLED_FLAG)) {
|
2021-09-13 09:29:04 +00:00
|
|
|
if(ATTRIB_POINTERS.normal.size != 3 || ATTRIB_POINTERS.normal.type != GL_FLOAT) {
|
2021-09-12 14:04:52 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2021-09-13 11:57:52 +00:00
|
|
|
GL_FORCE_INLINE GLuint _glRecalcFastPath() {
|
2021-09-12 14:04:52 +00:00
|
|
|
FAST_PATH_ENABLED = _glIsVertexDataFastPathCompatible();
|
|
|
|
return FAST_PATH_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern GLboolean IMMEDIATE_MODE_ACTIVE;
|
|
|
|
|
2021-09-13 09:29:04 +00:00
|
|
|
extern GLenum LAST_ERROR;
|
|
|
|
extern char ERROR_FUNCTION[64];
|
|
|
|
|
|
|
|
GL_FORCE_INLINE const char* _glErrorEnumAsString(GLenum error) {
|
|
|
|
switch(error) {
|
|
|
|
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
|
|
|
|
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
|
|
|
|
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
|
|
|
|
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
|
|
|
|
default:
|
|
|
|
return "GL_UNKNOWN_ERROR";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_FORCE_INLINE void _glKosThrowError(GLenum error, const char *function) {
|
|
|
|
if(LAST_ERROR == GL_NO_ERROR) {
|
|
|
|
LAST_ERROR = error;
|
|
|
|
sprintf(ERROR_FUNCTION, "%s\n", function);
|
|
|
|
fprintf(stderr, "GL ERROR: %s when calling %s\n", _glErrorEnumAsString(LAST_ERROR), ERROR_FUNCTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_FORCE_INLINE GLubyte _glKosHasError() {
|
|
|
|
return (LAST_ERROR != GL_NO_ERROR) ? GL_TRUE : GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_FORCE_INLINE void _glKosResetError() {
|
|
|
|
LAST_ERROR = GL_NO_ERROR;
|
|
|
|
sprintf(ERROR_FUNCTION, "\n");
|
|
|
|
}
|
2021-09-12 14:04:52 +00:00
|
|
|
|
|
|
|
GL_FORCE_INLINE GLboolean _glCheckImmediateModeInactive(const char* func) {
|
|
|
|
/* Returns 1 on error */
|
|
|
|
if(IMMEDIATE_MODE_ACTIVE) {
|
|
|
|
_glKosThrowError(GL_INVALID_OPERATION, func);
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2019-09-30 08:14:43 +00:00
|
|
|
|
2019-08-01 19:21:03 +00:00
|
|
|
typedef struct {
|
2020-05-22 06:20:08 +00:00
|
|
|
float n[3]; // 12 bytes
|
2021-04-30 06:58:57 +00:00
|
|
|
float finalColour[4]; //28 bytes
|
|
|
|
uint32_t padding; // 32 bytes
|
2019-08-01 19:21:03 +00:00
|
|
|
} EyeSpaceData;
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
extern void _glPerformLighting(Vertex* vertices, EyeSpaceData *es, const uint32_t count);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
unsigned char _glIsClippingEnabled();
|
|
|
|
void _glEnableClipping(unsigned char v);
|
2018-08-01 10:32:07 +00:00
|
|
|
|
2021-02-19 21:28:31 +00:00
|
|
|
GLuint _glFreeTextureMemory();
|
|
|
|
GLuint _glUsedTextureMemory();
|
|
|
|
GLuint _glFreeContiguousTextureMemory();
|
|
|
|
|
2021-04-14 20:38:33 +00:00
|
|
|
void _glApplyScissor(bool force);
|
|
|
|
|
2021-12-03 07:32:53 +00:00
|
|
|
#define MAX_GLDC_TEXTURE_UNITS 2
|
|
|
|
#define MAX_GLDC_LIGHTS 8
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2021-04-19 19:51:22 +00:00
|
|
|
/* This is from KOS pvr_buffers.c */
|
|
|
|
#define PVR_MIN_Z 0.0001f
|
|
|
|
|
2020-03-05 19:57:30 +00:00
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
|
|
|
#define MAX(a,b) (((a)>(b))?(a):(b))
|
|
|
|
#define CLAMP( X, _MIN, _MAX ) ( (X)<(_MIN) ? (_MIN) : ((X)>(_MAX) ? (_MAX) : (X)) )
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
#endif // PRIVATE_H
|