Skip to content

Commit

Permalink
expose Gfx to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Feb 10, 2019
1 parent 3e2ec57 commit abb2a7f
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/AxisLinesRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void AxisLinesRenderer_Render(double delta) {
VertexP3fC4b* ptr = vertices;
int i, count;

if (!Game_ShowAxisLines || Gfx_LostContext) return;
if (!Game_ShowAxisLines || Gfx.LostContext) return;
/* Don't do it in a ContextRecreated handler, because we only want VB recreated if ShowAxisLines in on. */
if (!axisLines_vb) {
axisLines_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, AXISLINES_NUM_VERTICES);
Expand Down
2 changes: 1 addition & 1 deletion src/Camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static bool cam_isForwardThird;
static void PerspectiveCamera_GetProjection(struct Matrix* proj) {
float fovy = Game_Fov * MATH_DEG2RAD;
float aspectRatio = (float)Game.Width / (float)Game.Height;
Matrix_PerspectiveFieldOfView(proj, fovy, aspectRatio, Gfx_MinZNear, (float)Game_ViewDistance);
Matrix_PerspectiveFieldOfView(proj, fovy, aspectRatio, Gfx.MinZNear, (float)Game_ViewDistance);
}

static void PerspectiveCamera_GetView(struct Matrix* mat) {
Expand Down
6 changes: 3 additions & 3 deletions src/Entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void Player_UpdateNameTex(struct Player* player) {
struct Entity* e = &player->Base;
e->VTABLE->ContextLost(e);

if (Gfx_LostContext) return;
if (Gfx.LostContext) return;
Player_MakeNameTexture(player);
}

Expand All @@ -544,7 +544,7 @@ static void Player_DrawName(struct Player* p) {
size.X = p->NameTex.Width * scale; size.Y = p->NameTex.Height * scale;

if (Entities.NamesMode == NAME_MODE_ALL_UNSCALED && LocalPlayer_Instance.Hacks.CanSeeAllNames) {
Matrix_Mul(&mat, &Gfx_View, &Gfx_Projection); /* TODO: This mul is slow, avoid it */
Matrix_Mul(&mat, &Gfx.View, &Gfx.Projection); /* TODO: This mul is slow, avoid it */
/* Get W component of transformed position */
scale = pos.X * mat.Row0.W + pos.Y * mat.Row1.W + pos.Z * mat.Row2.W + mat.Row3.W;
size.X *= scale * 0.2f; size.Y *= scale * 0.2f;
Expand Down Expand Up @@ -730,7 +730,7 @@ static void Player_CheckSkin(struct Player* p) {
Player_EnsurePow2(p, &bmp);
e->SkinType = Utils_GetSkinType(&bmp);

if (bmp.Width > Gfx_MaxTexWidth || bmp.Height > Gfx_MaxTexHeight) {
if (bmp.Width > Gfx.MaxTexWidth || bmp.Height > Gfx.MaxTexHeight) {
Chat_Add1("&cSkin %s is too large", &skin);
} else if (e->SkinType != SKIN_INVALID) {
if (e->Model->UsesHumanSkin) Player_ClearHat(&bmp, e->SkinType);
Expand Down
20 changes: 10 additions & 10 deletions src/EnvRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void EnvRenderer_UpdateClouds(void) {
int extent;
int x1, z1, x2, z2;

if (!World.Blocks || Gfx_LostContext) return;
if (!World.Blocks || Gfx.LostContext) return;
Gfx_DeleteVb(&clouds_vb);
if (EnvRenderer_Minimal) return;

Expand Down Expand Up @@ -223,15 +223,15 @@ void EnvRenderer_RenderSky(double deltaTime) {
if (skyY == normY) {
Gfx_DrawVb_IndexedTris(sky_vertices);
} else {
m = Gfx_View;
m = Gfx.View;
dy = skyY - normY;
/* inlined Y translation matrix multiply */
m.Row3.X += dy * m.Row1.X; m.Row3.Y += dy * m.Row1.Y;
m.Row3.Z += dy * m.Row1.Z; m.Row3.W += dy * m.Row1.W;

Gfx_LoadMatrix(MATRIX_VIEW, &m);
Gfx_DrawVb_IndexedTris(sky_vertices);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View);
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ static void EnvRenderer_UpdateSky(void) {
int extent, height;
int x1, z1, x2, z2;

if (!World.Blocks || Gfx_LostContext) return;
if (!World.Blocks || Gfx.LostContext) return;
Gfx_DeleteVb(&sky_vb);
if (EnvRenderer_Minimal) return;

Expand Down Expand Up @@ -318,7 +318,7 @@ void EnvRenderer_RenderSkybox(double deltaTime) {
Gfx_DrawVb_IndexedTris(SKYBOX_COUNT);

Gfx_SetTexturing(false);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View);
Gfx_SetDepthWrite(true);
}

Expand All @@ -345,7 +345,7 @@ static void EnvRenderer_UpdateSkybox(void) {
};
int i;

if (Gfx_LostContext) return;
if (Gfx.LostContext) return;
Gfx_DeleteVb(&skybox_vb);
if (EnvRenderer_Minimal) return;

Expand Down Expand Up @@ -576,7 +576,7 @@ void EnvRenderer_RenderMapEdges(double delta) {

static void EnvRenderer_MakeBorderTex(GfxResourceID* texId, BlockID block) {
TextureLoc loc = Block_Tex(block, FACE_YMAX);
if (Gfx_LostContext) return;
if (Gfx.LostContext) return;

Gfx_DeleteTexture(texId);
*texId = Atlas_LoadTile(loc);
Expand Down Expand Up @@ -694,7 +694,7 @@ static void EnvRenderer_UpdateMapSides(void) {
VertexP3fT2fC4b* ptr;
VertexP3fT2fC4b* cur;

if (!World.Blocks || Gfx_LostContext) return;
if (!World.Blocks || Gfx.LostContext) return;
Gfx_DeleteVb(&sides_vb);
block = Env_SidesBlock;

Expand Down Expand Up @@ -753,7 +753,7 @@ static void EnvRenderer_UpdateMapEdges(void) {
VertexP3fT2fC4b* ptr;
VertexP3fT2fC4b* cur;

if (!World.Blocks || Gfx_LostContext) return;
if (!World.Blocks || Gfx.LostContext) return;
Gfx_DeleteVb(&edges_vb);
block = Env_EdgeBlock;

Expand Down Expand Up @@ -815,7 +815,7 @@ static void EnvRenderer_UpdateAll(void) {
EnvRenderer_UpdateSkybox();
EnvRenderer_UpdateFog();

if (Gfx_LostContext) return;
if (Gfx.LostContext) return;
/* TODO: Don't allocate unless used? */
weather_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, WEATHER_VERTS_COUNT);
/* TODO: Don't need to do this on every new map */
Expand Down
16 changes: 8 additions & 8 deletions src/Game.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool Game_ChangeTerrainAtlas(Bitmap* atlas) {
Chat_AddRaw("&c Its height is less than its width.");
return false;
}
if (Gfx_LostContext) return false;
if (Gfx.LostContext) return false;

Atlas_Free();
Atlas_Update(atlas);
Expand All @@ -161,9 +161,9 @@ void Game_UserSetViewDistance(int distance) {

void Game_UpdateProjection(void) {
Game_DefaultFov = Options_GetInt(OPT_FIELD_OF_VIEW, 1, 179, 70);
Camera.Active->GetProjection(&Gfx_Projection);
Camera.Active->GetProjection(&Gfx.Projection);

Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx_Projection);
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
Event_RaiseVoid(&GfxEvents.ProjectionChanged);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String*
}

bool Game_ValidateBitmap(const String* file, Bitmap* bmp) {
int maxWidth = Gfx_MaxTexWidth, maxHeight = Gfx_MaxTexHeight;
int maxWidth = Gfx.MaxTexWidth, maxHeight = Gfx.MaxTexHeight;
if (!bmp->Scan0) {
Chat_Add1("&cError loading %s from the texture pack.", file);
return false;
Expand Down Expand Up @@ -429,7 +429,7 @@ static void Game_Load(void) {
Gfx_Init();
Gfx_SetVSync(true);
Gfx_MakeApiInfo();
Gfx_Mipmaps = Options_GetBool(OPT_MIPMAPS, false);
Gfx.Mipmaps = Options_GetBool(OPT_MIPMAPS, false);

Game_UpdateClientSize();
Game_LoadOptions();
Expand Down Expand Up @@ -525,9 +525,9 @@ static void Game_LimitFPS(uint64_t frameStart) {
}

static void Game_UpdateViewMatrix(void) {
Camera.Active->GetView(&Gfx_View);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
FrustumCulling_CalcFrustumEquations(&Gfx_Projection, &Gfx_View);
Camera.Active->GetView(&Gfx.View);
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx.View);
FrustumCulling_CalcFrustumEquations(&Gfx.Projection, &Gfx.View);
}

static void Game_Render3D(double delta, float t) {
Expand Down
Loading

0 comments on commit abb2a7f

Please sign in to comment.