From 2d307e6fc19a23074ed123ffa2463d2d7c3ce6f0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 25 Apr 2024 22:19:53 +1000 Subject: [PATCH] Dreamcast: Fix last commit oops --- src/Graphics_Dreamcast.c | 2 +- third_party/gldc/{include => }/gldc.h | 0 third_party/gldc/src/draw.c | 63 +++++++-------------------- third_party/gldc/src/flush.c | 1 - third_party/gldc/src/private.h | 2 +- third_party/gldc/src/state.c | 8 ++-- 6 files changed, 22 insertions(+), 54 deletions(-) rename third_party/gldc/{include => }/gldc.h (100%) diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index b0fce28ce..5a9440724 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -4,7 +4,7 @@ #include "Errors.h" #include "Logger.h" #include "Window.h" -#include "../third_party/gldc/include/gldc.h" +#include "../third_party/gldc/gldc.h" #include #include #include diff --git a/third_party/gldc/include/gldc.h b/third_party/gldc/gldc.h similarity index 100% rename from third_party/gldc/include/gldc.h rename to third_party/gldc/gldc.h diff --git a/third_party/gldc/src/draw.c b/third_party/gldc/src/draw.c index 0fb904cb0..a5b8a77ff 100644 --- a/third_party/gldc/src/draw.c +++ b/third_party/gldc/src/draw.c @@ -8,34 +8,12 @@ static const void* VERTEX_PTR; GLuint i = count; \ while(i--) - -/* Generating PVR vertices from the user-submitted data gets complicated, particularly - * when a realloc could invalidate pointers. This structure holds all the information - * we need on the target vertex array to allow passing around to the various stages (e.g. generate/clip etc.) - */ -typedef struct __attribute__((aligned(32))) { - PolyList* output; - uint32_t header_offset; // The offset of the header in the output list - uint32_t start_offset; // The offset into the output list -} SubmissionTarget; -static SubmissionTarget SUBMISSION_TARGET; - -GL_FORCE_INLINE PolyHeader* _glSubmissionTargetHeader(SubmissionTarget* target) { - return aligned_vector_at(&target->output->vector, target->header_offset); -} - -GL_FORCE_INLINE Vertex* _glSubmissionTargetStart(SubmissionTarget* target) { - return aligned_vector_at(&target->output->vector, target->start_offset); -} - -static void generateColouredQuads(SubmissionTarget* target, const GLsizei first, const GLuint count) { +static void generateColouredQuads(Vertex* dst, const GLsizei first, const GLuint count) { /* Read from the client buffers and generate an array of ClipVertices */ GLuint numQuads = count / 4; - Vertex* start = _glSubmissionTargetStart(target); /* Copy the pos, uv and color directly in one go */ const GLubyte* src = VERTEX_PTR + (first * 16); - Vertex* dst = start; const float w = 1.0f; PREFETCH(src); @@ -62,14 +40,12 @@ static void generateColouredQuads(SubmissionTarget* target, const GLsizei first, } } -static void generateTexturedQuads(SubmissionTarget* target, const GLsizei first, const GLuint count) { +static void generateTexturedQuads(Vertex* dst, const GLsizei first, const GLuint count) { /* Read from the client buffers and generate an array of ClipVertices */ GLuint numQuads = count / 4; - Vertex* start = _glSubmissionTargetStart(target); /* Copy the pos, uv and color directly in one go */ const GLubyte* src = VERTEX_PTR + (first * 24); - Vertex* dst = start; const float w = 1.0f; PREFETCH(src); @@ -96,47 +72,40 @@ static void generateTexturedQuads(SubmissionTarget* target, const GLsizei first, } } -void _glInitSubmissionTarget() { - SubmissionTarget* target = &SUBMISSION_TARGET; - - target->output = NULL; - target->header_offset = target->start_offset = 0; -} - extern void apply_poly_header(PolyHeader* header, PolyList* activePolyList); -GL_FORCE_INLINE void submitVertices(GLuint vertexCount) { - SubmissionTarget* const target = &SUBMISSION_TARGET; +GL_FORCE_INLINE Vertex* submitVertices(GLuint vertexCount) { TRACE(); - target->output = _glActivePolyList(); + PolyList* output = _glActivePolyList(); + uint32_t header_offset; + uint32_t start_offset; - uint32_t vector_size = aligned_vector_size(&target->output->vector); + uint32_t vector_size = aligned_vector_size(&output->vector); GLboolean header_required = (vector_size == 0) || STATE_DIRTY; - target->header_offset = vector_size; - target->start_offset = target->header_offset + (header_required ? 1 : 0); - gl_assert(target->header_offset >= 0); + header_offset = vector_size; + start_offset = header_offset + (header_required ? 1 : 0); /* Make room for the vertices and header */ - aligned_vector_extend(&target->output->vector, (header_required) + vertexCount); - gl_assert(target->header_offset < aligned_vector_size(&target->output->vector)); + aligned_vector_extend(&output->vector, (header_required) + vertexCount); + gl_assert(header_offset < aligned_vector_size(&output->vector)); if (header_required) { - apply_poly_header(_glSubmissionTargetHeader(target), target->output); + apply_poly_header(aligned_vector_at(&output->vector, header_offset), output); STATE_DIRTY = GL_FALSE; } + return aligned_vector_at(&output->vector, start_offset); } void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) { TRACE(); if (!count) return; - - submitVertices(count); + Vertex* start = submitVertices(count); if (TEXTURES_ENABLED) { - generateTexturedQuads(&SUBMISSION_TARGET, first, count); + generateTexturedQuads(start, first, count); } else { - generateColouredQuads(&SUBMISSION_TARGET, first, count); + generateColouredQuads(start, first, count); } } diff --git a/third_party/gldc/src/flush.c b/third_party/gldc/src/flush.c index b2de0e2a6..00b4e65e3 100644 --- a/third_party/gldc/src/flush.c +++ b/third_party/gldc/src/flush.c @@ -26,7 +26,6 @@ void APIENTRY glKosInit() { InitGPU(config.autosort_enabled, config.fsaa_enabled); AUTOSORT_ENABLED = config.autosort_enabled; - _glInitSubmissionTarget(); _glInitContext(); _glInitTextures(); diff --git a/third_party/gldc/src/private.h b/third_party/gldc/src/private.h index fbb48cc96..c73c4c80f 100644 --- a/third_party/gldc/src/private.h +++ b/third_party/gldc/src/private.h @@ -8,7 +8,7 @@ #include "platform.h" #include "types.h" -#include "../include/gldc.h" +#include "../gldc.h" #include "aligned_vector.h" diff --git a/third_party/gldc/src/state.c b/third_party/gldc/src/state.c index 5f6cd1400..3d5fa3193 100644 --- a/third_party/gldc/src/state.c +++ b/third_party/gldc/src/state.c @@ -257,10 +257,10 @@ Viewport VIEWPORT; /* Set the GL viewport */ void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { - VIEWPORT.hwidth = ((GLfloat)width) * 0.5f; - VIEWPORT.hheight = ((GLfloat)height) * -0.5f; - VIEWPORT.x_plus_hwidth = x + VIEWPORT.hwidth; - VIEWPORT.y_plus_hheight = y + VIEWPORT.hheight; + VIEWPORT.hwidth = width * 0.5f; + VIEWPORT.hheight = height * -0.5f; + VIEWPORT.x_plus_hwidth = x + width * 0.5f; + VIEWPORT.y_plus_hheight = y + height * 0.5f; }