diff --git a/src/Entity.c b/src/Entity.c index 118d5118a..136576601 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -245,7 +245,7 @@ static void MakeNameTexture(struct Entity* e) { } static void DrawName(struct Entity* e) { - struct VertexTextured vertices[4]; + struct VertexTextured* vertices; struct Model* model; struct Matrix mat; Vec3 pos; @@ -270,9 +270,13 @@ static void DrawName(struct Entity* e) { 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_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 */ diff --git a/src/EntityRenderers.c b/src/EntityRenderers.c index f0d2ff80b..8f027b4a6 100644 --- a/src/EntityRenderers.c +++ b/src/EntityRenderers.c @@ -198,7 +198,8 @@ static void EntityShadow_Draw(struct Entity* e) { } count = (int)(ptr - vertices); - Gfx_UpdateDynamicVb_IndexedTris(vb, vertices, count); + Gfx_SetDynamicVbData(vb, vertices, count); + Gfx_DrawVb_IndexedTris(count); } diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index 8261cf78a..2eee2e714 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -347,7 +347,8 @@ static double weather_accumulator; static IVec3 lastPos; #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)) static void InitWeatherHeightmap(void) { @@ -431,6 +432,7 @@ static float CalcRainAlphaAt(float x) { static RNGState snowDirRng; void EnvRenderer_RenderWeather(double deltaTime) { struct VertexTextured vertices[WEATHER_VERTS_COUNT]; + IVec3 coords[WEATHER_RANGE * WEATHER_RANGE]; struct VertexTextured* v; int weather, vCount; 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. */ pos.Y += 64; pos.Y = max(World.Height, pos.Y); + weather_accumulator += deltaTime; speed = (weather == WEATHER_RAINY ? 1.0f : 0.2f) * Env.WeatherSpeed; 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 */ - particles = weather == WEATHER_RAINY; - weather_accumulator += deltaTime; + particles = weather == WEATHER_RAINY && (weather_accumulator >= 0.25 || moved); v = vertices; col = Env.SunCol; @@ -471,12 +473,10 @@ void EnvRenderer_RenderWeather(double deltaTime) { x = pos.X + dx; z = pos.Z + dz; y = GetRainHeight(x, z); + if (pos.Y <= y) continue; height = pos.Y - y; - if (height <= 0) continue; - if (particles && (weather_accumulator >= 0.25 || moved)) { - Particles_RainSnowEffect((float)x, y, (float)z); - } + if (particles) Particles_RainSnowEffect((float)x, y, (float)z); dist = dx * dx + dz * dz; alpha = CalcRainAlphaAt((float)dist); @@ -514,9 +514,7 @@ void EnvRenderer_RenderWeather(double deltaTime) { } } - if (particles && (weather_accumulator >= 0.25f || moved)) { - weather_accumulator = 0; - } + if (particles) weather_accumulator = 0; if (v == vertices) return; Gfx_SetAlphaTest(false); @@ -525,7 +523,8 @@ void EnvRenderer_RenderWeather(double deltaTime) { Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED); 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_SetDepthWrite(true); diff --git a/src/Graphics.h b/src/Graphics.h index a5fa3e606..277a3ffb6 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -232,10 +232,6 @@ void Gfx_RecreateContext(void); /* Attempts to restore a lost context */ 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 */ void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color); /* Renders a 2D flat vertical gradient rectangle */ diff --git a/src/Model.c b/src/Model.c index dfcb9decb..d63b6c0d5 100644 --- a/src/Model.c +++ b/src/Model.c @@ -144,7 +144,9 @@ void Model_SetupState(struct Model* model, struct Entity* e) { void Model_UpdateVB(void) { 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; } diff --git a/src/Program.c b/src/Program.c index 988e33007..addcea54f 100644 --- a/src/Program.c +++ b/src/Program.c @@ -77,8 +77,8 @@ static int RunProgram(int argc, char** argv) { #ifdef _MSC_VER /* 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"); - //argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); + cc_string rawArgs = String_FromConst("UnknownShadow200"); + argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); #endif if (argsCount == 0) { diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index 0da828c53..8561a34ff 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -142,44 +142,47 @@ void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int 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 void Gfx_Draw2DFlat(int x, int y, int width, int height, PackedCol color) { - struct VertexColoured verts[4]; - struct VertexColoured* v = verts; + struct VertexColoured* v; + + 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 + 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; v->Y = (float)(y + height); v->Z = 0; v->Col = color; v++; - Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED); - Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4); + Gfx_UnlockDynamicVb(Gfx_quadVb); + Gfx_DrawVb_IndexedTris(4); } void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom) { - struct VertexColoured verts[4]; - struct VertexColoured* v = verts; + struct VertexColoured* v; + + 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 + 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_COLOURED); - Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4); + Gfx_UnlockDynamicVb(Gfx_quadVb); + Gfx_DrawVb_IndexedTris(4); } void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol color) { - struct VertexTextured texVerts[4]; - struct VertexTextured* ptr = texVerts; - Gfx_Make2DQuad(tex, color, &ptr); + struct VertexTextured* ptr; + 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