Merge branch 'master' of https://gitlab.com/simulant/GLdc
This commit is contained in:
commit
b6995edc66
@ -22,7 +22,7 @@ string(TOUPPER ${BACKEND} BACKEND_UPPER)
|
|||||||
add_definitions(-DBACKEND_${BACKEND_UPPER})
|
add_definitions(-DBACKEND_${BACKEND_UPPER})
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
|
|||||||
29
GL/draw.c
29
GL/draw.c
@ -946,35 +946,6 @@ static void light(SubmissionTarget* target) {
|
|||||||
_glPerformLighting(vertex, ES, target->count);
|
_glPerformLighting(vertex, ES, target->count);
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_FORCE_INLINE void divide(SubmissionTarget* target) {
|
|
||||||
TRACE();
|
|
||||||
|
|
||||||
/* Perform perspective divide on each vertex */
|
|
||||||
Vertex* vertex = _glSubmissionTargetStart(target);
|
|
||||||
|
|
||||||
const float h = GetVideoMode()->height;
|
|
||||||
|
|
||||||
ITERATE(target->count) {
|
|
||||||
const float f = MATH_Fast_Invert(vertex->w);
|
|
||||||
|
|
||||||
/* Convert to NDC and apply viewport */
|
|
||||||
vertex->xyz[0] = MATH_fmac(
|
|
||||||
VIEWPORT.hwidth, vertex->xyz[0] * f, VIEWPORT.x_plus_hwidth
|
|
||||||
);
|
|
||||||
vertex->xyz[1] = h - MATH_fmac(
|
|
||||||
VIEWPORT.hheight, vertex->xyz[1] * f, VIEWPORT.y_plus_hheight
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Apply depth range */
|
|
||||||
vertex->xyz[2] = MAX(
|
|
||||||
1.0f - MATH_fmac(vertex->xyz[2] * f, 0.5f, 0.5f),
|
|
||||||
PVR_MIN_Z
|
|
||||||
);
|
|
||||||
|
|
||||||
++vertex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GL_FORCE_INLINE int _calc_pvr_face_culling() {
|
GL_FORCE_INLINE int _calc_pvr_face_culling() {
|
||||||
if(!_glIsCullingEnabled()) {
|
if(!_glIsCullingEnabled()) {
|
||||||
return GPU_CULLING_SMALL;
|
return GPU_CULLING_SMALL;
|
||||||
|
|||||||
@ -158,30 +158,31 @@ void APIENTRY glColor3fv(const GLfloat* v) {
|
|||||||
COLOR[B8IDX] = (GLubyte)(v[2] * 255);
|
COLOR[B8IDX] = (GLubyte)(v[2] * 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef union punned {
|
||||||
|
GLubyte* byte;
|
||||||
|
GLfloat* flt;
|
||||||
|
uint32_t* u32;
|
||||||
|
void* vptr;
|
||||||
|
uintptr_t uptr;
|
||||||
|
} punned_t;
|
||||||
|
|
||||||
void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
|
void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
|
||||||
IM_ENABLED_VERTEX_ATTRIBUTES |= VERTEX_ENABLED_FLAG;
|
IM_ENABLED_VERTEX_ATTRIBUTES |= VERTEX_ENABLED_FLAG;
|
||||||
|
|
||||||
IMVertex* vert = aligned_vector_extend(&VERTICES, 1);
|
IMVertex* vert = aligned_vector_extend(&VERTICES, 1);
|
||||||
|
|
||||||
/* Resizing could've invalidated the pointers */
|
punned_t dest = { .flt = &vert->x };
|
||||||
IM_ATTRIBS.vertex.ptr = VERTICES.data;
|
*(dest.flt++) = x;
|
||||||
IM_ATTRIBS.uv.ptr = IM_ATTRIBS.vertex.ptr + 12;
|
*(dest.flt++) = y;
|
||||||
IM_ATTRIBS.st.ptr = IM_ATTRIBS.uv.ptr + 8;
|
*(dest.flt++) = z;
|
||||||
IM_ATTRIBS.colour.ptr = IM_ATTRIBS.st.ptr + 8;
|
*(dest.flt++) = UV_COORD[0];
|
||||||
IM_ATTRIBS.normal.ptr = IM_ATTRIBS.colour.ptr + 4;
|
*(dest.flt++) = UV_COORD[1];
|
||||||
|
*(dest.flt++) = ST_COORD[0];
|
||||||
uint32_t* dest = (uint32_t*) &vert->x;
|
*(dest.flt++) = ST_COORD[1];
|
||||||
*(dest++) = *((uint32_t*) &x);
|
*(dest.u32++) = *((uint32_t*)(void*) COLOR);
|
||||||
*(dest++) = *((uint32_t*) &y);
|
*(dest.flt++) = NORMAL[0];
|
||||||
*(dest++) = *((uint32_t*) &z);
|
*(dest.flt++) = NORMAL[1];
|
||||||
*(dest++) = *((uint32_t*) &UV_COORD[0]);
|
*(dest.flt++) = NORMAL[2];
|
||||||
*(dest++) = *((uint32_t*) &UV_COORD[1]);
|
|
||||||
*(dest++) = *((uint32_t*) &ST_COORD[0]);
|
|
||||||
*(dest++) = *((uint32_t*) &ST_COORD[1]);
|
|
||||||
*(dest++) = *((uint32_t*) COLOR);
|
|
||||||
*(dest++) = *((uint32_t*) &NORMAL[0]);
|
|
||||||
*(dest++) = *((uint32_t*) &NORMAL[1]);
|
|
||||||
*(dest++) = *((uint32_t*) &NORMAL[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glVertex3fv(const GLfloat* v) {
|
void APIENTRY glVertex3fv(const GLfloat* v) {
|
||||||
@ -254,6 +255,13 @@ void APIENTRY glNormal3fv(const GLfloat* v) {
|
|||||||
void APIENTRY glEnd() {
|
void APIENTRY glEnd() {
|
||||||
IMMEDIATE_MODE_ACTIVE = GL_FALSE;
|
IMMEDIATE_MODE_ACTIVE = GL_FALSE;
|
||||||
|
|
||||||
|
/* Resizing could've invalidated the pointers */
|
||||||
|
IM_ATTRIBS.vertex.ptr = VERTICES.data;
|
||||||
|
IM_ATTRIBS.uv.ptr = IM_ATTRIBS.vertex.ptr + 12;
|
||||||
|
IM_ATTRIBS.st.ptr = IM_ATTRIBS.uv.ptr + 8;
|
||||||
|
IM_ATTRIBS.colour.ptr = IM_ATTRIBS.st.ptr + 8;
|
||||||
|
IM_ATTRIBS.normal.ptr = IM_ATTRIBS.colour.ptr + 4;
|
||||||
|
|
||||||
GLuint* attrs = &ENABLED_VERTEX_ATTRIBUTES;
|
GLuint* attrs = &ENABLED_VERTEX_ATTRIBUTES;
|
||||||
|
|
||||||
/* Redirect attrib pointers */
|
/* Redirect attrib pointers */
|
||||||
|
|||||||
100
GL/matrix.c
100
GL/matrix.c
@ -15,13 +15,12 @@ GLfloat DEPTH_RANGE_MULTIPLIER_H = (0 + 1) / 2;
|
|||||||
|
|
||||||
static Stack __attribute__((aligned(32))) MATRIX_STACKS[4]; // modelview, projection, texture
|
static Stack __attribute__((aligned(32))) MATRIX_STACKS[4]; // modelview, projection, texture
|
||||||
static Matrix4x4 __attribute__((aligned(32))) NORMAL_MATRIX;
|
static Matrix4x4 __attribute__((aligned(32))) NORMAL_MATRIX;
|
||||||
|
static Matrix4x4 __attribute__((aligned(32))) VIEWPORT_MATRIX;
|
||||||
Viewport VIEWPORT = {
|
static Matrix4x4 __attribute__((aligned(32))) PROJECTION_MATRIX;
|
||||||
0, 0, 640, 480, 320.0f, 240.0f, 320.0f, 240.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
static GLenum MATRIX_MODE = GL_MODELVIEW;
|
static GLenum MATRIX_MODE = GL_MODELVIEW;
|
||||||
static GLubyte MATRIX_IDX = 0;
|
static GLubyte MATRIX_IDX = 0;
|
||||||
|
static GLboolean NORMAL_DIRTY, PROJECTION_DIRTY;
|
||||||
|
|
||||||
static const Matrix4x4 __attribute__((aligned(32))) IDENTITY = {
|
static const Matrix4x4 __attribute__((aligned(32))) IDENTITY = {
|
||||||
1.0f, 0.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
@ -94,12 +93,28 @@ static void transpose(GLfloat* m) {
|
|||||||
swap(m[11], m[14]);
|
swap(m[11], m[14]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void recalculateNormalMatrix() {
|
/* When projection matrix changes, need to pre-multiply with viewport transform matrix */
|
||||||
|
static void UpdateProjectionMatrix() {
|
||||||
|
PROJECTION_DIRTY = false;
|
||||||
|
UploadMatrix4x4(&VIEWPORT_MATRIX);
|
||||||
|
MultiplyMatrix4x4(stack_top(MATRIX_STACKS + (GL_PROJECTION & 0xF)));
|
||||||
|
DownloadMatrix4x4(&PROJECTION_MATRIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* When modelview matrix changes, need to re-compute normal matrix */
|
||||||
|
static void UpdateNormalMatrix() {
|
||||||
|
NORMAL_DIRTY = false;
|
||||||
MEMCPY4(NORMAL_MATRIX, stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)), sizeof(Matrix4x4));
|
MEMCPY4(NORMAL_MATRIX, stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)), sizeof(Matrix4x4));
|
||||||
inverse((GLfloat*) NORMAL_MATRIX);
|
inverse((GLfloat*) NORMAL_MATRIX);
|
||||||
transpose((GLfloat*) NORMAL_MATRIX);
|
transpose((GLfloat*) NORMAL_MATRIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void OnMatrixChanged() {
|
||||||
|
if(MATRIX_MODE == GL_MODELVIEW) NORMAL_DIRTY = true;
|
||||||
|
if(MATRIX_MODE == GL_PROJECTION) PROJECTION_DIRTY = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void APIENTRY glMatrixMode(GLenum mode) {
|
void APIENTRY glMatrixMode(GLenum mode) {
|
||||||
MATRIX_MODE = mode;
|
MATRIX_MODE = mode;
|
||||||
MATRIX_IDX = mode & 0xF;
|
MATRIX_IDX = mode & 0xF;
|
||||||
@ -111,17 +126,17 @@ void APIENTRY glPushMatrix() {
|
|||||||
void* ret = stack_push(MATRIX_STACKS + MATRIX_IDX, top);
|
void* ret = stack_push(MATRIX_STACKS + MATRIX_IDX, top);
|
||||||
(void) ret;
|
(void) ret;
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
OnMatrixChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glPopMatrix() {
|
void APIENTRY glPopMatrix() {
|
||||||
stack_pop(MATRIX_STACKS + MATRIX_IDX);
|
stack_pop(MATRIX_STACKS + MATRIX_IDX);
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
OnMatrixChanged();
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glLoadIdentity() {
|
void APIENTRY glLoadIdentity() {
|
||||||
stack_replace(MATRIX_STACKS + MATRIX_IDX, IDENTITY);
|
stack_replace(MATRIX_STACKS + MATRIX_IDX, IDENTITY);
|
||||||
|
OnMatrixChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
||||||
@ -141,10 +156,7 @@ void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
assert(top);
|
assert(top);
|
||||||
|
|
||||||
DownloadMatrix4x4(top);
|
DownloadMatrix4x4(top);
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -159,10 +171,7 @@ void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
MultiplyMatrix4x4(&scale);
|
MultiplyMatrix4x4(&scale);
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
||||||
@ -174,8 +183,13 @@ void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
float r = DEG2RAD * angle;
|
float r = DEG2RAD * angle;
|
||||||
float c = fcos(r);
|
#ifdef __DREAMCAST__
|
||||||
float s = fsin(r);
|
float s, c;
|
||||||
|
fsincos(r, &s, &c);
|
||||||
|
#else
|
||||||
|
float c = cosf(r);
|
||||||
|
float s = sinf(r);
|
||||||
|
#endif
|
||||||
|
|
||||||
VEC3_NORMALIZE(x, y, z);
|
VEC3_NORMALIZE(x, y, z);
|
||||||
|
|
||||||
@ -202,10 +216,7 @@ void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
|
|||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &rotate);
|
MultiplyMatrix4x4((const Matrix4x4*) &rotate);
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load an arbitrary matrix */
|
/* Load an arbitrary matrix */
|
||||||
@ -214,10 +225,7 @@ void APIENTRY glLoadMatrixf(const GLfloat *m) {
|
|||||||
|
|
||||||
memcpy(TEMP, m, sizeof(float) * 16);
|
memcpy(TEMP, m, sizeof(float) * 16);
|
||||||
stack_replace(MATRIX_STACKS + MATRIX_IDX, TEMP);
|
stack_replace(MATRIX_STACKS + MATRIX_IDX, TEMP);
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ortho */
|
/* Ortho */
|
||||||
@ -243,6 +251,7 @@ void APIENTRY glOrtho(GLfloat left, GLfloat right,
|
|||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &OrthoMatrix);
|
MultiplyMatrix4x4((const Matrix4x4*) &OrthoMatrix);
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
|
OnMatrixChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -274,6 +283,7 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right,
|
|||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &FrustumMatrix);
|
MultiplyMatrix4x4((const Matrix4x4*) &FrustumMatrix);
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
|
OnMatrixChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -285,10 +295,7 @@ void glMultMatrixf(const GLfloat *m) {
|
|||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
MultiplyMatrix4x4(&TEMP);
|
MultiplyMatrix4x4(&TEMP);
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load an arbitrary transposed matrix */
|
/* Load an arbitrary transposed matrix */
|
||||||
@ -319,10 +326,7 @@ void glLoadTransposeMatrixf(const GLfloat *m) {
|
|||||||
TEMP[M15] = m[15];
|
TEMP[M15] = m[15];
|
||||||
|
|
||||||
stack_replace(MATRIX_STACKS + MATRIX_IDX, TEMP);
|
stack_replace(MATRIX_STACKS + MATRIX_IDX, TEMP);
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Multiply the current matrix by an arbitrary transposed matrix */
|
/* Multiply the current matrix by an arbitrary transposed matrix */
|
||||||
@ -352,22 +356,19 @@ void glMultTransposeMatrixf(const GLfloat *m) {
|
|||||||
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) &TEMP);
|
MultiplyMatrix4x4((const Matrix4x4*) &TEMP);
|
||||||
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
|
||||||
|
OnMatrixChanged();
|
||||||
if(MATRIX_MODE == GL_MODELVIEW) {
|
|
||||||
recalculateNormalMatrix();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the GL viewport */
|
/* Set the GL viewport */
|
||||||
void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
|
void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
|
||||||
VIEWPORT.x = x;
|
VIEWPORT_MATRIX[M0] = width * 0.5f;
|
||||||
VIEWPORT.y = y;
|
VIEWPORT_MATRIX[M5] = height * -0.5f;
|
||||||
VIEWPORT.width = width;
|
VIEWPORT_MATRIX[M10] = 1.0f;
|
||||||
VIEWPORT.height = height;
|
VIEWPORT_MATRIX[M15] = 1.0f;
|
||||||
VIEWPORT.hwidth = ((GLfloat) VIEWPORT.width) * 0.5f;
|
|
||||||
VIEWPORT.hheight = ((GLfloat) VIEWPORT.height) * 0.5f;
|
VIEWPORT_MATRIX[M12] = x + width * 0.5f;
|
||||||
VIEWPORT.x_plus_hwidth = VIEWPORT.x + VIEWPORT.hwidth;
|
VIEWPORT_MATRIX[M13] = GetVideoMode()->height - (y + height * 0.5f);
|
||||||
VIEWPORT.y_plus_hheight = VIEWPORT.y + VIEWPORT.hheight;
|
PROJECTION_DIRTY = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the depth range */
|
/* Set the depth range */
|
||||||
@ -459,14 +460,17 @@ void _glMatrixLoadModelView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _glMatrixLoadProjection() {
|
void _glMatrixLoadProjection() {
|
||||||
UploadMatrix4x4((const Matrix4x4*) stack_top(MATRIX_STACKS + (GL_PROJECTION & 0xF)));
|
if (PROJECTION_DIRTY) UpdateProjectionMatrix();
|
||||||
|
UploadMatrix4x4(&PROJECTION_MATRIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glMatrixLoadModelViewProjection() {
|
void _glMatrixLoadModelViewProjection() {
|
||||||
UploadMatrix4x4((const Matrix4x4*) stack_top(MATRIX_STACKS + (GL_PROJECTION & 0xF)));
|
if (PROJECTION_DIRTY) UpdateProjectionMatrix();
|
||||||
|
UploadMatrix4x4(&PROJECTION_MATRIX);
|
||||||
MultiplyMatrix4x4((const Matrix4x4*) stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)));
|
MultiplyMatrix4x4((const Matrix4x4*) stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glMatrixLoadNormal() {
|
void _glMatrixLoadNormal() {
|
||||||
|
if (NORMAL_DIRTY) UpdateNormalMatrix();
|
||||||
UploadMatrix4x4((const Matrix4x4*) &NORMAL_MATRIX);
|
UploadMatrix4x4((const Matrix4x4*) &NORMAL_MATRIX);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,9 +79,10 @@ GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex, const float h, i
|
|||||||
for(int v = 0; v < count; ++v) {
|
for(int v = 0; v < count; ++v) {
|
||||||
const float f = _glFastInvert(vertex[v].w);
|
const float f = _glFastInvert(vertex[v].w);
|
||||||
|
|
||||||
/* Convert to NDC and apply viewport */
|
/* Convert to screenspace */
|
||||||
vertex[v].xyz[0] = (vertex[v].xyz[0] * f * 320) + 320;
|
/* (note that vertices have already been viewport transformed) */
|
||||||
vertex[v].xyz[1] = (vertex[v].xyz[1] * f * -240) + 240;
|
vertex[v].xyz[0] *= f;
|
||||||
|
vertex[v].xyz[1] *= f;
|
||||||
|
|
||||||
/* Orthographic projections need to use invZ otherwise we lose
|
/* Orthographic projections need to use invZ otherwise we lose
|
||||||
the depth information. As w == 1, and clip-space range is -w to +w
|
the depth information. As w == 1, and clip-space range is -w to +w
|
||||||
|
|||||||
@ -75,17 +75,13 @@ void SceneListBegin(GPUList list) {
|
|||||||
vertex_counter = 0;
|
vertex_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex, const float h) {
|
GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex) {
|
||||||
const float f = 1.0f / (vertex->w);
|
const float f = 1.0f / (vertex->w);
|
||||||
|
|
||||||
/* Convert to NDC and apply viewport */
|
/* Convert to screenspace */
|
||||||
vertex->xyz[0] = __builtin_fmaf(
|
/* (note that vertices have already been viewport transformed) */
|
||||||
VIEWPORT.hwidth, vertex->xyz[0] * f, VIEWPORT.x_plus_hwidth
|
vertex->xyz[0] = vertex->xyz[0] * f;
|
||||||
);
|
vertex->xyz[1] = vertex->xyz[1] * f;
|
||||||
|
|
||||||
vertex->xyz[1] = h - __builtin_fmaf(
|
|
||||||
VIEWPORT.hheight, vertex->xyz[1] * f, VIEWPORT.y_plus_hheight
|
|
||||||
);
|
|
||||||
|
|
||||||
if(vertex->w == 1.0f) {
|
if(vertex->w == 1.0f) {
|
||||||
vertex->xyz[2] = 1.0f / (1.0001f + vertex->xyz[2]);
|
vertex->xyz[2] = 1.0f / (1.0001f + vertex->xyz[2]);
|
||||||
@ -143,8 +139,6 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float h = GetVideoMode()->height;
|
|
||||||
|
|
||||||
uint8_t visible_mask = 0;
|
uint8_t visible_mask = 0;
|
||||||
uint8_t counter = 0;
|
uint8_t counter = 0;
|
||||||
|
|
||||||
@ -182,19 +176,19 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
switch(visible_mask) {
|
switch(visible_mask) {
|
||||||
case 15: /* All visible, but final vertex in strip */
|
case 15: /* All visible, but final vertex in strip */
|
||||||
{
|
{
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v1, h);
|
_glPerspectiveDivideVertex(v1);
|
||||||
_glPushHeaderOrVertex(v1);
|
_glPushHeaderOrVertex(v1);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v2, h);
|
_glPerspectiveDivideVertex(v2);
|
||||||
_glPushHeaderOrVertex(v2);
|
_glPushHeaderOrVertex(v2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
/* All visible, push the first vertex and move on */
|
/* All visible, push the first vertex and move on */
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
@ -210,13 +204,13 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v2, v0, b);
|
_glClipEdge(v2, v0, b);
|
||||||
b->flags = GPU_CMD_VERTEX_EOL;
|
b->flags = GPU_CMD_VERTEX_EOL;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -233,13 +227,13 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v2, v0, b);
|
_glClipEdge(v2, v0, b);
|
||||||
b->flags = GPU_CMD_VERTEX;
|
b->flags = GPU_CMD_VERTEX;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
}
|
}
|
||||||
@ -262,13 +256,13 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v1, v2, b);
|
_glClipEdge(v1, v2, b);
|
||||||
b->flags = v2->flags;
|
b->flags = v2->flags;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(c, h);
|
_glPerspectiveDivideVertex(c);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -285,19 +279,19 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v2, v0, b);
|
_glClipEdge(v2, v0, b);
|
||||||
b->flags = GPU_CMD_VERTEX;
|
b->flags = GPU_CMD_VERTEX;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
_glClipEdge(v1, v2, a);
|
_glClipEdge(v1, v2, a);
|
||||||
a->flags = v2->flags;
|
a->flags = v2->flags;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(c, h);
|
_glPerspectiveDivideVertex(c);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
}
|
}
|
||||||
@ -319,17 +313,17 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v1, v2, b);
|
_glClipEdge(v1, v2, b);
|
||||||
b->flags = GPU_CMD_VERTEX;
|
b->flags = GPU_CMD_VERTEX;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
if(counter % 2 == 1) {
|
if(counter % 2 == 1) {
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(c, h);
|
_glPerspectiveDivideVertex(c);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -349,15 +343,15 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v1, v2, b);
|
_glClipEdge(v1, v2, b);
|
||||||
b->flags = GPU_CMD_VERTEX;
|
b->flags = GPU_CMD_VERTEX;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(c, h);
|
_glPerspectiveDivideVertex(c);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
|
|
||||||
c->flags = GPU_CMD_VERTEX_EOL;
|
c->flags = GPU_CMD_VERTEX_EOL;
|
||||||
@ -380,15 +374,15 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v1, v2, b);
|
_glClipEdge(v1, v2, b);
|
||||||
b->flags = GPU_CMD_VERTEX;
|
b->flags = GPU_CMD_VERTEX;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(v0, h);
|
_glPerspectiveDivideVertex(v0);
|
||||||
_glPushHeaderOrVertex(v0);
|
_glPushHeaderOrVertex(v0);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(c, h);
|
_glPerspectiveDivideVertex(c);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
}
|
}
|
||||||
@ -411,17 +405,17 @@ void SceneListSubmit(Vertex* v2, int n) {
|
|||||||
_glClipEdge(v2, v0, b);
|
_glClipEdge(v2, v0, b);
|
||||||
b->flags = GPU_CMD_VERTEX;
|
b->flags = GPU_CMD_VERTEX;
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(a, h);
|
_glPerspectiveDivideVertex(a);
|
||||||
_glPushHeaderOrVertex(a);
|
_glPushHeaderOrVertex(a);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(c, h);
|
_glPerspectiveDivideVertex(c);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(b, h);
|
_glPerspectiveDivideVertex(b);
|
||||||
_glPushHeaderOrVertex(b);
|
_glPushHeaderOrVertex(b);
|
||||||
_glPushHeaderOrVertex(c);
|
_glPushHeaderOrVertex(c);
|
||||||
|
|
||||||
_glPerspectiveDivideVertex(d, h);
|
_glPerspectiveDivideVertex(d);
|
||||||
_glPushHeaderOrVertex(d);
|
_glPushHeaderOrVertex(d);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
14
GL/private.h
14
GL/private.h
@ -104,20 +104,6 @@ typedef struct {
|
|||||||
AlignedVector vector;
|
AlignedVector vector;
|
||||||
} PolyList;
|
} PolyList;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
GLint x;
|
|
||||||
GLint y;
|
|
||||||
GLint width;
|
|
||||||
GLint height;
|
|
||||||
|
|
||||||
float x_plus_hwidth;
|
|
||||||
float y_plus_hheight;
|
|
||||||
float hwidth; /* width * 0.5f */
|
|
||||||
float hheight; /* height * 0.5f */
|
|
||||||
} Viewport;
|
|
||||||
|
|
||||||
extern Viewport VIEWPORT;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Palette data is always stored in RAM as RGBA8888 and packed as ARGB8888
|
/* Palette data is always stored in RAM as RGBA8888 and packed as ARGB8888
|
||||||
* when uploaded to the PVR */
|
* when uploaded to the PVR */
|
||||||
|
|||||||
@ -80,9 +80,7 @@ static struct {
|
|||||||
.color_control = GL_SINGLE_COLOR,
|
.color_control = GL_SINGLE_COLOR,
|
||||||
.color_material_mode = GL_AMBIENT_AND_DIFFUSE,
|
.color_material_mode = GL_AMBIENT_AND_DIFFUSE,
|
||||||
.color_material_mask = AMBIENT_MASK | DIFFUSE_MASK,
|
.color_material_mask = AMBIENT_MASK | DIFFUSE_MASK,
|
||||||
.lights = {0},
|
|
||||||
.enabled_light_count = 0,
|
.enabled_light_count = 0,
|
||||||
.material = {0},
|
|
||||||
.shade_model = GL_SMOOTH
|
.shade_model = GL_SMOOTH
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,6 @@ void DrawGLScene()
|
|||||||
{
|
{
|
||||||
const float RED [] = {1.0, 0, 0, 0.5};
|
const float RED [] = {1.0, 0, 0, 0.5};
|
||||||
const float BLUE [] = {0.0, 0, 1, 0.5};
|
const float BLUE [] = {0.0, 0, 1, 0.5};
|
||||||
const float NONE [] = {0, 0, 0, 0};
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
|
||||||
|
|
||||||
|
|||||||
@ -48,7 +48,6 @@ int dtex_to_gl_texture(texture *tex, char* filename) {
|
|||||||
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
||||||
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
||||||
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
||||||
GLboolean strided = (header.type & (1 << 25)) > 0;
|
|
||||||
GLuint format = (header.type >> 27) & 0b111;
|
GLuint format = (header.type >> 27) & 0b111;
|
||||||
|
|
||||||
image->data = (char *) malloc (header.size);
|
image->data = (char *) malloc (header.size);
|
||||||
|
|||||||
@ -26,7 +26,7 @@ KOS_INIT_ROMDISK(romdisk);
|
|||||||
float xrot, yrot, zrot;
|
float xrot, yrot, zrot;
|
||||||
|
|
||||||
/* storage for one texture */
|
/* storage for one texture */
|
||||||
int texture[1];
|
GLuint texture[1];
|
||||||
|
|
||||||
// Load Bitmaps And Convert To Textures
|
// Load Bitmaps And Convert To Textures
|
||||||
void LoadGLTextures() {
|
void LoadGLTextures() {
|
||||||
@ -81,7 +81,7 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
|
|||||||
|
|
||||||
GLfloat l1_pos[] = {5.0, 0.0, 1.0, 1.0};
|
GLfloat l1_pos[] = {5.0, 0.0, 1.0, 1.0};
|
||||||
GLfloat l1_diff[] = {1.0, 0.0, 0.0, 1.0};
|
GLfloat l1_diff[] = {1.0, 0.0, 0.0, 1.0};
|
||||||
GLfloat l1_amb[] = {0.5, 0.5, 0.5, 1.0};
|
//GLfloat l1_amb[] = {0.5, 0.5, 0.5, 1.0};
|
||||||
|
|
||||||
//glLightfv(GL_LIGHT1, GL_AMBIENT, l1_amb);
|
//glLightfv(GL_LIGHT1, GL_AMBIENT, l1_amb);
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diff);
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diff);
|
||||||
@ -93,7 +93,7 @@ void InitGL(int Width, int Height) // We call this right after our OpenG
|
|||||||
GLfloat l2_pos[] = {0.0, 15.0, 1.0, 1.0};
|
GLfloat l2_pos[] = {0.0, 15.0, 1.0, 1.0};
|
||||||
GLfloat l2_dir[] = {0.0, -1.0, 0.0};
|
GLfloat l2_dir[] = {0.0, -1.0, 0.0};
|
||||||
GLfloat l2_diff[] = {0.5, 0.5, 0.0, 1.0};
|
GLfloat l2_diff[] = {0.5, 0.5, 0.0, 1.0};
|
||||||
GLfloat l2_amb[] = {0.5, 0.5, 0.5, 1.0};
|
//GLfloat l2_amb[] = {0.5, 0.5, 0.5, 1.0};
|
||||||
|
|
||||||
glEnable(GL_LIGHT2);
|
glEnable(GL_LIGHT2);
|
||||||
glLightfv(GL_LIGHT2, GL_DIFFUSE, l2_diff);
|
glLightfv(GL_LIGHT2, GL_DIFFUSE, l2_diff);
|
||||||
@ -145,7 +145,7 @@ void DrawTexturedQuad(int tex, float x, float y, float z)
|
|||||||
GLfloat y0 = y - texH / 2;
|
GLfloat y0 = y - texH / 2;
|
||||||
GLfloat x1 = x + texW / 2;
|
GLfloat x1 = x + texW / 2;
|
||||||
GLfloat y1 = y + texH / 2;
|
GLfloat y1 = y + texH / 2;
|
||||||
GLfloat color[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
//GLfloat color[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
GLfloat mat_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
GLfloat mat_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
|
||||||
GLfloat vertex_data[] = {
|
GLfloat vertex_data[] = {
|
||||||
@ -172,14 +172,6 @@ void DrawTexturedQuad(int tex, float x, float y, float z)
|
|||||||
0.0, 0.0, 1.0
|
0.0, 0.0, 1.0
|
||||||
};
|
};
|
||||||
|
|
||||||
GLfloat color_data[] = {
|
|
||||||
/* 2D Coordinate, texture coordinate */
|
|
||||||
color[0], color[1], color[2], color[3],
|
|
||||||
color[0], color[1], color[2], color[3],
|
|
||||||
color[0], color[1], color[2], color[3],
|
|
||||||
color[0], color[1], color[2], color[3]
|
|
||||||
};
|
|
||||||
|
|
||||||
//GLint indices[] = {0,1,2,3,2,3};
|
//GLint indices[] = {0,1,2,3,2,3};
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|||||||
@ -24,8 +24,7 @@ KOS_INIT_ROMDISK(romdisk);
|
|||||||
#include "../loadbmp.h"
|
#include "../loadbmp.h"
|
||||||
|
|
||||||
float xrot, yrot, zrot;
|
float xrot, yrot, zrot;
|
||||||
|
GLuint texture[1];
|
||||||
int texture[1];
|
|
||||||
|
|
||||||
void LoadGLTextures() {
|
void LoadGLTextures() {
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ int ImageLoad(char *filename, Image *image) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
image->sizeX = sizeX;
|
image->sizeX = sizeX;
|
||||||
printf("Width of %s: %d\n", filename, sizeX);
|
printf("Width of %s: %ld\n", filename, sizeX);
|
||||||
|
|
||||||
// read the height
|
// read the height
|
||||||
if ((i = fread(&sizeY, 4, 1, file)) != 1) {
|
if ((i = fread(&sizeY, 4, 1, file)) != 1) {
|
||||||
@ -43,7 +43,7 @@ int ImageLoad(char *filename, Image *image) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
image->sizeY = sizeY;
|
image->sizeY = sizeY;
|
||||||
printf("Height of %s: %d\n", filename, sizeY);
|
printf("Height of %s: %ld\n", filename, sizeY);
|
||||||
|
|
||||||
// calculate the size (assuming 24 bits or 3 bytes per pixel).
|
// calculate the size (assuming 24 bits or 3 bytes per pixel).
|
||||||
size = image->sizeX * image->sizeY * 3;
|
size = image->sizeX * image->sizeY * 3;
|
||||||
|
|||||||
@ -20,9 +20,7 @@ KOS_INIT_ROMDISK(romdisk);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../loadbmp.h"
|
#include "../loadbmp.h"
|
||||||
|
GLuint texture[1];
|
||||||
/* storage for one texture */
|
|
||||||
int texture[1];
|
|
||||||
|
|
||||||
// Load Bitmaps And Convert To Textures
|
// Load Bitmaps And Convert To Textures
|
||||||
void LoadGLTextures() {
|
void LoadGLTextures() {
|
||||||
|
|||||||
@ -62,7 +62,7 @@ int ImageLoad(char *filename, Image *image) {
|
|||||||
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
||||||
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
||||||
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
||||||
GLboolean strided = (header.type & (1 << 25)) > 0;
|
//GLboolean strided = (header.type & (1 << 25)) > 0;
|
||||||
GLuint format = (header.type >> 27) & 0b111;
|
GLuint format = (header.type >> 27) & 0b111;
|
||||||
|
|
||||||
image->data = (char *) malloc (header.size);
|
image->data = (char *) malloc (header.size);
|
||||||
@ -70,8 +70,8 @@ int ImageLoad(char *filename, Image *image) {
|
|||||||
image->sizeY = header.height;
|
image->sizeY = header.height;
|
||||||
image->dataSize = header.size;
|
image->dataSize = header.size;
|
||||||
|
|
||||||
GLuint expected = 2 * header.width * header.height;
|
//GLuint expected = 2 * header.width * header.height;
|
||||||
GLuint ratio = (GLuint) (((GLfloat) expected) / ((GLfloat) header.size));
|
//GLuint ratio = (GLuint) (((GLfloat) expected) / ((GLfloat) header.size));
|
||||||
|
|
||||||
fread(image->data, image->dataSize, 1, file);
|
fread(image->data, image->dataSize, 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ KOS_INIT_ROMDISK(romdisk);
|
|||||||
float xrot, yrot, zrot;
|
float xrot, yrot, zrot;
|
||||||
|
|
||||||
/* storage for one texture */
|
/* storage for one texture */
|
||||||
int texture[1];
|
GLuint texture[1];
|
||||||
|
|
||||||
/* Image type - contains height, width, and data */
|
/* Image type - contains height, width, and data */
|
||||||
struct Image {
|
struct Image {
|
||||||
@ -59,7 +59,7 @@ int ImageLoad(char *filename, Image *image) {
|
|||||||
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
GLboolean twiddled = (header.type & (1 << 26)) < 1;
|
||||||
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
GLboolean compressed = (header.type & (1 << 30)) > 0;
|
||||||
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
GLboolean mipmapped = (header.type & (1 << 31)) > 0;
|
||||||
GLboolean strided = (header.type & (1 << 25)) > 0;
|
//GLboolean strided = (header.type & (1 << 25)) > 0;
|
||||||
GLuint format = (header.type >> 27) & 0b111;
|
GLuint format = (header.type >> 27) & 0b111;
|
||||||
|
|
||||||
image->data = (char *) malloc (header.size);
|
image->data = (char *) malloc (header.size);
|
||||||
@ -67,8 +67,8 @@ int ImageLoad(char *filename, Image *image) {
|
|||||||
image->sizeY = header.height;
|
image->sizeY = header.height;
|
||||||
image->dataSize = header.size;
|
image->dataSize = header.size;
|
||||||
|
|
||||||
GLuint expected = 2 * header.width * header.height;
|
//GLuint expected = 2 * header.width * header.height;
|
||||||
GLuint ratio = (GLuint) (((GLfloat) expected) / ((GLfloat) header.size));
|
//GLuint ratio = (GLuint) (((GLfloat) expected) / ((GLfloat) header.size));
|
||||||
|
|
||||||
fread(image->data, image->dataSize, 1, file);
|
fread(image->data, image->dataSize, 1, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
@ -11,6 +11,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __DREAMCAST__
|
||||||
|
#include <kos.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define FPS 60
|
#define FPS 60
|
||||||
uint32_t waittime = 1000.0f/FPS;
|
uint32_t waittime = 1000.0f/FPS;
|
||||||
uint32_t framestarttime = 0;
|
uint32_t framestarttime = 0;
|
||||||
@ -227,8 +232,6 @@ int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
BOOL done=FALSE; // Bool Variable To Exit Loop
|
|
||||||
|
|
||||||
glKosInit();
|
glKosInit();
|
||||||
|
|
||||||
InitGL();
|
InitGL();
|
||||||
|
|||||||
@ -22,8 +22,7 @@ KOS_INIT_ROMDISK(romdisk);
|
|||||||
|
|
||||||
/* floats for x rotation, y rotation, z rotation */
|
/* floats for x rotation, y rotation, z rotation */
|
||||||
float xrot, yrot, zrot;
|
float xrot, yrot, zrot;
|
||||||
/* storage for one texture */
|
GLuint texture[1];
|
||||||
int texture[1];
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
/* floats for x rotation, y rotation, z rotation */
|
/* floats for x rotation, y rotation, z rotation */
|
||||||
float xrot, yrot, zrot;
|
float xrot, yrot, zrot;
|
||||||
|
|
||||||
int textures[3];
|
GLuint textures[3];
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
@ -272,7 +272,7 @@ int BMP_GetPalette(FILE *pFile)
|
|||||||
bitCount = BmpInfoHeader.ClrImportant * sizeof(RGB_QUAD);
|
bitCount = BmpInfoHeader.ClrImportant * sizeof(RGB_QUAD);
|
||||||
|
|
||||||
if (fread(BmpRgbQuad, 1, bitCount, pFile) != bitCount){
|
if (fread(BmpRgbQuad, 1, bitCount, pFile) != bitCount){
|
||||||
fprintf(stderr, "Failed to read palette: %d\n", bitCount);
|
fprintf(stderr, "Failed to read palette: %ld\n", bitCount);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ int BMP_GetPalette(FILE *pFile)
|
|||||||
int BMP_Depack(FILE *pFile,char *pZone)
|
int BMP_Depack(FILE *pFile,char *pZone)
|
||||||
{
|
{
|
||||||
char PadRead[4];
|
char PadRead[4];
|
||||||
int32_t i, j, Offset, PadSize, pix, c;
|
int32_t i, j, Offset, PadSize, c;
|
||||||
|
|
||||||
if (BmpInfoHeader.Compression != BMP_BI_RGB)
|
if (BmpInfoHeader.Compression != BMP_BI_RGB)
|
||||||
return 0;
|
return 0;
|
||||||
@ -356,7 +356,7 @@ int LoadPalettedBMP(const char* filename, Image* image)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* store palette information */
|
/* store palette information */
|
||||||
image->palette = BmpPal;
|
image->palette = (char*)BmpPal;
|
||||||
image->palette_width = 16;
|
image->palette_width = 16;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -287,7 +287,7 @@ static bool write_samples(const char* path) {
|
|||||||
root = ARCS;
|
root = ARCS;
|
||||||
for(int i = 0; i < BUCKET_SIZE; ++i) {
|
for(int i = 0; i < BUCKET_SIZE; ++i) {
|
||||||
if(root->pc) {
|
if(root->pc) {
|
||||||
printf("Incrementing %d for %x. ", (root->pc - lowest_address) / bin_size, (unsigned int) root->pc);
|
printf("Incrementing %ld for %x. ", (root->pc - lowest_address) / bin_size, (unsigned int) root->pc);
|
||||||
bins[(root->pc - lowest_address) / bin_size]++;
|
bins[(root->pc - lowest_address) / bin_size]++;
|
||||||
printf("Now: %d\n", (int) bins[(root->pc - lowest_address) / bin_size]);
|
printf("Now: %d\n", (int) bins[(root->pc - lowest_address) / bin_size]);
|
||||||
|
|
||||||
|
|||||||
@ -435,7 +435,7 @@ bool test_clip_case_001() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 5);
|
check_equal(sent.size(), 5u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
@ -461,7 +461,7 @@ bool test_clip_case_010() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 4);
|
check_equal(sent.size(), 4u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
@ -481,7 +481,7 @@ bool test_clip_case_100() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 5);
|
check_equal(sent.size(), 5u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
@ -507,7 +507,7 @@ bool test_clip_case_110() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 6);
|
check_equal(sent.size(), 6u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
@ -530,7 +530,7 @@ bool test_clip_case_011() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 6);
|
check_equal(sent.size(), 6u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
@ -553,7 +553,7 @@ bool test_clip_case_101() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 6);
|
check_equal(sent.size(), 6u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
@ -576,7 +576,7 @@ bool test_clip_case_111() {
|
|||||||
|
|
||||||
SceneListSubmit(&data[0], data.size());
|
SceneListSubmit(&data[0], data.size());
|
||||||
|
|
||||||
check_equal(sent.size(), 4);
|
check_equal(sent.size(), 4u);
|
||||||
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
check_equal(sent[0].flags, GPU_CMD_POLYHDR);
|
||||||
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
check_equal(sent[1].flags, GPU_CMD_VERTEX);
|
||||||
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
check_equal(sent[2].flags, GPU_CMD_VERTEX);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user