Combine Graphics/GraphicsCommon

This commit is contained in:
UnknownShadow200 2018-11-24 11:45:02 +11:00
parent 5fbd10b331
commit cd2d70bd8c
28 changed files with 456 additions and 416 deletions

View File

@ -1,7 +1,6 @@
#include "AxisLinesRenderer.h"
#include "Graphics.h"
#include "Game.h"
#include "GraphicsCommon.h"
#include "SelectionBox.h"
#include "PackedCol.h"
#include "Camera.h"
@ -71,6 +70,6 @@ void AxisLinesRenderer_Render(double delta) {
ptr->Col = cols[i >> 2];
}
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(axisLines_vb, vertices, count);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_UpdateDynamicVb_IndexedTris(axisLines_vb, vertices, count);
}

View File

@ -320,6 +320,7 @@ static void Png_ComputeTransparency(Bitmap* bmp, BitmapCol col) {
/* Most bits per sample is 16. Most samples per pixel is 4. Add 1 for filter byte. */
/* Need to store both current and prior row, per PNG specification. */
#define PNG_BUFFER_SIZE ((PNG_MAX_DIMS * 2 * 4 + 1) * 2)
/* TODO: Test a lot of .png files and ensure output is right */
ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
uint8_t tmp[PNG_PALETTE * 3];

View File

@ -10,7 +10,6 @@
#include "Entity.h"
#include "Window.h"
#include "Graphics.h"
#include "GraphicsCommon.h"
#include "Funcs.h"
#include "Block.h"
#include "EnvRenderer.h"

View File

@ -239,7 +239,6 @@
<ClInclude Include="Game.h" />
<ClInclude Include="ExtMath.h" />
<ClInclude Include="Graphics.h" />
<ClInclude Include="GraphicsCommon.h" />
<ClInclude Include="Platform.h" />
<ClInclude Include="String.h" />
<ClInclude Include="Core.h" />
@ -286,7 +285,6 @@
<ClCompile Include="MapRenderer.c" />
<ClCompile Include="Options.c" />
<ClCompile Include="PackedCol.c" />
<ClCompile Include="GraphicsCommon.c" />
<ClCompile Include="Particle.c" />
<ClCompile Include="BlockPhysics.c" />
<ClCompile Include="PickedPosRenderer.c" />

View File

@ -141,9 +141,6 @@
<ClInclude Include="ExtMath.h">
<Filter>Header Files\Math</Filter>
</ClInclude>
<ClInclude Include="GraphicsCommon.h">
<Filter>Header Files\Graphics</Filter>
</ClInclude>
<ClInclude Include="VertexStructs.h">
<Filter>Header Files\Graphics</Filter>
</ClInclude>
@ -320,9 +317,6 @@
<ClCompile Include="Vectors.c">
<Filter>Source Files\Math</Filter>
</ClCompile>
<ClCompile Include="GraphicsCommon.c">
<Filter>Source Files\Graphics</Filter>
</ClCompile>
<ClCompile Include="ExtMath.c">
<Filter>Source Files\Math</Filter>
</ClCompile>

View File

@ -105,4 +105,11 @@ typedef void* GfxResourceID;
typedef uint32_t GfxResourceID;
#define GFX_NULL 0
#endif
/* Contains the information to describe a 2D textured quad. */
struct Texture {
GfxResourceID ID;
int16_t X, Y; uint16_t Width, Height;
TextureRec uv;
};
#endif

View File

@ -4,7 +4,6 @@
#include "Platform.h"
#include "ExtMath.h"
#include "ErrorHandler.h"
#include "GraphicsCommon.h"
#include "Bitmap.h"
#include "Game.h"

View File

@ -11,7 +11,6 @@
#include "Lighting.h"
#include "Drawer2D.h"
#include "Particle.h"
#include "GraphicsCommon.h"
#include "AsyncDownloader.h"
#include "Chat.h"
#include "Model.h"
@ -388,7 +387,7 @@ void Entities_DrawShadows(void) {
Gfx_SetAlphaBlending(true);
Gfx_SetTexturing(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
ShadowComponent_Draw(Entities_List[ENTITIES_SELF_ID]);
if (Entities_ShadowMode == SHADOW_MODE_CIRCLE_ALL) {
@ -558,8 +557,8 @@ static void Player_DrawName(struct Player* p) {
}
Particle_DoRender(&size, &pos, &p->NameTex.uv, col, vertices);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(GfxCommon_texVb, vertices, 4);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_UpdateDynamicVb_IndexedTris(Gfx_texVb, vertices, 4);
}
static struct Player* Player_FirstOtherWithSameSkin(struct Player* player) {

View File

@ -3,8 +3,8 @@
#include "EntityComponents.h"
#include "Physics.h"
#include "Constants.h"
#include "GraphicsCommon.h"
#include "Input.h"
#include "PackedCol.h"
/* Represents an in-game entity.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/

View File

@ -10,7 +10,6 @@
#include "Funcs.h"
#include "VertexStructs.h"
#include "Graphics.h"
#include "GraphicsCommon.h"
#include "Physics.h"
#include "Model.h"
#include "Audio.h"
@ -642,7 +641,7 @@ void ShadowComponent_Draw(struct Entity* e) {
/* TODO: Should shadow component use its own VB? */
ptr = vertices;
if (Entities_ShadowMode == SHADOW_MODE_SNAP_TO_BLOCK) {
vb = GfxCommon_texVb;
vb = Gfx_texVb;
x1 = Math_Floor(pos.X); z1 = Math_Floor(pos.Z);
if (!ShadowComponent_GetBlocks(e, x1, y, z1, data)) return;
@ -675,7 +674,7 @@ void ShadowComponent_Draw(struct Entity* e) {
}
count = (int)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(vb, vertices, count);
Gfx_UpdateDynamicVb_IndexedTris(vb, vertices, count);
}

View File

@ -12,7 +12,6 @@
#include "ErrorHandler.h"
#include "Stream.h"
#include "Block.h"
#include "GraphicsCommon.h"
#include "Event.h"
#include "TerrainAtlas.h"
#include "Platform.h"
@ -143,7 +142,7 @@ void EnvRenderer_RenderClouds(double deltaTime) {
Gfx_SetAlphaTest(true);
Gfx_SetTexturing(true);
Gfx_BindTexture(clouds_tex);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_BindVb(clouds_vb);
Gfx_DrawVb_IndexedTris(clouds_vertices);
Gfx_SetAlphaTest(false);
@ -221,7 +220,7 @@ void EnvRenderer_RenderSky(double deltaTime) {
normY = (float)World_Height + 8.0f;
skyY = max(Camera_CurrentPos.Y + 8.0f, normY);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_BindVb(sky_vb);
if (skyY == normY) {
@ -303,7 +302,7 @@ void EnvRenderer_RenderSkybox(double deltaTime) {
Gfx_SetDepthWrite(false);
Gfx_SetTexturing(true);
Gfx_BindTexture(skybox_tex);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
/* Base skybox rotation */
m = Matrix_Identity;
@ -527,9 +526,9 @@ void EnvRenderer_RenderWeather(double deltaTime) {
Gfx_SetDepthWrite(false);
Gfx_SetAlphaArgBlend(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
vCount = (int)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(weather_vb, vertices, vCount);
Gfx_UpdateDynamicVb_IndexedTris(weather_vb, vertices, vCount);
Gfx_SetAlphaArgBlend(false);
Gfx_SetDepthWrite(true);
@ -549,16 +548,16 @@ void EnvRenderer_RenderBorders(BlockID block, GfxResourceID vb, GfxResourceID te
if (!vb) return;
Gfx_SetTexturing(true);
GfxCommon_SetupAlphaState(Block_Draw[block]);
Gfx_SetupAlphaState(Block_Draw[block]);
Gfx_EnableMipmaps();
Gfx_BindTexture(tex);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_BindVb(vb);
Gfx_DrawVb_IndexedTris(count);
Gfx_DisableMipmaps();
GfxCommon_RestoreAlphaState(Block_Draw[block]);
Gfx_RestoreAlphaState(Block_Draw[block]);
Gfx_SetTexturing(false);
}

View File

@ -30,7 +30,6 @@
#include "EnvRenderer.h"
#include "HeldBlockRenderer.h"
#include "PickedPosRenderer.h"
#include "GraphicsCommon.h"
#include "Menus.h"
#include "Audio.h"
#include "Stream.h"
@ -684,7 +683,7 @@ static void Game_RenderFrame(double delta) {
frameStart = Stopwatch_Measure();
Gfx_BeginFrame();
Gfx_BindIb(GfxCommon_defaultIb);
Gfx_BindIb(Gfx_defaultIb);
Game_Accumulator += delta;
Game_Vertices = 0;

View File

@ -2,13 +2,13 @@
#include "ErrorHandler.h"
#include "Platform.h"
#include "Window.h"
#include "GraphicsCommon.h"
#include "Funcs.h"
#include "Chat.h"
#include "Game.h"
#include "ExtMath.h"
#include "Bitmap.h"
#include "Event.h"
#include "Block.h"
#include "ExtMath.h"
#define WIN32_LEAN_AND_MEAN
#define NOSERVICE
@ -21,6 +21,245 @@ static int gfx_batchStride, gfx_batchFormat = -1;
static bool gfx_vsync, gfx_fogEnabled;
bool Gfx_GetFog(void) { return gfx_fogEnabled; }
/*########################################################################################################################*
*------------------------------------------------------Generic/Common-----------------------------------------------------*
*#########################################################################################################################*/
static char Gfx_ApiBuffer[7][STRING_SIZE];
String Gfx_ApiInfo[7] = {
String_FromArray(Gfx_ApiBuffer[0]), String_FromArray(Gfx_ApiBuffer[1]),
String_FromArray(Gfx_ApiBuffer[2]), String_FromArray(Gfx_ApiBuffer[3]),
String_FromArray(Gfx_ApiBuffer[4]), String_FromArray(Gfx_ApiBuffer[5]),
String_FromArray(Gfx_ApiBuffer[6]),
};
CC_NOINLINE static void Gfx_InitDefaultResources(void) {
uint16_t indices[GFX_MAX_INDICES];
Gfx_MakeIndices(indices, GFX_MAX_INDICES);
Gfx_defaultIb = Gfx_CreateIb(indices, GFX_MAX_INDICES);
Gfx_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
Gfx_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4);
}
CC_NOINLINE static void Gfx_FreeDefaultResources(void) {
Gfx_DeleteVb(&Gfx_quadVb);
Gfx_DeleteVb(&Gfx_texVb);
Gfx_DeleteIb(&Gfx_defaultIb);
}
void Gfx_LoseContext(const char* reason) {
Gfx_LostContext = true;
Platform_Log1("Lost graphics context: %c", reason);
Event_RaiseVoid(&GfxEvents_ContextLost);
Gfx_FreeDefaultResources();
}
void Gfx_RecreateContext(void) {
Gfx_LostContext = false;
Platform_LogConst("Recreating graphics context");
Event_RaiseVoid(&GfxEvents_ContextRecreated);
Gfx_InitDefaultResources();
}
void Gfx_UpdateDynamicVb_Lines(GfxResourceID vb, void* vertices, int vCount) {
Gfx_SetDynamicVbData(vb, vertices, vCount);
Gfx_DrawVb_Lines(vCount);
}
void Gfx_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCount) {
Gfx_SetDynamicVbData(vb, vertices, vCount);
Gfx_DrawVb_IndexedTris(vCount);
}
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;
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;
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4);
}
void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom) {
VertexP3fC4b verts[4];
VertexP3fC4b v; v.Z = 0.0f;
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;
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_UpdateDynamicVb_IndexedTris(Gfx_quadVb, verts, 4);
}
void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol col) {
VertexP3fT2fC4b texVerts[4];
VertexP3fT2fC4b* ptr = texVerts;
Gfx_Make2DQuad(tex, col, &ptr);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_UpdateDynamicVb_IndexedTris(Gfx_texVb, texVerts, 4);
}
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);
#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. */
x1 -= 0.5f; x2 -= 0.5f;
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;
}
static bool gfx_hadFog;
void Gfx_Mode2D(int width, int height) {
struct Matrix ortho;
Gfx_CalcOrthoMatrix((float)width, (float)height, &ortho);
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
Gfx_LoadMatrix(&ortho);
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
Gfx_LoadIdentityMatrix();
Gfx_SetDepthTest(false);
Gfx_SetAlphaBlending(true);
gfx_hadFog = Gfx_GetFog();
if (gfx_hadFog) Gfx_SetFog(false);
}
void Gfx_Mode3D(void) {
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
Gfx_LoadMatrix(&Gfx_Projection);
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
Gfx_LoadMatrix(&Gfx_View);
Gfx_SetDepthTest(true);
Gfx_SetAlphaBlending(false);
if (gfx_hadFog) Gfx_SetFog(true);
}
void Gfx_MakeIndices(uint16_t* indices, int iCount) {
int element = 0, i;
for (i = 0; i < iCount; i += 6) {
indices[0] = (uint16_t)(element + 0);
indices[1] = (uint16_t)(element + 1);
indices[2] = (uint16_t)(element + 2);
indices[3] = (uint16_t)(element + 2);
indices[4] = (uint16_t)(element + 3);
indices[5] = (uint16_t)(element + 0);
indices += 6; element += 4;
}
}
void Gfx_SetupAlphaState(uint8_t draw) {
if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(true);
if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(true);
if (draw == DRAW_TRANSPARENT_THICK) Gfx_SetAlphaTest(true);
if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(true);
}
void Gfx_RestoreAlphaState(uint8_t draw) {
if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(false);
if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(false);
if (draw == DRAW_TRANSPARENT_THICK) Gfx_SetAlphaTest(false);
if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(false);
}
/* Quoted from http://www.realtimerendering.com/blog/gpus-prefer-premultiplication/
The short version: if you want your renderer to properly handle textures with alphas when using
bilinear interpolation or mipmapping, you need to premultiply your PNG color data by their (unassociated) alphas. */
static BitmapCol GfxCommon_Average(BitmapCol p1, BitmapCol p2) {
uint32_t a1, a2, aSum;
uint32_t b1, g1, r1;
uint32_t b2, g2, r2;
BitmapCol ave;
a1 = p1.A; a2 = p2.A;
aSum = (a1 + a2);
aSum = aSum > 0 ? aSum : 1; /* avoid divide by 0 below */
/* Convert RGB to pre-multiplied form */
b1 = p1.B * a1; g1 = p1.G * a1; r1 = p1.R * a1;
b2 = p2.B * a2; g2 = p2.G * a2; r2 = p2.R * a2;
/* https://stackoverflow.com/a/347376
We need to convert RGB back from the pre-multiplied average into normal form
((r1 + r2) / 2) / ((a1 + a2) / 2)
but we just cancel out the / 2*/
ave.B = (b1 + b2) / aSum;
ave.G = (g1 + g2) / aSum;
ave.R = (r1 + r2) / aSum;
ave.A = aSum >> 1;
return ave;
}
void Gfx_GenMipmaps(int width, int height, uint8_t* lvlScan0, uint8_t* scan0) {
BitmapCol* baseSrc = (BitmapCol*)scan0;
BitmapCol* baseDst = (BitmapCol*)lvlScan0;
int srcWidth = width << 1;
int x, y;
for (y = 0; y < height; y++) {
int srcY = (y << 1);
BitmapCol* src0 = baseSrc + srcY * srcWidth;
BitmapCol* src1 = src0 + srcWidth;
BitmapCol* dst = baseDst + y * width;
for (x = 0; x < width; x++) {
int srcX = (x << 1);
BitmapCol src00 = src0[srcX], src01 = src0[srcX + 1];
BitmapCol src10 = src1[srcX], src11 = src1[srcX + 1];
/* bilinear filter this mipmap */
BitmapCol ave0 = GfxCommon_Average(src00, src01);
BitmapCol ave1 = GfxCommon_Average(src10, src11);
dst[x] = GfxCommon_Average(ave0, ave1);
}
}
}
int Gfx_MipmapsLevels(int width, int height) {
int lvlsWidth = Math_Log2(width), lvlsHeight = Math_Log2(height);
if (Gfx_CustomMipmapsLevels) {
int lvls = min(lvlsWidth, lvlsHeight);
return min(lvls, 4);
} else {
return max(lvlsWidth, lvlsHeight);
}
}
void Texture_Render(const struct Texture* tex) {
PackedCol white = PACKEDCOL_WHITE;
Gfx_BindTexture(tex->ID);
Gfx_Draw2DTexture(tex, white);
}
void Texture_RenderShaded(const struct Texture* tex, PackedCol shadeCol) {
Gfx_BindTexture(tex->ID);
Gfx_Draw2DTexture(tex, shadeCol);
}
/*########################################################################################################################*
*--------------------------------------------------------Direct3D9--------------------------------------------------------*
*#########################################################################################################################*/
@ -116,7 +355,7 @@ static void D3D9_RecreateDevice(void) {
D3D9_SetDefaultRenderStates();
D3D9_RestoreRenderStates();
GfxCommon_RecreateContext();
Gfx_RecreateContext();
}
void Gfx_Init(void) {
@ -150,11 +389,11 @@ void Gfx_Init(void) {
Gfx_CustomMipmapsLevels = true;
D3D9_SetDefaultRenderStates();
GfxCommon_Init();
Gfx_InitDefaultResources();
}
void Gfx_Free(void) {
GfxCommon_Free();
Gfx_FreeDefaultResources();
D3D9_FreeResource(&device);
D3D9_FreeResource(&d3d);
}
@ -205,7 +444,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp
uint8_t* cur;
Bitmap mipmap;
int lvls = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
int lvls = Gfx_MipmapsLevels(bmp->Width, bmp->Height);
int lvl, width = bmp->Width, height = bmp->Height;
for (lvl = 1; lvl <= lvls; lvl++) {
@ -214,7 +453,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp
if (height > 1) height /= 2;
cur = Mem_Alloc(width * height, BITMAP_SIZEOF_PIXEL, "mipmaps");
GfxCommon_GenMipmaps(width, height, cur, prev);
Gfx_GenMipmaps(width, height, cur, prev);
Bitmap_Create(&mipmap, width, height, cur);
if (partial) {
@ -232,7 +471,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
IDirect3DTexture9* tex;
ReturnCode res;
int mipmapsLevels = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
int mipmapsLevels = Gfx_MipmapsLevels(bmp->Width, bmp->Height);
int levels = 1 + (mipmaps ? mipmapsLevels : 0);
if (!Math_IsPowOf2(bmp->Width) || !Math_IsPowOf2(bmp->Height)) {
@ -531,7 +770,7 @@ void Gfx_BindIb(GfxResourceID ib) {
void Gfx_DeleteVb(GfxResourceID* vb) { D3D9_FreeResource(vb); }
void Gfx_DeleteIb(GfxResourceID* ib) { D3D9_FreeResource(ib); }
void Gfx_SetBatchFormat(VertexFormat fmt) {
void Gfx_SetVertexFormat(VertexFormat fmt) {
if (fmt == gfx_batchFormat) return;
gfx_batchFormat = fmt;
@ -654,7 +893,7 @@ void Gfx_SetVSync(bool value) {
if (gfx_vsync == value) return;
gfx_vsync = value;
GfxCommon_LoseContext(" (toggling VSync)");
Gfx_LoseContext(" (toggling VSync)");
D3D9_RecreateDevice();
}
@ -672,7 +911,7 @@ void Gfx_EndFrame(void) {
if (res != D3DERR_DEVICELOST) ErrorHandler_Fail2(res, "D3D9_EndFrame");
/* TODO: Make sure this actually works on all graphics cards.*/
GfxCommon_LoseContext(" (Direct3D9 device lost)");
Gfx_LoseContext(" (Direct3D9 device lost)");
D3D9_LoopUntilRetrieved();
D3D9_RecreateDevice();
}
@ -724,7 +963,7 @@ void Gfx_UpdateApiInfo(void) {
}
void Gfx_OnWindowResize(void) {
GfxCommon_LoseContext(" (resizing window)");
Gfx_LoseContext(" (resizing window)");
D3D9_RecreateDevice();
}
#endif
@ -823,7 +1062,7 @@ void Gfx_Init(void) {
Gfx_CustomMipmapsLevels = true;
GL_CheckVboSupport();
#endif
GfxCommon_Init();
Gfx_InitDefaultResources();
glHint(GL_FOG_HINT, GL_NICEST);
glEnableClientState(GL_VERTEX_ARRAY);
@ -831,7 +1070,7 @@ void Gfx_Init(void) {
}
void Gfx_Free(void) {
GfxCommon_Free();
Gfx_FreeDefaultResources();
GLContext_Free();
}
@ -845,7 +1084,7 @@ static void GL_DoMipmaps(GfxResourceID texId, int x, int y, Bitmap* bmp, bool pa
uint8_t* prev = bmp->Scan0;
uint8_t* cur;
int lvls = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
int lvls = Gfx_MipmapsLevels(bmp->Width, bmp->Height);
int lvl, width = bmp->Width, height = bmp->Height;
for (lvl = 1; lvl <= lvls; lvl++) {
@ -854,7 +1093,7 @@ static void GL_DoMipmaps(GfxResourceID texId, int x, int y, Bitmap* bmp, bool pa
if (height > 1) height /= 2;
cur = Mem_Alloc(width * height, BITMAP_SIZEOF_PIXEL, "mipmaps");
GfxCommon_GenMipmaps(width, height, cur, prev);
Gfx_GenMipmaps(width, height, cur, prev);
if (partial) {
glTexSubImage2D(GL_TEXTURE_2D, lvl, x, y, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, cur);
@ -881,7 +1120,7 @@ GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
if (mipmaps) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
if (Gfx_CustomMipmapsLevels) {
int lvls = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
int lvls = Gfx_MipmapsLevels(bmp->Width, bmp->Height);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, lvls);
}
} else {
@ -1043,14 +1282,14 @@ GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) { return gl
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
/* We need to setup client state properly when building the list */
int curFormat = gfx_batchFormat, stride;
Gfx_SetBatchFormat(fmt);
Gfx_SetVertexFormat(fmt);
GfxResourceID list = glGenLists(1);
glNewList(list, GL_COMPILE);
count &= ~0x01; /* Need to get rid of the 1 extra element, see comment in chunk mesh builder for why */
uint16_t indices[GFX_MAX_INDICES];
GfxCommon_MakeIndices(indices, ICOUNT(count));
Gfx_MakeIndices(indices, ICOUNT(count));
stride = Gfx_strideSizes[fmt];
glVertexPointer(3, GL_FLOAT, stride, vertices);
@ -1061,7 +1300,7 @@ GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
glDrawElements(GL_TRIANGLES, ICOUNT(count), GL_UNSIGNED_SHORT, indices);
glEndList();
Gfx_SetBatchFormat(curFormat);
Gfx_SetVertexFormat(curFormat);
return list;
}
@ -1101,7 +1340,7 @@ void GL_SetupVbPos3fTex2fCol4b_Range(int startVertex) {
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexP3fT2fC4b), (void*)(offset + 16));
}
void Gfx_SetBatchFormat(VertexFormat fmt) {
void Gfx_SetVertexFormat(VertexFormat fmt) {
if (fmt == gfx_batchFormat) return;
if (gfx_batchFormat == VERTEX_FORMAT_P3FT2FC4B) {

View File

@ -4,6 +4,7 @@
#include "Vectors.h"
#include "GameStructs.h"
#include "Bitmap.h"
#include "VertexStructs.h"
/* Abstracts a 3D graphics rendering API.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
@ -40,6 +41,10 @@ bool Gfx_Mipmaps;
bool Gfx_CustomMipmapsLevels;
struct Matrix Gfx_View, Gfx_Projection;
extern String Gfx_ApiInfo[7];
GfxResourceID Gfx_defaultIb;
GfxResourceID Gfx_quadVb, Gfx_texVb;
#define ICOUNT(verticesCount) (((verticesCount) >> 2) * 6)
#define GFX_MAX_INDICES (65536 / 4 * 6)
#define GFX_MAX_VERTICES 65536
@ -47,65 +52,176 @@ struct Matrix Gfx_View, Gfx_Projection;
/* Callback invoked when the context is lost. Repeatedly invoked until a context can be retrieved. */
ScheduledTaskCallback Gfx_LostContextFunction;
/* Creates a new texture. (and also generates mipmaps if mipmaps) */
/* NOTE: Only set mipmaps to true if Gfx_Mipmaps is also true, because whether textures
use mipmapping may be either a per-texture or global state depending on the backend. */
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps);
/* Updates a region of the given texture. (and mipmapped regions if mipmaps) */
void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, Bitmap* part, bool mipmaps);
/* Sets the currently active texture. */
void Gfx_BindTexture(GfxResourceID texId);
/* Deletes the given texture, then sets it to GFX_NULL. */
void Gfx_DeleteTexture(GfxResourceID* texId);
/* Sets whether texture colour is used when rendering vertices. */
void Gfx_SetTexturing(bool enabled);
/* Turns on mipmapping. (if Gfx_Mipmaps is enabled) */
/* NOTE: You must have created textures with mipmaps true for this to work. */
void Gfx_EnableMipmaps(void);
/* Turns off mipmapping. (if GfX_Mipmaps is enabled) */
/* NOTE: You must have created textures with mipmaps true for this to work. */
void Gfx_DisableMipmaps(void);
/* Returns whether fog blending is enabled. */
bool Gfx_GetFog(void);
/* Sets whether fog blending is enabled. */
void Gfx_SetFog(bool enabled);
/* Sets the colour of the blended fog. */
void Gfx_SetFogCol(PackedCol col);
/* Sets thickness of fog for FOG_EXP/FOG_EXP2 modes. */
void Gfx_SetFogDensity(float value);
/* Sets extent/end of fog for FOG_LINEAR mode. */
void Gfx_SetFogEnd(float value);
/* Sets in what way fog is blended. */
void Gfx_SetFogMode(FogFunc func);
/* Sets whether backface culling is performed. */
void Gfx_SetFaceCulling(bool enabled);
/* Sets whether new pixels may be discarded based on their alpha. */
void Gfx_SetAlphaTest(bool enabled);
/* Sets in what way pixels may be discarded based on their alpha. */
void Gfx_SetAlphaTestFunc(CompareFunc func, float refValue);
/* Sets whether existing and new pixels are blended together. */
void Gfx_SetAlphaBlending(bool enabled);
/* Sets in what way existing and new pixels are blended. */
void Gfx_SetAlphaBlendFunc(BlendFunc srcFunc, BlendFunc dstFunc);
/* Sets whether blending between the alpha components of the texture and vertex colour is performed. */
/* Sets whether blending between the alpha components of texture and vertex colour is performed. */
void Gfx_SetAlphaArgBlend(bool enabled);
/* Clears the colour and depth buffer to default. */
void Gfx_Clear(void);
/* Sets the colour that the colour buffer is cleared to. */
void Gfx_ClearCol(PackedCol col);
/* Sets whether pixels may be discard based on z/depth. */
void Gfx_SetDepthTest(bool enabled);
/* Sets in what may pixels may be discarded based on z/depth. */
void Gfx_SetDepthTestFunc(CompareFunc func);
/* Sets whether R/G/B/A of pixels are actually written to the colour buffer channels. */
void Gfx_SetColWriteMask(bool r, bool g, bool b, bool a);
/* Sets whether z/depth of pixels is actually written to the depth buffer. */
void Gfx_SetDepthWrite(bool enabled);
/* Creates a new dynamic vertex buffer, whose contents can be updated later. */
GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices);
/* Creates a new vertex buffer and fills out its contents. */
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count);
/* Creates a new index buffer and fills out its contents. */
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount);
/* Sets the currently active vertex buffer. */
void Gfx_BindVb(GfxResourceID vb);
/* Sets the currently active index buffer. */
void Gfx_BindIb(GfxResourceID ib);
/* Deletes the given vertex buffer, then sets it to GFX_NULL. */
void Gfx_DeleteVb(GfxResourceID* vb);
/* Deletes the given index buffer, then sets it to GFX_NULL. */
void Gfx_DeleteIb(GfxResourceID* ib);
void Gfx_SetBatchFormat(VertexFormat fmt);
/* Sets the format of the rendered vertices. */
void Gfx_SetVertexFormat(VertexFormat fmt);
/* Updates the data of a dynamic vertex buffer. */
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount);
/* Renders vertices from the currently bound vertex buffer as lines. */
void Gfx_DrawVb_Lines(int verticesCount);
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
/* NOTE: Offsets each index by startVertex. */
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex);
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
void Gfx_DrawVb_IndexedTris(int verticesCount);
/* Special case Gfx_DrawVb_IndexedTris_Range for map renderer */
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex);
/* Sets the currently active matrix. */
void Gfx_SetMatrixMode(MatrixType type);
/* Loads the given matrix over the currently active matrix. */
void Gfx_LoadMatrix(struct Matrix* matrix);
/* Loads the identity matrix over the currently active matrix. */
void Gfx_LoadIdentityMatrix(void);
/* Calculates an orthographic matrix suitable with this backend. (usually for 2D) */
void Gfx_CalcOrthoMatrix(float width, float height, struct Matrix* matrix);
/* Calculates a projection matrix suitable with this backend. (usually for 3D) */
void Gfx_CalcPerspectiveMatrix(float fov, float aspect, float zNear, float zFar, struct Matrix* matrix);
/* Outputs a .png screenshot of the backbuffer */
/* Outputs a .png screenshot of the backbuffer. */
ReturnCode Gfx_TakeScreenshot(struct Stream* output, int width, int height);
/* Warns if this graphics API has problems with the user's GPU. Returns whether legacy rendering mode is needed. */
/* Warns in chat if the backend has problems with the user's GPU. /*
/* Returns whether legacy rendering mode for borders/sky/clouds is needed. */
bool Gfx_WarnIfNecessary(void);
/* Sets up state for rendering a new frame. */
void Gfx_BeginFrame(void);
/* Finishes rendering a frame, and swaps it with the back buffer. */
void Gfx_EndFrame(void);
/* Sets whether to synchronise with monitor refresh to avoid tearing. */
/* NOTE: This setting may be unsupported or just ignored. */
void Gfx_SetVSync(bool value);
/* Updates state when the window's dimensions have changed. */
/* NOTE: This may require recreating the context depending on the backend. */
void Gfx_OnWindowResize(void);
/* Fills Gfx_ApiInfo with information about the backend state and the user's GPU. */
void Gfx_MakeApiInfo(void);
/* Updates Gfx_ApiInfo with current backend state information. */
/* NOTE: This is information such as current free memory, etc. */
void Gfx_UpdateApiInfo(void);
/* Raises ContextLost event and updates state for lost contexts. */
void Gfx_LoseContext(const char* reason);
/* Raises ContextRecreated event and restores state from lost contexts. */
void Gfx_RecreateContext(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_Lines(GfxResourceID vb, void* vertices, int vCount);
/* 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 col);
/* Renders a 2D flat vertical gradient rectangle. */
void Gfx_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom);
/* Renders a 2D coloured texture. */
void Gfx_Draw2DTexture(const struct Texture* tex, PackedCol col);
/* Fills out the vertices for rendering a 2D coloured texture. */
void Gfx_Make2DQuad(const struct Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices);
/* Switches state to be suitable for drawing 2D graphics. */
/* NOTE: This means turning off fog/depth test, changing matrices, etc.*/
void Gfx_Mode2D(int width, int height);
/* Switches state to be suitable for drawing 3D graphics. */
/* NOTE: This means restoring fog/depth test, restoring matrices, etc. */
void Gfx_Mode3D(void);
/* Fills out indices array with {0,1,2} {2,3,0}, {4,5,6} {6,7,4} etc. */
void Gfx_MakeIndices(uint16_t* indices, int iCount);
/* Sets appropriate alpha test/blending for given block draw type. */
void Gfx_SetupAlphaState(uint8_t draw);
/* Undoes changes to alpha test/blending state by Gfx_SetupAlphaState. */
void Gfx_RestoreAlphaState(uint8_t draw);
/* Generates the next mipmaps level bitmap for the given bitmap. */
void Gfx_GenMipmaps(int width, int height, uint8_t* lvlScan0, uint8_t* scan0);
/* Returns the maximum number of mipmaps levels used for given size. */
int Gfx_MipmapsLevels(int width, int height);
/* Statically initialises the position and dimensions of this texture */
#define Tex_Rect(x,y, width,height) x,y,width,height
/* Statically initialises the texture coordinate corners of this texture */
#define Tex_UV(u1,v1, u2,v2) u1,v1,u2,v2
/* Sets the position and dimensions of this texture */
#define Tex_SetRect(tex, x,y, width, height) tex.X = x; tex.Y = y; tex.Width = width; tex.Height = height;
/* Sets texture coordinate corners of this texture */
/* Useful to only draw a sub-region of the texture's pixels */
#define Tex_SetUV(tex, u1,v1, u2,v2) tex.uv.U1 = u1; tex.uv.V1 = v1; tex.uv.U2 = u2; tex.uv.V2 = v2;
/* Binds then renders the given texture. */
void Texture_Render(const struct Texture* tex);
/* Binds then renders the given texture. */
void Texture_RenderShaded(const struct Texture* tex, PackedCol shadeCol);
#endif

View File

@ -1,242 +0,0 @@
#include "GraphicsCommon.h"
#include "Graphics.h"
#include "Platform.h"
#include "Block.h"
#include "Event.h"
#include "Funcs.h"
#include "ExtMath.h"
static char Gfx_ApiBuffer[7][STRING_SIZE];
String Gfx_ApiInfo[7] = {
String_FromArray(Gfx_ApiBuffer[0]), String_FromArray(Gfx_ApiBuffer[1]),
String_FromArray(Gfx_ApiBuffer[2]), String_FromArray(Gfx_ApiBuffer[3]),
String_FromArray(Gfx_ApiBuffer[4]), String_FromArray(Gfx_ApiBuffer[5]),
String_FromArray(Gfx_ApiBuffer[6]),
};
void GfxCommon_Init(void) {
uint16_t indices[GFX_MAX_INDICES];
GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
GfxCommon_defaultIb = Gfx_CreateIb(indices, GFX_MAX_INDICES);
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
GfxCommon_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4);
}
void GfxCommon_Free(void) {
Gfx_DeleteVb(&GfxCommon_quadVb);
Gfx_DeleteVb(&GfxCommon_texVb);
Gfx_DeleteIb(&GfxCommon_defaultIb);
}
void GfxCommon_LoseContext(const char* reason) {
Gfx_LostContext = true;
Platform_Log1("Lost graphics context: %c", reason);
Event_RaiseVoid(&GfxEvents_ContextLost);
GfxCommon_Free();
}
void GfxCommon_RecreateContext(void) {
Gfx_LostContext = false;
Platform_LogConst("Recreating graphics context");
Event_RaiseVoid(&GfxEvents_ContextRecreated);
GfxCommon_Init();
}
void GfxCommon_UpdateDynamicVb_Lines(GfxResourceID vb, void* vertices, int vCount) {
Gfx_SetDynamicVbData(vb, vertices, vCount);
Gfx_DrawVb_Lines(vCount);
}
void GfxCommon_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCount) {
Gfx_SetDynamicVbData(vb, vertices, vCount);
Gfx_DrawVb_IndexedTris(vCount);
}
void GfxCommon_Draw2DFlat(int x, int y, int width, int height, PackedCol col) {
VertexP3fC4b verts[4];
VertexP3fC4b v; v.Z = 0.0f; v.Col = col;
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;
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(GfxCommon_quadVb, verts, 4);
}
void GfxCommon_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom) {
VertexP3fC4b verts[4];
VertexP3fC4b v; v.Z = 0.0f;
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;
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(GfxCommon_quadVb, verts, 4);
}
void GfxCommon_Draw2DTexture(const struct Texture* tex, PackedCol col) {
VertexP3fT2fC4b texVerts[4];
VertexP3fT2fC4b* ptr = texVerts;
GfxCommon_Make2DQuad(tex, col, &ptr);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(GfxCommon_texVb, texVerts, 4);
}
void GfxCommon_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);
#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. */
x1 -= 0.5f; x2 -= 0.5f;
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;
}
static bool gfx_hadFog;
void GfxCommon_Mode2D(int width, int height) {
struct Matrix ortho;
Gfx_CalcOrthoMatrix((float)width, (float)height, &ortho);
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
Gfx_LoadMatrix(&ortho);
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
Gfx_LoadIdentityMatrix();
Gfx_SetDepthTest(false);
Gfx_SetAlphaBlending(true);
gfx_hadFog = Gfx_GetFog();
if (gfx_hadFog) Gfx_SetFog(false);
}
void GfxCommon_Mode3D(void) {
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
Gfx_LoadMatrix(&Gfx_Projection);
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
Gfx_LoadMatrix(&Gfx_View);
Gfx_SetDepthTest(true);
Gfx_SetAlphaBlending(false);
if (gfx_hadFog) Gfx_SetFog(true);
}
void GfxCommon_MakeIndices(uint16_t* indices, int iCount) {
int element = 0, i;
for (i = 0; i < iCount; i += 6) {
indices[0] = (uint16_t)(element + 0);
indices[1] = (uint16_t)(element + 1);
indices[2] = (uint16_t)(element + 2);
indices[3] = (uint16_t)(element + 2);
indices[4] = (uint16_t)(element + 3);
indices[5] = (uint16_t)(element + 0);
indices += 6; element += 4;
}
}
void GfxCommon_SetupAlphaState(uint8_t draw) {
if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(true);
if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(true);
if (draw == DRAW_TRANSPARENT_THICK) Gfx_SetAlphaTest(true);
if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(true);
}
void GfxCommon_RestoreAlphaState(uint8_t draw) {
if (draw == DRAW_TRANSLUCENT) Gfx_SetAlphaBlending(false);
if (draw == DRAW_TRANSPARENT) Gfx_SetAlphaTest(false);
if (draw == DRAW_TRANSPARENT_THICK) Gfx_SetAlphaTest(false);
if (draw == DRAW_SPRITE) Gfx_SetAlphaTest(false);
}
/* Quoted from http://www.realtimerendering.com/blog/gpus-prefer-premultiplication/
The short version: if you want your renderer to properly handle textures with alphas when using
bilinear interpolation or mipmapping, you need to premultiply your PNG color data by their (unassociated) alphas. */
static BitmapCol GfxCommon_Average(BitmapCol p1, BitmapCol p2) {
uint32_t a1, a2, aSum;
uint32_t b1, g1, r1;
uint32_t b2, g2, r2;
BitmapCol ave;
a1 = p1.A; a2 = p2.A;
aSum = (a1 + a2);
aSum = aSum > 0 ? aSum : 1; /* avoid divide by 0 below */
/* Convert RGB to pre-multiplied form */
b1 = p1.B * a1; g1 = p1.G * a1; r1 = p1.R * a1;
b2 = p2.B * a2; g2 = p2.G * a2; r2 = p2.R * a2;
/* https://stackoverflow.com/a/347376
We need to convert RGB back from the pre-multiplied average into normal form
((r1 + r2) / 2) / ((a1 + a2) / 2)
but we just cancel out the / 2*/
ave.B = (b1 + b2) / aSum;
ave.G = (g1 + g2) / aSum;
ave.R = (r1 + r2) / aSum;
ave.A = aSum >> 1;
return ave;
}
void GfxCommon_GenMipmaps(int width, int height, uint8_t* lvlScan0, uint8_t* scan0) {
BitmapCol* baseSrc = (BitmapCol*)scan0;
BitmapCol* baseDst = (BitmapCol*)lvlScan0;
int srcWidth = width << 1;
int x, y;
for (y = 0; y < height; y++) {
int srcY = (y << 1);
BitmapCol* src0 = baseSrc + srcY * srcWidth;
BitmapCol* src1 = src0 + srcWidth;
BitmapCol* dst = baseDst + y * width;
for (x = 0; x < width; x++) {
int srcX = (x << 1);
BitmapCol src00 = src0[srcX], src01 = src0[srcX + 1];
BitmapCol src10 = src1[srcX], src11 = src1[srcX + 1];
/* bilinear filter this mipmap */
BitmapCol ave0 = GfxCommon_Average(src00, src01);
BitmapCol ave1 = GfxCommon_Average(src10, src11);
dst[x] = GfxCommon_Average(ave0, ave1);
}
}
}
int GfxCommon_MipmapsLevels(int width, int height) {
int lvlsWidth = Math_Log2(width), lvlsHeight = Math_Log2(height);
if (Gfx_CustomMipmapsLevels) {
int lvls = min(lvlsWidth, lvlsHeight);
return min(lvls, 4);
} else {
return max(lvlsWidth, lvlsHeight);
}
}
void Texture_Render(const struct Texture* tex) {
PackedCol white = PACKEDCOL_WHITE;
Gfx_BindTexture(tex->ID);
GfxCommon_Draw2DTexture(tex, white);
}
void Texture_RenderShaded(const struct Texture* tex, PackedCol shadeCol) {
Gfx_BindTexture(tex->ID);
GfxCommon_Draw2DTexture(tex, shadeCol);
}

View File

@ -1,56 +0,0 @@
#ifndef CC_GFXCOMMON_H
#define CC_GFXCOMMON_H
#include "VertexStructs.h"
/* Provides common/shared methods for a 3D graphics rendering API.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
extern String Gfx_ApiInfo[7];
GfxResourceID GfxCommon_defaultIb;
/* Contains the information necessary to describe a 2D textured quad. */
struct Texture {
GfxResourceID ID;
int16_t X, Y; uint16_t Width, Height;
TextureRec uv;
};
/* Statically initialises the position and dimensions of this texture */
#define Tex_Rect(x,y, width,height) x,y,width,height
/* Statically initialises the texture coordinate corners of this texture */
#define Tex_UV(u1,v1, u2,v2) u1,v1,u2,v2
/* Sets the position and dimensions of this texture */
#define Tex_SetRect(tex, x,y, width, height) tex.X = x; tex.Y = y; tex.Width = width; tex.Height = height;
/* Sets texture coordinate corners of this texture */
/* Useful to only draw a sub-region of the texture's pixels */
#define Tex_SetUV(tex, u1,v1, u2,v2) tex.uv.U1 = u1; tex.uv.V1 = v1; tex.uv.U2 = u2; tex.uv.V2 = v2;
void GfxCommon_Init(void);
void GfxCommon_Free(void);
void GfxCommon_LoseContext(const char* reason);
void GfxCommon_RecreateContext(void);
/* Binds and draws the specified subset of the vertices in the current dynamic vertex buffer
This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. */
void GfxCommon_UpdateDynamicVb_Lines(GfxResourceID vb, void* vertices, int vCount);
/*Binds and draws the specified subset of the vertices in the current dynamic vertex buffer
This method also replaces the dynamic vertex buffer's data first with the given vertices before drawing. */
void GfxCommon_UpdateDynamicVb_IndexedTris(GfxResourceID vb, void* vertices, int vCount);
GfxResourceID GfxCommon_quadVb, GfxCommon_texVb;
void GfxCommon_Draw2DFlat(int x, int y, int width, int height, PackedCol col);
void GfxCommon_Draw2DGradient(int x, int y, int width, int height, PackedCol top, PackedCol bottom);
void GfxCommon_Draw2DTexture(const struct Texture* tex, PackedCol col);
void GfxCommon_Make2DQuad(const struct Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices);
void GfxCommon_Mode2D(int width, int height);
void GfxCommon_Mode3D(void);
void GfxCommon_MakeIndices(uint16_t* indices, int iCount);
void GfxCommon_SetupAlphaState(uint8_t draw);
void GfxCommon_RestoreAlphaState(uint8_t draw);
void GfxCommon_GenMipmaps(int width, int height, uint8_t* lvlScan0, uint8_t* scan0);
int GfxCommon_MipmapsLevels(int width, int height);
void Texture_Render(const struct Texture* tex);
void Texture_RenderShaded(const struct Texture* tex, PackedCol shadeCol);
#endif

View File

@ -1,7 +1,6 @@
#include "Gui.h"
#include "Window.h"
#include "Game.h"
#include "GraphicsCommon.h"
#include "Graphics.h"
#include "Event.h"
#include "Drawer2D.h"
@ -203,7 +202,7 @@ void Gui_FreeOverlay(void* overlay) {
void Gui_RenderGui(double delta) {
bool showHUD, hudBefore;
GfxCommon_Mode2D(Game_Width, Game_Height);
Gfx_Mode2D(Game_Width, Game_Height);
showHUD = !Gui_Active || !Gui_Active->HidesHUD;
hudBefore = !Gui_Active || !Gui_Active->RenderHUDOver;
@ -214,7 +213,7 @@ void Gui_RenderGui(double delta) {
if (showHUD && !hudBefore) { Elem_Render(Gui_HUD, delta); }
if (Gui_OverlaysCount) { Elem_Render(Gui_Overlays[0], delta); }
GfxCommon_Mode3D();
Gfx_Mode3D();
}
void Gui_OnResize(void) {
@ -287,7 +286,7 @@ void TextAtlas_Add(struct TextAtlas* atlas, int charI, VertexP3fT2fC4b** vertice
part.uv.U2 = part.uv.U1 + width * atlas->uScale;
atlas->CurX += width;
GfxCommon_Make2DQuad(&part, white, vertices);
Gfx_Make2DQuad(&part, white, vertices);
}
void TextAtlas_AddInt(struct TextAtlas* atlas, int value, VertexP3fT2fC4b** vertices) {

View File

@ -1,8 +1,8 @@
#ifndef CC_GUI_H
#define CC_GUI_H
#include "Input.h"
#include "GraphicsCommon.h"
#include "Event.h"
#include "VertexStructs.h"
/* Describes and manages 2D GUI elements on screen.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/

View File

@ -3,7 +3,6 @@
#include "Game.h"
#include "Inventory.h"
#include "Graphics.h"
#include "GraphicsCommon.h"
#include "Camera.h"
#include "ExtMath.h"
#include "Event.h"
@ -39,9 +38,9 @@ static void HeldBlockRenderer_RenderModel(void) {
model = Model_Get(&block);
held_entity.ModelScale = Vector3_Create1(0.4f);
GfxCommon_SetupAlphaState(Block_Draw[held_block]);
Gfx_SetupAlphaState(Block_Draw[held_block]);
Model_Render(model, &held_entity);
GfxCommon_RestoreAlphaState(Block_Draw[held_block]);
Gfx_RestoreAlphaState(Block_Draw[held_block]);
}
Gfx_SetTexturing(false);

View File

@ -1,6 +1,5 @@
#include "IsometricDrawer.h"
#include "Drawer.h"
#include "GraphicsCommon.h"
#include "Graphics.h"
#include "PackedCol.h"
#include "ExtMath.h"
@ -55,7 +54,7 @@ static void IsometricDrawer_Flush(void) {
if (iso_lastTexIndex != -1) {
Gfx_BindTexture(Atlas1D_TexIds[iso_lastTexIndex]);
count = (int)(iso_vertices - iso_vertices_base);
GfxCommon_UpdateDynamicVb_IndexedTris(iso_vb, iso_vertices_base, count);
Gfx_UpdateDynamicVb_IndexedTris(iso_vb, iso_vertices_base, count);
}
iso_lastTexIndex = iso_texIndex;

View File

@ -161,7 +161,7 @@ void MapRenderer_RenderNormal(double delta) {
int batch;
if (!mapChunks) return;
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetTexturing(true);
Gfx_SetAlphaTest(true);
@ -240,7 +240,7 @@ void MapRenderer_RenderTranslucent(double delta) {
/* First fill depth buffer */
vertices = Game_Vertices;
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetTexturing(false);
Gfx_SetAlphaBlending(false);
Gfx_SetColWriteMask(false, false, false, false);

View File

@ -2,7 +2,6 @@
#include "Widgets.h"
#include "Game.h"
#include "Event.h"
#include "GraphicsCommon.h"
#include "Platform.h"
#include "Inventory.h"
#include "Drawer2D.h"
@ -233,7 +232,7 @@ static void Menu_RenderBounds(void) {
Then using wolfram alpha to solve the glblendfunc equation */
PackedCol topCol = PACKEDCOL_CONST(24, 24, 24, 105);
PackedCol bottomCol = PACKEDCOL_CONST(51, 51, 98, 162);
GfxCommon_Draw2DGradient(0, 0, Game_Width, Game_Height, topCol, bottomCol);
Gfx_Draw2DGradient(0, 0, Game_Width, Game_Height, topCol, bottomCol);
}
static int Menu_DoMouseDown(void* screen, int x, int y, MouseButton btn) {
@ -900,8 +899,8 @@ static void EditHotkeyScreen_Render(void* screen, double delta) {
MenuScreen_Render(screen, delta);
x = Game_Width / 2; y = Game_Height / 2;
GfxCommon_Draw2DFlat(x - 250, y - 65, 500, 2, grey);
GfxCommon_Draw2DFlat(x - 250, y + 45, 500, 2, grey);
Gfx_Draw2DFlat(x - 250, y - 65, 500, 2, grey);
Gfx_Draw2DFlat(x - 250, y + 45, 500, 2, grey);
}
static void EditHotkeyScreen_Free(void* screen) {
@ -1311,7 +1310,7 @@ static void SaveLevelScreen_Render(void* screen, double delta) {
MenuScreen_Render(screen, delta);
x = Game_Width / 2; y = Game_Height / 2;
GfxCommon_Draw2DFlat(x - 250, y + 90, 500, 2, grey);
Gfx_Draw2DFlat(x - 250, y + 90, 500, 2, grey);
}
static void SaveLevelScreen_Free(void* screen) {
@ -1979,7 +1978,7 @@ static void MenuOptionsScreen_Render(void* screen, double delta) {
if (!s->ExtHelp.LinesCount) return;
w = &s->ExtHelp;
GfxCommon_Draw2DFlat(w->X - EXTHELP_PAD, w->Y - EXTHELP_PAD,
Gfx_Draw2DFlat(w->X - EXTHELP_PAD, w->Y - EXTHELP_PAD,
w->Width + EXTHELP_PAD * 2, w->Height + EXTHELP_PAD * 2, tableCol);
Gfx_SetTexturing(true);
@ -2996,12 +2995,12 @@ static void TexIdsOverlay_RenderTerrain(struct TexIdsOverlay* s) {
tex.uv.V1 = Atlas1D_RowId(i + s->BaseTexLoc) * Atlas1D_InvTileSize;
tex.uv.V2 = tex.uv.V1 + UV2_Scale * Atlas1D_InvTileSize;
GfxCommon_Make2DQuad(&tex, col, &ptr);
Gfx_Make2DQuad(&tex, col, &ptr);
}
Gfx_BindTexture(Atlas1D_TexIds[idx]);
count = (int)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(s->DynamicVb, vertices, count);
Gfx_UpdateDynamicVb_IndexedTris(s->DynamicVb, vertices, count);
}
}
@ -3028,7 +3027,7 @@ static void TexIdsOverlay_RenderTextOverlay(struct TexIdsOverlay* s) {
Gfx_BindTexture(idAtlas->Tex.ID);
count = (int)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(s->DynamicVb, vertices, count);
Gfx_UpdateDynamicVb_IndexedTris(s->DynamicVb, vertices, count);
ptr = vertices;
}
}
@ -3045,7 +3044,7 @@ static void TexIdsOverlay_Render(void* screen, double delta) {
Menu_RenderBounds();
Gfx_SetTexturing(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Menu_Render(s, delta);
origXOffset = s->XOffset;

View File

@ -2,7 +2,6 @@
#include "ExtMath.h"
#include "Funcs.h"
#include "Game.h"
#include "GraphicsCommon.h"
#include "Graphics.h"
#include "Entity.h"
#include "Camera.h"
@ -108,7 +107,7 @@ void Model_Render(struct Model* model, struct Entity* entity) {
if (model->Bobbing) pos.Y += entity->Anim.BobbingModel;
Model_SetupState(model, entity);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
model->GetTransform(entity, pos, &entity->Transform);
Matrix_Mul(&m, &entity->Transform, &Gfx_View);
@ -153,7 +152,7 @@ void Model_SetupState(struct Model* model, struct Entity* entity) {
void Model_UpdateVB(void) {
struct Model* model = Model_ActiveModel;
GfxCommon_UpdateDynamicVb_IndexedTris(Model_Vb, Model_Vertices, model->index);
Gfx_UpdateDynamicVb_IndexedTris(Model_Vb, Model_Vertices, model->index);
model->index = 0;
}
@ -255,7 +254,7 @@ void Model_RenderArm(struct Model* model, struct Entity* entity) {
if (model->Bobbing) pos.Y += entity->Anim.BobbingModel;
Model_SetupState(model, entity);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Model_ApplyTexture(entity);
if (Game_ClassicArmModel) {

View File

@ -6,7 +6,6 @@
#include "Entity.h"
#include "TerrainAtlas.h"
#include "Graphics.h"
#include "GraphicsCommon.h"
#include "Funcs.h"
#include "Game.h"
#include "Event.h"
@ -183,7 +182,7 @@ static void Rain_Render(float t) {
}
Gfx_BindTexture(Particles_TexId);
GfxCommon_UpdateDynamicVb_IndexedTris(Particles_VB, vertices, rain_count * 4);
Gfx_UpdateDynamicVb_IndexedTris(Particles_VB, vertices, rain_count * 4);
}
static void Rain_RemoveAt(int index) {
@ -369,7 +368,7 @@ void Particles_Render(double delta, float t) {
Gfx_SetTexturing(true);
Gfx_SetAlphaTest(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
Terrain_Render(t);
Rain_Render(t);

View File

@ -2,7 +2,6 @@
#include "PackedCol.h"
#include "VertexStructs.h"
#include "Graphics.h"
#include "GraphicsCommon.h"
#include "Game.h"
#include "Event.h"
#include "Picking.h"
@ -38,9 +37,9 @@ void PickedPosRenderer_Render(double delta) {
Gfx_SetAlphaBlending(true);
Gfx_SetDepthWrite(false);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
GfxCommon_UpdateDynamicVb_IndexedTris(pickedPos_vb, pickedPos_vertices, PICKEDPOS_NUM_VERTICES);
Gfx_UpdateDynamicVb_IndexedTris(pickedPos_vb, pickedPos_vertices, PICKEDPOS_NUM_VERTICES);
Gfx_SetDepthWrite(true);
Gfx_SetAlphaBlending(false);
}

View File

@ -2,7 +2,6 @@
#include "Widgets.h"
#include "Game.h"
#include "Event.h"
#include "GraphicsCommon.h"
#include "Platform.h"
#include "Inventory.h"
#include "Drawer2D.h"
@ -299,7 +298,7 @@ static void StatusScreen_DrawPosition(struct StatusScreen* s) {
/* Make "Position: " prefix */
tex = atlas->Tex;
tex.X = 2; tex.Width = atlas->Offset;
GfxCommon_Make2DQuad(&tex, col, &ptr);
Gfx_Make2DQuad(&tex, col, &ptr);
Vector3I_Floor(&pos, &LocalPlayer_Instance.Base.Position);
atlas->CurX = atlas->Offset + 2;
@ -316,7 +315,7 @@ static void StatusScreen_DrawPosition(struct StatusScreen* s) {
Gfx_BindTexture(atlas->Tex.ID);
/* TODO: Do we need to use a separate VB here? */
count = (int)(ptr - vertices);
GfxCommon_UpdateDynamicVb_IndexedTris(Model_Vb, vertices, count);
Gfx_UpdateDynamicVb_IndexedTris(Model_Vb, vertices, count);
}
static bool StatusScreen_HacksChanged(struct StatusScreen* s) {
@ -524,9 +523,9 @@ static void LoadingScreen_UpdateBackgroundVB(VertexP3fT2fC4b* vertices, int coun
Gfx_BindTexture(Atlas1D_TexIds[atlasIndex]);
}
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
/* TODO: Do we need to use a separate VB here? */
GfxCommon_UpdateDynamicVb_IndexedTris(Model_Vb, vertices, count);
Gfx_UpdateDynamicVb_IndexedTris(Model_Vb, vertices, count);
}
#define LOADING_TILE_SIZE 64
@ -548,7 +547,7 @@ static void LoadingScreen_DrawBackground(void) {
for (y = 0; y < Game_Height; y += LOADING_TILE_SIZE) {
tex.Y = y;
GfxCommon_Make2DQuad(&tex, col, &ptr);
Gfx_Make2DQuad(&tex, col, &ptr);
count += 4;
if (count < Array_Elems(vertices)) continue;
@ -590,8 +589,8 @@ static void LoadingScreen_Render(void* screen, double delta) {
y = Gui_CalcPos(ANCHOR_CENTRE, 34, PROG_BAR_HEIGHT, Game_Height);
progWidth = (int)(PROG_BAR_WIDTH * s->Progress);
GfxCommon_Draw2DFlat(x, y, PROG_BAR_WIDTH, PROG_BAR_HEIGHT, backCol);
GfxCommon_Draw2DFlat(x, y, progWidth, PROG_BAR_HEIGHT, progCol);
Gfx_Draw2DFlat(x, y, PROG_BAR_WIDTH, PROG_BAR_HEIGHT, backCol);
Gfx_Draw2DFlat(x, y, progWidth, PROG_BAR_HEIGHT, progCol);
}
static void LoadingScreen_Free(void* screen) {
@ -861,7 +860,7 @@ static void ChatScreen_RenderBackground(struct ChatScreen* s) {
if (height > 0) {
PackedCol backCol = PACKEDCOL_CONST(0, 0, 0, 127);
GfxCommon_Draw2DFlat(x - 5, y - 5, width + 10, height + 10, backCol);
Gfx_Draw2DFlat(x - 5, y - 5, width + 10, height + 10, backCol);
}
}
@ -1490,7 +1489,7 @@ static void DisconnectScreen_Render(void* screen, double delta) {
PackedCol bottom = PACKEDCOL_CONST(80, 16, 16, 255);
if (s->CanReconnect) { DisconnectScreen_UpdateDelayLeft(s, delta); }
GfxCommon_Draw2DGradient(0, 0, Game_Width, Game_Height, top, bottom);
Gfx_Draw2DGradient(0, 0, Game_Width, Game_Height, top, bottom);
Gfx_SetTexturing(true);
Elem_Render(&s->Title, delta);

View File

@ -1,7 +1,6 @@
#include "SelectionBox.h"
#include "ExtMath.h"
#include "Graphics.h"
#include "GraphicsCommon.h"
#include "Event.h"
#include "Funcs.h"
#include "Game.h"
@ -192,13 +191,13 @@ void Selections_Render(double delta) {
SelectionBox_Render(&selections_list[i], &facesPtr, &edgesPtr);
}
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FC4B);
GfxCommon_UpdateDynamicVb_Lines(selections_LineVB, edgeVertices,
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FC4B);
Gfx_UpdateDynamicVb_Lines(selections_LineVB, edgeVertices,
selections_count * SELECTIONS_VERTICES);
Gfx_SetDepthWrite(false);
Gfx_SetAlphaBlending(true);
GfxCommon_UpdateDynamicVb_IndexedTris(selections_VB, faceVertices,
Gfx_UpdateDynamicVb_IndexedTris(selections_VB, faceVertices,
selections_count * SELECTIONS_VERTICES);
Gfx_SetDepthWrite(true);
Gfx_SetAlphaBlending(false);

View File

@ -1,7 +1,6 @@
#include "Widgets.h"
#include "Graphics.h"
#include "Drawer2D.h"
#include "GraphicsCommon.h"
#include "ExtMath.h"
#include "Funcs.h"
#include "Window.h"
@ -141,11 +140,11 @@ static void ButtonWidget_Render(void* widget, double delta) {
back.Width = (w->Width / 2);
back.uv.U1 = 0.0f; back.uv.U2 = BUTTON_uWIDTH * scale;
GfxCommon_Draw2DTexture(&back, white);
Gfx_Draw2DTexture(&back, white);
back.X += (w->Width / 2);
back.uv.U1 = BUTTON_uWIDTH * (1.0f - scale); back.uv.U2 = BUTTON_uWIDTH;
GfxCommon_Draw2DTexture(&back, white);
Gfx_Draw2DTexture(&back, white);
}
if (!w->Texture.ID) return;
@ -225,7 +224,7 @@ static void ScrollbarWidget_Render(void* widget, double delta) {
bool hovered;
x = w->X; width = w->Width;
GfxCommon_Draw2DFlat(x, w->Y, width, w->Height, Scroll_BackCol);
Gfx_Draw2DFlat(x, w->Y, width, w->Height, Scroll_BackCol);
ScrollbarWidget_GetScrollbarCoords(w, &y, &height);
x += SCROLL_BORDER; y += w->Y;
@ -233,15 +232,15 @@ static void ScrollbarWidget_Render(void* widget, double delta) {
hovered = Gui_Contains(x, y, width, height, Mouse_X, Mouse_Y);
barCol = hovered ? Scroll_HoverCol : Scroll_BarCol;
GfxCommon_Draw2DFlat(x, y, width, height, barCol);
Gfx_Draw2DFlat(x, y, width, height, barCol);
if (height < 20) return;
x += SCROLL_NUBS_WIDTH; y += (height / 2);
width -= SCROLL_NUBS_WIDTH * 2;
GfxCommon_Draw2DFlat(x, y - 1 - 4, width, SCROLL_BORDER, Scroll_BackCol);
GfxCommon_Draw2DFlat(x, y - 1, width, SCROLL_BORDER, Scroll_BackCol);
GfxCommon_Draw2DFlat(x, y - 1 + 4, width, SCROLL_BORDER, Scroll_BackCol);
Gfx_Draw2DFlat(x, y - 1 - 4, width, SCROLL_BORDER, Scroll_BackCol);
Gfx_Draw2DFlat(x, y - 1, width, SCROLL_BORDER, Scroll_BackCol);
Gfx_Draw2DFlat(x, y - 1 + 4, width, SCROLL_BORDER, Scroll_BackCol);
}
static bool ScrollbarWidget_MouseDown(void* widget, int x, int y, MouseButton btn) {
@ -334,7 +333,7 @@ static void HotbarWidget_RenderHotbarOutline(struct HotbarWidget* w) {
w->SelTex.ID = tex;
w->SelTex.X = (int)(x - w->SelBlockSize / 2);
GfxCommon_Draw2DTexture(&w->SelTex, white);
Gfx_Draw2DTexture(&w->SelTex, white);
}
static void HotbarWidget_RenderHotbarBlocks(struct HotbarWidget* w) {
@ -655,7 +654,7 @@ static void TableWidget_Render(void* widget, double delta) {
PackedCol topSelCol = PACKEDCOL_CONST(255, 255, 255, 142);
PackedCol bottomSelCol = PACKEDCOL_CONST(255, 255, 255, 192);
GfxCommon_Draw2DGradient(Table_X(w), Table_Y(w),
Gfx_Draw2DGradient(Table_X(w), Table_Y(w),
Table_Width(w), Table_Height(w), topBackCol, bottomBackCol);
if (w->RowsCount > TABLE_MAX_ROWS_DISPLAYED) {
@ -668,11 +667,11 @@ static void TableWidget_Render(void* widget, double delta) {
off = cellSize * 0.1f;
size = (int)(cellSize + off * 2);
GfxCommon_Draw2DGradient((int)(x - off), (int)(y - off),
Gfx_Draw2DGradient((int)(x - off), (int)(y - off),
size, size, topSelCol, bottomSelCol);
}
Gfx_SetTexturing(true);
Gfx_SetBatchFormat(VERTEX_FORMAT_P3FT2FC4B);
Gfx_SetVertexFormat(VERTEX_FORMAT_P3FT2FC4B);
IsometricDrawer_BeginBatch(vertices, w->VB);
for (i = 0; i < w->ElementsCount; i++) {
@ -1465,7 +1464,7 @@ static void MenuInputWidget_Render(void* widget, double delta) {
PackedCol backCol = PACKEDCOL_CONST(30, 30, 30, 200);
Gfx_SetTexturing(false);
GfxCommon_Draw2DFlat(w->X, w->Y, w->Width, w->Height, backCol);
Gfx_Draw2DFlat(w->X, w->Y, w->Width, w->Height, backCol);
Gfx_SetTexturing(true);
Texture_Render(&w->InputTex);
@ -1642,7 +1641,7 @@ static void ChatInputWidget_Render(void* widget, double delta) {
/* Cover whole window width to match original classic behaviour */
if (Game_PureClassic) { width = max(width, Game_Width - x * 4); }
GfxCommon_Draw2DFlat(x, y, width + w->Padding * 2, w->PrefixHeight, backCol);
Gfx_Draw2DFlat(x, y, width + w->Padding * 2, w->PrefixHeight, backCol);
y += w->LineSizes[i].Height;
}
@ -2169,7 +2168,7 @@ static void PlayerListWidget_Render(void* widget, double delta) {
Gfx_SetTexturing(false);
offset = title->Height + 10;
height = max(300, w->Height + title->Height);
GfxCommon_Draw2DGradient(w->X, w->Y - offset, w->Width, height, topCol, bottomCol);
Gfx_Draw2DGradient(w->X, w->Y - offset, w->Width, height, topCol, bottomCol);
Gfx_SetTexturing(true);
title->YOffset = w->Y - offset + 5;