2018-05-05 19:38:55 +00:00
|
|
|
#ifndef PRIVATE_H
|
|
|
|
#define PRIVATE_H
|
|
|
|
|
|
|
|
#include "../include/gl.h"
|
2018-05-11 14:39:28 +00:00
|
|
|
#include "../containers/aligned_vector.h"
|
|
|
|
#include "../containers/named_array.h"
|
2018-05-31 08:38:34 +00:00
|
|
|
#include "./clip.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
|
|
|
|
2018-08-20 20:19:12 +00:00
|
|
|
#define CLIP_VERTEX_INT_PADDING 6
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
typedef struct {
|
2018-08-20 20:19:12 +00:00
|
|
|
pvr_poly_hdr_t hdr;
|
|
|
|
unsigned int padding[CLIP_VERTEX_INT_PADDING];
|
|
|
|
} 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 */
|
2018-08-20 20:19:12 +00:00
|
|
|
|
|
|
|
/* Padding to match clip vertex */
|
|
|
|
unsigned int padding[CLIP_VERTEX_INT_PADDING];
|
2018-05-11 14:39:28 +00:00
|
|
|
} 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-02-21 20:35:18 +00:00
|
|
|
GLushort width;
|
2018-09-20 14:01:13 +00:00
|
|
|
GLenum format;
|
|
|
|
} 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;
|
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;
|
|
|
|
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
PolyList *activePolyList();
|
2018-08-04 20:00:26 +00:00
|
|
|
PolyList *transparentPolyList();
|
2018-05-05 19:38:55 +00:00
|
|
|
|
|
|
|
void initAttributePointers();
|
2018-09-15 10:45:38 +00:00
|
|
|
void _glInitContext();
|
|
|
|
void _glInitLights();
|
2018-05-12 13:39:20 +00:00
|
|
|
void initImmediateMode();
|
2018-05-16 20:00:41 +00:00
|
|
|
void initMatrices();
|
2018-05-20 15:44:16 +00:00
|
|
|
void initFramebuffers();
|
2018-05-16 20:00:41 +00:00
|
|
|
|
|
|
|
void _matrixLoadNormal();
|
|
|
|
void _matrixLoadModelView();
|
|
|
|
void _matrixLoadTexture();
|
|
|
|
void _applyRenderMatrix();
|
|
|
|
|
2019-02-28 08:46:13 +00:00
|
|
|
matrix_t* _glGetProjectionMatrix();
|
|
|
|
|
2018-05-20 20:28:48 +00:00
|
|
|
void wipeTextureOnFramebuffers(GLuint texture);
|
2018-05-12 13:54:06 +00:00
|
|
|
GLubyte checkImmediateModeInactive(const char* func);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
pvr_poly_cxt_t* getPVRContext();
|
|
|
|
GLubyte _glKosInitTextures();
|
2018-08-14 08:49:31 +00:00
|
|
|
|
|
|
|
void _glUpdatePVRTextureContext(pvr_poly_cxt_t* context, GLshort textureUnit);
|
|
|
|
|
2018-08-21 15:15:43 +00:00
|
|
|
typedef struct {
|
|
|
|
const void* ptr;
|
|
|
|
GLenum type;
|
|
|
|
GLsizei stride;
|
|
|
|
GLint size;
|
|
|
|
} AttribPointer;
|
|
|
|
|
2018-08-22 08:24:49 +00:00
|
|
|
GLboolean _glCheckValidEnum(GLint param, GLenum* values, const char* func);
|
|
|
|
|
2018-08-21 15:08:06 +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
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
TextureObject* getTexture0();
|
|
|
|
TextureObject* getTexture1();
|
|
|
|
TextureObject* getBoundTexture();
|
2018-08-14 08:49:31 +00:00
|
|
|
GLubyte _glGetActiveTexture();
|
2018-08-21 14:50:59 +00:00
|
|
|
GLuint _glGetActiveClientTexture();
|
2018-08-14 08:49:31 +00:00
|
|
|
|
2019-02-21 21:58:31 +00:00
|
|
|
GLboolean _glIsSharedTexturePaletteEnabled();
|
|
|
|
void _glApplyColorTable();
|
|
|
|
|
2018-05-11 14:39:28 +00:00
|
|
|
GLboolean isBlendingEnabled();
|
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
|
|
|
|
2018-05-12 13:05:54 +00:00
|
|
|
GLboolean isLightingEnabled();
|
|
|
|
GLboolean isLightEnabled(GLubyte light);
|
2018-08-22 08:24:49 +00:00
|
|
|
GLboolean _glIsColorMaterialEnabled();
|
|
|
|
void _glCalculateLightingContribution(const GLint light, const GLfloat* pos, const GLfloat* normal, uint8_t* bgra, GLfloat* colour);
|
2018-05-12 13:05:54 +00:00
|
|
|
|
2018-08-01 10:32:07 +00:00
|
|
|
unsigned char isClippingEnabled();
|
|
|
|
void enableClipping(unsigned char v);
|
|
|
|
|
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
|