Normalize line endings in libgl to LF rather than CRLF.

This commit is contained in:
Lawrence Sebald 2014-08-29 15:56:23 -04:00
parent 5daf045d0c
commit be969bd840
19 changed files with 5835 additions and 5835 deletions

2764
gl-api.c

File diff suppressed because it is too large Load Diff

232
gl-api.h
View File

@ -1,116 +1,116 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-api.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
The functions defined in this header are for internal use by the API,
and not for use externally.
*/
#ifndef GL_API_H
#define GL_API_H
typedef struct {
float pos[3];
float norm[3];
} glVertex; /* Simple Vertex used for Dynamic Vertex Lighting */
typedef unsigned short uint16;
typedef unsigned char uint8;
/* Vertex Main Buffer Internal Functions */
inline void _glKosVertexBufSwitchOP();
inline void _glKosVertexBufSwitchTR();
inline void *_glKosVertexBufAddress(unsigned char list);
inline void *_glKosVertexBufPointer();
inline void *_glKosTRVertexBufPointer();
inline void _glKosVertexBufIncrement();
inline void _glKosTRVertexBufIncrement();
inline void _glKosVertexBufAdd(unsigned int count);
inline void _glKosTRVertexBufAdd(unsigned int count);
inline void _glKosVertexBufDecrement();
inline void _glKosVertexBufReset();
inline unsigned int _glKosVertexBufCount(unsigned char list);
unsigned char _glKosList();
inline void _glKosVertexBufCopy(void *src, void *dst, GLuint count);
inline void _glKosResetEnabledTex();
/* Vertex Clip Buffer Internal Functions */
inline void *_glKosClipBufAddress();
inline void *_glKosClipBufPointer();
inline void _glKosClipBufIncrement();
inline void _glKosClipBufReset();
/* Vertex Array Buffer Internal Functions */
inline void _glKosArrayBufIncrement();
inline void _glKosArrayBufReset();
inline glVertex *_glKosArrayBufAddr();
inline glVertex *_glKosArrayBufPtr();
/* Initialize the OpenGL PVR Pipeline */
int _glKosInitPVR();
/* Compile the current Polygon Header for the PVR */
void _glKosCompileHdr();
void _glKosCompileHdrTx();
void _glKosCompileHdrTx2();
/* Clipping Internal Functions */
void _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts);
unsigned int _glKosClipTriangleStrip(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipTriangles(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipQuads(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipTrianglesTransformed(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, GLuint count);
unsigned char _glKosClipTriTransformed(pvr_vertex_t *vin, float *w, pvr_vertex_t *vout);
unsigned int _glKosClipQuadsTransformed(pvr_vertex_t *vin, float *w, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipTriangleStripTransformed(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, GLuint count);
/* Lighting Internal Functions */
void _glKosInitLighting();
void _glKosEnableLight(const GLuint light);
void _glKosDisableLight(const GLuint light);
void _glKosSetEyePosition(GLfloat *position);
void _glKosVertexComputeLighting(pvr_vertex_t *v, int verts);
void _glKosVertexLight(glVertex *P, pvr_vertex_t *v);
unsigned int _glKosVertexLightColor(glVertex *P);
void _glKosVertexLights(glVertex *P, pvr_vertex_t *v, GLuint count);
/* Vertex Position Submission Internal Functions */
void _glKosVertex2ft(GLfloat x, GLfloat y);
void _glKosVertex2ftv(GLfloat *xy);
void _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3ftv(GLfloat *xyz);
void _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3fcv(GLfloat *xyz);
void _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3fpv(GLfloat *xyz);
void _glKosVertex3fl(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3flv(GLfloat *xyz);
void _glKosVertex3flc(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3flcv(GLfloat *xyz);
void _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3fsv(GLfloat *xyz);
/* Matrix Internal Functions */
void _glKosInitMatrix();
void _glKosMatrixLoadModelView();
void _glKosMatrixLoadModelRot();
void _glKosMatrixApplyScreenSpace();
void _glKosMatrixApplyRender();
void _glKosMatrixLoadRender();
/* API Enabled Capabilities Internal Functions */
GLint _glKosEnabledTexture2D();
GLubyte _glKosEnabledNearZClip();
GLubyte _glKosEnabledLighting();
/* RGB Pixel Colorspace Internal Functions */
uint16 __glKosAverageQuadPixelRGB565(uint16 p1, uint16 p2, uint16 p3, uint16 p4);
uint16 __glKosAverageQuadPixelARGB1555(uint16 p1, uint16 p2, uint16 p3, uint16 p4);
uint16 __glKosAverageQuadPixelARGB4444(uint16 p1, uint16 p2, uint16 p3, uint16 p4);
uint16 __glKosAverageBiPixelRGB565(uint16 p1, uint16 p2);
uint16 __glKosAverageBiPixelARGB1555(uint16 p1, uint16 p2);
uint16 __glKosAverageBiPixelARGB4444(uint16 p1, uint16 p2);
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-api.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
The functions defined in this header are for internal use by the API,
and not for use externally.
*/
#ifndef GL_API_H
#define GL_API_H
typedef struct {
float pos[3];
float norm[3];
} glVertex; /* Simple Vertex used for Dynamic Vertex Lighting */
typedef unsigned short uint16;
typedef unsigned char uint8;
/* Vertex Main Buffer Internal Functions */
inline void _glKosVertexBufSwitchOP();
inline void _glKosVertexBufSwitchTR();
inline void *_glKosVertexBufAddress(unsigned char list);
inline void *_glKosVertexBufPointer();
inline void *_glKosTRVertexBufPointer();
inline void _glKosVertexBufIncrement();
inline void _glKosTRVertexBufIncrement();
inline void _glKosVertexBufAdd(unsigned int count);
inline void _glKosTRVertexBufAdd(unsigned int count);
inline void _glKosVertexBufDecrement();
inline void _glKosVertexBufReset();
inline unsigned int _glKosVertexBufCount(unsigned char list);
unsigned char _glKosList();
inline void _glKosVertexBufCopy(void *src, void *dst, GLuint count);
inline void _glKosResetEnabledTex();
/* Vertex Clip Buffer Internal Functions */
inline void *_glKosClipBufAddress();
inline void *_glKosClipBufPointer();
inline void _glKosClipBufIncrement();
inline void _glKosClipBufReset();
/* Vertex Array Buffer Internal Functions */
inline void _glKosArrayBufIncrement();
inline void _glKosArrayBufReset();
inline glVertex *_glKosArrayBufAddr();
inline glVertex *_glKosArrayBufPtr();
/* Initialize the OpenGL PVR Pipeline */
int _glKosInitPVR();
/* Compile the current Polygon Header for the PVR */
void _glKosCompileHdr();
void _glKosCompileHdrTx();
void _glKosCompileHdrTx2();
/* Clipping Internal Functions */
void _glKosTransformClipBuf(pvr_vertex_t *v, GLuint verts);
unsigned int _glKosClipTriangleStrip(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipTriangles(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipQuads(pvr_vertex_t *vin, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipTrianglesTransformed(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, GLuint count);
unsigned char _glKosClipTriTransformed(pvr_vertex_t *vin, float *w, pvr_vertex_t *vout);
unsigned int _glKosClipQuadsTransformed(pvr_vertex_t *vin, float *w, pvr_vertex_t *vout, unsigned int vertices);
unsigned int _glKosClipTriangleStripTransformed(pvr_vertex_t *src, float *w, pvr_vertex_t *dst, GLuint count);
/* Lighting Internal Functions */
void _glKosInitLighting();
void _glKosEnableLight(const GLuint light);
void _glKosDisableLight(const GLuint light);
void _glKosSetEyePosition(GLfloat *position);
void _glKosVertexComputeLighting(pvr_vertex_t *v, int verts);
void _glKosVertexLight(glVertex *P, pvr_vertex_t *v);
unsigned int _glKosVertexLightColor(glVertex *P);
void _glKosVertexLights(glVertex *P, pvr_vertex_t *v, GLuint count);
/* Vertex Position Submission Internal Functions */
void _glKosVertex2ft(GLfloat x, GLfloat y);
void _glKosVertex2ftv(GLfloat *xy);
void _glKosVertex3ft(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3ftv(GLfloat *xyz);
void _glKosVertex3fc(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3fcv(GLfloat *xyz);
void _glKosVertex3fp(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3fpv(GLfloat *xyz);
void _glKosVertex3fl(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3flv(GLfloat *xyz);
void _glKosVertex3flc(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3flcv(GLfloat *xyz);
void _glKosVertex3fs(GLfloat x, GLfloat y, GLfloat z);
void _glKosVertex3fsv(GLfloat *xyz);
/* Matrix Internal Functions */
void _glKosInitMatrix();
void _glKosMatrixLoadModelView();
void _glKosMatrixLoadModelRot();
void _glKosMatrixApplyScreenSpace();
void _glKosMatrixApplyRender();
void _glKosMatrixLoadRender();
/* API Enabled Capabilities Internal Functions */
GLint _glKosEnabledTexture2D();
GLubyte _glKosEnabledNearZClip();
GLubyte _glKosEnabledLighting();
/* RGB Pixel Colorspace Internal Functions */
uint16 __glKosAverageQuadPixelRGB565(uint16 p1, uint16 p2, uint16 p3, uint16 p4);
uint16 __glKosAverageQuadPixelARGB1555(uint16 p1, uint16 p2, uint16 p3, uint16 p4);
uint16 __glKosAverageQuadPixelARGB4444(uint16 p1, uint16 p2, uint16 p3, uint16 p4);
uint16 __glKosAverageBiPixelRGB565(uint16 p1, uint16 p2);
uint16 __glKosAverageBiPixelARGB1555(uint16 p1, uint16 p2);
uint16 __glKosAverageBiPixelARGB4444(uint16 p1, uint16 p2);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +1,58 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-arrays.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Arrays Input Primitive Types Supported:
-GL_TRIANGLES
-GL_TRIANGLE_STRIPS
-GL_QUADS
Here, it is not necessary to enable or disable client states;
the API is aware of what arrays have been submitted, and will
render accordingly. If you submit a normal pointer, dynamic
vertex lighting will be applied even if you submit a color
pointer, so only submit one or the other.
ToDo: glDrawElements() is not yet implemented.
*/
#ifndef GL_ARRAYS_H
#define GL_ARRAYS_H
#include "gl.h"
#define GL_USE_ARRAY 0x0001
#define GL_USE_TEXTURE 0x0010
#define GL_USE_COLOR 0x0100
#define GL_USE_NORMAL 0x1000
#define GL_USE_TEXTURE_COLOR 0x0111
#define GL_USE_TEXTURE_LIT 0x1011
void (*_glKosArrayTexCoordFunc)(pvr_vertex_t *);
void (*_glKosArrayColorFunc)(pvr_vertex_t *);
void (*_glKosElementTexCoordFunc)(pvr_vertex_t *, GLuint);
void (*_glKosElementColorFunc)(pvr_vertex_t *, GLuint);
static GLfloat *GL_VERTEX_POINTER = NULL;
static GLushort GL_VERTEX_STRIDE = 0;
static GLfloat *GL_NORMAL_POINTER = NULL;
static GLushort GL_NORMAL_STRIDE = 0;
static GLfloat *GL_TEXCOORD_POINTER = NULL;
static GLushort GL_TEXCOORD_STRIDE = 0;
static GLfloat *GL_TEXCOORD2_POINTER = NULL;
static GLushort GL_TEXCOORD2_STRIDE = 0;
static GLfloat *GL_COLOR_POINTER = NULL;
static GLushort GL_COLOR_STRIDE = 0;
static GLubyte GL_COLOR_COMPONENTS = 0;
static GLenum GL_COLOR_TYPE = 0;
static GLubyte *GL_INDEX_POINTER_U8 = NULL;
static GLushort *GL_INDEX_POINTER_U16 = NULL;
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-arrays.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Arrays Input Primitive Types Supported:
-GL_TRIANGLES
-GL_TRIANGLE_STRIPS
-GL_QUADS
Here, it is not necessary to enable or disable client states;
the API is aware of what arrays have been submitted, and will
render accordingly. If you submit a normal pointer, dynamic
vertex lighting will be applied even if you submit a color
pointer, so only submit one or the other.
ToDo: glDrawElements() is not yet implemented.
*/
#ifndef GL_ARRAYS_H
#define GL_ARRAYS_H
#include "gl.h"
#define GL_USE_ARRAY 0x0001
#define GL_USE_TEXTURE 0x0010
#define GL_USE_COLOR 0x0100
#define GL_USE_NORMAL 0x1000
#define GL_USE_TEXTURE_COLOR 0x0111
#define GL_USE_TEXTURE_LIT 0x1011
void (*_glKosArrayTexCoordFunc)(pvr_vertex_t *);
void (*_glKosArrayColorFunc)(pvr_vertex_t *);
void (*_glKosElementTexCoordFunc)(pvr_vertex_t *, GLuint);
void (*_glKosElementColorFunc)(pvr_vertex_t *, GLuint);
static GLfloat *GL_VERTEX_POINTER = NULL;
static GLushort GL_VERTEX_STRIDE = 0;
static GLfloat *GL_NORMAL_POINTER = NULL;
static GLushort GL_NORMAL_STRIDE = 0;
static GLfloat *GL_TEXCOORD_POINTER = NULL;
static GLushort GL_TEXCOORD_STRIDE = 0;
static GLfloat *GL_TEXCOORD2_POINTER = NULL;
static GLushort GL_TEXCOORD2_STRIDE = 0;
static GLfloat *GL_COLOR_POINTER = NULL;
static GLushort GL_COLOR_STRIDE = 0;
static GLubyte GL_COLOR_COMPONENTS = 0;
static GLenum GL_COLOR_TYPE = 0;
static GLubyte *GL_INDEX_POINTER_U8 = NULL;
static GLushort *GL_INDEX_POINTER_U16 = NULL;
#endif

1490
gl-clip.c

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +1,44 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-clip.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Near-Z Clipping Algorithm (C) 2013-2014 Josh PH3NOM Pearson
Input Primitive Types Supported:
-GL_TRIANGLES
-GL_TRIANGLE_STRIPS
-GL_QUADS
Outputs a mix of Triangles and Triangle Strips for use with the PVR
*/
#ifndef GL_CLIP_H
#define GL_CLIP_H
#include "gl.h"
#include "gl-sh4.h"
#define NONE 0x0000 /* Clip Codes */
#define FIRST 0x0001
#define SECOND 0x0010
#define THIRD 0x0100
#define ALL 0x0111
#define FIRST_TWO_OUT 0x0011
#define FIRST_AND_LAST_OUT 0x0101
#define LAST_TWO_OUT 0x0110
#define ALPHA 0xFF000000 /* Color Components using PVR's Packed 32bit int */
#define RED 0x00FF0000
#define GREEN 0x0000FF00
#define BLUE 0x000000FF
#define CLIP_NEARZ -0.5f /* Clip Threshold */
typedef struct {
float x, y, z;
} float3;
typedef struct {
unsigned char b, g, r, a;
} colorui;
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-clip.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Near-Z Clipping Algorithm (C) 2013-2014 Josh PH3NOM Pearson
Input Primitive Types Supported:
-GL_TRIANGLES
-GL_TRIANGLE_STRIPS
-GL_QUADS
Outputs a mix of Triangles and Triangle Strips for use with the PVR
*/
#ifndef GL_CLIP_H
#define GL_CLIP_H
#include "gl.h"
#include "gl-sh4.h"
#define NONE 0x0000 /* Clip Codes */
#define FIRST 0x0001
#define SECOND 0x0010
#define THIRD 0x0100
#define ALL 0x0111
#define FIRST_TWO_OUT 0x0011
#define FIRST_AND_LAST_OUT 0x0101
#define LAST_TWO_OUT 0x0110
#define ALPHA 0xFF000000 /* Color Components using PVR's Packed 32bit int */
#define RED 0x00FF0000
#define GREEN 0x0000FF00
#define BLUE 0x000000FF
#define CLIP_NEARZ -0.5f /* Clip Threshold */
typedef struct {
float x, y, z;
} float3;
typedef struct {
unsigned char b, g, r, a;
} colorui;
#endif

204
gl-fog.c
View File

@ -1,102 +1,102 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-fog.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Functionality adapted from the original KOS libgl fog code:
Copyright (C) 2002 Benoit Miller
OpenGL Fog - Wrapper for the PowerVR fog functions in KOS.
*/
#include "gl.h"
static GLuint FOG_MODE = GL_EXP; /* GL_LINEAR, GL_EXP, or GL_EXP2 FOG */
static GLfloat FOG_DENSITY = 1.0f, /* Density - GL_EXP, or GL_EXP2 FOG */
FOG_START = 0.0f, /* Linear FOG */
FOG_END = 1.0f; /* Linear FOG */
void glFogi(GLenum pname, GLint param) {
switch(pname) {
case GL_FOG_MODE:
switch(param) {
case GL_LINEAR:
return pvr_fog_table_linear(FOG_START, FOG_END);
case GL_EXP:
return pvr_fog_table_exp(FOG_DENSITY);
case GL_EXP2:
return pvr_fog_table_exp2(FOG_DENSITY);
default:
return;
}
default:
return;
}
}
void glFogf(GLenum pname, GLfloat param) {
switch(pname) {
case GL_FOG_START:
FOG_START = param;
if(FOG_MODE == GL_LINEAR)
return pvr_fog_table_linear(FOG_START, FOG_END);
return;
case GL_FOG_END:
FOG_END = param;
if(FOG_MODE == GL_LINEAR)
return pvr_fog_table_linear(FOG_START, FOG_END);
return;
case GL_FOG_DENSITY:
FOG_DENSITY = param;
if(FOG_MODE == GL_EXP)
return pvr_fog_table_exp(FOG_DENSITY);
if(FOG_MODE == GL_EXP2)
return pvr_fog_table_exp2(FOG_DENSITY);
return;
default:
return;
}
}
void glFogfv(GLenum pname, const GLfloat *params) {
switch(pname) {
case GL_FOG_MODE:
return glFogi(pname, (GLint) * params);
case GL_FOG_DENSITY:
FOG_DENSITY = *params;
if(FOG_MODE == GL_EXP)
return pvr_fog_table_exp(FOG_DENSITY);
if(FOG_MODE == GL_EXP2)
return pvr_fog_table_exp2(FOG_DENSITY);
return;
case GL_FOG_START:
case GL_FOG_END:
return glFogf(pname, *params);
case GL_FOG_COLOR:
return pvr_fog_table_color(params[3], params[0], params[1], params[2]);
case GL_FOG_INDEX:
default:
return;
}
}
/* KallistiGL for KallistiOS ##version##
libgl/gl-fog.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Functionality adapted from the original KOS libgl fog code:
Copyright (C) 2002 Benoit Miller
OpenGL Fog - Wrapper for the PowerVR fog functions in KOS.
*/
#include "gl.h"
static GLuint FOG_MODE = GL_EXP; /* GL_LINEAR, GL_EXP, or GL_EXP2 FOG */
static GLfloat FOG_DENSITY = 1.0f, /* Density - GL_EXP, or GL_EXP2 FOG */
FOG_START = 0.0f, /* Linear FOG */
FOG_END = 1.0f; /* Linear FOG */
void glFogi(GLenum pname, GLint param) {
switch(pname) {
case GL_FOG_MODE:
switch(param) {
case GL_LINEAR:
return pvr_fog_table_linear(FOG_START, FOG_END);
case GL_EXP:
return pvr_fog_table_exp(FOG_DENSITY);
case GL_EXP2:
return pvr_fog_table_exp2(FOG_DENSITY);
default:
return;
}
default:
return;
}
}
void glFogf(GLenum pname, GLfloat param) {
switch(pname) {
case GL_FOG_START:
FOG_START = param;
if(FOG_MODE == GL_LINEAR)
return pvr_fog_table_linear(FOG_START, FOG_END);
return;
case GL_FOG_END:
FOG_END = param;
if(FOG_MODE == GL_LINEAR)
return pvr_fog_table_linear(FOG_START, FOG_END);
return;
case GL_FOG_DENSITY:
FOG_DENSITY = param;
if(FOG_MODE == GL_EXP)
return pvr_fog_table_exp(FOG_DENSITY);
if(FOG_MODE == GL_EXP2)
return pvr_fog_table_exp2(FOG_DENSITY);
return;
default:
return;
}
}
void glFogfv(GLenum pname, const GLfloat *params) {
switch(pname) {
case GL_FOG_MODE:
return glFogi(pname, (GLint) * params);
case GL_FOG_DENSITY:
FOG_DENSITY = *params;
if(FOG_MODE == GL_EXP)
return pvr_fog_table_exp(FOG_DENSITY);
if(FOG_MODE == GL_EXP2)
return pvr_fog_table_exp2(FOG_DENSITY);
return;
case GL_FOG_START:
case GL_FOG_END:
return glFogf(pname, *params);
case GL_FOG_COLOR:
return pvr_fog_table_color(params[3], params[0], params[1], params[2]);
case GL_FOG_INDEX:
default:
return;
}
}

1124
gl-light.c

File diff suppressed because it is too large Load Diff

View File

@ -1,51 +1,51 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-light.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Dynamic Vertex Lighting.
By default, specular lighting is enabled.
For now, specular can be disabled by setting GL_ENABLE_SPECULAR
below when you build the library.
By default, specular lighting uses a fast POW implementation, at
sacrifice of accuracy. Change GL_ENABLE_FAST_POW to suit your needs.
*/
#ifndef GL_LIGHT_H
#define GL_LIGHT_H
#include "gl-sh4.h"
#define GL_ENABLE_SPECULAR 1
#define GL_ENABLE_FAST_POW 1
int _glKosSpotlight(void *glLight, void *vertex6f, void *Lvectorout);
float _glKosSpecular(void *vertex6f, void *eyepos, void *Lvectorin);
typedef struct {
float r, g, b, a;
} rgba;
typedef struct {
float Ke[4]; /* RGBA material emissive color # 0.0, 0.0, 0.0, 1.0 */
float Ka[4]; /* RGBA material ambient reflectance # 0.2, 0.2, 0.2, 1.0 */
float Kd[4]; /* RGBA material diffuse reflectance # 0.8, 0.8, 0.8, 1.0 */
float Ks[4]; /* RGBA material diffuse reflectance # 0.0, 0.0, 0.0, 1.0 */
float Shine; /* Material Specular Shine # 0.0f */
} glMaterial;
typedef struct {
float Pos[4]; /* XYZW Position of Light # 0.0, 0.0, 1.0, 0.0 */
float Dir[3]; /* Spot Light Direction # 0.0, 0.0, -1.0 */
float CutOff; /* Spot Light CutOff #-1.0f */
float Kc, /* Constant Attenuation # 1.0f */
Kl, /* Linear Attenuation # 0.0f */
Kq; /* Quadratic Attenuation # 0.0f */
float Exponent; /* Spot Light Exponent # 0.0f */
float Kd[4]; /* RGBA Diffuse Light Contribution # 1.0, 1.0, 1.0, 1.0 */
float Ks[4]; /* RGBA Specular Light Contribution # 1.0, 1.0, 1.0, 1.0 */
float Ka[4]; /* RGBA Ambient Light Contribution # 0.0, 0.0, 0.0, 1.0 */
} glLight;
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-light.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Dynamic Vertex Lighting.
By default, specular lighting is enabled.
For now, specular can be disabled by setting GL_ENABLE_SPECULAR
below when you build the library.
By default, specular lighting uses a fast POW implementation, at
sacrifice of accuracy. Change GL_ENABLE_FAST_POW to suit your needs.
*/
#ifndef GL_LIGHT_H
#define GL_LIGHT_H
#include "gl-sh4.h"
#define GL_ENABLE_SPECULAR 1
#define GL_ENABLE_FAST_POW 1
int _glKosSpotlight(void *glLight, void *vertex6f, void *Lvectorout);
float _glKosSpecular(void *vertex6f, void *eyepos, void *Lvectorin);
typedef struct {
float r, g, b, a;
} rgba;
typedef struct {
float Ke[4]; /* RGBA material emissive color # 0.0, 0.0, 0.0, 1.0 */
float Ka[4]; /* RGBA material ambient reflectance # 0.2, 0.2, 0.2, 1.0 */
float Kd[4]; /* RGBA material diffuse reflectance # 0.8, 0.8, 0.8, 1.0 */
float Ks[4]; /* RGBA material diffuse reflectance # 0.0, 0.0, 0.0, 1.0 */
float Shine; /* Material Specular Shine # 0.0f */
} glMaterial;
typedef struct {
float Pos[4]; /* XYZW Position of Light # 0.0, 0.0, 1.0, 0.0 */
float Dir[3]; /* Spot Light Direction # 0.0, 0.0, -1.0 */
float CutOff; /* Spot Light CutOff #-1.0f */
float Kc, /* Constant Attenuation # 1.0f */
Kl, /* Linear Attenuation # 0.0f */
Kq; /* Quadratic Attenuation # 0.0f */
float Exponent; /* Spot Light Exponent # 0.0f */
float Kd[4]; /* RGBA Diffuse Light Contribution # 1.0, 1.0, 1.0, 1.0 */
float Ks[4]; /* RGBA Specular Light Contribution # 1.0, 1.0, 1.0, 1.0 */
float Ka[4]; /* RGBA Ambient Light Contribution # 0.0, 0.0, 0.0, 1.0 */
} glLight;
#endif

View File

@ -1,403 +1,403 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-matrix.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Copyright (C) 2014 Lawrence Sebald
Some functionality adapted from the original KOS libgl:
Copyright (C) 2001 Dan Potter
The GL matrix operations use the KOS SH4 matrix operations.
Basically, we keep two seperate matrix stacks:
1.) Internal GL API Matrix Stack ( screenview, modelview, etc. ) ( fixed stack size )
2.) External Matrix Stack for client to push / pop ( size of each stack is determined by MAX_MATRICES )
*/
#include <string.h>
#include "gl.h"
#include "glu.h"
#include "gl-api.h"
#include "gl-sh4.h"
/* This Matrix contains the GL Base Stack */
static matrix4f Matrix[GL_MATRIX_COUNT] __attribute__((aligned(32)));
static GLsizei MatrixMode = 0;
/* This Matrix contains the GL Push/Pop Stack ( fixed size per mode, 32 matrices )*/
static const GLsizei MAX_MATRICES = 32;
static matrix4f MatrixStack[GL_MATRIX_COUNT][32] __attribute__((aligned(32)));
static GLsizei MatrixStackPos[GL_MATRIX_COUNT];
/* Viewport mapping */
static GLfloat gl_viewport_scale[3], gl_viewport_offset[3];
/* Depth range */
static GLclampf gl_depthrange_near, gl_depthrange_far;
/* Viewport size */
static GLint gl_viewport_x1, gl_viewport_y1, gl_viewport_width, gl_viewport_height;
/* Frustum attributes */
typedef struct {
float left, right, bottom, top, znear, zfar;
} gl_frustum_t;
static gl_frustum_t gl_frustum;
/* Frustum Matrix */
static matrix4f FrustumMatrix __attribute__((aligned(32))) = {
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, -1.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f }
};
/* Ortho Matrix */
static matrix4f OrthoMatrix __attribute__((aligned(32))) = {
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
/* Matrix for user to submit externally, ensure 32byte allignment */
static matrix4f ml __attribute__((aligned(32)));
/* Look-At Matrix */
static matrix4f MatrixLookAt __attribute__((aligned(32))) = {
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
/* Modelview Rotation Matrix - Applied to Vertex Normal when Lighting is Enabled */
static matrix4f MatrixMdlRot __attribute__((aligned(32))) = {
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
void glMatrixMode(GLenum mode) {
if(mode >= GL_SCREENVIEW && mode <= GL_IDENTITY)
MatrixMode = mode;
}
void glPushMatrix() {
if(MatrixStackPos[MatrixMode] < MAX_MATRICES - 1) {
mat_load(Matrix + MatrixMode);
mat_store(&MatrixStack[MatrixMode][MatrixStackPos[MatrixMode]]);
++MatrixStackPos[MatrixMode];
}
}
void glPopMatrix() {
if(MatrixStackPos[MatrixMode]) {
--MatrixStackPos[MatrixMode];
mat_load(&MatrixStack[MatrixMode][MatrixStackPos[MatrixMode]]);
mat_store(Matrix + MatrixMode);
}
}
void glLoadIdentity() {
mat_load(Matrix + GL_IDENTITY);
mat_store(Matrix + MatrixMode);
if(MatrixMode == GL_MODELVIEW)
mat_store(&MatrixMdlRot);
}
void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
mat_load(Matrix + MatrixMode);
mat_translate(x, y, z);
mat_store(Matrix + MatrixMode);
}
void glScalef(GLfloat x, GLfloat y, GLfloat z) {
mat_load(Matrix + MatrixMode);
mat_scale(x, y, z);
mat_store(Matrix + MatrixMode);
}
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
float r = DEG2RAD * angle;
mat_load(Matrix + MatrixMode);
mat_rotate(r * x, r * y, r * z);
mat_store(Matrix + MatrixMode);
if(MatrixMode == GL_MODELVIEW) {
mat_load(&MatrixMdlRot);
mat_rotate(r * x, r * y, r * z);
mat_store(&MatrixMdlRot);
}
}
/* Load an arbitrary matrix */
void glLoadMatrixf(const GLfloat *m) {
memcpy(ml, m, sizeof(matrix4f));
mat_load(&ml);
mat_store(Matrix + MatrixMode);
}
/* Load an arbitrary transposed matrix */
void glLoadTransposeMatrixf(const GLfloat *m) {
ml[0][0] = m[0];
ml[0][1] = m[4];
ml[0][2] = m[8];
ml[0][3] = m[12];
ml[1][0] = m[1];
ml[1][1] = m[5];
ml[1][2] = m[9];
ml[1][3] = m[13];
ml[2][0] = m[2];
ml[2][1] = m[6];
ml[2][2] = m[10];
ml[2][3] = m[14];
ml[3][0] = m[3];
ml[3][1] = m[7];
ml[3][2] = m[11];
ml[3][3] = m[15];
mat_load(&ml);
mat_store(Matrix + MatrixMode);
}
/* Multiply the current matrix by an arbitrary matrix */
void glMultMatrixf(const GLfloat *m) {
memcpy(ml, m, sizeof(matrix4f));
mat_load(Matrix + MatrixMode);
mat_apply(&ml);
mat_store(Matrix + MatrixMode);
}
/* Multiply the current matrix by an arbitrary transposed matrix */
void glMultTransposeMatrixf(const GLfloat *m) {
ml[0][0] = m[0];
ml[0][1] = m[4];
ml[0][2] = m[8];
ml[0][3] = m[12];
ml[1][0] = m[1];
ml[1][1] = m[5];
ml[1][2] = m[9];
ml[1][3] = m[13];
ml[2][0] = m[2];
ml[2][1] = m[6];
ml[2][2] = m[10];
ml[2][3] = m[14];
ml[3][0] = m[3];
ml[3][1] = m[7];
ml[3][2] = m[11];
ml[3][3] = m[15];
mat_load(Matrix + MatrixMode);
mat_apply(&ml);
mat_store(Matrix + MatrixMode);
}
/* Set the depth range */
void glDepthRange(GLclampf n, GLclampf f) {
/* clamp the values... */
if(n < 0.0f) n = 0.0f;
else if(n > 1.0f) n = 1.0f;
if(f < 0.0f) f = 0.0f;
else if(f > 1.0f) f = 1.0f;
gl_depthrange_near = n;
gl_depthrange_far = f;
/* Adjust the viewport scale and offset for Z */
gl_viewport_scale[2] = ((f - n) / 2.0f);
gl_viewport_offset[2] = (n + f) / 2.0f;
}
/* Set the GL viewport */
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
gl_viewport_x1 = x;
gl_viewport_y1 = y;
gl_viewport_width = width;
gl_viewport_height = height;
/* Calculate the viewport scale and offset */
gl_viewport_scale[0] = (GLfloat)width / 2.0f;
gl_viewport_offset[0] = gl_viewport_scale[0] + (GLfloat)x;
gl_viewport_scale[1] = (GLfloat)height / 2.0f;
gl_viewport_offset[1] = gl_viewport_scale[1] + (GLfloat)y;
gl_viewport_scale[2] = (gl_depthrange_far - gl_depthrange_near) / 2.0f;
gl_viewport_offset[2] = (gl_depthrange_near + gl_depthrange_far) / 2.0f;
gl_viewport_offset[2] += 0.0001f;
/* Set the Screenview Matrix based on the viewport */
Matrix[GL_SCREENVIEW][0][0] = gl_viewport_scale[0];
Matrix[GL_SCREENVIEW][1][1] = -gl_viewport_scale[1];
Matrix[GL_SCREENVIEW][2][2] = 1;
Matrix[GL_SCREENVIEW][3][0] = gl_viewport_offset[0];
Matrix[GL_SCREENVIEW][3][1] = vid_mode->height - gl_viewport_offset[1];
}
/* Set the GL frustum */
void glFrustum(GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat znear, GLfloat zfar) {
gl_frustum.left = left;
gl_frustum.right = right;
gl_frustum.bottom = bottom;
gl_frustum.top = top;
gl_frustum.znear = znear;
gl_frustum.zfar = zfar;
FrustumMatrix[0][0] = (2.0f * znear) / (right - left);
FrustumMatrix[2][0] = (right + left) / (right - left);
FrustumMatrix[1][1] = (2.0f * znear) / (top - bottom);
FrustumMatrix[2][1] = (top + bottom) / (top - bottom);
FrustumMatrix[2][2] = zfar / (zfar - znear);
FrustumMatrix[3][2] = -(zfar * znear) / (zfar - znear);
mat_load(Matrix + MatrixMode);
mat_apply(&FrustumMatrix);
mat_store(Matrix + MatrixMode);
}
/* Ortho */
void glOrtho(GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat znear, GLfloat zfar) {
OrthoMatrix[0][0] = 2.0f / (right - left);
OrthoMatrix[1][1] = 2.0f / (top - bottom);
OrthoMatrix[2][2] = -2.0f / (zfar - znear);
OrthoMatrix[3][0] = -(right + left) / (right - left);;
OrthoMatrix[3][1] = -(top + bottom) / (top - bottom);
OrthoMatrix[3][2] = -(zfar + znear) / (zfar - znear);
mat_load(Matrix + MatrixMode);
mat_apply(&OrthoMatrix);
mat_store(Matrix + MatrixMode);
}
/* Set the Perspective */
void gluPerspective(GLfloat angle, GLfloat aspect,
GLfloat znear, GLfloat zfar) {
GLfloat xmin, xmax, ymin, ymax;
ymax = znear * ftan(angle * F_PI / 360.0f);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, znear, zfar);
}
/* Vector Cross Product - Used by glhLookAtf2 */
void vec3f_cross(vector3f v1, vector3f v2, vector3f result) {
result[0] = v1[1] * v2[2] - v1[2] * v2[1];
result[1] = v1[2] * v2[0] - v1[0] * v2[2];
result[2] = v1[0] * v2[1] - v1[1] * v2[0];
}
/* glhLookAtf2 adapted from http://www.opengl.org/wiki/GluLookAt_code */
void glhLookAtf2(vector3f eyePosition3D,
vector3f center3D,
vector3f upVector3D) {
vector3f forward, side, up;
_glKosSetEyePosition(eyePosition3D);
vec3f_sub_normalize(center3D[0], center3D[1], center3D[2],
eyePosition3D[0], eyePosition3D[1], eyePosition3D[2],
forward[0], forward[1], forward[2]);
//Side = forward x up
vec3f_cross(forward, upVector3D, side);
vec3f_normalize(side[0], side[1], side[2]);
//Recompute up as: up = side x forward
vec3f_cross(side, forward, up);
MatrixLookAt[0][0] = side[0];
MatrixLookAt[1][0] = side[1];
MatrixLookAt[2][0] = side[2];
MatrixLookAt[3][0] = 0;
MatrixLookAt[0][1] = up[0];
MatrixLookAt[1][1] = up[1];
MatrixLookAt[2][1] = up[2];
MatrixLookAt[3][1] = 0;
MatrixLookAt[0][2] = -forward[0];
MatrixLookAt[1][2] = -forward[1];
MatrixLookAt[2][2] = -forward[2];
MatrixLookAt[3][2] = 0;
MatrixLookAt[0][3] =
MatrixLookAt[1][3] =
MatrixLookAt[2][3] = 0;
MatrixLookAt[3][3] = 1;
// Does not modify internal Modelview matrix
mat_load(&MatrixLookAt);
mat_translate(-eyePosition3D[0], -eyePosition3D[1], -eyePosition3D[2]);
mat_store(&MatrixLookAt);
}
void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy,
GLfloat upz) {
vector3f eye = { eyex, eyey, eyez };
vector3f point = { centerx, centery, centerz };
vector3f up = { upx, upy, upz };
glhLookAtf2(eye, point, up);
}
void _glKosMatrixApplyRender() {
mat_load(Matrix + GL_SCREENVIEW);
mat_apply(Matrix + GL_PROJECTION);
mat_apply(&MatrixLookAt);
mat_apply(Matrix + GL_MODELVIEW);
mat_store(Matrix + GL_RENDER);
}
void _glKosMatrixLoadRender() {
mat_load(Matrix + GL_RENDER);
}
void _glKosMatrixLoadModelView() {
mat_load(Matrix + GL_MODELVIEW);
}
void _glKosMatrixLoadModelRot() {
mat_load(&MatrixMdlRot);
}
void _glKosMatrixApplyScreenSpace() {
mat_load(Matrix + GL_SCREENVIEW);
mat_apply(Matrix + GL_PROJECTION);
mat_apply(&MatrixLookAt);
}
void _glKosInitMatrix() {
mat_identity();
mat_store(Matrix + GL_SCREENVIEW);
mat_store(Matrix + GL_PROJECTION);
mat_store(Matrix + GL_MODELVIEW);
mat_store(Matrix + GL_TEXTURE);
mat_store(Matrix + GL_IDENTITY);
mat_store(Matrix + GL_RENDER);
int i;
for(i = 0; i < GL_MATRIX_COUNT; i++)
MatrixStackPos[i] = 0;
glDepthRange(0.0f, 1.0f);
glViewport(0, 0, vid_mode->width, vid_mode->height);
}
void glKosGetMatrix(GLenum mode, GLfloat *params) {
if(mode < GL_SCREENVIEW || mode > GL_RENDER)
*params = (GLfloat)GL_INVALID_ENUM;
memcpy(params, Matrix + mode, sizeof(GLfloat) * 16);
}
/* KallistiGL for KallistiOS ##version##
libgl/gl-matrix.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Copyright (C) 2014 Lawrence Sebald
Some functionality adapted from the original KOS libgl:
Copyright (C) 2001 Dan Potter
The GL matrix operations use the KOS SH4 matrix operations.
Basically, we keep two seperate matrix stacks:
1.) Internal GL API Matrix Stack ( screenview, modelview, etc. ) ( fixed stack size )
2.) External Matrix Stack for client to push / pop ( size of each stack is determined by MAX_MATRICES )
*/
#include <string.h>
#include "gl.h"
#include "glu.h"
#include "gl-api.h"
#include "gl-sh4.h"
/* This Matrix contains the GL Base Stack */
static matrix4f Matrix[GL_MATRIX_COUNT] __attribute__((aligned(32)));
static GLsizei MatrixMode = 0;
/* This Matrix contains the GL Push/Pop Stack ( fixed size per mode, 32 matrices )*/
static const GLsizei MAX_MATRICES = 32;
static matrix4f MatrixStack[GL_MATRIX_COUNT][32] __attribute__((aligned(32)));
static GLsizei MatrixStackPos[GL_MATRIX_COUNT];
/* Viewport mapping */
static GLfloat gl_viewport_scale[3], gl_viewport_offset[3];
/* Depth range */
static GLclampf gl_depthrange_near, gl_depthrange_far;
/* Viewport size */
static GLint gl_viewport_x1, gl_viewport_y1, gl_viewport_width, gl_viewport_height;
/* Frustum attributes */
typedef struct {
float left, right, bottom, top, znear, zfar;
} gl_frustum_t;
static gl_frustum_t gl_frustum;
/* Frustum Matrix */
static matrix4f FrustumMatrix __attribute__((aligned(32))) = {
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, -1.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f }
};
/* Ortho Matrix */
static matrix4f OrthoMatrix __attribute__((aligned(32))) = {
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
/* Matrix for user to submit externally, ensure 32byte allignment */
static matrix4f ml __attribute__((aligned(32)));
/* Look-At Matrix */
static matrix4f MatrixLookAt __attribute__((aligned(32))) = {
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
/* Modelview Rotation Matrix - Applied to Vertex Normal when Lighting is Enabled */
static matrix4f MatrixMdlRot __attribute__((aligned(32))) = {
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
void glMatrixMode(GLenum mode) {
if(mode >= GL_SCREENVIEW && mode <= GL_IDENTITY)
MatrixMode = mode;
}
void glPushMatrix() {
if(MatrixStackPos[MatrixMode] < MAX_MATRICES - 1) {
mat_load(Matrix + MatrixMode);
mat_store(&MatrixStack[MatrixMode][MatrixStackPos[MatrixMode]]);
++MatrixStackPos[MatrixMode];
}
}
void glPopMatrix() {
if(MatrixStackPos[MatrixMode]) {
--MatrixStackPos[MatrixMode];
mat_load(&MatrixStack[MatrixMode][MatrixStackPos[MatrixMode]]);
mat_store(Matrix + MatrixMode);
}
}
void glLoadIdentity() {
mat_load(Matrix + GL_IDENTITY);
mat_store(Matrix + MatrixMode);
if(MatrixMode == GL_MODELVIEW)
mat_store(&MatrixMdlRot);
}
void glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
mat_load(Matrix + MatrixMode);
mat_translate(x, y, z);
mat_store(Matrix + MatrixMode);
}
void glScalef(GLfloat x, GLfloat y, GLfloat z) {
mat_load(Matrix + MatrixMode);
mat_scale(x, y, z);
mat_store(Matrix + MatrixMode);
}
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
float r = DEG2RAD * angle;
mat_load(Matrix + MatrixMode);
mat_rotate(r * x, r * y, r * z);
mat_store(Matrix + MatrixMode);
if(MatrixMode == GL_MODELVIEW) {
mat_load(&MatrixMdlRot);
mat_rotate(r * x, r * y, r * z);
mat_store(&MatrixMdlRot);
}
}
/* Load an arbitrary matrix */
void glLoadMatrixf(const GLfloat *m) {
memcpy(ml, m, sizeof(matrix4f));
mat_load(&ml);
mat_store(Matrix + MatrixMode);
}
/* Load an arbitrary transposed matrix */
void glLoadTransposeMatrixf(const GLfloat *m) {
ml[0][0] = m[0];
ml[0][1] = m[4];
ml[0][2] = m[8];
ml[0][3] = m[12];
ml[1][0] = m[1];
ml[1][1] = m[5];
ml[1][2] = m[9];
ml[1][3] = m[13];
ml[2][0] = m[2];
ml[2][1] = m[6];
ml[2][2] = m[10];
ml[2][3] = m[14];
ml[3][0] = m[3];
ml[3][1] = m[7];
ml[3][2] = m[11];
ml[3][3] = m[15];
mat_load(&ml);
mat_store(Matrix + MatrixMode);
}
/* Multiply the current matrix by an arbitrary matrix */
void glMultMatrixf(const GLfloat *m) {
memcpy(ml, m, sizeof(matrix4f));
mat_load(Matrix + MatrixMode);
mat_apply(&ml);
mat_store(Matrix + MatrixMode);
}
/* Multiply the current matrix by an arbitrary transposed matrix */
void glMultTransposeMatrixf(const GLfloat *m) {
ml[0][0] = m[0];
ml[0][1] = m[4];
ml[0][2] = m[8];
ml[0][3] = m[12];
ml[1][0] = m[1];
ml[1][1] = m[5];
ml[1][2] = m[9];
ml[1][3] = m[13];
ml[2][0] = m[2];
ml[2][1] = m[6];
ml[2][2] = m[10];
ml[2][3] = m[14];
ml[3][0] = m[3];
ml[3][1] = m[7];
ml[3][2] = m[11];
ml[3][3] = m[15];
mat_load(Matrix + MatrixMode);
mat_apply(&ml);
mat_store(Matrix + MatrixMode);
}
/* Set the depth range */
void glDepthRange(GLclampf n, GLclampf f) {
/* clamp the values... */
if(n < 0.0f) n = 0.0f;
else if(n > 1.0f) n = 1.0f;
if(f < 0.0f) f = 0.0f;
else if(f > 1.0f) f = 1.0f;
gl_depthrange_near = n;
gl_depthrange_far = f;
/* Adjust the viewport scale and offset for Z */
gl_viewport_scale[2] = ((f - n) / 2.0f);
gl_viewport_offset[2] = (n + f) / 2.0f;
}
/* Set the GL viewport */
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
gl_viewport_x1 = x;
gl_viewport_y1 = y;
gl_viewport_width = width;
gl_viewport_height = height;
/* Calculate the viewport scale and offset */
gl_viewport_scale[0] = (GLfloat)width / 2.0f;
gl_viewport_offset[0] = gl_viewport_scale[0] + (GLfloat)x;
gl_viewport_scale[1] = (GLfloat)height / 2.0f;
gl_viewport_offset[1] = gl_viewport_scale[1] + (GLfloat)y;
gl_viewport_scale[2] = (gl_depthrange_far - gl_depthrange_near) / 2.0f;
gl_viewport_offset[2] = (gl_depthrange_near + gl_depthrange_far) / 2.0f;
gl_viewport_offset[2] += 0.0001f;
/* Set the Screenview Matrix based on the viewport */
Matrix[GL_SCREENVIEW][0][0] = gl_viewport_scale[0];
Matrix[GL_SCREENVIEW][1][1] = -gl_viewport_scale[1];
Matrix[GL_SCREENVIEW][2][2] = 1;
Matrix[GL_SCREENVIEW][3][0] = gl_viewport_offset[0];
Matrix[GL_SCREENVIEW][3][1] = vid_mode->height - gl_viewport_offset[1];
}
/* Set the GL frustum */
void glFrustum(GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat znear, GLfloat zfar) {
gl_frustum.left = left;
gl_frustum.right = right;
gl_frustum.bottom = bottom;
gl_frustum.top = top;
gl_frustum.znear = znear;
gl_frustum.zfar = zfar;
FrustumMatrix[0][0] = (2.0f * znear) / (right - left);
FrustumMatrix[2][0] = (right + left) / (right - left);
FrustumMatrix[1][1] = (2.0f * znear) / (top - bottom);
FrustumMatrix[2][1] = (top + bottom) / (top - bottom);
FrustumMatrix[2][2] = zfar / (zfar - znear);
FrustumMatrix[3][2] = -(zfar * znear) / (zfar - znear);
mat_load(Matrix + MatrixMode);
mat_apply(&FrustumMatrix);
mat_store(Matrix + MatrixMode);
}
/* Ortho */
void glOrtho(GLfloat left, GLfloat right,
GLfloat bottom, GLfloat top,
GLfloat znear, GLfloat zfar) {
OrthoMatrix[0][0] = 2.0f / (right - left);
OrthoMatrix[1][1] = 2.0f / (top - bottom);
OrthoMatrix[2][2] = -2.0f / (zfar - znear);
OrthoMatrix[3][0] = -(right + left) / (right - left);;
OrthoMatrix[3][1] = -(top + bottom) / (top - bottom);
OrthoMatrix[3][2] = -(zfar + znear) / (zfar - znear);
mat_load(Matrix + MatrixMode);
mat_apply(&OrthoMatrix);
mat_store(Matrix + MatrixMode);
}
/* Set the Perspective */
void gluPerspective(GLfloat angle, GLfloat aspect,
GLfloat znear, GLfloat zfar) {
GLfloat xmin, xmax, ymin, ymax;
ymax = znear * ftan(angle * F_PI / 360.0f);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, znear, zfar);
}
/* Vector Cross Product - Used by glhLookAtf2 */
void vec3f_cross(vector3f v1, vector3f v2, vector3f result) {
result[0] = v1[1] * v2[2] - v1[2] * v2[1];
result[1] = v1[2] * v2[0] - v1[0] * v2[2];
result[2] = v1[0] * v2[1] - v1[1] * v2[0];
}
/* glhLookAtf2 adapted from http://www.opengl.org/wiki/GluLookAt_code */
void glhLookAtf2(vector3f eyePosition3D,
vector3f center3D,
vector3f upVector3D) {
vector3f forward, side, up;
_glKosSetEyePosition(eyePosition3D);
vec3f_sub_normalize(center3D[0], center3D[1], center3D[2],
eyePosition3D[0], eyePosition3D[1], eyePosition3D[2],
forward[0], forward[1], forward[2]);
//Side = forward x up
vec3f_cross(forward, upVector3D, side);
vec3f_normalize(side[0], side[1], side[2]);
//Recompute up as: up = side x forward
vec3f_cross(side, forward, up);
MatrixLookAt[0][0] = side[0];
MatrixLookAt[1][0] = side[1];
MatrixLookAt[2][0] = side[2];
MatrixLookAt[3][0] = 0;
MatrixLookAt[0][1] = up[0];
MatrixLookAt[1][1] = up[1];
MatrixLookAt[2][1] = up[2];
MatrixLookAt[3][1] = 0;
MatrixLookAt[0][2] = -forward[0];
MatrixLookAt[1][2] = -forward[1];
MatrixLookAt[2][2] = -forward[2];
MatrixLookAt[3][2] = 0;
MatrixLookAt[0][3] =
MatrixLookAt[1][3] =
MatrixLookAt[2][3] = 0;
MatrixLookAt[3][3] = 1;
// Does not modify internal Modelview matrix
mat_load(&MatrixLookAt);
mat_translate(-eyePosition3D[0], -eyePosition3D[1], -eyePosition3D[2]);
mat_store(&MatrixLookAt);
}
void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx,
GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy,
GLfloat upz) {
vector3f eye = { eyex, eyey, eyez };
vector3f point = { centerx, centery, centerz };
vector3f up = { upx, upy, upz };
glhLookAtf2(eye, point, up);
}
void _glKosMatrixApplyRender() {
mat_load(Matrix + GL_SCREENVIEW);
mat_apply(Matrix + GL_PROJECTION);
mat_apply(&MatrixLookAt);
mat_apply(Matrix + GL_MODELVIEW);
mat_store(Matrix + GL_RENDER);
}
void _glKosMatrixLoadRender() {
mat_load(Matrix + GL_RENDER);
}
void _glKosMatrixLoadModelView() {
mat_load(Matrix + GL_MODELVIEW);
}
void _glKosMatrixLoadModelRot() {
mat_load(&MatrixMdlRot);
}
void _glKosMatrixApplyScreenSpace() {
mat_load(Matrix + GL_SCREENVIEW);
mat_apply(Matrix + GL_PROJECTION);
mat_apply(&MatrixLookAt);
}
void _glKosInitMatrix() {
mat_identity();
mat_store(Matrix + GL_SCREENVIEW);
mat_store(Matrix + GL_PROJECTION);
mat_store(Matrix + GL_MODELVIEW);
mat_store(Matrix + GL_TEXTURE);
mat_store(Matrix + GL_IDENTITY);
mat_store(Matrix + GL_RENDER);
int i;
for(i = 0; i < GL_MATRIX_COUNT; i++)
MatrixStackPos[i] = 0;
glDepthRange(0.0f, 1.0f);
glViewport(0, 0, vid_mode->width, vid_mode->height);
}
void glKosGetMatrix(GLenum mode, GLfloat *params) {
if(mode < GL_SCREENVIEW || mode > GL_RENDER)
*params = (GLfloat)GL_INVALID_ENUM;
memcpy(params, Matrix + mode, sizeof(GLfloat) * 16);
}

430
gl-pvr.c
View File

@ -1,215 +1,215 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-pvr.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Vertex Buffer Routines for interfacing the Dreamcast's SH4 CPU and PowerVR GPU.
What we are doing here is using a Vertex Buffer in main RAM to store the
submitted data, untill the user finishes the scene by either calling
glSwapBuffer() to submit the buffer to the PVR for render to the screen OR
glSwapBufferToTexture() to submit the buffer to the PVR for render to texture.
This solution means the client can switch between transparent and opaque polygon
sumbission at any time, in no particular order, with no penalty in speed.
The size of the Vertex Buffer can be controlled by setting some params on gl-pvr.h:
GL_PVR_VERTEX_BUF_SIZE controls size of Vertex Buffer in the PVR VRAM
GL_MAX_VERTS conrols the number of vertices per list in the Vertex Buffer in SH4 RAM
*/
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gl.h"
#include "gl-sh4.h"
#include "gl-pvr.h"
/* Vertex Buffer Functions *************************************************************************/
#ifdef GL_USE_MALLOC
static pvr_cmd_t *GL_VBUF[2] __attribute__((aligned(32))); /* Dynamic Vertex Buffer */
static pvr_cmd_t *GL_CBUF; /* Dynamic Clip Buffer */
#else
static pvr_cmd_t GL_VBUF[2][GL_MAX_VERTS] __attribute__((aligned(32))); /* Static Vertex Buffer */
static pvr_cmd_t GL_CBUF[GL_MAX_VERTS / 2]; /* Static Clip Buffer */
#endif
static unsigned int GL_VERTS[2] = {0, 0},
GL_CVERTS = 0,
GL_LIST = GL_LIST_OP;
/* Custom version of sq_cpy from KOS for copying vertex data to the PVR */
static inline void pvr_list_submit(void *src, int n) {
unsigned int *d = TA_SQ_ADDR;
unsigned int *s = src;
/* fill/write queues as many times necessary */
while(n--) {
asm("pref @%0" : : "r"(s + 8)); /* prefetch 32 bytes for next loop */
d[0] = *(s++);
d[1] = *(s++);
d[2] = *(s++);
d[3] = *(s++);
d[4] = *(s++);
d[5] = *(s++);
d[6] = *(s++);
d[7] = *(s++);
asm("pref @%0" : : "r"(d));
d += 8;
}
/* Wait for both store queues to complete */
d = (unsigned int *)0xe0000000;
d[0] = d[8] = 0;
}
inline void *_glKosClipBufAddress() {
return &GL_CBUF[0];
}
inline void *_glKosClipBufPointer() {
return &GL_CBUF[GL_CVERTS];
}
inline void _glKosClipBufIncrement() {
++GL_CVERTS;
}
inline void _glKosClipBufAdd(unsigned int count) {
GL_CVERTS += count;
}
inline void _glKosClipBufReset() {
GL_CVERTS = 0;
}
inline void _glKosVertexBufSwitchOP() {
GL_LIST = GL_LIST_OP;
}
inline void _glKosVertexBufSwitchTR() {
GL_LIST = GL_LIST_TR;
}
inline void *_glKosVertexBufAddress(unsigned char list) {
return &GL_VBUF[list][0];
}
inline void *_glKosVertexBufPointer() {
return &GL_VBUF[GL_LIST][GL_VERTS[GL_LIST]];
}
inline void _glKosVertexBufIncrement() {
++GL_VERTS[GL_LIST];
}
inline void *_glKosTRVertexBufPointer() {
return &GL_VBUF[GL_LIST_TR][GL_VERTS[GL_LIST_TR]];
}
inline void _glKosTRVertexBufIncrement() {
++GL_VERTS[GL_LIST_TR];
}
inline void _glKosVertexBufAdd(unsigned int count) {
GL_VERTS[GL_LIST] += count;
}
inline void _glKosTRVertexBufAdd(unsigned int count) {
GL_VERTS[GL_LIST_TR] += count;
}
inline void _glKosVertexBufDecrement() {
--GL_VERTS[GL_LIST];
}
inline void _glKosVertexBufReset() {
GL_VERTS[0] = GL_VERTS[1] = 0;
}
inline unsigned int _glKosVertexBufCount(unsigned char list) {
return GL_VERTS[list];
}
unsigned char _glKosList() {
return GL_LIST;
}
inline void _glKosVertexBufCopy(void *dst, void *src, GLuint count) {
memcpy(dst, src, count * 0x20);
}
static inline void glutSwapBuffer() {
pvr_list_begin(PVR_LIST_OP_POLY);
pvr_list_submit(_glKosVertexBufAddress(GL_LIST_OP), _glKosVertexBufCount(GL_LIST_OP));
pvr_list_finish();
pvr_list_begin(PVR_LIST_TR_POLY);
pvr_list_submit(_glKosVertexBufAddress(GL_LIST_TR), _glKosVertexBufCount(GL_LIST_TR));
pvr_list_finish();
pvr_scene_finish();
}
void glutSwapBuffers() {
pvr_wait_ready();
pvr_scene_begin();
glutSwapBuffer();
_glKosVertexBufReset();
}
void glutSwapBuffersToTexture(void *dst, GLsizei *x, GLsizei *y) {
pvr_wait_ready();
pvr_scene_begin_txr(dst, x, y);
glutSwapBuffer();
_glKosVertexBufReset();
}
void glutCopyBufferToTexture(void *dst, GLsizei *x, GLsizei *y) {
pvr_wait_ready();
pvr_scene_begin_txr(dst, x, y);
glutSwapBuffer();
}
int _glKosInitPVR() {
pvr_init_params_t params = {
/* Enable opaque and translucent polygons with size 32 and 32 */
{ PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_0 },
GL_PVR_VERTEX_BUF_SIZE, /* Vertex buffer size */
0, /* No DMA */
0 /* No FSAA */
};
pvr_init(&params);
#ifdef GL_USE_DMA
pvr_dma_init();
#endif
#ifdef GL_USE_MALLOC
GL_VBUF[0] = memalign(0x20, GL_MAX_VERTS * sizeof(pvr_cmd_t));
GL_VBUF[1] = memalign(0x20, GL_MAX_VERTS * sizeof(pvr_cmd_t));
GL_CBUF = malloc((GL_MAX_VERTS / 2) * sizeof(pvr_cmd_t));
#endif
return 1;
}
/* KallistiGL for KallistiOS ##version##
libgl/gl-pvr.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Vertex Buffer Routines for interfacing the Dreamcast's SH4 CPU and PowerVR GPU.
What we are doing here is using a Vertex Buffer in main RAM to store the
submitted data, untill the user finishes the scene by either calling
glSwapBuffer() to submit the buffer to the PVR for render to the screen OR
glSwapBufferToTexture() to submit the buffer to the PVR for render to texture.
This solution means the client can switch between transparent and opaque polygon
sumbission at any time, in no particular order, with no penalty in speed.
The size of the Vertex Buffer can be controlled by setting some params on gl-pvr.h:
GL_PVR_VERTEX_BUF_SIZE controls size of Vertex Buffer in the PVR VRAM
GL_MAX_VERTS conrols the number of vertices per list in the Vertex Buffer in SH4 RAM
*/
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gl.h"
#include "gl-sh4.h"
#include "gl-pvr.h"
/* Vertex Buffer Functions *************************************************************************/
#ifdef GL_USE_MALLOC
static pvr_cmd_t *GL_VBUF[2] __attribute__((aligned(32))); /* Dynamic Vertex Buffer */
static pvr_cmd_t *GL_CBUF; /* Dynamic Clip Buffer */
#else
static pvr_cmd_t GL_VBUF[2][GL_MAX_VERTS] __attribute__((aligned(32))); /* Static Vertex Buffer */
static pvr_cmd_t GL_CBUF[GL_MAX_VERTS / 2]; /* Static Clip Buffer */
#endif
static unsigned int GL_VERTS[2] = {0, 0},
GL_CVERTS = 0,
GL_LIST = GL_LIST_OP;
/* Custom version of sq_cpy from KOS for copying vertex data to the PVR */
static inline void pvr_list_submit(void *src, int n) {
unsigned int *d = TA_SQ_ADDR;
unsigned int *s = src;
/* fill/write queues as many times necessary */
while(n--) {
asm("pref @%0" : : "r"(s + 8)); /* prefetch 32 bytes for next loop */
d[0] = *(s++);
d[1] = *(s++);
d[2] = *(s++);
d[3] = *(s++);
d[4] = *(s++);
d[5] = *(s++);
d[6] = *(s++);
d[7] = *(s++);
asm("pref @%0" : : "r"(d));
d += 8;
}
/* Wait for both store queues to complete */
d = (unsigned int *)0xe0000000;
d[0] = d[8] = 0;
}
inline void *_glKosClipBufAddress() {
return &GL_CBUF[0];
}
inline void *_glKosClipBufPointer() {
return &GL_CBUF[GL_CVERTS];
}
inline void _glKosClipBufIncrement() {
++GL_CVERTS;
}
inline void _glKosClipBufAdd(unsigned int count) {
GL_CVERTS += count;
}
inline void _glKosClipBufReset() {
GL_CVERTS = 0;
}
inline void _glKosVertexBufSwitchOP() {
GL_LIST = GL_LIST_OP;
}
inline void _glKosVertexBufSwitchTR() {
GL_LIST = GL_LIST_TR;
}
inline void *_glKosVertexBufAddress(unsigned char list) {
return &GL_VBUF[list][0];
}
inline void *_glKosVertexBufPointer() {
return &GL_VBUF[GL_LIST][GL_VERTS[GL_LIST]];
}
inline void _glKosVertexBufIncrement() {
++GL_VERTS[GL_LIST];
}
inline void *_glKosTRVertexBufPointer() {
return &GL_VBUF[GL_LIST_TR][GL_VERTS[GL_LIST_TR]];
}
inline void _glKosTRVertexBufIncrement() {
++GL_VERTS[GL_LIST_TR];
}
inline void _glKosVertexBufAdd(unsigned int count) {
GL_VERTS[GL_LIST] += count;
}
inline void _glKosTRVertexBufAdd(unsigned int count) {
GL_VERTS[GL_LIST_TR] += count;
}
inline void _glKosVertexBufDecrement() {
--GL_VERTS[GL_LIST];
}
inline void _glKosVertexBufReset() {
GL_VERTS[0] = GL_VERTS[1] = 0;
}
inline unsigned int _glKosVertexBufCount(unsigned char list) {
return GL_VERTS[list];
}
unsigned char _glKosList() {
return GL_LIST;
}
inline void _glKosVertexBufCopy(void *dst, void *src, GLuint count) {
memcpy(dst, src, count * 0x20);
}
static inline void glutSwapBuffer() {
pvr_list_begin(PVR_LIST_OP_POLY);
pvr_list_submit(_glKosVertexBufAddress(GL_LIST_OP), _glKosVertexBufCount(GL_LIST_OP));
pvr_list_finish();
pvr_list_begin(PVR_LIST_TR_POLY);
pvr_list_submit(_glKosVertexBufAddress(GL_LIST_TR), _glKosVertexBufCount(GL_LIST_TR));
pvr_list_finish();
pvr_scene_finish();
}
void glutSwapBuffers() {
pvr_wait_ready();
pvr_scene_begin();
glutSwapBuffer();
_glKosVertexBufReset();
}
void glutSwapBuffersToTexture(void *dst, GLsizei *x, GLsizei *y) {
pvr_wait_ready();
pvr_scene_begin_txr(dst, x, y);
glutSwapBuffer();
_glKosVertexBufReset();
}
void glutCopyBufferToTexture(void *dst, GLsizei *x, GLsizei *y) {
pvr_wait_ready();
pvr_scene_begin_txr(dst, x, y);
glutSwapBuffer();
}
int _glKosInitPVR() {
pvr_init_params_t params = {
/* Enable opaque and translucent polygons with size 32 and 32 */
{ PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_0 },
GL_PVR_VERTEX_BUF_SIZE, /* Vertex buffer size */
0, /* No DMA */
0 /* No FSAA */
};
pvr_init(&params);
#ifdef GL_USE_DMA
pvr_dma_init();
#endif
#ifdef GL_USE_MALLOC
GL_VBUF[0] = memalign(0x20, GL_MAX_VERTS * sizeof(pvr_cmd_t));
GL_VBUF[1] = memalign(0x20, GL_MAX_VERTS * sizeof(pvr_cmd_t));
GL_CBUF = malloc((GL_MAX_VERTS / 2) * sizeof(pvr_cmd_t));
#endif
return 1;
}

108
gl-pvr.h
View File

@ -1,54 +1,54 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-pvr.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Vertex Buffer Routines for interfacing the Dreamcast's SH4 CPU and PowerVR GPU.
*/
#ifndef GL_PVR_H
#define GL_PVR_H
/* GL->PVR Commands */
typedef struct {
unsigned int cmd[8];
} pvr_cmd_t; /* Generic 32byte command for the pvr */
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 */
} pvr_cmd_tclip_t; /* Tile Clip command for the pvr */
#define GL_PVR_VERTEX_BUF_SIZE 2560 * 256 /* PVR Vertex buffer size */
#define GL_MAX_VERTS 1024*64 /* SH4 Vertex Count */
#define GL_MAX_TEXTURES 1024 /* Textures in Buffer */
#define GL_USE_MALLOC 1 /* Use Dynamic Vertex Array */
//#define GL_USE_FLOAT 0 /* Use PVR's floating-point color Vertex Type (64bit) *NoOp* */
//#define GL_USE_DMA 0 /* Use PVR DMA for vertex data transfer *NoOp* */
#define GL_LIST_OP 0
#define GL_LIST_TR 1
/* Misc SH4->PVR Commands */
#define TA_SQ_ADDR (unsigned int *)(void *) \
(0xe0000000 | (((unsigned long)0x10000000) & 0x03ffffe0))
#define QACRTA ((((unsigned int)0x10000000)>>26)<<2)&0x1c
#define PVR_TA_TXR_FILTER_SHIFT 14
#define GL_PVR_FILTER_POINT 0x00
#define GL_PVR_FILTER_BILINEAR 0x01
#define GL_PVR_FILTER_TRILINEAR_A 0x10
#define GL_PVR_FILTER_TRILINEAR_B 0x11
#define PVR_TA_SUPER_SAMPLE_SHIFT 12
#define GL_PVR_SAMPLE_POINT 0x0
#define GL_PVR_SAMPLE_SUPER 0x1
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-pvr.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Vertex Buffer Routines for interfacing the Dreamcast's SH4 CPU and PowerVR GPU.
*/
#ifndef GL_PVR_H
#define GL_PVR_H
/* GL->PVR Commands */
typedef struct {
unsigned int cmd[8];
} pvr_cmd_t; /* Generic 32byte command for the pvr */
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 */
} pvr_cmd_tclip_t; /* Tile Clip command for the pvr */
#define GL_PVR_VERTEX_BUF_SIZE 2560 * 256 /* PVR Vertex buffer size */
#define GL_MAX_VERTS 1024*64 /* SH4 Vertex Count */
#define GL_MAX_TEXTURES 1024 /* Textures in Buffer */
#define GL_USE_MALLOC 1 /* Use Dynamic Vertex Array */
//#define GL_USE_FLOAT 0 /* Use PVR's floating-point color Vertex Type (64bit) *NoOp* */
//#define GL_USE_DMA 0 /* Use PVR DMA for vertex data transfer *NoOp* */
#define GL_LIST_OP 0
#define GL_LIST_TR 1
/* Misc SH4->PVR Commands */
#define TA_SQ_ADDR (unsigned int *)(void *) \
(0xe0000000 | (((unsigned long)0x10000000) & 0x03ffffe0))
#define QACRTA ((((unsigned int)0x10000000)>>26)<<2)&0x1c
#define PVR_TA_TXR_FILTER_SHIFT 14
#define GL_PVR_FILTER_POINT 0x00
#define GL_PVR_FILTER_BILINEAR 0x01
#define GL_PVR_FILTER_TRILINEAR_A 0x10
#define GL_PVR_FILTER_TRILINEAR_B 0x11
#define PVR_TA_SUPER_SAMPLE_SHIFT 12
#define GL_PVR_SAMPLE_POINT 0x0
#define GL_PVR_SAMPLE_SUPER 0x1
#endif

232
gl-rgb.c
View File

@ -1,116 +1,116 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-rgb.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
A set of functions for working with ARGB pixel data, used by gluBuild2DMipmaps(...).
*/
#include "gl.h"
#include "gl-rgb.h"
//===================================================================================================//
//== ARGB Bit Masks ==//
static unsigned char ARGB1555_ALPHA(unsigned short c) {
return (c & ARGB1555_ALPHA_MASK) >> ARGB1555_ALPHA_SHIFT;
}
static unsigned char ARGB1555_RED(unsigned short c) {
return (c & ARGB1555_RED_MASK) >> ARGB1555_RED_SHIFT;
}
static unsigned char ARGB1555_GREEN(unsigned short c) {
return (c & ARGB1555_GREEN_MASK) >> ARGB1555_GREEN_SHIFT;
}
static unsigned char ARGB1555_BLUE(unsigned short c) {
return (c & ARGB1555_BLUE_MASK) >> ARGB1555_BLUE_SHIFT;
}
static unsigned char ARGB4444_ALPHA(unsigned short c) {
return (c & ARGB4444_ALPHA_MASK) >> ARGB4444_ALPHA_SHIFT;
}
static unsigned char ARGB4444_RED(unsigned short c) {
return (c & ARGB4444_RED_MASK) >> ARGB4444_RED_SHIFT;
}
static unsigned char ARGB4444_GREEN(unsigned short c) {
return (c & ARGB4444_GREEN_MASK) >> ARGB4444_GREEN_SHIFT;
}
static unsigned char ARGB4444_BLUE(unsigned short c) {
return (c & ARGB4444_BLUE_MASK) >> ARGB4444_BLUE_SHIFT;
}
static unsigned char RGB565_RED(unsigned short c) {
return (c & RGB565_RED_MASK) >> RGB565_RED_SHIFT;
}
static unsigned char RGB565_GREEN(unsigned short c) {
return (c & RGB565_GREEN_MASK) >> RGB565_GREEN_SHIFT;
}
static unsigned char RGB565_BLUE(unsigned short c) {
return c & RGB565_BLUE_MASK;
}
//===================================================================================================//
//== Block Compression ==//
uint16 __glKosAverageQuadPixelRGB565(uint16 p1, uint16 p2, uint16 p3, uint16 p4) {
uint8 R = (RGB565_RED(p1) + RGB565_RED(p2) + RGB565_RED(p3) + RGB565_RED(p4)) / 4;
uint8 G = (RGB565_GREEN(p1) + RGB565_GREEN(p2) + RGB565_GREEN(p3) + RGB565_GREEN(p4)) / 4;
uint8 B = (RGB565_BLUE(p1) + RGB565_BLUE(p2) + RGB565_BLUE(p3) + RGB565_BLUE(p4)) / 4;
return R << RGB565_RED_SHIFT | G << RGB565_GREEN_SHIFT | B;
}
uint16 __glKosAverageQuadPixelARGB1555(uint16 p1, uint16 p2, uint16 p3, uint16 p4) {
uint8 A = (ARGB1555_ALPHA(p1) + ARGB1555_ALPHA(p2) + ARGB1555_ALPHA(p3) + ARGB1555_ALPHA(p4)) / 4;
uint8 R = (ARGB1555_RED(p1) + ARGB1555_RED(p2) + ARGB1555_RED(p3) + ARGB1555_RED(p4)) / 4;
uint8 G = (ARGB1555_GREEN(p1) + ARGB1555_GREEN(p2) + ARGB1555_GREEN(p3) + ARGB1555_GREEN(p4)) / 4;
uint8 B = (ARGB1555_BLUE(p1) + ARGB1555_BLUE(p2) + ARGB1555_BLUE(p3) + ARGB1555_BLUE(p4)) / 4;
return ((A & RGB1_MAX) << ARGB1555_ALPHA_SHIFT) | ((R & RGB5_MAX) << ARGB1555_RED_SHIFT)
| ((G & RGB5_MAX) << ARGB1555_GREEN_SHIFT) | (B & RGB5_MAX);
}
uint16 __glKosAverageQuadPixelARGB4444(uint16 p1, uint16 p2, uint16 p3, uint16 p4) {
uint8 A = (ARGB4444_ALPHA(p1) + ARGB4444_ALPHA(p2) + ARGB4444_ALPHA(p3) + ARGB4444_ALPHA(p4)) / 4;
uint8 R = (ARGB4444_RED(p1) + ARGB4444_RED(p2) + ARGB4444_RED(p3) + ARGB4444_RED(p4)) / 4;
uint8 G = (ARGB4444_GREEN(p1) + ARGB4444_GREEN(p2) + ARGB4444_GREEN(p3) + ARGB4444_GREEN(p4)) / 4;
uint8 B = (ARGB4444_BLUE(p1) + ARGB4444_BLUE(p2) + ARGB4444_BLUE(p3) + ARGB4444_BLUE(p4)) / 4;
return ((A & RGB4_MAX) << ARGB4444_ALPHA_SHIFT) | ((R & RGB4_MAX) << ARGB4444_RED_SHIFT)
| ((G & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | (B & RGB4_MAX);
}
uint16 __glKosAverageBiPixelRGB565(uint16 p1, uint16 p2) {
uint8 R = (RGB565_RED(p1) + RGB565_RED(p2)) / 2;
uint8 G = (RGB565_GREEN(p1) + RGB565_GREEN(p2)) / 2;
uint8 B = (RGB565_BLUE(p1) + RGB565_BLUE(p2)) / 2;
return R << RGB565_RED_SHIFT | G << RGB565_GREEN_SHIFT | B;
}
uint16 __glKosAverageBiPixelARGB1555(uint16 p1, uint16 p2) {
uint8 A = (ARGB1555_ALPHA(p1) + ARGB1555_ALPHA(p2)) / 4;
uint8 R = (ARGB1555_RED(p1) + ARGB1555_RED(p2)) / 4;
uint8 G = (ARGB1555_GREEN(p1) + ARGB1555_GREEN(p2)) / 4;
uint8 B = (ARGB1555_BLUE(p1) + ARGB1555_BLUE(p2)) / 4;
return ((A & RGB1_MAX) << ARGB1555_ALPHA_SHIFT) | ((R & RGB5_MAX) << ARGB1555_RED_SHIFT)
| ((G & RGB5_MAX) << ARGB1555_GREEN_SHIFT) | (B & RGB5_MAX);
}
uint16 __glKosAverageBiPixelARGB4444(uint16 p1, uint16 p2) {
uint8 A = (ARGB4444_ALPHA(p1) + ARGB4444_ALPHA(p2)) / 4;
uint8 R = (ARGB4444_RED(p1) + ARGB4444_RED(p2)) / 4;
uint8 G = (ARGB4444_GREEN(p1) + ARGB4444_GREEN(p2)) / 4;
uint8 B = (ARGB4444_BLUE(p1) + ARGB4444_BLUE(p2)) / 4;
return ((A & RGB4_MAX) << ARGB4444_ALPHA_SHIFT) | ((R & RGB4_MAX) << ARGB4444_RED_SHIFT)
| ((G & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | (B & RGB4_MAX);
}
/* KallistiGL for KallistiOS ##version##
libgl/gl-rgb.c
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
A set of functions for working with ARGB pixel data, used by gluBuild2DMipmaps(...).
*/
#include "gl.h"
#include "gl-rgb.h"
//===================================================================================================//
//== ARGB Bit Masks ==//
static unsigned char ARGB1555_ALPHA(unsigned short c) {
return (c & ARGB1555_ALPHA_MASK) >> ARGB1555_ALPHA_SHIFT;
}
static unsigned char ARGB1555_RED(unsigned short c) {
return (c & ARGB1555_RED_MASK) >> ARGB1555_RED_SHIFT;
}
static unsigned char ARGB1555_GREEN(unsigned short c) {
return (c & ARGB1555_GREEN_MASK) >> ARGB1555_GREEN_SHIFT;
}
static unsigned char ARGB1555_BLUE(unsigned short c) {
return (c & ARGB1555_BLUE_MASK) >> ARGB1555_BLUE_SHIFT;
}
static unsigned char ARGB4444_ALPHA(unsigned short c) {
return (c & ARGB4444_ALPHA_MASK) >> ARGB4444_ALPHA_SHIFT;
}
static unsigned char ARGB4444_RED(unsigned short c) {
return (c & ARGB4444_RED_MASK) >> ARGB4444_RED_SHIFT;
}
static unsigned char ARGB4444_GREEN(unsigned short c) {
return (c & ARGB4444_GREEN_MASK) >> ARGB4444_GREEN_SHIFT;
}
static unsigned char ARGB4444_BLUE(unsigned short c) {
return (c & ARGB4444_BLUE_MASK) >> ARGB4444_BLUE_SHIFT;
}
static unsigned char RGB565_RED(unsigned short c) {
return (c & RGB565_RED_MASK) >> RGB565_RED_SHIFT;
}
static unsigned char RGB565_GREEN(unsigned short c) {
return (c & RGB565_GREEN_MASK) >> RGB565_GREEN_SHIFT;
}
static unsigned char RGB565_BLUE(unsigned short c) {
return c & RGB565_BLUE_MASK;
}
//===================================================================================================//
//== Block Compression ==//
uint16 __glKosAverageQuadPixelRGB565(uint16 p1, uint16 p2, uint16 p3, uint16 p4) {
uint8 R = (RGB565_RED(p1) + RGB565_RED(p2) + RGB565_RED(p3) + RGB565_RED(p4)) / 4;
uint8 G = (RGB565_GREEN(p1) + RGB565_GREEN(p2) + RGB565_GREEN(p3) + RGB565_GREEN(p4)) / 4;
uint8 B = (RGB565_BLUE(p1) + RGB565_BLUE(p2) + RGB565_BLUE(p3) + RGB565_BLUE(p4)) / 4;
return R << RGB565_RED_SHIFT | G << RGB565_GREEN_SHIFT | B;
}
uint16 __glKosAverageQuadPixelARGB1555(uint16 p1, uint16 p2, uint16 p3, uint16 p4) {
uint8 A = (ARGB1555_ALPHA(p1) + ARGB1555_ALPHA(p2) + ARGB1555_ALPHA(p3) + ARGB1555_ALPHA(p4)) / 4;
uint8 R = (ARGB1555_RED(p1) + ARGB1555_RED(p2) + ARGB1555_RED(p3) + ARGB1555_RED(p4)) / 4;
uint8 G = (ARGB1555_GREEN(p1) + ARGB1555_GREEN(p2) + ARGB1555_GREEN(p3) + ARGB1555_GREEN(p4)) / 4;
uint8 B = (ARGB1555_BLUE(p1) + ARGB1555_BLUE(p2) + ARGB1555_BLUE(p3) + ARGB1555_BLUE(p4)) / 4;
return ((A & RGB1_MAX) << ARGB1555_ALPHA_SHIFT) | ((R & RGB5_MAX) << ARGB1555_RED_SHIFT)
| ((G & RGB5_MAX) << ARGB1555_GREEN_SHIFT) | (B & RGB5_MAX);
}
uint16 __glKosAverageQuadPixelARGB4444(uint16 p1, uint16 p2, uint16 p3, uint16 p4) {
uint8 A = (ARGB4444_ALPHA(p1) + ARGB4444_ALPHA(p2) + ARGB4444_ALPHA(p3) + ARGB4444_ALPHA(p4)) / 4;
uint8 R = (ARGB4444_RED(p1) + ARGB4444_RED(p2) + ARGB4444_RED(p3) + ARGB4444_RED(p4)) / 4;
uint8 G = (ARGB4444_GREEN(p1) + ARGB4444_GREEN(p2) + ARGB4444_GREEN(p3) + ARGB4444_GREEN(p4)) / 4;
uint8 B = (ARGB4444_BLUE(p1) + ARGB4444_BLUE(p2) + ARGB4444_BLUE(p3) + ARGB4444_BLUE(p4)) / 4;
return ((A & RGB4_MAX) << ARGB4444_ALPHA_SHIFT) | ((R & RGB4_MAX) << ARGB4444_RED_SHIFT)
| ((G & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | (B & RGB4_MAX);
}
uint16 __glKosAverageBiPixelRGB565(uint16 p1, uint16 p2) {
uint8 R = (RGB565_RED(p1) + RGB565_RED(p2)) / 2;
uint8 G = (RGB565_GREEN(p1) + RGB565_GREEN(p2)) / 2;
uint8 B = (RGB565_BLUE(p1) + RGB565_BLUE(p2)) / 2;
return R << RGB565_RED_SHIFT | G << RGB565_GREEN_SHIFT | B;
}
uint16 __glKosAverageBiPixelARGB1555(uint16 p1, uint16 p2) {
uint8 A = (ARGB1555_ALPHA(p1) + ARGB1555_ALPHA(p2)) / 4;
uint8 R = (ARGB1555_RED(p1) + ARGB1555_RED(p2)) / 4;
uint8 G = (ARGB1555_GREEN(p1) + ARGB1555_GREEN(p2)) / 4;
uint8 B = (ARGB1555_BLUE(p1) + ARGB1555_BLUE(p2)) / 4;
return ((A & RGB1_MAX) << ARGB1555_ALPHA_SHIFT) | ((R & RGB5_MAX) << ARGB1555_RED_SHIFT)
| ((G & RGB5_MAX) << ARGB1555_GREEN_SHIFT) | (B & RGB5_MAX);
}
uint16 __glKosAverageBiPixelARGB4444(uint16 p1, uint16 p2) {
uint8 A = (ARGB4444_ALPHA(p1) + ARGB4444_ALPHA(p2)) / 4;
uint8 R = (ARGB4444_RED(p1) + ARGB4444_RED(p2)) / 4;
uint8 G = (ARGB4444_GREEN(p1) + ARGB4444_GREEN(p2)) / 4;
uint8 B = (ARGB4444_BLUE(p1) + ARGB4444_BLUE(p2)) / 4;
return ((A & RGB4_MAX) << ARGB4444_ALPHA_SHIFT) | ((R & RGB4_MAX) << ARGB4444_RED_SHIFT)
| ((G & RGB4_MAX) << ARGB4444_GREEN_SHIFT) | (B & RGB4_MAX);
}

126
gl-rgb.h
View File

@ -1,63 +1,63 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-rgb.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
A set of functions for working with ARGB pixel data.
*/
#ifndef GL_RGB_H
#define GL_RGB_H
typedef GLubyte GLrgb3ub[3];
typedef GLubyte GLrgba4ub[3];
typedef GLfloat GLrgb3f[3];
typedef GLfloat GLrgba4f[4];
#define RGB565_RED_MASK 0xF800
#define RGB565_GREEN_MASK 0x7E0
#define RGB565_BLUE_MASK 0x1F
#define RGB565_RED_SHIFT 0xB
#define RGB565_GREEN_SHIFT 0x5
#define RGB565_BLUE_SHIFT 0x0
#define ARGB4444_ALPHA_MASK 0xF000
#define ARGB4444_RED_MASK 0x0F00
#define ARGB4444_GREEN_MASK 0x00F0
#define ARGB4444_BLUE_MASK 0x000F
#define ARGB4444_ALPHA_SHIFT 0xC
#define ARGB4444_RED_SHIFT 0x8
#define ARGB4444_GREEN_SHIFT 0x4
#define ARGB4444_BLUE_SHIFT 0x0
#define ARGB1555_ALPHA_MASK 0x8000
#define ARGB1555_RED_MASK 0x7C00
#define ARGB1555_GREEN_MASK 0x3E0
#define ARGB1555_BLUE_MASK 0x1F
#define ARGB1555_ALPHA_SHIFT 0xF
#define ARGB1555_RED_SHIFT 0xA
#define ARGB1555_GREEN_SHIFT 0x5
#define ARGB1555_BLUE_SHIFT 0x0
#define ARGB32_ALPHA_MASK 0xFF000000
#define ARGB32_RGB_MASK 0xFFFFFF
#define ARGB32_RED_SHIFT 0x8
#define RGBA32_APLHA_MASK 0xFF
#define RGBA32_RGB_MASK 0xFFFFFF00
#define RGB1_MAX 0x1
#define RGB4_MAX 0xF
#define RGB5_MAX 0x1F
#define RGB6_MAX 0x3F
#define RGB8_MAX 0xFF
#define RGBA32_2_ARGB32(n) (((n & ARGB32_RGB_MASK) << ARGB32_RED_SHIFT) | (n & ARGB32_ALPHA_MASK))
#define ARGB_PACK_RGBF(r,g,b) (0xFF000000 | ((r*0xFF) << 16) | ((g*0xFF)<<8) | (b*0xFF))
#define ARGB_PACK_ARGBF(a,r,g,b) (((a*0xFF) << 24) | ((r*0xFF) << 16) | ((g*0xFF)<<8) | (b*0xFF))
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-rgb.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
A set of functions for working with ARGB pixel data.
*/
#ifndef GL_RGB_H
#define GL_RGB_H
typedef GLubyte GLrgb3ub[3];
typedef GLubyte GLrgba4ub[3];
typedef GLfloat GLrgb3f[3];
typedef GLfloat GLrgba4f[4];
#define RGB565_RED_MASK 0xF800
#define RGB565_GREEN_MASK 0x7E0
#define RGB565_BLUE_MASK 0x1F
#define RGB565_RED_SHIFT 0xB
#define RGB565_GREEN_SHIFT 0x5
#define RGB565_BLUE_SHIFT 0x0
#define ARGB4444_ALPHA_MASK 0xF000
#define ARGB4444_RED_MASK 0x0F00
#define ARGB4444_GREEN_MASK 0x00F0
#define ARGB4444_BLUE_MASK 0x000F
#define ARGB4444_ALPHA_SHIFT 0xC
#define ARGB4444_RED_SHIFT 0x8
#define ARGB4444_GREEN_SHIFT 0x4
#define ARGB4444_BLUE_SHIFT 0x0
#define ARGB1555_ALPHA_MASK 0x8000
#define ARGB1555_RED_MASK 0x7C00
#define ARGB1555_GREEN_MASK 0x3E0
#define ARGB1555_BLUE_MASK 0x1F
#define ARGB1555_ALPHA_SHIFT 0xF
#define ARGB1555_RED_SHIFT 0xA
#define ARGB1555_GREEN_SHIFT 0x5
#define ARGB1555_BLUE_SHIFT 0x0
#define ARGB32_ALPHA_MASK 0xFF000000
#define ARGB32_RGB_MASK 0xFFFFFF
#define ARGB32_RED_SHIFT 0x8
#define RGBA32_APLHA_MASK 0xFF
#define RGBA32_RGB_MASK 0xFFFFFF00
#define RGB1_MAX 0x1
#define RGB4_MAX 0xF
#define RGB5_MAX 0x1F
#define RGB6_MAX 0x3F
#define RGB8_MAX 0xFF
#define RGBA32_2_ARGB32(n) (((n & ARGB32_RGB_MASK) << ARGB32_RED_SHIFT) | (n & ARGB32_ALPHA_MASK))
#define ARGB_PACK_RGBF(r,g,b) (0xFF000000 | ((r*0xFF) << 16) | ((g*0xFF)<<8) | (b*0xFF))
#define ARGB_PACK_ARGBF(a,r,g,b) (((a*0xFF) << 24) | ((r*0xFF) << 16) | ((g*0xFF)<<8) | (b*0xFF))
#endif

View File

@ -1,232 +1,232 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-sh4-light.S
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Dynamic Vertex Lighting
This Assembly file contains 2 functions:
_glKosSpotLight - This function computes diffuse / spotlight / attenuation
_glKosSpecular - This functions computes the Specular Term
*/
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!float _glKosSpecular( void * vertex6f, void * eyepos, void * Lvectorin );
.globl __glKosSpecular
!r4 = [arg][void*] = vertex
!r5 = [arg][void*] = eyepos
!r6 = [arg][void*] = L vector
!fr0 = return value
!fv0 = vertex position (P)(N)
!fv4 = eye position (E)
!fv8 = L vector (L)
__glKosSpecular:
fmov @r4+, fr0 ! load vertex x to fv0
fmov @r4+, fr1 ! load vertex y to fv0
fmov @r4+, fr2 ! load vertex z to fv0
fmov @r5+, fr4 ! load eye pos x to fv4
fmov @r5+, fr5 ! load eye pos y to fv4
fmov @r5+, fr6 ! load eye pos z to fv4
fmov @r6+, fr8 ! load L vector x to fv8
fmov @r6+, fr9 ! load L vector y to fv8
fmov @r6+, fr10 ! load L vector z to fv8
fsub fr0, fr4 ! fv4 = V = normalize ( E - P )
fsub fr1, fr5
fsub fr2, fr6
fldi0 fr3 ! load 0 for P w
fldi0 fr7 ! load 0 for E w
fipr fv4, fv4 ! Normalize V vector
fsqrt fr7
fcmp/gt fr3, fr7 ! V w <=0 = skip ndiv
bf .SKIPVndiv
fdiv fr7, fr4
fdiv fr7, fr5
fdiv fr7, fr6
.SKIPVndiv:
fadd fr4, fr8 ! fv8 = H = normalize( L + V )
fadd fr5, fr9
fadd fr6, fr10
fldi0 fr11 ! load 0 for H w
fipr fv8, fv8 ! Normalize H vector
fsqrt fr11
fcmp/gt fr3, fr11 ! H w <=0 = skip ndiv
bf .SKIPHndiv
fdiv fr11, fr8
fdiv fr11, fr9
fdiv fr11, fr10
.SKIPHndiv:
fmov @r4+, fr0 ! load N to fv0
fmov @r4+, fr1
fmov @r4+, fr2
fipr fv0, fv8 ! N dot H for specular term
rts
fmov fr11, fr0 ! move N dot H to fr0 for return
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!int _glKosSpotlight( void * glLight, void * vertex6f, void * Lvectorout );
.globl __glKosSpotlight
!r0 = return value | true or false
!r1 = boolean flag
!r2 = boolean false
!r4 = [arg] = light
!r5 = [arg] = vertex
!r6 = [arg] = output
!fv0 = vertex position
!fv4 = light position | L vector | normalize(light pos - vertex pos) | w = attenuation distance
!fv8 = light direction | N vector = Vertex Normal
!fv12 = Spot vector | normalize(vertex pos - light pos)
__glKosSpotlight:
mov #0, r1 ! load 0 for boolean flag
mov #0, r2 ! load 0 for boolean false
fmov @r4+, fr4 ! load light position x to fv4
fmov @r4+, fr5 ! load light position y to fv4
fmov @r4+, fr6 ! load light position z to fv4
fmov @r4+, fr7 ! load light position w to fv4
fmov @r4+, fr8 ! load light direction x to fv8
fmov @r4+, fr9 ! load light direction y to fv8
fmov @r4+, fr10 ! load light direction z to fv8
fmov @r5+, fr0 ! load vertex position x to fv0
fmov @r5+, fr1 ! load vertex position y to fv0
fmov @r5+, fr2 ! load vertex position z to fv0
fldi0 fr11 ! load 0 for light dir w
fcmp/gt fr11, fr7 ! light pos w component set = spot light
bf .VERTEXLIGHT0 ! light not a spot light - branch to vertex lighting
fschg
fmov dr0, dr12 ! copy vertex x,y to fv12
fschg
fmov fr2, fr14 ! copy vertex z to fv12
fsub fr4, fr12 ! fv12 = ( vertex position - light position)
fsub fr5, fr13
fsub fr6, fr14
fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv12 ! Normalize vector
fsqrt fr15
fcmp/gt fr11, fr15 ! Check for Normalization division
bf .SPOTcosdir ! If w < 0, skip division
fdiv fr12, fr15
fdiv fr13, fr15
fdiv fr14, fr15
.SPOTcosdir:
fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv8 ! fr11 now holds light cosDir
fmov @r4+, fr15 ! load light cutOff to fr15
mov #1, r1 ! load 1 for boolean flag = indicate light cutOff was read
fcmp/gt fr15, fr11 ! cosDir > cutOff ? 0 : 1
bt .RET0spot ! vertex outside of spotlight = return 0
.VERTEXLIGHT0:
fsub fr0, fr4 ! fv4 = L vector = ( light position - vertex position)
fsub fr1, fr5
fsub fr2, fr6
fldi0 fr7 ! load 0 for L w
fldi0 fr11 ! load 0 for N w
fipr fv4, fv4 ! Normalize L vector
fsqrt fr7
fcmp/gt fr11, fr7 ! Normalization division if w component > 0
bf .SDIVlv
fdiv fr7, fr4
fdiv fr7, fr5
fdiv fr7, fr6 ! fv4 = Normalized L Vector
.SDIVlv:
fmov fr7, fr3 ! copy L w to fr3
fldi0 fr7 ! load 0 for L w
fcmp/gt fr7, fr3
bf .RET0spot ! if L w < 0, return 0 now to avoid pointless computations
fmov @r5+, fr8 ! load normal to fv8
fmov @r5+, fr9 ! load normal to fv8
fmov @r5+, fr10 ! load normal to fv8
fipr fv8, fv4 ! N dot L
fcmp/gt fr11, fr7 ! L w < = 0 ? L w = 0
bf .RET0spot: ! if L w < 0, return 0 now to avoid pointless computations
.WRITEDi:
fschg
fmov dr4, @r6 ! write L vector x to output
fschg
add #8, r6
fmov fr6, @r6 ! write L vector z to output
add #4, r6
cmp/gt r2, r1
bt .READattenf
add #4, r4
.READattenf:
fmov @r4+, fr8 ! vertex normal gets overwritten by atten factors
fmov @r4+, fr9
fmov @r4+, fr10
fldi1 fr11
fmul fr3, fr9 ! calculate attenuation
fmul fr3, fr10
fmul fr3, fr10
fadd fr9, fr8
fadd fr10, fr8
fdiv fr8, fr11 ! fr11 = A
fmul fr7, fr11 ! D * A
fmov fr11, @r6 ! write D*A to output
.RET1spot:
rts
mov #1, r0
.RET0spot:
rts
mov #0, r0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* KallistiGL for KallistiOS ##version##
libgl/gl-sh4-light.S
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Dynamic Vertex Lighting
This Assembly file contains 2 functions:
_glKosSpotLight - This function computes diffuse / spotlight / attenuation
_glKosSpecular - This functions computes the Specular Term
*/
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!float _glKosSpecular( void * vertex6f, void * eyepos, void * Lvectorin );
.globl __glKosSpecular
!r4 = [arg][void*] = vertex
!r5 = [arg][void*] = eyepos
!r6 = [arg][void*] = L vector
!fr0 = return value
!fv0 = vertex position (P)(N)
!fv4 = eye position (E)
!fv8 = L vector (L)
__glKosSpecular:
fmov @r4+, fr0 ! load vertex x to fv0
fmov @r4+, fr1 ! load vertex y to fv0
fmov @r4+, fr2 ! load vertex z to fv0
fmov @r5+, fr4 ! load eye pos x to fv4
fmov @r5+, fr5 ! load eye pos y to fv4
fmov @r5+, fr6 ! load eye pos z to fv4
fmov @r6+, fr8 ! load L vector x to fv8
fmov @r6+, fr9 ! load L vector y to fv8
fmov @r6+, fr10 ! load L vector z to fv8
fsub fr0, fr4 ! fv4 = V = normalize ( E - P )
fsub fr1, fr5
fsub fr2, fr6
fldi0 fr3 ! load 0 for P w
fldi0 fr7 ! load 0 for E w
fipr fv4, fv4 ! Normalize V vector
fsqrt fr7
fcmp/gt fr3, fr7 ! V w <=0 = skip ndiv
bf .SKIPVndiv
fdiv fr7, fr4
fdiv fr7, fr5
fdiv fr7, fr6
.SKIPVndiv:
fadd fr4, fr8 ! fv8 = H = normalize( L + V )
fadd fr5, fr9
fadd fr6, fr10
fldi0 fr11 ! load 0 for H w
fipr fv8, fv8 ! Normalize H vector
fsqrt fr11
fcmp/gt fr3, fr11 ! H w <=0 = skip ndiv
bf .SKIPHndiv
fdiv fr11, fr8
fdiv fr11, fr9
fdiv fr11, fr10
.SKIPHndiv:
fmov @r4+, fr0 ! load N to fv0
fmov @r4+, fr1
fmov @r4+, fr2
fipr fv0, fv8 ! N dot H for specular term
rts
fmov fr11, fr0 ! move N dot H to fr0 for return
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!int _glKosSpotlight( void * glLight, void * vertex6f, void * Lvectorout );
.globl __glKosSpotlight
!r0 = return value | true or false
!r1 = boolean flag
!r2 = boolean false
!r4 = [arg] = light
!r5 = [arg] = vertex
!r6 = [arg] = output
!fv0 = vertex position
!fv4 = light position | L vector | normalize(light pos - vertex pos) | w = attenuation distance
!fv8 = light direction | N vector = Vertex Normal
!fv12 = Spot vector | normalize(vertex pos - light pos)
__glKosSpotlight:
mov #0, r1 ! load 0 for boolean flag
mov #0, r2 ! load 0 for boolean false
fmov @r4+, fr4 ! load light position x to fv4
fmov @r4+, fr5 ! load light position y to fv4
fmov @r4+, fr6 ! load light position z to fv4
fmov @r4+, fr7 ! load light position w to fv4
fmov @r4+, fr8 ! load light direction x to fv8
fmov @r4+, fr9 ! load light direction y to fv8
fmov @r4+, fr10 ! load light direction z to fv8
fmov @r5+, fr0 ! load vertex position x to fv0
fmov @r5+, fr1 ! load vertex position y to fv0
fmov @r5+, fr2 ! load vertex position z to fv0
fldi0 fr11 ! load 0 for light dir w
fcmp/gt fr11, fr7 ! light pos w component set = spot light
bf .VERTEXLIGHT0 ! light not a spot light - branch to vertex lighting
fschg
fmov dr0, dr12 ! copy vertex x,y to fv12
fschg
fmov fr2, fr14 ! copy vertex z to fv12
fsub fr4, fr12 ! fv12 = ( vertex position - light position)
fsub fr5, fr13
fsub fr6, fr14
fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv12 ! Normalize vector
fsqrt fr15
fcmp/gt fr11, fr15 ! Check for Normalization division
bf .SPOTcosdir ! If w < 0, skip division
fdiv fr12, fr15
fdiv fr13, fr15
fdiv fr14, fr15
.SPOTcosdir:
fldi0 fr15 ! set fv12 w component to 0
fipr fv12, fv8 ! fr11 now holds light cosDir
fmov @r4+, fr15 ! load light cutOff to fr15
mov #1, r1 ! load 1 for boolean flag = indicate light cutOff was read
fcmp/gt fr15, fr11 ! cosDir > cutOff ? 0 : 1
bt .RET0spot ! vertex outside of spotlight = return 0
.VERTEXLIGHT0:
fsub fr0, fr4 ! fv4 = L vector = ( light position - vertex position)
fsub fr1, fr5
fsub fr2, fr6
fldi0 fr7 ! load 0 for L w
fldi0 fr11 ! load 0 for N w
fipr fv4, fv4 ! Normalize L vector
fsqrt fr7
fcmp/gt fr11, fr7 ! Normalization division if w component > 0
bf .SDIVlv
fdiv fr7, fr4
fdiv fr7, fr5
fdiv fr7, fr6 ! fv4 = Normalized L Vector
.SDIVlv:
fmov fr7, fr3 ! copy L w to fr3
fldi0 fr7 ! load 0 for L w
fcmp/gt fr7, fr3
bf .RET0spot ! if L w < 0, return 0 now to avoid pointless computations
fmov @r5+, fr8 ! load normal to fv8
fmov @r5+, fr9 ! load normal to fv8
fmov @r5+, fr10 ! load normal to fv8
fipr fv8, fv4 ! N dot L
fcmp/gt fr11, fr7 ! L w < = 0 ? L w = 0
bf .RET0spot: ! if L w < 0, return 0 now to avoid pointless computations
.WRITEDi:
fschg
fmov dr4, @r6 ! write L vector x to output
fschg
add #8, r6
fmov fr6, @r6 ! write L vector z to output
add #4, r6
cmp/gt r2, r1
bt .READattenf
add #4, r4
.READattenf:
fmov @r4+, fr8 ! vertex normal gets overwritten by atten factors
fmov @r4+, fr9
fmov @r4+, fr10
fldi1 fr11
fmul fr3, fr9 ! calculate attenuation
fmul fr3, fr10
fmul fr3, fr10
fadd fr9, fr8
fadd fr10, fr8
fdiv fr8, fr11 ! fr11 = A
fmul fr7, fr11 ! D * A
fmov fr11, @r6 ! write D*A to output
.RET1spot:
rts
mov #1, r0
.RET0spot:
rts
mov #0, r0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

104
gl-sh4.h
View File

@ -1,52 +1,52 @@
/* KallistiGL for KallistiOS ##version##
libgl/gl-sh4.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Macros for utilizing the Dreamcast's SH4 CPU vector / matrix math functions.
*/
#ifndef GL_SH4_H
#define GL_SH4_H
typedef float vector3f[3]; /* 3 float vector */
typedef float matrix4f[4][4]; /* 4x4 float matrix */
/* DEG2RAD - convert Degrees to Radians = PI / 180.0f */
#define DEG2RAD (0.01745329251994329576923690768489)
/* Calculate Spot Light Angle Cosine = (PI / 180.0f) * (n / 2) */
#define LCOS(n) fcos(n*0.00872664625997164788461845384244)
/* Internal GL API macro */
#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" ); \
}
/* Internal GL API macro */
#define mat_trans_fv12_nodiv() { \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) ); \
}
#define mat_trans_fv12_nodivw() { \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w) \
: "0" (__x), "1" (__y), "2" (__z), "3" (__w) ); \
}
#endif
/* KallistiGL for KallistiOS ##version##
libgl/gl-sh4.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Macros for utilizing the Dreamcast's SH4 CPU vector / matrix math functions.
*/
#ifndef GL_SH4_H
#define GL_SH4_H
typedef float vector3f[3]; /* 3 float vector */
typedef float matrix4f[4][4]; /* 4x4 float matrix */
/* DEG2RAD - convert Degrees to Radians = PI / 180.0f */
#define DEG2RAD (0.01745329251994329576923690768489)
/* Calculate Spot Light Angle Cosine = (PI / 180.0f) * (n / 2) */
#define LCOS(n) fcos(n*0.00872664625997164788461845384244)
/* Internal GL API macro */
#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" ); \
}
/* Internal GL API macro */
#define mat_trans_fv12_nodiv() { \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z) \
: "0" (__x), "1" (__y), "2" (__z) ); \
}
#define mat_trans_fv12_nodivw() { \
__asm__ __volatile__( \
"fldi1 fr15\n" \
"ftrv xmtrx, fv12\n" \
: "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w) \
: "0" (__x), "1" (__y), "2" (__z), "3" (__w) ); \
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +1,45 @@
/* KallistiGL for KallistiOS ##version##
libgl/glu.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Some functionality adapted from the original KOS libgl:
Copyright (C) 2001 Dan Potter
Copyright (C) 2002 Benoit Miller
*/
#ifndef __GL_GLU_H
#define __GL_GLU_H
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <GL/gl.h>
#define GLU_FALSE GL_FALSE
#define GLU_TRUE GL_TRUE
/* Mip-Mapped Textures MUST be square or rectangle */
GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat,
GLsizei width, GLsizei height,
GLenum format, GLenum type,
const void *data);
/* gluPerspective - Set the Perspective for Rendering. */
GLAPI void APIENTRY gluPerspective(GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar);
/* gluLookAt - Set Camera Position for Rendering. */
GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz);
/* glhLookAtf2 = gluLookAt operating on 3 float vectors. */
GLAPI void APIENTRY glhLookAtf2(GLfloat *eyePosition3D,
GLfloat *center3D,
GLfloat *upVector3D);
__END_DECLS
#endif /* !__GL_GLU_H */
/* KallistiGL for KallistiOS ##version##
libgl/glu.h
Copyright (C) 2013-2014 Josh "PH3NOM" Pearson
Some functionality adapted from the original KOS libgl:
Copyright (C) 2001 Dan Potter
Copyright (C) 2002 Benoit Miller
*/
#ifndef __GL_GLU_H
#define __GL_GLU_H
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <GL/gl.h>
#define GLU_FALSE GL_FALSE
#define GLU_TRUE GL_TRUE
/* Mip-Mapped Textures MUST be square or rectangle */
GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat,
GLsizei width, GLsizei height,
GLenum format, GLenum type,
const void *data);
/* gluPerspective - Set the Perspective for Rendering. */
GLAPI void APIENTRY gluPerspective(GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar);
/* gluLookAt - Set Camera Position for Rendering. */
GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz);
/* glhLookAtf2 = gluLookAt operating on 3 float vectors. */
GLAPI void APIENTRY glhLookAtf2(GLfloat *eyePosition3D,
GLfloat *center3D,
GLfloat *upVector3D);
__END_DECLS
#endif /* !__GL_GLU_H */

