More stubbing + porting

This commit is contained in:
Luke Benstead 2021-04-05 12:49:58 +01:00
parent 7e879b2c61
commit 7214852dca
7 changed files with 58 additions and 44 deletions

View File

@ -32,18 +32,6 @@ static const Matrix4x4 IDENTITY = {
GLfloat NEAR_PLANE_DISTANCE = 0.0f;
static inline void upload_matrix(Matrix4x4* m) {
mat_load((matrix_t*) m);
}
static inline void multiply_matrix(Matrix4x4* m) {
mat_apply((matrix_t*) m);
}
static inline void download_matrix(Matrix4x4* m) {
mat_store((matrix_t*) m);
}
Matrix4x4* _glGetProjectionMatrix() {
return (Matrix4x4*) stack_top(&MATRIX_STACKS[1]);
}
@ -64,6 +52,8 @@ void _glInitMatrices() {
memcpy4(NORMAL_MATRIX, IDENTITY, sizeof(Matrix4x4));
memcpy4(SCREENVIEW_MATRIX, IDENTITY, sizeof(Matrix4x4));
const VideoMode* vid_mode = GetVideoMode();
glDepthRange(0.0f, 1.0f);
glViewport(0, 0, vid_mode->width, vid_mode->height);
}
@ -143,9 +133,9 @@ void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z) {
trn[M13] = y;
trn[M14] = z;
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix(&trn);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4(&trn);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
if(MATRIX_MODE == GL_MODELVIEW) {
recalculateNormalMatrix();
@ -165,9 +155,9 @@ void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z) {
scale[M5] = y;
scale[M10] = z;
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix(&scale);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4(&scale);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
if(MATRIX_MODE == GL_MODELVIEW) {
recalculateNormalMatrix();
@ -208,9 +198,9 @@ void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) {
rotate[M9] = yz * invc - xs;
rotate[M10] = (z * z) * invc + c;
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix(&rotate);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4(&rotate);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
if(MATRIX_MODE == GL_MODELVIEW) {
recalculateNormalMatrix();
@ -268,9 +258,9 @@ void APIENTRY glOrtho(GLfloat left, GLfloat right,
OrthoMatrix[M13] = -(top + bottom) / (top - bottom);
OrthoMatrix[M14] = -(zfar + znear) / (zfar - znear);
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix(&OrthoMatrix);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4(&OrthoMatrix);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
}
@ -282,7 +272,7 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right,
/* Frustum Matrix */
static Matrix4x4 FrustumMatrix __attribute__((aligned(32)));
memset(FrustumMatrix, 0, sizeof(float) * 16);
MEMSET(FrustumMatrix, 0, sizeof(float) * 16);
const float near2 = 2.0f * znear;
const float A = (right + left) / (right - left);
@ -299,9 +289,9 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right,
FrustumMatrix[M11] = -1.0f;
FrustumMatrix[M14] = D;
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix(&FrustumMatrix);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4(&FrustumMatrix);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
}
@ -329,9 +319,9 @@ void glMultMatrixf(const GLfloat *m) {
TEMP[M14] = m[14];
TEMP[M15] = m[15];
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix((Matrix4x4*) &TEMP);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4((Matrix4x4*) &TEMP);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
if(MATRIX_MODE == GL_MODELVIEW) {
recalculateNormalMatrix();
@ -396,9 +386,9 @@ void glMultTransposeMatrixf(const GLfloat *m) {
TEMP[M14] = m[11];
TEMP[M15] = m[15];
upload_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
multiply_matrix(&TEMP);
download_matrix(stack_top(MATRIX_STACKS + MATRIX_IDX));
UploadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
MultiplyMatrix4x4(&TEMP);
DownloadMatrix4x4(stack_top(MATRIX_STACKS + MATRIX_IDX));
if(MATRIX_MODE == GL_MODELVIEW) {
recalculateNormalMatrix();
@ -407,6 +397,8 @@ void glMultTransposeMatrixf(const GLfloat *m) {
/* Set the GL viewport */
void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
const VideoMode* vid_mode = GetVideoMode();
gl_viewport_x1 = x;
gl_viewport_y1 = y;
gl_viewport_width = width;

View File

@ -3,6 +3,8 @@
#include <stdint.h>
#include <stdbool.h>
#define MEMSET(dst, v, size) memset((dst), (v), (size))
typedef enum GPUAlpha {
GPU_ALPHA_DISABLE = 0,
GPU_ALPHA_ENABLE = 1
@ -147,6 +149,13 @@ typedef enum GPUTextureEnv {
GPU_TXRENV_MODULATEALPHA = 3
} GPUTextureEnv;
typedef struct VideoMode {
uint16_t width;
uint16_t height;
} VideoMode;
const VideoMode* GetVideoMode();
/* Duplication of pvr_poly_cxt_t from KOS so that we can
* compile on non-KOS platforms for testing */

View File

@ -9,6 +9,15 @@
#include "../types.h"
#include "sh4_math.h"
#define FASTCPY(dst, src, bytes) \
(bytes % 32 == 0) ? sq_cpy(dst, src, bytes) : memcpy(dst, src, bytes)
#define FASTCPY4(dst, src, bytes) \
(bytes % 32 == 0) ? sq_cpy(dst, src, bytes) : memcpy4(dst, src, bytes)
#define MEMSET4(dst, v, size) memset4((dst), (v), (size))
#define NORMALIZEVEC3(x, y, z) vec3f_normalize((x), (y), (z))
inline void CompilePolyHeader(PolyHeader* out, const PolyContext* in) {
pvr_poly_compile((pvr_poly_hdr_t*) out, (pvr_poly_cxt_t*) in);
}

View File

@ -1,14 +1,20 @@
#pragma once
#include <math.h>
#include <memory.h>
#include "../types.h"
#define MATH_Fast_Divide(n, d) (n / d)
#define MATH_fmac(a, b, c) (a * b + c)
#define MATH_Fast_Sqrt(x) sqrt((x))
#define MATH_fsrra(x) (1.0f / sqrt((x)))
#define MATH_Fast_Sqrt(x) sqrtf((x))
#define MATH_fsrra(x) (1.0f / sqrtf((x)))
#define MATH_Fast_Invert(x) (1.0f / (x))
#define FASTCPY(dst, src, bytes) memcpy(dst, src, bytes)
#define FASTCPY4(dst, src, bytes) memcpy(dst, src, bytes)
#define MEMSET4(dst, v, size) memset((dst), (v), (size))
inline void CompilePolyHeader(PolyHeader* out, const PolyContext* in) {
(void) out;
(void) in;

View File

@ -18,12 +18,6 @@ extern void* memcpy4 (void *dest, const void *src, size_t count);
#define GL_FORCE_INLINE static GL_INLINE_DEBUG
#define _GL_UNUSED(x) (void)(x)
#define FASTCPY(dst, src, bytes) \
(bytes % 32 == 0) ? sq_cpy(dst, src, bytes) : memcpy(dst, src, bytes);
#define FASTCPY4(dst, src, bytes) \
(bytes % 32 == 0) ? sq_cpy(dst, src, bytes) : memcpy4(dst, src, bytes);
#define _PACK4(v) ((v * 0xF) / 0xFF)
#define PACK_ARGB4444(a,r,g,b) (_PACK4(a) << 12) | (_PACK4(r) << 8) | (_PACK4(g) << 4) | (_PACK4(b))
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )

View File

@ -557,6 +557,9 @@ void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
PVRTileClipCommand *c = aligned_vector_extend(&_glActivePolyList()->vector, 1);
GLint miny, maxx, maxy;
const VideoMode* vid_mode = GetVideoMode();
GLsizei gl_scissor_width = MAX( MIN(width, vid_mode->width), 0 );
GLsizei gl_scissor_height = MAX( MIN(height, vid_mode->height), 0 );

View File

@ -7,6 +7,7 @@
#include <string.h>
#include "config.h"
#include "platform.h"
#include "../include/glext.h"
#include "../include/glkos.h"
@ -53,7 +54,7 @@ static TexturePalette* _initTexturePalette() {
TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette));
assert(palette);
memset4(palette, 0x0, sizeof(TexturePalette));
MEMSET4(palette, 0x0, sizeof(TexturePalette));
palette->bank = -1;
return palette;
}
@ -629,7 +630,7 @@ void APIENTRY glCompressedTexImage2DARB(GLenum target,
active->data = yalloc_alloc_and_defrag(imageSize);
if(data) {
sq_cpy(active->data, data, imageSize);
FASTCPY(active->data, data, imageSize);
}
}