mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-11 16:45:48 -04:00
Eliminate usage of Gfx_UpdateDynamicVb_IndexedTris
This commit is contained in:
parent
60e5b4efa0
commit
a4fb5098ef
10
src/Entity.c
10
src/Entity.c
@ -245,7 +245,7 @@ static void MakeNameTexture(struct Entity* e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void DrawName(struct Entity* e) {
|
static void DrawName(struct Entity* e) {
|
||||||
struct VertexTextured vertices[4];
|
struct VertexTextured* vertices;
|
||||||
struct Model* model;
|
struct Model* model;
|
||||||
struct Matrix mat;
|
struct Matrix mat;
|
||||||
Vec3 pos;
|
Vec3 pos;
|
||||||
@ -270,9 +270,13 @@ static void DrawName(struct Entity* e) {
|
|||||||
size.X *= scale * 0.2f; size.Y *= scale * 0.2f;
|
size.X *= scale * 0.2f; size.Y *= scale * 0.2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Particle_DoRender(&size, &pos, &e->NameTex.uv, PACKEDCOL_WHITE, vertices);
|
|
||||||
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(Gfx_texVb, vertices, 4);
|
|
||||||
|
vertices = (struct VertexTextured*)Gfx_LockDynamicVb(Gfx_texVb, VERTEX_FORMAT_TEXTURED, 4);
|
||||||
|
Particle_DoRender(&size, &pos, &e->NameTex.uv, PACKEDCOL_WHITE, vertices);
|
||||||
|
Gfx_UnlockDynamicVb(Gfx_texVb);
|
||||||
|
|
||||||
|
Gfx_DrawVb_IndexedTris(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deletes the texture containing the entity's nametag */
|
/* Deletes the texture containing the entity's nametag */
|
||||||
|
@ -198,7 +198,8 @@ static void EntityShadow_Draw(struct Entity* e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
count = (int)(ptr - vertices);
|
count = (int)(ptr - vertices);
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(vb, vertices, count);
|
Gfx_SetDynamicVbData(vb, vertices, count);
|
||||||
|
Gfx_DrawVb_IndexedTris(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -347,7 +347,8 @@ static double weather_accumulator;
|
|||||||
static IVec3 lastPos;
|
static IVec3 lastPos;
|
||||||
|
|
||||||
#define WEATHER_EXTENT 4
|
#define WEATHER_EXTENT 4
|
||||||
#define WEATHER_VERTS_COUNT 8 * (WEATHER_EXTENT * 2 + 1) * (WEATHER_EXTENT * 2 + 1)
|
#define WEATHER_RANGE (WEATHER_EXTENT * 2 + 1)
|
||||||
|
#define WEATHER_VERTS_COUNT 8 * WEATHER_RANGE * WEATHER_RANGE
|
||||||
#define Weather_Pack(x, z) ((x) * World.Length + (z))
|
#define Weather_Pack(x, z) ((x) * World.Length + (z))
|
||||||
|
|
||||||
static void InitWeatherHeightmap(void) {
|
static void InitWeatherHeightmap(void) {
|
||||||
@ -431,6 +432,7 @@ static float CalcRainAlphaAt(float x) {
|
|||||||
static RNGState snowDirRng;
|
static RNGState snowDirRng;
|
||||||
void EnvRenderer_RenderWeather(double deltaTime) {
|
void EnvRenderer_RenderWeather(double deltaTime) {
|
||||||
struct VertexTextured vertices[WEATHER_VERTS_COUNT];
|
struct VertexTextured vertices[WEATHER_VERTS_COUNT];
|
||||||
|
IVec3 coords[WEATHER_RANGE * WEATHER_RANGE];
|
||||||
struct VertexTextured* v;
|
struct VertexTextured* v;
|
||||||
int weather, vCount;
|
int weather, vCount;
|
||||||
IVec3 pos;
|
IVec3 pos;
|
||||||
@ -456,12 +458,12 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
/* Rain should extend up by 64 blocks, or to the top of the world. */
|
/* Rain should extend up by 64 blocks, or to the top of the world. */
|
||||||
pos.Y += 64;
|
pos.Y += 64;
|
||||||
pos.Y = max(World.Height, pos.Y);
|
pos.Y = max(World.Height, pos.Y);
|
||||||
|
weather_accumulator += deltaTime;
|
||||||
|
|
||||||
speed = (weather == WEATHER_RAINY ? 1.0f : 0.2f) * Env.WeatherSpeed;
|
speed = (weather == WEATHER_RAINY ? 1.0f : 0.2f) * Env.WeatherSpeed;
|
||||||
vOffsetBase = (float)Game.Time * speed;
|
vOffsetBase = (float)Game.Time * speed;
|
||||||
vPlane1Offset = weather == WEATHER_RAINY ? 0 : 0.25f; /* Offset v on 1 plane while snowing to avoid the unnatural mirrored texture effect */
|
vPlane1Offset = weather == WEATHER_RAINY ? 0 : 0.25f; /* Offset v on 1 plane while snowing to avoid the unnatural mirrored texture effect */
|
||||||
particles = weather == WEATHER_RAINY;
|
particles = weather == WEATHER_RAINY && (weather_accumulator >= 0.25 || moved);
|
||||||
weather_accumulator += deltaTime;
|
|
||||||
|
|
||||||
v = vertices;
|
v = vertices;
|
||||||
col = Env.SunCol;
|
col = Env.SunCol;
|
||||||
@ -471,12 +473,10 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
x = pos.X + dx; z = pos.Z + dz;
|
x = pos.X + dx; z = pos.Z + dz;
|
||||||
|
|
||||||
y = GetRainHeight(x, z);
|
y = GetRainHeight(x, z);
|
||||||
|
if (pos.Y <= y) continue;
|
||||||
height = pos.Y - y;
|
height = pos.Y - y;
|
||||||
if (height <= 0) continue;
|
|
||||||
|
|
||||||
if (particles && (weather_accumulator >= 0.25 || moved)) {
|
if (particles) Particles_RainSnowEffect((float)x, y, (float)z);
|
||||||
Particles_RainSnowEffect((float)x, y, (float)z);
|
|
||||||
}
|
|
||||||
|
|
||||||
dist = dx * dx + dz * dz;
|
dist = dx * dx + dz * dz;
|
||||||
alpha = CalcRainAlphaAt((float)dist);
|
alpha = CalcRainAlphaAt((float)dist);
|
||||||
@ -514,9 +514,7 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (particles && (weather_accumulator >= 0.25f || moved)) {
|
if (particles) weather_accumulator = 0;
|
||||||
weather_accumulator = 0;
|
|
||||||
}
|
|
||||||
if (v == vertices) return;
|
if (v == vertices) return;
|
||||||
|
|
||||||
Gfx_SetAlphaTest(false);
|
Gfx_SetAlphaTest(false);
|
||||||
@ -525,7 +523,8 @@ void EnvRenderer_RenderWeather(double deltaTime) {
|
|||||||
|
|
||||||
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
||||||
vCount = (int)(v - vertices);
|
vCount = (int)(v - vertices);
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(weather_vb, vertices, vCount);
|
Gfx_SetDynamicVbData(weather_vb, vertices, vCount);
|
||||||
|
Gfx_DrawVb_IndexedTris(vCount);
|
||||||
|
|
||||||
Gfx_SetAlphaArgBlend(false);
|
Gfx_SetAlphaArgBlend(false);
|
||||||
Gfx_SetDepthWrite(true);
|
Gfx_SetDepthWrite(true);
|
||||||
|
@ -232,10 +232,6 @@ void Gfx_RecreateContext(void);
|
|||||||
/* Attempts to restore a lost context */
|
/* Attempts to restore a lost context */
|
||||||
cc_bool Gfx_TryRestoreContext(void);
|
cc_bool Gfx_TryRestoreContext(void);
|
||||||
|
|
||||||
/* Binds and draws the specified subset of the vertices in the current dynamic vertex buffer */
|
|
||||||
/* NOTE: This replaces the dynamic vertex buffer's data first with the given vertices before drawing */
|
|
||||||
void Gfx_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCount);
|
|
||||||
|
|
||||||
/* Renders a 2D flat coloured rectangle */
|
/* Renders a 2D flat coloured rectangle */
|
||||||
void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color);
|
void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color);
|
||||||
/* Renders a 2D flat vertical gradient rectangle */
|
/* Renders a 2D flat vertical gradient rectangle */
|
||||||
|
@ -144,7 +144,9 @@ void Model_SetupState(struct Model* model, struct Entity* e) {
|
|||||||
|
|
||||||
void Model_UpdateVB(void) {
|
void Model_UpdateVB(void) {
|
||||||
struct Model* model = Models.Active;
|
struct Model* model = Models.Active;
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(Models.Vb, Models.Vertices, model->index);
|
|
||||||
|
Gfx_SetDynamicVbData(Models.Vb, Models.Vertices, model->index);
|
||||||
|
Gfx_DrawVb_IndexedTris(model->index);
|
||||||
model->index = 0;
|
model->index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ static int RunProgram(int argc, char** argv) {
|
|||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||||
//cc_string rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565");
|
//cc_string rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565");
|
||||||
//cc_string rawArgs = String_FromConst("UnknownShadow200");
|
cc_string rawArgs = String_FromConst("UnknownShadow200");
|
||||||
//argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
|
argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argsCount == 0) {
|
if (argsCount == 0) {
|
||||||
|
@ -142,44 +142,47 @@ void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count) {
|
|||||||
return Gfx_LockVb(*vb, fmt, count);
|
return Gfx_LockVb(*vb, fmt, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCount) {
|
|
||||||
Gfx_SetDynamicVbData(vb, vertices, vCount);
|
|
||||||
Gfx_DrawVb_IndexedTris(vCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef CC_BUILD_3DS
|
#ifndef CC_BUILD_3DS
|
||||||
void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color) {
|
void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color) {
|
||||||
struct VertexColoured verts[4];
|
struct VertexColoured* v;
|
||||||
struct VertexColoured* v = verts;
|
|
||||||
|
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
|
||||||
|
v = (struct VertexColoured*)Gfx_LockDynamicVb(Gfx_quadVb, VERTEX_FORMAT_COLOURED, 4);
|
||||||
|
|
||||||
v->X = (float)x; v->Y = (float)y; v->Z = 0; v->Col = color; v++;
|
v->X = (float)x; v->Y = (float)y; v->Z = 0; v->Col = color; v++;
|
||||||
v->X = (float)(x + width); v->Y = (float)y; v->Z = 0; v->Col = color; v++;
|
v->X = (float)(x + width); v->Y = (float)y; v->Z = 0; v->Col = color; v++;
|
||||||
v->X = (float)(x + width); v->Y = (float)(y + height); v->Z = 0; v->Col = color; v++;
|
v->X = (float)(x + width); v->Y = (float)(y + height); v->Z = 0; v->Col = color; v++;
|
||||||
v->X = (float)x; v->Y = (float)(y + height); v->Z = 0; v->Col = color; v++;
|
v->X = (float)x; v->Y = (float)(y + height); v->Z = 0; v->Col = color; v++;
|
||||||
|
|
||||||
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
|
Gfx_UnlockDynamicVb(Gfx_quadVb);
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4);
|
Gfx_DrawVb_IndexedTris(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom) {
|
void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom) {
|
||||||
struct VertexColoured verts[4];
|
struct VertexColoured* v;
|
||||||
struct VertexColoured* v = verts;
|
|
||||||
|
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
|
||||||
|
v = (struct VertexColoured*)Gfx_LockDynamicVb(Gfx_quadVb, VERTEX_FORMAT_COLOURED, 4);
|
||||||
|
|
||||||
v->X = (float)x; v->Y = (float)y; v->Z = 0; v->Col = top; 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; 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 + 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++;
|
v->X = (float)x; v->Y = (float)(y + height); v->Z = 0; v->Col = bottom; v++;
|
||||||
|
|
||||||
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
|
Gfx_UnlockDynamicVb(Gfx_quadVb);
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4);
|
Gfx_DrawVb_IndexedTris(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol color) {
|
void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol color) {
|
||||||
struct VertexTextured texVerts[4];
|
struct VertexTextured* ptr;
|
||||||
struct VertexTextured* ptr = texVerts;
|
|
||||||
Gfx_Make2DQuad(tex, color, &ptr);
|
|
||||||
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED);
|
||||||
Gfx_UpdateDynamicVb_IndexedTris(Gfx_texVb, texVerts, 4);
|
ptr = (struct VertexTextured*)Gfx_LockDynamicVb(Gfx_texVb, VERTEX_FORMAT_TEXTURED, 4);
|
||||||
|
|
||||||
|
Gfx_Make2DQuad(tex, color, &ptr);
|
||||||
|
|
||||||
|
Gfx_UnlockDynamicVb(Gfx_texVb);
|
||||||
|
Gfx_DrawVb_IndexedTris(4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user