Fixed spritebatch flickering on Dolphin
This commit is contained in:
@@ -50,7 +50,6 @@ errorret_t displayInit(void) {
|
|||||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, mat));
|
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, mat));
|
||||||
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, NULL));
|
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, NULL));
|
||||||
|
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,14 +35,13 @@ errorret_t spriteBatchPush(
|
|||||||
const float_t u1,
|
const float_t u1,
|
||||||
const float_t v1
|
const float_t v1
|
||||||
) {
|
) {
|
||||||
errorChain(spriteBatchPush3D(
|
return spriteBatchPush3D(
|
||||||
(vec3){ minX, minY, 0 },
|
(vec3){ minX, minY, 0 },
|
||||||
(vec3){ maxX, maxY, 0 },
|
(vec3){ maxX, maxY, 0 },
|
||||||
color,
|
color,
|
||||||
(vec2){ u0, v0 },
|
(vec2){ u0, v0 },
|
||||||
(vec2){ u1, v1 }
|
(vec2){ u1, v1 }
|
||||||
));
|
);
|
||||||
errorOk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t spriteBatchPush3D(
|
errorret_t spriteBatchPush3D(
|
||||||
@@ -53,11 +52,14 @@ errorret_t spriteBatchPush3D(
|
|||||||
const vec2 uv1
|
const vec2 uv1
|
||||||
) {
|
) {
|
||||||
// Need to flush?
|
// Need to flush?
|
||||||
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX) {
|
if(SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX_PER_FLUSH) {
|
||||||
errorChain(spriteBatchFlush());
|
errorChain(spriteBatchFlush());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t vertexOffset = SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT;
|
size_t vertexOffset = (
|
||||||
|
SPRITEBATCH.spriteCount +
|
||||||
|
(SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH)
|
||||||
|
) * QUAD_VERTEX_COUNT;
|
||||||
quadBuffer3D(
|
quadBuffer3D(
|
||||||
&SPRITEBATCH_VERTICES[vertexOffset],
|
&SPRITEBATCH_VERTICES[vertexOffset],
|
||||||
min, max, color, uv0, uv1
|
min, max, color, uv0, uv1
|
||||||
@@ -68,6 +70,7 @@ errorret_t spriteBatchPush3D(
|
|||||||
|
|
||||||
void spriteBatchClear() {
|
void spriteBatchClear() {
|
||||||
SPRITEBATCH.spriteCount = 0;
|
SPRITEBATCH.spriteCount = 0;
|
||||||
|
SPRITEBATCH.spriteFlush = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t spriteBatchFlush() {
|
errorret_t spriteBatchFlush() {
|
||||||
@@ -76,9 +79,19 @@ errorret_t spriteBatchFlush() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
|
size_t vertexCount = QUAD_VERTEX_COUNT * SPRITEBATCH.spriteCount;
|
||||||
errorChain(meshFlush(&SPRITEBATCH.mesh, 0, vertexCount));
|
size_t vertexOffset = (
|
||||||
errorChain(meshDraw(&SPRITEBATCH.mesh, 0, vertexCount));
|
SPRITEBATCH.spriteFlush * SPRITEBATCH_SPRITES_MAX_PER_FLUSH *
|
||||||
spriteBatchClear();
|
QUAD_VERTEX_COUNT
|
||||||
|
);
|
||||||
|
errorChain(meshFlush(&SPRITEBATCH.mesh, vertexOffset, vertexCount));
|
||||||
|
errorChain(meshDraw(&SPRITEBATCH.mesh, vertexOffset, vertexCount));
|
||||||
|
|
||||||
|
SPRITEBATCH.spriteFlush++;
|
||||||
|
if(SPRITEBATCH.spriteFlush >= SPRITEBATCH_FLUSH_COUNT) {
|
||||||
|
SPRITEBATCH.spriteFlush = 0;
|
||||||
|
}
|
||||||
|
SPRITEBATCH.spriteCount = 0;
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "display/mesh/quad.h"
|
#include "display/mesh/quad.h"
|
||||||
|
|
||||||
#define SPRITEBATCH_SPRITES_MAX 16
|
#define SPRITEBATCH_SPRITES_MAX 32
|
||||||
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)
|
#define SPRITEBATCH_VERTEX_COUNT (SPRITEBATCH_SPRITES_MAX * QUAD_VERTEX_COUNT)
|
||||||
|
#define SPRITEBATCH_FLUSH_COUNT 4
|
||||||
|
#define SPRITEBATCH_SPRITES_MAX_PER_FLUSH (\
|
||||||
|
SPRITEBATCH_SPRITES_MAX / SPRITEBATCH_FLUSH_COUNT \
|
||||||
|
)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mesh_t mesh;
|
mesh_t mesh;
|
||||||
int32_t spriteCount;
|
int32_t spriteCount;
|
||||||
|
int32_t spriteFlush;
|
||||||
} spritebatch_t;
|
} spritebatch_t;
|
||||||
|
|
||||||
// Have to define these seperately because of alignment in certain platforms.
|
// Have to define these seperately because of alignment in certain platforms.
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ errorret_t displayInitDolphin(void) {
|
|||||||
|
|
||||||
// Setup cull modes
|
// Setup cull modes
|
||||||
GX_SetCullMode(GX_CULL_NONE);
|
GX_SetCullMode(GX_CULL_NONE);
|
||||||
GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE);
|
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
|
||||||
|
GX_SetZMode(GX_TRUE, GX_ALWAYS, GX_FALSE);
|
||||||
GX_SetDispCopyGamma(GX_GM_1_0);
|
GX_SetDispCopyGamma(GX_GM_1_0);
|
||||||
GX_SetColorUpdate(GX_TRUE);
|
GX_SetColorUpdate(GX_TRUE);
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ errorret_t meshDrawDolphin(
|
|||||||
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride);
|
GX_SetArray(GX_VA_CLR0, (void*)&mesh->vertices[vertexOffset].color.r, stride);
|
||||||
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
|
GX_SetArray(GX_VA_TEX0, (void*)&mesh->vertices[vertexOffset].uv[0], stride);
|
||||||
|
|
||||||
|
GX_InvVtxCache();
|
||||||
|
|
||||||
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
|
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)vertexCount);
|
||||||
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
|
for(uint16_t i = 0; i < (uint16_t)vertexCount; ++i) {
|
||||||
GX_Position1x16(i);
|
GX_Position1x16(i);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ errorret_t shaderSetTextureDolphin(
|
|||||||
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
|
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
|
||||||
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
|
||||||
|
|
||||||
GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
|
// GX_SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
|
||||||
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
|
|||||||
@@ -113,8 +113,10 @@ errorret_t meshFlushGL(
|
|||||||
errorChain(errorGLCheck());
|
errorChain(errorGLCheck());
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
vertCount * sizeof(meshvertex_t),
|
mesh->vertexCount * sizeof(meshvertex_t),
|
||||||
&mesh->vertices[vertOffset],
|
mesh->vertices,
|
||||||
|
// vertCount * sizeof(meshvertex_t),
|
||||||
|
// &mesh->vertices[vertOffset],
|
||||||
GL_DYNAMIC_DRAW
|
GL_DYNAMIC_DRAW
|
||||||
);
|
);
|
||||||
errorChain(errorGLCheck());
|
errorChain(errorGLCheck());
|
||||||
|
|||||||
Reference in New Issue
Block a user