minorly optimise particle/name vertex drawing

This commit is contained in:
UnknownShadow200 2019-08-06 18:38:08 +10:00
parent 91434616ae
commit 78d34c6da9
6 changed files with 58 additions and 68 deletions

View File

@ -27,7 +27,7 @@ void AxisLinesRenderer_Render(double delta) {
Vec3 coords[5], pos;
VertexP3fC4b vertices[AXISLINES_NUM_VERTICES];
VertexP3fC4b* ptr = vertices;
VertexP3fC4b* v = vertices;
int i, count;
if (!AxisLinesRenderer_Enabled || Gfx.LostContext) return;
@ -46,11 +46,11 @@ void AxisLinesRenderer_Render(double delta) {
Vec3_Add1(&coords[3], &pos, AXISLINES_THICKNESS);
Vec3_Add1(&coords[4], &pos, AXISLINES_LENGTH);
for (i = 0; i < count; i++, ptr++) {
ptr->X = coords[indices[i*3 + 0]].X;
ptr->Y = coords[indices[i*3 + 1]].Y;
ptr->Z = coords[indices[i*3 + 2]].Z;
ptr->Col = cols[i >> 2];
for (i = 0; i < count; i++, v++) {
v->X = coords[indices[i*3 + 0]].X;
v->Y = coords[indices[i*3 + 1]].Y;
v->Z = coords[indices[i*3 + 2]].Z;
v->Col = cols[i >> 2];
}
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);

View File

@ -458,7 +458,7 @@ struct ShadowData { float Y; BlockID Block; uint8_t A; };
static bool lequal(float a, float b) { return a < b || Math_AbsF(a - b) < 0.001f; }
static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity* e, struct ShadowData* data, float x1, float z1, float x2, float z2) {
PackedCol col = PACKEDCOL_CONST(255, 255, 255, 0);
VertexP3fT2fC4b* ptr, v;
VertexP3fT2fC4b* v;
Vec3 cen;
float u1, v1, u2, v2;
@ -476,29 +476,28 @@ static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity
x2 = min(x2, cen.X + shadow_radius); u2 = u2 <= 1.0f ? u2 : 1.0f;
z2 = min(z2, cen.Z + shadow_radius); v2 = v2 <= 1.0f ? v2 : 1.0f;
ptr = *vertices;
v.Y = data->Y; v.Col = col; v.Col.A = data->A;
v = *vertices;
col.A = data->A;
v.X = x1; v.Z = z1; v.U = u1; v.V = v1; *ptr++ = v;
v.X = x2; v.U = u2; *ptr++ = v;
v.Z = z2; v.V = v2; *ptr++ = v;
v.X = x1; v.U = u1; *ptr++ = v;
v->X = x1; v->Y = data->Y; v->Z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
v->X = x2; v->Y = data->Y; v->Z = z1; v->Col = col; v->U = u2; v->V = v1; v++;
v->X = x2; v->Y = data->Y; v->Z = z2; v->Col = col; v->U = u2; v->V = v2; v++;
v->X = x1; v->Y = data->Y; v->Z = z2; v->Col = col; v->U = u1; v->V = v2; v++;
*vertices = ptr;
*vertices = v;
}
static void ShadowComponent_DrawSquareShadow(VertexP3fT2fC4b** vertices, float y, float x, float z) {
PackedCol col = PACKEDCOL_CONST(255, 255, 255, 220);
float uv1 = 63/128.0f, uv2 = 64/128.0f;
VertexP3fT2fC4b* ptr = *vertices;
VertexP3fT2fC4b v; v.Y = y; v.Col = col;
VertexP3fT2fC4b* v = *vertices;
v.X = x; v.Z = z; v.U = uv1; v.V = uv1; *ptr = v; ptr++;
v.X = x + 1.0f; v.U = uv2; *ptr = v; ptr++;
v.Z = z + 1.0f; v.V = uv2; *ptr = v; ptr++;
v.X = x; v.U = uv1; *ptr = v; ptr++;
v->X = x; v->Y = y; v->Z = z; v->Col = col; v->U = uv1; v->V = uv1; v++;
v->X = x + 1; v->Y = y; v->Z = z; v->Col = col; v->U = uv2; v->V = uv1; v++;
v->X = x + 1; v->Y = y; v->Z = z + 1; v->Col = col; v->U = uv2; v->V = uv2; v++;
v->X = x; v->Y = y; v->Z = z + 1; v->Col = col; v->U = uv1; v->V = uv2; v++;
*vertices = ptr;
*vertices = v;
}
/* Shadow may extend down multiple blocks vertically */

View File

@ -664,7 +664,7 @@ static void EnvRenderer_DrawBorderY(int x1, int z1, int x2, int z2, float y, Pac
z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ;
u2 = (float)x2 - (float)x1; v2 = (float)z2 - (float)z1;
u2 = (float)x2 - (float)x1; v2 = (float)z2 - (float)z1;
v->X = (float)x1 + offset; v->Y = yy; v->Z = (float)z1 + offset; v->Col = col; v->U = 0; v->V = 0; v++;
v->X = (float)x1 + offset; v->Y = yy; v->Z = (float)z2 + offset; v->Col = col; v->U = 0; v->V = v2; v++;
v->X = (float)x2 + offset; v->Y = yy; v->Z = (float)z2 + offset; v->Col = col; v->U = u2; v->V = v2; v++;

View File

@ -93,12 +93,12 @@ void Gfx_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCoun
void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol col) {
VertexP3fC4b verts[4];
VertexP3fC4b v; v.Z = 0.0f; v.Col = col;
VertexP3fC4b* v = verts;
v.X = (float)x; v.Y = (float)y; verts[0] = v;
v.X = (float)(x + width); verts[1] = v;
v.Y = (float)(y + height); verts[2] = v;
v.X = (float)x; verts[3] = v;
v->X = (float)x; v->Y = (float)y; v->Z = 0; v->Col = col; v++;
v->X = (float)(x + width); v->Y = (float)y; v->Z = 0; v->Col = col; v++;
v->X = (float)(x + width); v->Y = (float)(y + height); v->Z = 0; v->Col = col; v++;
v->X = (float)x; v->Y = (float)(y + height); v->Z = 0; v->Col = col; v++;
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4);
@ -106,12 +106,12 @@ void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol col) {
void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom) {
VertexP3fC4b verts[4];
VertexP3fC4b v; v.Z = 0.0f;
VertexP3fC4b* v = verts;
v.X = (float)x; v.Y = (float)y; v.Col = top; verts[0] = v;
v.X = (float)(x + width); verts[1] = v;
v.Y = (float)(y + height); v.Col = bottom; verts[2] = v;
v.X = (float)x; verts[3] = v;
v->X = (float)x; v->Y = (float)y; v->Z = 0; v->Col = top; v++;
v->X = (float)(x + width); v->Y = (float)y; v->Z = 0; v->Col = top; v++;
v->X = (float)(x + width); v->Y = (float)(y + height); v->Z = 0; v->Col = bottom; v++;
v->X = (float)x; v->Y = (float)(y + height); v->Z = 0; v->Col = bottom; v++;
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4);
@ -128,6 +128,8 @@ void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol col) {
void Gfx_Make2DQuad(const struct Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices) {
float x1 = (float)tex->X, x2 = (float)(tex->X + tex->Width);
float y1 = (float)tex->Y, y2 = (float)(tex->Y + tex->Height);
VertexP3fT2fC4b* v = *vertices;
#ifdef CC_BUILD_D3D9
/* NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx", */
/* i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this. */
@ -135,13 +137,11 @@ void Gfx_Make2DQuad(const struct Texture* tex, PackedCol col, VertexP3fT2fC4b**
y1 -= 0.5f; y2 -= 0.5f;
#endif
VertexP3fT2fC4b* ptr = *vertices;
VertexP3fT2fC4b v; v.Z = 0.0f; v.Col = col;
v.X = x1; v.Y = y1; v.U = tex->uv.U1; v.V = tex->uv.V1; ptr[0] = v;
v.X = x2; v.U = tex->uv.U2; ptr[1] = v;
v.Y = y2; v.V = tex->uv.V2; ptr[2] = v;
v.X = x1; v.U = tex->uv.U1; ptr[3] = v;
*vertices += 4;
v->X = x1; v->Y = y1; v->Z = 0; v->Col = col; v->U = tex->uv.U1; v->V = tex->uv.V1; v++;
v->X = x2; v->Y = y1; v->Z = 0; v->Col = col; v->U = tex->uv.U2; v->V = tex->uv.V1; v++;
v->X = x2; v->Y = y2; v->Z = 0; v->Col = col; v->U = tex->uv.U2; v->V = tex->uv.V2; v++;
v->X = x1; v->Y = y2; v->Z = 0; v->Col = col; v->U = tex->uv.U1; v->V = tex->uv.V2; v++;
*vertices = v;
}
static bool gfx_hadFog;

View File

@ -20,9 +20,8 @@ static GfxResourceID Particles_TexId, Particles_VB;
static RNGState rnd;
static bool particle_hitTerrain;
void Particle_DoRender(Vec2* size, Vec3* pos, TextureRec* rec, PackedCol col, VertexP3fT2fC4b* vertices) {
void Particle_DoRender(Vec2* size, Vec3* pos, TextureRec* rec, PackedCol col, VertexP3fT2fC4b* v) {
struct Matrix* view;
VertexP3fT2fC4b v;
float sX, sY;
Vec3 centre;
float aX, aY, aZ, bX, bY, bZ;
@ -33,19 +32,11 @@ void Particle_DoRender(Vec2* size, Vec3* pos, TextureRec* rec, PackedCol col, Ve
aX = view->Row0.X * sX; aY = view->Row1.X * sX; aZ = view->Row2.X * sX; /* right * size.X * 0.5f */
bX = view->Row0.Y * sY; bY = view->Row1.Y * sY; bZ = view->Row2.Y * sY; /* up * size.Y * 0.5f */
v.Col = col;
v.X = centre.X - aX - bX; v.Y = centre.Y - aY - bY; v.Z = centre.Z - aZ - bZ;
v.U = rec->U1; v.V = rec->V2; vertices[0] = v;
v.X = centre.X - aX + bX; v.Y = centre.Y - aY + bY; v.Z = centre.Z - aZ + bZ;
v.V = rec->V1; vertices[1] = v;
v.X = centre.X + aX + bX; v.Y = centre.Y + aY + bY; v.Z = centre.Z + aZ + bZ;
v.U = rec->U2; vertices[2] = v;
v.X = centre.X + aX - bX; v.Y = centre.Y + aY - bY; v.Z = centre.Z + aZ - bZ;
v.V = rec->V2; vertices[3] = v;
v->X = centre.X - aX - bX; v->Y = centre.Y - aY - bY; v->Z = centre.Z - aZ - bZ; v->Col = col; v->U = rec->U1; v->V = rec->V2; v++;
v->X = centre.X - aX + bX; v->Y = centre.Y - aY + bY; v->Z = centre.Z - aZ + bZ; v->Col = col; v->U = rec->U1; v->V = rec->V1; v++;
v->X = centre.X + aX + bX; v->Y = centre.Y + aY + bY; v->Z = centre.Z + aZ + bZ; v->Col = col; v->U = rec->U2; v->V = rec->V1; v++;
v->X = centre.X + aX - bX; v->Y = centre.Y + aY - bY; v->Z = centre.Z + aZ - bZ; v->Col = col; v->U = rec->U2; v->V = rec->V2; v++;
}
static void Particle_Reset(struct Particle* p, Vec3 pos, Vec3 velocity, float lifetime) {

View File

@ -29,7 +29,7 @@ static void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** faceVer
0,0,0, 0,1,0, 1,0,0, 1,1,0, 1,0,1, 1,1,1, 0,0,1, 0,1,1, /* X/Z */
};
VertexP3fC4b* ptr;
VertexP3fC4b* v;
PackedCol col;
int i;
@ -39,24 +39,24 @@ static void SelectionBox_Render(struct SelectionBox* box, VertexP3fC4b** faceVer
Vec3_Add1(&coords[1], &box->Max, offset);
col = box->Col;
ptr = *faceVertices;
for (i = 0; i < Array_Elems(faceIndices); i += 3, ptr++) {
ptr->X = coords[faceIndices[i + 0]].X;
ptr->Y = coords[faceIndices[i + 1]].Y;
ptr->Z = coords[faceIndices[i + 2]].Z;
ptr->Col = col;
v = *faceVertices;
for (i = 0; i < Array_Elems(faceIndices); i += 3, v++) {
v->X = coords[faceIndices[i + 0]].X;
v->Y = coords[faceIndices[i + 1]].Y;
v->Z = coords[faceIndices[i + 2]].Z;
v->Col = col;
}
*faceVertices = ptr;
*faceVertices = v;
col.R = ~col.R; col.G = ~col.G; col.B = ~col.B;
ptr = *edgeVertices;
for (i = 0; i < Array_Elems(edgeIndices); i += 3, ptr++) {
ptr->X = coords[edgeIndices[i + 0]].X;
ptr->Y = coords[edgeIndices[i + 1]].Y;
ptr->Z = coords[edgeIndices[i + 2]].Z;
ptr->Col = col;
v = *edgeVertices;
for (i = 0; i < Array_Elems(edgeIndices); i += 3, v++) {
v->X = coords[edgeIndices[i + 0]].X;
v->Y = coords[edgeIndices[i + 1]].Y;
v->Z = coords[edgeIndices[i + 2]].Z;
v->Col = col;
}
*edgeVertices = ptr;
*edgeVertices = v;
}
static int SelectionBox_Compare(struct SelectionBox* a, struct SelectionBox* b) {