View File

@ -1,30 +1,30 @@
/* KallistiGL for KallistiOS ##version##
libgl/glut.h
Copyright (C) 2014 Josh Pearson
Copyright (C) 2014 Lawrence Sebald
*/
#ifndef __GL_GLUT_H
#define __GL_GLUT_H
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <GL/gl.h>
/* Flush the Submitted Primitive Data to the GPU for render to screen */
GLAPI void APIENTRY glutSwapBuffers();
/* Flush the Submitted Primitive Data to the GPU for render to texture */
GLAPI void APIENTRY glutSwapBuffersToTexture(void *dst, GLsizei *x, GLsizei *y);
/* Copy the Submitted Primitive Data to the GPU for render to texture */
/* This will leave the Vertex Data in the Main Buffer to be Flushed on the
next frame rendered */
GLAPI void APIENTRY glutCopyBufferToTexture(void *dst, GLsizei *x, GLsizei *y);
__END_DECLS
#endif /* !__GL_GLUT_H */
/* KallistiGL for KallistiOS ##version##
libgl/glut.h
Copyright (C) 2014 Josh Pearson
Copyright (C) 2014 Lawrence Sebald
*/
#ifndef __GL_GLUT_H
#define __GL_GLUT_H
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <GL/gl.h>
/* Flush the Submitted Primitive Data to the GPU for render to screen */
GLAPI void APIENTRY glutSwapBuffers();
/* Flush the Submitted Primitive Data to the GPU for render to texture */
GLAPI void APIENTRY glutSwapBuffersToTexture(void *dst, GLsizei *x, GLsizei *y);
/* Copy the Submitted Primitive Data to the GPU for render to texture */
/* This will leave the Vertex Data in the Main Buffer to be Flushed on the
next frame rendered */
GLAPI void APIENTRY glutCopyBufferToTexture(void *dst, GLsizei *x, GLsizei *y);
__END_DECLS
#endif /* !__GL_GLUT_H */