From eeeae88ece51191c237cd3a1b04ab0dab55b87fe Mon Sep 17 00:00:00 2001 From: Hayden Kowalchuk <819028+mrneo240@users.noreply.github.com> Date: Tue, 18 Feb 2020 12:10:32 -0500 Subject: [PATCH] merge: master --- GL/clip.c | 25 +++++++++------- GL/glu.c | 4 +-- GL/matrix.c | 35 +++++++++++++++-------- GL/texture.c | 4 +-- containers/named_array.c | 5 ++-- samples/multitexture_arrays/pvr-texture.c | 2 +- 6 files changed, 46 insertions(+), 29 deletions(-) diff --git a/GL/clip.c b/GL/clip.c index e4a8307..73ac433 100644 --- a/GL/clip.c +++ b/GL/clip.c @@ -32,32 +32,28 @@ void _glClipLineToNearZ(const Vertex* v1, const Vertex* v2, Vertex* vout, float* float vec [] = {v2->xyz[0] - v1->xyz[0], v2->xyz[1] - v1->xyz[1], v2->xyz[2] - v1->xyz[2]}; - vout->xyz[0] = v1->xyz[0] + (vec[0] * (*t)); - vout->xyz[1] = v1->xyz[1] + (vec[1] * (*t)); - vout->xyz[2] = v1->xyz[2] + (vec[2] * (*t)); + vout->xyz[0] = MATH_fmac(vec[0], (*t), v1->xyz[0]); + vout->xyz[1] = MATH_fmac(vec[1], (*t), v1->xyz[1]); + vout->xyz[2] = MATH_fmac(vec[2], (*t), v1->xyz[2]); + } static inline void interpolateFloat(const float v1, const float v2, const float t, float* out) { - float v = v2 - v1; - *out = (v * t) + v1; + *out = MATH_fmac(v2 - v1,t, v1); } static inline void interpolateVec2(const float* v1, const float* v2, const float t, float* out) { - /* FIXME: SH4 has an asm instruction for this */ interpolateFloat(v1[0], v2[0], t, &out[0]); interpolateFloat(v1[1], v2[1], t, &out[1]); } static inline void interpolateVec3(const float* v1, const float* v2, const float t, float* out) { - /* FIXME: SH4 has an asm instruction for this */ - interpolateFloat(v1[0], v2[0], t, &out[0]); interpolateFloat(v1[1], v2[1], t, &out[1]); interpolateFloat(v1[2], v2[2], t, &out[2]); } static inline void interpolateVec4(const float* v1, const float* v2, const float t, float* out) { - /* FIXME: SH4 has an asm instruction for this */ interpolateFloat(v1[0], v2[0], t, &out[0]); interpolateFloat(v1[1], v2[1], t, &out[1]); interpolateFloat(v1[2], v2[2], t, &out[2]); @@ -120,7 +116,16 @@ void _glClipTriangle(const Triangle* triangle, const uint8_t visible, Submission interpolateVec2(ve1->st, ve2->st, t, veNext.st); if(flatShade) { - *((uint32_t*) next.bgra) = *((uint32_t*) vertices[2].bgra); + /* Original */ + //*((uint32_t*) next.bgra) = *((uint32_t*) vertices[2].bgra); + + /* "Correct" memcpy */ + //memcpy(next.bgra, vertices[2].bgra, 4); + + /* manual aliasing */ + uint32_t* a = (void*)(&vertices[2].bgra[0]); + uint32_t* b = (void*)(&next.bgra[0]); + *b = *a; } else { interpolateColour(v1->bgra, v2->bgra, t, next.bgra); } diff --git a/GL/glu.c b/GL/glu.c index be92029..610caf3 100644 --- a/GL/glu.c +++ b/GL/glu.c @@ -104,8 +104,8 @@ GLint APIENTRY gluBuild2DMipmaps( GLenum target,GLint internalFormat, GLsizei wi while(th > maxtex) th /= 2; - levels = 1 + floor(log2(tw)); - level = 1 + floor(log2(th)); + levels = 1 + floorf(log2f(tw)); + level = 1 + floorf(log2f(th)); if (level > levels) levels = level; diff --git a/GL/matrix.c b/GL/matrix.c index 5d3a629..76b4f8f 100644 --- a/GL/matrix.c +++ b/GL/matrix.c @@ -299,7 +299,7 @@ void APIENTRY glFrustum(GLfloat left, GLfloat right, /* Frustum Matrix */ static Matrix4x4 FrustumMatrix __attribute__((aligned(32))); - memset(FrustumMatrix, 0, sizeof(float) * 16); + memset4(FrustumMatrix, 0, sizeof(float) * 16); const float near2 = 2.0f * znear; const float A = (right + left) / (right - left); @@ -476,18 +476,15 @@ void APIENTRY glDepthRange(GLclampf n, GLclampf f) { DEPTH_RANGE_MULTIPLIER_H = (n + f) / 2.0f; } -#include "sh4_math.h" - -/* Vector Cross Product - Used by glhLookAtf2 */ -static inline void vec3f_cross(GLfloat* v1, GLfloat* v2, GLfloat* 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]); +/* Vector Cross Product - Used by gluLookAt */ +static inline void vec3f_cross(const GLfloat* v1, const GLfloat* v2, GLfloat* 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]; } - static inline void vec3f_normalize_sh4(float *v){ - float length, ilength; + float length, ilength; ilength = MATH_fsrra(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); length = MATH_Invert(ilength); @@ -525,8 +522,22 @@ void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, m[2] = -f[0]; m[6] = -f[1]; m[10] = -f[2]; m[14] = 0.0f; m[3] = 0.0f; m[7] = 0.0f; m[11] = 0.0f; m[15] = 1.0f; - glMultMatrixf(m); - glTranslatef(-eyex, -eyey, -eyez); + static Matrix4x4 trn __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 + }; + + trn[M12] = -eyex; + trn[M13] = -eyey; + trn[M14] = -eyez; + + // Does not modify internal Modelview matrix + upload_matrix(&m); + multiply_matrix(&trn); + multiply_matrix(stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF))); + download_matrix(stack_top(MATRIX_STACKS + (GL_MODELVIEW & 0xF))); } void _glApplyRenderMatrix() { diff --git a/GL/texture.c b/GL/texture.c index bf00983..95ec42f 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -35,7 +35,7 @@ static TexturePalette* _initTexturePalette() { TexturePalette* palette = (TexturePalette*) malloc(sizeof(TexturePalette)); assert(palette); - memset(palette, 0x0, sizeof(TexturePalette)); + memset4(palette, 0x0, sizeof(TexturePalette)); palette->bank = -1; return palette; } @@ -282,7 +282,7 @@ GLubyte* _glGetMipmapLocation(TextureObject* obj, GLuint level) { } GLuint _glGetMipmapLevelCount(TextureObject* obj) { - return 1 + floor(log2(MAX(obj->width, obj->height))); + return 1 + floorf(log2f(MAX(obj->width, obj->height))); } static GLuint _glGetMipmapDataSize(TextureObject* obj) { diff --git a/containers/named_array.c b/containers/named_array.c index 6efa7dc..44bee8e 100644 --- a/containers/named_array.c +++ b/containers/named_array.c @@ -30,18 +30,19 @@ void named_array_init(NamedArray* array, unsigned int element_size, unsigned int array->max_element_count = max_elements; float c = (float) max_elements / 8.0f; - array->marker_count = (unsigned char) ceil(c); + array->marker_count = (unsigned char) ceilf(c); #ifdef _arch_dreamcast // Use 32-bit aligned memory on the Dreamcast array->elements = (unsigned char*) memalign(0x20, element_size * max_elements); array->used_markers = (unsigned char*) memalign(0x20, array->marker_count); + memset4(array->elements, 0, element_size * max_elements); #else array->elements = (unsigned char*) malloc(element_size * max_elements); array->used_markers = (unsigned char*) malloc(array->marker_count); + memset(array->elements, 0, element_size * max_elements); #endif memset(array->used_markers, 0, sizeof(unsigned char) * array->marker_count); - memset(array->elements, 0, element_size * max_elements); } diff --git a/samples/multitexture_arrays/pvr-texture.c b/samples/multitexture_arrays/pvr-texture.c index 66b16d7..ae88c6e 100644 --- a/samples/multitexture_arrays/pvr-texture.c +++ b/samples/multitexture_arrays/pvr-texture.c @@ -22,7 +22,7 @@ static GLuint PVR_TextureWidth(unsigned char *HDR); static GLuint PVR_TextureFormat(unsigned char *HDR); static GLuint _glGetMipmapLevelCount(GLuint width, GLuint height) { - return 1 + floor(log2(MAX(width, height))); + return 1 + floorf(log2f(MAX(width, height))); } static GLuint _glGetMipmapDataSize(GLuint width, GLuint height) {