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>
|
2019-09-06 08:35:33 +00:00
|
|
|
#include <dc/matrix.h>
|
|
|
|
#include <dc/pvr.h>
|
|
|
|
#include <dc/vec3f.h>
|
|
|
|
#include <dc/fmath.h>
|
|
|
|
#include <dc/matrix3d.h>
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2018-05-05 19:38:55 +00:00
|
|
|
#include "../include/gl.h"
|
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
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
#define TRACE_ENABLED 0
|
|
|
|
#define TRACE() if(TRACE_ENABLED) {fprintf(stderr, "%s\n", __func__);}
|
|
|
|
|
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
|
|
|
typedef float Matrix4x4[16];
|
|
|
|
|
|
|
|
/* 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 {
|
2018-08-20 20:19:12 +00:00
|
|
|
pvr_poly_hdr_t hdr;
|
|
|
|
} PVRHeader;
|
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;
|
|
|
|
|
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 {
|
|
|
|
GLushort width;
|
|
|
|
GLushort height;
|
|
|
|
GLuint color; /* This is the PVR texture format */
|
|
|
|
GLubyte env;
|
2018-08-08 08:50:57 +00:00
|
|
|
GLushort mipmap; /* Bitmask of supplied mipmap levels */
|
|
|
|
GLubyte mipmapCount; /* The number of mipmap levels */
|
2018-05-11 14:39:28 +00:00
|
|
|
GLubyte uv_clamp;
|
|
|
|
GLuint index;
|
|
|
|
GLvoid *data;
|
2018-08-08 15:50:09 +00:00
|
|
|
GLuint dataStride;
|
2018-08-09 08:32:29 +00:00
|
|
|
|
|
|
|
GLenum minFilter;
|
|
|
|
GLenum magFilter;
|
2018-08-20 07:34:54 +00:00
|
|
|
|
|
|
|
GLboolean isCompressed;
|
2018-09-22 19:45:17 +00:00
|
|
|
GLboolean isPaletted;
|
2018-09-20 14:01:13 +00:00
|
|
|
|
|
|
|
TexturePalette* palette;
|
2019-03-10 11:18:56 +00:00
|
|
|
|
|
|
|
/* When using the shared palette, this is the bank (0-3) */
|
|
|
|
GLushort shared_bank;
|
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];
|
2018-05-12 13:05:54 +00:00
|
|
|
GLfloat exponent;
|
|
|
|
} 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];
|
2018-08-04 18:34:07 +00:00
|
|
|
GLboolean is_directional;
|
2018-05-12 13:05:54 +00:00
|
|
|
} LightSource;
|
|
|
|
|
2019-03-24 08:09:02 +00:00
|
|
|
typedef struct {
|
|
|
|
/* Same 32 byte layout as pvr_vertex_t */
|
|
|
|
uint32_t flags;
|
|
|
|
float xyz[3];
|
|
|
|
float uv[2];
|
|
|
|
uint8_t bgra[4];
|
|
|
|
|
|
|
|
/* In the pvr_vertex_t structure, this next 4 bytes is oargb
|
|
|
|
* but we're not using that for now, so having W here makes the code
|
|
|
|
* simpler */
|
|
|
|
float w;
|
2019-03-25 09:44:59 +00:00
|
|
|
} Vertex;
|
2019-03-24 08:09:02 +00:00
|
|
|
|
2019-03-25 19:04:50 +00:00
|
|
|
/* FIXME: SH4 has a swap.w instruction, we should leverage it here! */
|
|
|
|
#define _SWAP32(x, y) \
|
|
|
|
do { \
|
|
|
|
uint32_t t = *((uint32_t*) &x); \
|
|
|
|
*((uint32_t*) &x) = *((uint32_t*) &y); \
|
|
|
|
*((uint32_t*) &y) = t; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
*((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); \
|
|
|
|
*((uint32_t*) &y) = *((uint32_t*) &x) ^ *((uint32_t*) &y); \
|
|
|
|
*((uint32_t*) &x) = *((uint32_t*) &x) ^ *((uint32_t*) &y); */
|
|
|
|
|
|
|
|
|
|
|
|
#define swapVertex(a, b) \
|
|
|
|
do { \
|
|
|
|
_SWAP32(a->flags, b->flags); \
|
|
|
|
_SWAP32(a->xyz[0], b->xyz[0]); \
|
|
|
|
_SWAP32(a->xyz[1], b->xyz[1]); \
|
|
|
|
_SWAP32(a->xyz[2], b->xyz[2]); \
|
|
|
|
_SWAP32(a->uv[0], b->uv[0]); \
|
|
|
|
_SWAP32(a->uv[1], b->uv[1]); \
|
|
|
|
_SWAP32(a->bgra, b->bgra); \
|
|
|
|
_SWAP32(a->w, b->w); \
|
|
|
|
} 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;
|
|
|
|
|
|
|
|
PVRHeader* _glSubmissionTargetHeader(SubmissionTarget* target);
|
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;
|
|
|
|
|
2019-03-25 09:44:59 +00:00
|
|
|
void _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout, float* t);
|
2019-03-24 08:09:02 +00:00
|
|
|
void _glClipTriangleStrip(SubmissionTarget* target, uint8_t fladeShade);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2019-03-03 19:02:25 +00:00
|
|
|
PolyList *_glActivePolyList();
|
|
|
|
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();
|
|
|
|
void _glMatrixLoadTexture();
|
|
|
|
void _glApplyRenderMatrix();
|
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);
|
|
|
|
GLubyte _glCheckImmediateModeInactive(const char* func);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
pvr_poly_cxt_t* _glGetPVRContext();
|
2019-03-03 19:02:25 +00:00
|
|
|
GLubyte _glInitTextures();
|
2018-08-14 08:49:31 +00:00
|
|
|
|
|
|
|
void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit);
|
2019-04-17 13:55:30 +00:00
|
|
|
void _glAllocateSpaceForMipmaps(TextureObject* active);
|
2018-08-14 08:49:31 +00:00
|
|
|
|
2019-09-14 19:51:47 +00:00
|
|
|
extern GLfloat NEAR_PLANE_DISTANCE;
|
|
|
|
|
|
|
|
GLfloat _glGetNearPlane();
|
|
|
|
|
2018-08-21 15:15:43 +00:00
|
|
|
typedef struct {
|
|
|
|
const void* ptr;
|
|
|
|
GLenum type;
|
|
|
|
GLsizei stride;
|
|
|
|
GLint size;
|
|
|
|
} AttribPointer;
|
|
|
|
|
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();
|
2018-08-14 08:49:31 +00:00
|
|
|
GLubyte _glGetActiveTexture();
|
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
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
GLboolean _glIsBlendingEnabled();
|
2019-03-10 17:53:58 +00:00
|
|
|
GLboolean _glIsAlphaTestEnabled();
|
|
|
|
|
2018-08-14 08:49:31 +00:00
|
|
|
GLboolean _glIsMipmapComplete(const TextureObject* obj);
|
2018-08-09 07:56:43 +00:00
|
|
|
GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level);
|
|
|
|
GLuint _glGetMipmapLevelCount(TextureObject* obj);
|
2018-05-11 14:39:28 +00:00
|
|
|
|
2019-03-03 19:06:01 +00:00
|
|
|
GLboolean _glIsLightingEnabled();
|
|
|
|
GLboolean _glIsLightEnabled(GLubyte light);
|
2018-08-22 08:24:49 +00:00
|
|
|
GLboolean _glIsColorMaterialEnabled();
|
2019-08-01 19:21:03 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float xyz[3];
|
|
|
|
float n[3];
|
|
|
|
} EyeSpaceData;
|
|
|
|
|
|
|
|
extern void _glCalculateLighting(EyeSpaceData* ES, Vertex* vertex);
|
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
|
|
|
|
2018-05-20 15:16:53 +00:00
|
|
|
void _glKosThrowError(GLenum error, const char *function);
|
|
|
|
void _glKosPrintError();
|
|
|
|
GLubyte _glKosHasError();
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
#define PVR_VERTEX_BUF_SIZE 2560 * 256
|
|
|
|
#define MAX_TEXTURE_UNITS 2
|
2018-05-12 13:05:54 +00:00
|
|
|
#define MAX_LIGHTS 8
|
2018-05-11 14:39:28 +00:00
|
|
|
|
|
|
|
#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
#define mat_trans_fv12() { \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"fldi1 fr15\n" \
|
|
|
|
"ftrv xmtrx, fv12\n" \
|
|
|
|
"fldi1 fr14\n" \
|
|
|
|
"fdiv fr15, fr14\n" \
|
|
|
|
"fmul fr14, fr12\n" \
|
|
|
|
"fmul fr14, fr13\n" \
|
|
|
|
: "=f" (__x), "=f" (__y), "=f" (__z) \
|
|
|
|
: "0" (__x), "1" (__y), "2" (__z) \
|
|
|
|
: "fr15" ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PRIVATE_H
|