Back to floats.

This commit is contained in:
2025-10-10 09:16:08 -05:00
parent c4c43b23ad
commit 349e6e7c94
16 changed files with 164 additions and 220 deletions

View File

@@ -76,4 +76,53 @@ void quadBuffer(
{ u0, v1 }, // UV
{ minX, maxY, z } // Position
};
}
void quadBuffer3D(
meshvertex_t *vertices,
const vec3 min,
const vec3 max,
const color_t color,
const vec2 uvMin,
const vec2 uvMax
) {
assertNotNull(vertices, "Vertices cannot be NULL");
assertNotNull(min, "Min vector cannot be NULL");
assertNotNull(max, "Max vector cannot be NULL");
assertNotNull(uvMin, "UV Min vector cannot be NULL");
assertNotNull(uvMax, "UV Max vector cannot be NULL");
// First triangle
vertices[0] = (meshvertex_t) {
{ color.r, color.g, color.b, color.a }, // Color
{ uvMin[0], uvMin[1] }, // UV
{ min[0], min[1], min[2] } // Position
};
vertices[1] = (meshvertex_t) {
{ color.r, color.g, color.b, color.a }, // Color
{ uvMax[0], uvMin[1] }, // UV
{ max[0], min[1], min[2] } // Position
};
vertices[2] = (meshvertex_t) {
{ color.r, color.g, color.b, color.a }, // Color
{ uvMax[0], uvMax[1] }, // UV
{ max[0], max[1], min[2] } // Position
};
// Second triangle
vertices[3] = (meshvertex_t) {
{ color.r, color.g, color.b, color.a }, // Color
{ uvMin[0], uvMin[1] }, // UV
{ min[0], min[1], min[2] } // Position
};
vertices[4] = (meshvertex_t) {
{ color.r, color.g, color.b, color.a }, // Color
{ uvMax[0], uvMax[1] }, // UV
{ max[0], max[1], min[2] } // Position
};
vertices[5] = (meshvertex_t) {
{ color.r, color.g, color.b, color.a }, // Color
{ uvMin[0], uvMax[1] }, // UV
{ min[0], max[1], min[2] } // Position
};
}

View File

@@ -45,4 +45,23 @@ void quadBuffer(
const float_t v0,
const float_t u1,
const float_t v1
);
/**
* Buffers a 3D quad into the provided vertex array.
*
* @param vertices The vertex array to buffer into.
* @param min The minimum XYZ coordinates of the quad.
* @param max The maximum XYZ coordinates of the quad.
* @param color The color of the quad.
* @param uvMin The minimum UV coordinates of the quad.
* @param uvMax The maximum UV coordinates of the quad.
*/
void quadBuffer3D(
meshvertex_t *vertices,
const vec3 min,
const vec3 max,
const color_t color,
const vec2 uvMin,
const vec2 uvMax
);

View File

@@ -55,6 +55,31 @@ void spriteBatchPush(
SPRITEBATCH.spriteCount++;
}
void spriteBatchPush3D(
texture_t *texture,
const vec3 min,
const vec3 max,
const color_t color,
const vec2 uv0,
const vec2 uv1
) {
// Need to flush?
if(
SPRITEBATCH.currentTexture != texture ||
SPRITEBATCH.spriteCount >= SPRITEBATCH_SPRITES_MAX
) {
spriteBatchFlush();
SPRITEBATCH.currentTexture = texture;
}
quadBuffer3D(
&SPRITEBATCH.vertices[SPRITEBATCH.spriteCount * QUAD_VERTEX_COUNT],
min, max, color, uv0, uv1
);
SPRITEBATCH.spriteCount++;
}
void spriteBatchClear() {
SPRITEBATCH.spriteCount = 0;
SPRITEBATCH.currentTexture = NULL;

View File

@@ -61,6 +61,26 @@ void spriteBatchPush(
const float_t v1
);
/**
* Pushes a 3D sprite to the batch. This is like spriteBatchPush but takes
* 3D coordinates instead of 2D.
*
* @param texture The texture to use for the sprite.
* @param min The minimum (x,y,z) coordinate of the sprite.
* @param max The maximum (x,y,z) coordinate of the sprite.
* @param color The color to tint the sprite with.
* @param uvMin The texture coordinate for the top-left corner of the sprite.
* @param uvMax The texture coordinate for the bottom-right corner of the sprite.
*/
void spriteBatchPush3D(
texture_t *texture,
const vec3 min,
const vec3 max,
const color_t color,
const vec2 uvMin,
const vec2 uvMax
);
/**
* Clears the sprite batch. This will mean calling flush renders nothing.
*/