mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Rename FastColour to PackedCol, start work on writing D3D9 resource creation methods in C.
Do I even have a clue what I'm doing?
This commit is contained in:
parent
f6a4df5f6a
commit
4fb9af812e
@ -496,6 +496,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise resize and add more elements
|
||||
int oldLength = array.Length;
|
||||
Array.Resize(ref array, array.Length + expSize);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "BlockID.h"
|
||||
#include "BlockEnums.h"
|
||||
#include "String.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
#include "Game.h"
|
||||
#include "Vectors.h"
|
||||
#include "Bitmap.h"
|
||||
@ -31,7 +31,7 @@ String Block_Name[Block_Count];
|
||||
|
||||
/* Gets the custom fog colour that should be used when the player is standing within this block.
|
||||
Note that this is only used for exponential fog mode. */
|
||||
FastColour Block_FogColour[Block_Count];
|
||||
PackedCol Block_FogColour[Block_Count];
|
||||
|
||||
/* Gets the fog density for the given block.
|
||||
A value of 0 means this block does not apply fog.*/
|
||||
|
@ -181,7 +181,7 @@
|
||||
<ClInclude Include="TerrainAtlas2D.h" />
|
||||
<ClInclude Include="WorldEvents.h" />
|
||||
<ClInclude Include="EventHandler.h" />
|
||||
<ClInclude Include="FastColour.h" />
|
||||
<ClInclude Include="PackedCol.h" />
|
||||
<ClInclude Include="Funcs.h" />
|
||||
<ClInclude Include="Game.h" />
|
||||
<ClInclude Include="ExtMath.h" />
|
||||
@ -211,7 +211,7 @@
|
||||
<ClCompile Include="Bitmap.c" />
|
||||
<ClCompile Include="EventHandler.c" />
|
||||
<ClCompile Include="ExtMath.c" />
|
||||
<ClCompile Include="FastColour.c" />
|
||||
<ClCompile Include="PackedCol.c" />
|
||||
<ClCompile Include="Funcs.c" />
|
||||
<ClCompile Include="GraphicsCommon.c" />
|
||||
<ClCompile Include="Matrix.c" />
|
||||
|
@ -108,9 +108,6 @@
|
||||
<ClInclude Include="DefaultSet.h">
|
||||
<Filter>Header Files\Blocks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FastColour.h">
|
||||
<Filter>Header Files\2D\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BlockID.h">
|
||||
<Filter>Header Files\Blocks</Filter>
|
||||
</ClInclude>
|
||||
@ -183,6 +180,9 @@
|
||||
<ClInclude Include="TerrainAtlas2D.h">
|
||||
<Filter>Header Files\TexturePack</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="PackedCol.h">
|
||||
<Filter>Header Files\2D\Utils</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
@ -218,9 +218,6 @@
|
||||
<ClCompile Include="Vectors.c">
|
||||
<Filter>Source Files\Math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FastColour.c">
|
||||
<Filter>Source Files\2D\Utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Texture.c">
|
||||
<Filter>Source Files\Graphics</Filter>
|
||||
</ClCompile>
|
||||
@ -260,5 +257,8 @@
|
||||
<ClCompile Include="TerrainAtlas2D.c">
|
||||
<Filter>Source Files\TexturePack</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PackedCol.c">
|
||||
<Filter>Source Files\2D\Utils</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -30,20 +30,20 @@ Platform_Log(logMsg);
|
||||
|
||||
|
||||
/* We only ever create a single index buffer internally. */
|
||||
IDirect3DIndexBuffer9* d3d9_ibuffers[2];
|
||||
Int32 d3d9_ibuffersCapacity = 2;
|
||||
bool d3d9_ibuffersAllocated;
|
||||
#define d3d9_iBuffersExpSize 2
|
||||
IDirect3DIndexBuffer9* d3d9_ibuffers[d3d9_iBuffersExpSize];
|
||||
Int32 d3d9_ibuffersCapacity = d3d9_iBuffersExpSize;
|
||||
|
||||
/* TODO: This number's probably not big enough... */
|
||||
IDirect3DVertexBuffer9* d3d9_vbuffers[2048];
|
||||
Int32 d3d9_vbuffersCapacity = 2048;
|
||||
bool d3d9_vbuffersAllocated;
|
||||
#define d3d9_vBuffersExpSize 2048
|
||||
IDirect3DVertexBuffer9* d3d9_vbuffers[d3d9_vBuffersExpSize];
|
||||
Int32 d3d9_vbuffersCapacity = d3d9_vBuffersExpSize;
|
||||
|
||||
/* At most we can have 256 entities with their own texture each.
|
||||
Adding another 128 gives us a lot of leeway. */
|
||||
IDirect3DTexture9* d3d9_textures[384];
|
||||
Int32 d3d9_texturesCapacity = 384;
|
||||
bool d3d9_texturesAllocated;
|
||||
#define d3d9_texturesExpSize 384
|
||||
IDirect3DTexture9* d3d9_textures[d3d9_texturesExpSize];
|
||||
Int32 d3d9_texturesCapacity = d3d9_texturesExpSize;
|
||||
|
||||
|
||||
void Gfx_Init() {
|
||||
@ -79,9 +79,15 @@ void Gfx_Free() {
|
||||
D3D9_LogLeakedResource("Index buffer leak! ID: ", i);
|
||||
}
|
||||
|
||||
if (d3d9_ibuffersAllocated) Platform_MemFree(d3d9_ibuffers);
|
||||
if (d3d9_vbuffersAllocated) Platform_MemFree(d3d9_vbuffers);
|
||||
if (d3d9_texturesAllocated) Platform_MemFree(d3d9_textures);
|
||||
if (d3d9_ibuffersCapacity != d3d9_iBuffersExpSize) {
|
||||
Platform_MemFree(d3d9_ibuffers);
|
||||
}
|
||||
if (d3d9_vbuffersCapacity != d3d9_vBuffersExpSize) {
|
||||
Platform_MemFree(d3d9_vbuffers);
|
||||
}
|
||||
if (d3d9_texturesCapacity != d3d9_texturesExpSize) {
|
||||
Platform_MemFree(d3d9_textures);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +117,7 @@ void Gfx_SetFog(bool enabled) {
|
||||
}
|
||||
|
||||
UInt32 d3d9_fogCol = 0xFF000000; /* black */
|
||||
void Gfx_SetFogColour(FastColour col) {
|
||||
void Gfx_SetFogColour(PackedCol col) {
|
||||
if (col.Packed == d3d9_fogCol) return;
|
||||
|
||||
d3d9_fogCol = col.Packed;
|
||||
@ -203,7 +209,7 @@ void Gfx_Clear() {
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_Clear");
|
||||
}
|
||||
|
||||
void Gfx_ClearColour(FastColour col) {
|
||||
void Gfx_ClearColour(PackedCol col) {
|
||||
d3d9_clearCol = col.Packed;
|
||||
}
|
||||
|
||||
@ -233,6 +239,51 @@ void Gfx_SetDepthWrite(bool enabled) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
Int32 Gfx_CreateDynamicVb(Int32 vertexFormat, Int32 maxVertices) {
|
||||
Int32 size = maxVertices * Gfx_strideSizes[vertexFormat];
|
||||
IDirect3DVertexBuffer9* vbuffer;
|
||||
ReturnCode hresult = IDirect3DDevice9_CreateVertexBuffer(device, size, D3DUSAGE_DYNAMIC,
|
||||
d3d9_formatMappings[vertexFormat], D3DPOOL_DEFAULT, &vbuffer, NULL);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateDynamicVb");
|
||||
|
||||
return D3D9_GetOrExpand(&d3d9_vbuffers, &d3d9_vbuffersCapacity, vbuffer, d3d9_vBuffersExpSize);
|
||||
}
|
||||
|
||||
Int32 Gfx_CreateVb(void* vertices, Int32 vertexFormat, Int32 count) {
|
||||
Int32 size = count * Gfx_strideSizes[vertexFormat];
|
||||
IDirect3DVertexBuffer9* vbuffer;
|
||||
ReturnCode hresult = IDirect3DDevice9_CreateVertexBuffer(device, size, 0,
|
||||
d3d9_formatMappings[vertexFormat], D3DPOOL_DEFAULT, &vbuffer, NULL);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateVb");
|
||||
|
||||
void* dst;
|
||||
hresult = IDirect3DVertexBuffer9_Lock(vbuffer, 0, size, dst, 0);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateVb - Lock");
|
||||
Platform_MemCpy(dst, vertices, size);
|
||||
hresult = IDirect3DVertexBuffer9_Unlock(vbuffer);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateVb - Unlock");
|
||||
|
||||
return D3D9_GetOrExpand(&d3d9_vbuffers, &d3d9_vbuffersCapacity, vbuffer, d3d9_vBuffersExpSize);
|
||||
}
|
||||
|
||||
Int32 Gfx_CreateIb(void* indices, Int32 indicesCount) {
|
||||
Int32 size = indicesCount * sizeof(UInt16);
|
||||
IDirect3DIndexBuffer9* ibuffer;
|
||||
ReturnCode hresult = IDirect3DDevice9_CreateIndexBuffer(device, size, 0,
|
||||
D3DFMT_INDEX16, D3DPOOL_MANAGED, &ibuffer, NULL);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateIb");
|
||||
|
||||
void* dst;
|
||||
hresult = IDirect3DIndexBuffer9_Lock(ibuffer, 0, size, dst, 0);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateIb - Lock");
|
||||
Platform_MemCpy(dst, indices, size);
|
||||
hresult = IDirect3DIndexBuffer9_Unlock(ibuffer);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_CreateIb - Unlock");
|
||||
|
||||
return D3D9_GetOrExpand(&d3d9_ibuffers, &d3d9_ibuffersCapacity, ibuffer, d3d9_iBuffersExpSize);
|
||||
}
|
||||
|
||||
Int32 d3d9_batchStride;
|
||||
void Gfx_BindVb(Int32 vb) {
|
||||
ReturnCode hresult = IDirect3DDevice9_SetStreamSource(device, 0, d3d9_vbuffers[vb], 0, d3d9_batchStride);
|
||||
@ -265,6 +316,21 @@ void Gfx_DrawVb(Int32 drawMode, Int32 startVertex, Int32 vCount) {
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_DrawVb");
|
||||
}
|
||||
|
||||
void Gfx_SetDynamicVbData(Int32 vb, void* vertices, Int32 vCount) {
|
||||
Int32 size = vCount * d3d9_batchStride;
|
||||
IDirect3DVertexBuffer9* vbuffer = d3d9_vbuffers[vb];
|
||||
|
||||
void* dst;
|
||||
ReturnCode hresult = IDirect3DVertexBuffer9_Lock(vbuffer, 0, size, dst, D3DLOCK_DISCARD);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_SetDynamicVbData - Lock");
|
||||
Platform_MemCpy(dst, vertices, size);
|
||||
hresult = IDirect3DVertexBuffer9_Unlock(vbuffer);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_SetDynamicVbData - Unlock");
|
||||
|
||||
hresult = IDirect3DDevice9_SetStreamSource(device, 0, d3d9_vbuffers[vb], 0, d3d9_batchStride);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_SetDynamicVbData - Bind");
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedVb(Int32 drawMode, Int32 indicesCount, Int32 startIndex) {
|
||||
Int32 numPrims = D3D9_NumPrimitives(drawMode, indicesCount);
|
||||
ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, d3d9_modeMappings[drawMode], 0,
|
||||
@ -383,4 +449,36 @@ void D3D9_DeleteResource(void** resources, Int32 capacity, Int32* id) {
|
||||
String_AppendInt32(&logMsg, resourceID);
|
||||
Platform_Log(logMsg);
|
||||
}
|
||||
|
||||
Int32 D3D9_GetOrExpand(void*** resourcesPtr, Int32* capacity, void* resource, Int32 expSize) {
|
||||
Int32 i;
|
||||
void** resources = *resourcesPtr;
|
||||
for (i = 1; i < *capacity; i++) {
|
||||
if (resources[i] == NULL) {
|
||||
resources[i] = resource;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise resize and add more elements
|
||||
Int32 oldLength = *capacity;
|
||||
(*capacity) += expSize;
|
||||
|
||||
// Allocate resized pointers table
|
||||
void** newResources = Platform_MemAlloc(*capacity * sizeof(void*));
|
||||
if (newResources == NULL) {
|
||||
ErrorHandler_Fail("D3D9 - failed to resize pointers table");
|
||||
}
|
||||
*resourcesPtr = newResources;
|
||||
|
||||
// Update elements in new table
|
||||
for (i = 0; i < oldLength; i++) {
|
||||
newResources[i] = resources[i];
|
||||
}
|
||||
// Free old allocated memory if necessary
|
||||
if (oldLength != expSize) Platform_MemFree(resources);
|
||||
|
||||
newResources[oldLength] = resource;
|
||||
return oldLength;
|
||||
}
|
||||
#endif
|
@ -35,4 +35,5 @@ Int32 d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFV
|
||||
|
||||
static void D3D9_DeleteResource(void** resources, Int32 capacity, Int32* id);
|
||||
|
||||
static Int32 D3D9_GetOrExpand(void*** resourcesPtr, Int32* capacity, void* resource, Int32 expSize);
|
||||
#endif
|
@ -22,12 +22,12 @@ Real32 DefaultSet_FogDensity(BlockID b) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
FastColour DefaultSet_FogColour(BlockID b) {
|
||||
PackedCol DefaultSet_FogColour(BlockID b) {
|
||||
if (b == BlockID_Water || b == BlockID_StillWater)
|
||||
return FastColour_Create3(5, 5, 51);
|
||||
return PackedCol_Create3(5, 5, 51);
|
||||
if (b == BlockID_Lava || b == BlockID_StillLava)
|
||||
return FastColour_Create3(153, 25, 0);
|
||||
return FastColour_Create4(0, 0, 0, 0);
|
||||
return PackedCol_Create3(153, 25, 0);
|
||||
return PackedCol_Create4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
UInt8 DefaultSet_Collide(BlockID b) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CS_DEFAULT_BLOCKS_H
|
||||
#define CS_DEFAULT_BLOCKS_H
|
||||
#include "Typedefs.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
/* List of properties for core blocks.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
@ -16,7 +16,7 @@ bool DefaultSet_FullBright(BlockID b);
|
||||
Real32 DefaultSet_FogDensity(BlockID b);
|
||||
|
||||
/* Gets the fog colour of this block. */
|
||||
FastColour DefaultSet_FogColour(BlockID b);
|
||||
PackedCol DefaultSet_FogColour(BlockID b);
|
||||
|
||||
/* Gets the collide type of a block. */
|
||||
UInt8 DefaultSet_Collide(BlockID b);
|
||||
|
@ -1,24 +0,0 @@
|
||||
#include "FastColour.h"
|
||||
|
||||
FastColour FastColour_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a) {
|
||||
FastColour col;
|
||||
col.R = r; col.G = g; col.B = b; col.A = a;
|
||||
return col;
|
||||
}
|
||||
|
||||
FastColour FastColour_Create3(UInt8 r, UInt8 g, UInt8 b) {
|
||||
FastColour col;
|
||||
col.R = r; col.G = g; col.B = b; col.A = 255;
|
||||
return col;
|
||||
}
|
||||
|
||||
bool FastColour_Equals(FastColour a, FastColour b) {
|
||||
return a.Packed == b.Packed;
|
||||
}
|
||||
|
||||
FastColour FastColour_Scale(FastColour value, Real32 t) {
|
||||
value.R = (UInt8)(value.R * t);
|
||||
value.G = (UInt8)(value.G * t);
|
||||
value.B = (UInt8)(value.B * t);
|
||||
return value;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#ifndef FASTCOLOUR_H
|
||||
#define FASTCOLOUR_H
|
||||
#include "Typedefs.h"
|
||||
/* Manipulates an ARGB colour, in a format suitable for the native graphics api.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
/* Represents an ARGB colour, in a format suitable for the native graphics api. */
|
||||
typedef struct FastColour {
|
||||
union {
|
||||
#if USE_DX
|
||||
struct { UInt8 B; UInt8 G; UInt8 R; UInt8 A; };
|
||||
#else
|
||||
struct { UInt8 R; UInt8 G; UInt8 B; UInt8 A; };
|
||||
#endif
|
||||
UInt32 Packed;
|
||||
};
|
||||
} FastColour;
|
||||
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
FastColour FastColour_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a);
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
FastColour FastColour_Create3(UInt8 r, UInt8 g, UInt8 b);
|
||||
|
||||
/* Returns whether two packed colours are equal. */
|
||||
bool FastColour_Equals(FastColour a, FastColour b);
|
||||
|
||||
/* Multiplies the RGB components by t, where t is in [0, 1] */
|
||||
FastColour FastColour_Scale(FastColour value, Real32 t);
|
||||
|
||||
/* TODO: actual constant values? may need to rethink FastColour */
|
||||
#define FastColour_White FastColour_Create3(255, 255, 255)
|
||||
#endif
|
@ -3,7 +3,7 @@
|
||||
#include "Typedefs.h"
|
||||
#include "EventHandler.h"
|
||||
#include "Bitmap.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
#include "String.h"
|
||||
#include "Matrix.h"
|
||||
#include "Game.h"
|
||||
@ -68,7 +68,7 @@ void Gfx_SetTexturing(bool enabled);
|
||||
void Gfx_SetFog(bool enabled);
|
||||
|
||||
/* Sets the fog colour that is blended with final primitive colours. */
|
||||
void Gfx_SetFogColour(FastColour col);
|
||||
void Gfx_SetFogColour(PackedCol col);
|
||||
|
||||
/* Sets the density of exp and exp^2 fog */
|
||||
void Gfx_SetFogDensity(Real32 value);
|
||||
@ -106,7 +106,7 @@ void Gfx_SetAlphaArgBlend(bool enabled);
|
||||
void Gfx_Clear();
|
||||
|
||||
/* Sets the colour the screen is cleared to when Clear() is called. */
|
||||
void Gfx_ClearColour(FastColour col);
|
||||
void Gfx_ClearColour(PackedCol col);
|
||||
|
||||
|
||||
/* Whether depth testing is currently enabled. */
|
||||
|
@ -43,7 +43,7 @@ void GfxCommon_UpdateDynamicIndexedVb(Int32 drawMode, Int32 vb, void* vertices,
|
||||
}
|
||||
|
||||
void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
FastColour col) {
|
||||
PackedCol col) {
|
||||
VertexP3fC4b quadVerts[4];
|
||||
VertexP3C4b_Set(&quadVerts[0], x, y, 0, col);
|
||||
VertexP3C4b_Set(&quadVerts[1], x + width, y, 0, col);
|
||||
@ -55,7 +55,7 @@ void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
}
|
||||
|
||||
void GfxCommon_Draw2DGradient(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
FastColour topCol, FastColour bottomCol) {
|
||||
PackedCol topCol, PackedCol bottomCol) {
|
||||
VertexP3fC4b quadVerts[4];
|
||||
VertexP3C4b_Set(&quadVerts[0], x, y, 0, topCol);
|
||||
VertexP3C4b_Set(&quadVerts[1], x + width, y, 0, topCol);
|
||||
@ -66,7 +66,7 @@ void GfxCommon_Draw2DGradient(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
GfxCommon_UpdateDynamicIndexedVb(DrawMode_Triangles, GfxCommon_quadVb, quadVerts, 4);
|
||||
}
|
||||
|
||||
void GfxCommon_Draw2DTexture(Texture* tex, FastColour col) {
|
||||
void GfxCommon_Draw2DTexture(Texture* tex, PackedCol col) {
|
||||
VertexP3fT2fC4b texVerts[4];
|
||||
VertexP3fT2fC4b* ptr = texVerts;
|
||||
GfxCommon_Make2DQuad(tex, col, &ptr);
|
||||
@ -74,7 +74,7 @@ void GfxCommon_Draw2DTexture(Texture* tex, FastColour col) {
|
||||
GfxCommon_UpdateDynamicIndexedVb(DrawMode_Triangles, GfxCommon_texVb, texVerts, 4);
|
||||
}
|
||||
|
||||
void GfxCommon_Make2DQuad(Texture* tex, FastColour col, VertexP3fT2fC4b** vertices) {
|
||||
void GfxCommon_Make2DQuad(Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices) {
|
||||
Real32 x1 = tex->X, y1 = tex->Y, x2 = tex->X + tex->Width, y2 = tex->Y + tex->Height;
|
||||
#if USE_DX
|
||||
/* NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CS_GFXCOMMON_H
|
||||
#define CS_GFXCOMMON_H
|
||||
#include "Typedefs.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
#include "String.h"
|
||||
#include "Texture.h"
|
||||
#include "VertexStructs.h"
|
||||
@ -36,20 +36,20 @@ Int32 GfxCommon_quadVb;
|
||||
|
||||
/* Draws a 2D flat coloured quad to the screen.*/
|
||||
void GfxCommon_Draw2DFlat(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
FastColour col);
|
||||
PackedCol col);
|
||||
|
||||
/* Draws a 2D gradient coloured quad to the screen.*/
|
||||
void GfxCommon_Draw2DGradient(Real32 x, Real32 y, Real32 width, Real32 height,
|
||||
FastColour topCol, FastColour bottomCol);
|
||||
PackedCol topCol, PackedCol bottomCol);
|
||||
|
||||
|
||||
int GfxCommon_texVb;
|
||||
|
||||
/* Draws a 2D texture to the screen. */
|
||||
void GfxCommon_Draw2DTexture(Texture* tex, FastColour col);
|
||||
void GfxCommon_Draw2DTexture(Texture* tex, PackedCol col);
|
||||
|
||||
/* Makes the 2D vertices that compose a texture quad.*/
|
||||
void GfxCommon_Make2DQuad(Texture* tex, FastColour col, VertexP3fT2fC4b** vertices);
|
||||
void GfxCommon_Make2DQuad(Texture* tex, PackedCol col, VertexP3fT2fC4b** vertices);
|
||||
|
||||
|
||||
/* Updates the various matrix stacks and properties so that the graphics API state
|
||||
|
30
src/Client/PackedCol.c
Normal file
30
src/Client/PackedCol.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "PackedCol.h"
|
||||
|
||||
PackedCol PackedCol_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a) {
|
||||
PackedCol col;
|
||||
col.R = r; col.G = g; col.B = b; col.A = a;
|
||||
return col;
|
||||
}
|
||||
|
||||
PackedCol PackedCol_Create3(UInt8 r, UInt8 g, UInt8 b) {
|
||||
PackedCol col;
|
||||
col.R = r; col.G = g; col.B = b; col.A = 255;
|
||||
return col;
|
||||
}
|
||||
|
||||
bool PackedCol_Equals(PackedCol a, PackedCol b) {
|
||||
return a.Packed == b.Packed;
|
||||
}
|
||||
|
||||
PackedCol PackedCol_Scale(PackedCol value, Real32 t) {
|
||||
value.R = (UInt8)(value.R * t);
|
||||
value.G = (UInt8)(value.G * t);
|
||||
value.B = (UInt8)(value.B * t);
|
||||
return value;
|
||||
}
|
||||
|
||||
void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yBottom) {
|
||||
*xSide = PackedCol_Scale(normal, PackedCol_ShadeX);
|
||||
*zSide = PackedCol_Scale(normal, PackedCol_ShadeZ);
|
||||
*yBottom = PackedCol_Scale(normal, PackedCol_ShadeYBottom);
|
||||
}
|
44
src/Client/PackedCol.h
Normal file
44
src/Client/PackedCol.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef FASTCOLOUR_H
|
||||
#define FASTCOLOUR_H
|
||||
#include "Typedefs.h"
|
||||
/* Manipulates an ARGB colour, in a format suitable for the native graphics api.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
/* Represents an ARGB colour, in a format suitable for the native graphics api. */
|
||||
typedef struct PackedCol {
|
||||
union {
|
||||
#if USE_DX
|
||||
struct { UInt8 B; UInt8 G; UInt8 R; UInt8 A; };
|
||||
#else
|
||||
struct { UInt8 R; UInt8 G; UInt8 B; UInt8 A; };
|
||||
#endif
|
||||
UInt32 Packed;
|
||||
};
|
||||
} PackedCol;
|
||||
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
PackedCol PackedCol_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a);
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
PackedCol PackedCol_Create3(UInt8 r, UInt8 g, UInt8 b);
|
||||
|
||||
/* Returns whether two packed colours are equal. */
|
||||
bool PackedCol_Equals(PackedCol a, PackedCol b);
|
||||
|
||||
/* Multiplies the RGB components by t, where t is in [0, 1] */
|
||||
PackedCol PackedCol_Scale(PackedCol value, Real32 t);
|
||||
|
||||
|
||||
#define PackedCol_ShadeX 0.6f
|
||||
#define PackedCol_ShadeZ 0.8f
|
||||
#define PackedCol_ShadeYBottom 0.5f
|
||||
|
||||
/* Retrieves shaded colours for ambient block face lighting. */
|
||||
void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yBottom);
|
||||
|
||||
|
||||
/* TODO: actual constant values? may need to rethink PackedCol */
|
||||
#define FastColour_White PackedCol_Create3(255, 255, 255)
|
||||
#endif
|
@ -34,7 +34,7 @@ void Texture_Render(Texture* tex) {
|
||||
GfxCommon_Draw2DTexture(tex, FastColour_White);
|
||||
}
|
||||
|
||||
void Texture_RenderShaded(Texture* tex, FastColour shadeColour) {
|
||||
void Texture_RenderShaded(Texture* tex, PackedCol shadeColour) {
|
||||
Gfx_BindTexture(tex->ID);
|
||||
GfxCommon_Draw2DTexture(tex, shadeColour);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#ifndef CS_TEXTURE_H
|
||||
#define CS_TEXTURE_H
|
||||
#include "Typedefs.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
#include "TextureRec.h"
|
||||
|
||||
/* Represents a simple 2D textured quad.
|
||||
@ -47,5 +47,5 @@ bool Texture_IsValid(Texture* tex);
|
||||
void Texture_Render(Texture* tex);
|
||||
|
||||
/* Renders this texture to the screen, with the given colour as a shade. */
|
||||
void Texture_RenderShaded(Texture* tex, FastColour shadeColour);
|
||||
void Texture_RenderShaded(Texture* tex, PackedCol shadeColour);
|
||||
#endif
|
@ -1,12 +1,12 @@
|
||||
#include "VertexStructs.h"
|
||||
|
||||
void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, FastColour col) {
|
||||
void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, PackedCol col) {
|
||||
target->X = x; target->Y = y; target->Z = z;
|
||||
target->Colour = col;
|
||||
}
|
||||
|
||||
void VertexP3fT2fC4b_Set(VertexP3fT2fC4b* target, Real32 x, Real32 y, Real32 z,
|
||||
Real32 u, Real32 v, FastColour col) {
|
||||
Real32 u, Real32 v, PackedCol col) {
|
||||
target->X = x; target->Y = y; target->Z = z;
|
||||
target->Colour = col; target->U = u; target->V = v;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#ifndef CS_VERTEXSTRUCTS_H
|
||||
#define CS_VERTEXSTRUCTS_H
|
||||
#include "Typedefs.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
/* Represents simple vertex formats.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
@ -10,10 +10,10 @@
|
||||
/* 3 floats for position (XYZ), 4 bytes for colour. */
|
||||
typedef struct VertexP3fC4b {
|
||||
Real32 X, Y, Z;
|
||||
FastColour Colour;
|
||||
PackedCol Colour;
|
||||
} VertexP3fC4b;
|
||||
|
||||
void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, FastColour col);
|
||||
void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, PackedCol col);
|
||||
|
||||
/* 3 * 4 + 4 * 1 */
|
||||
#define VertexP3fC4b_Size 16
|
||||
@ -22,12 +22,12 @@ void VertexP3C4b_Set(VertexP3fC4b* target, Real32 x, Real32 y, Real32 z, FastCol
|
||||
/* 3 floats for position (XYZ), 2 floats for texture coordinates (UV), 4 bytes for colour. */
|
||||
typedef struct VertexP3fT2fC4b {
|
||||
Real32 X, Y, Z;
|
||||
FastColour Colour;
|
||||
PackedCol Colour;
|
||||
Real32 U, V;
|
||||
} VertexP3fT2fC4b;
|
||||
|
||||
void VertexP3fT2fC4b_Set(VertexP3fT2fC4b* target, Real32 x, Real32 y, Real32 z,
|
||||
Real32 u, Real32 v, FastColour col);
|
||||
Real32 u, Real32 v, PackedCol col);
|
||||
|
||||
/* 3 * 4 + 2 * 4 + 4 * 1 */
|
||||
#define VertexP3fT2fC4b_Size 24;
|
||||
|
@ -23,15 +23,15 @@ WorldEvents_RaiseEnvVariableChanged(envVar);
|
||||
|
||||
/* Sets a colour and potentially raises event. */
|
||||
#define WorldEnv_SetCol(value, dst, envVar)\
|
||||
if (FastColour_Equals(value, dst)) return;\
|
||||
if (PackedCol_Equals(value, dst)) return;\
|
||||
dst = value;\
|
||||
WorldEvents_RaiseEnvVariableChanged(envVar);
|
||||
|
||||
|
||||
void WorldEnv_Reset() {
|
||||
WorldEnv_DefaultSkyCol = FastColour_Create3(0x99, 0xCC, 0xFF);
|
||||
WorldEnv_DefaultFogCol = FastColour_Create3(0xFF, 0xFF, 0xFF);
|
||||
WorldEnv_DefaultCloudsCol = FastColour_Create3(0xFF, 0xFF, 0xFF);
|
||||
WorldEnv_DefaultSkyCol = PackedCol_Create3(0x99, 0xCC, 0xFF);
|
||||
WorldEnv_DefaultFogCol = PackedCol_Create3(0xFF, 0xFF, 0xFF);
|
||||
WorldEnv_DefaultCloudsCol = PackedCol_Create3(0xFF, 0xFF, 0xFF);
|
||||
|
||||
WorldEnv_EdgeHeight = -1;
|
||||
WorldEnv_SidesOffset = -2;
|
||||
@ -53,16 +53,16 @@ void WorldEnv_Reset() {
|
||||
}
|
||||
|
||||
void WorldEnv_ResetLight() {
|
||||
WorldEnv_DefaultShadowCol = FastColour_Create3(0x9B, 0x9B, 0x9B);
|
||||
WorldEnv_DefaultSunCol = FastColour_Create3(0xFF, 0xFF, 0xFF);
|
||||
WorldEnv_DefaultShadowCol = PackedCol_Create3(0x9B, 0x9B, 0x9B);
|
||||
WorldEnv_DefaultSunCol = PackedCol_Create3(0xFF, 0xFF, 0xFF);
|
||||
|
||||
WorldEnv_ShadowCol = WorldEnv_DefaultShadowCol;
|
||||
FastColour_GetShaded(WorldEnv_ShadowCol, &WorldEnv_ShadowXSide,
|
||||
&WorldEnv_ShadowZSide, &WorldEnv_ShadowYBottom);
|
||||
PackedCol_GetShaded(WorldEnv_ShadowCol, &WorldEnv_ShadowXSide,
|
||||
&WorldEnv_ShadowZSide, &WorldEnv_ShadowYBottom);
|
||||
|
||||
WorldEnv_SunCol = WorldEnv_DefaultSunCol;
|
||||
FastColour_GetShaded(WorldEnv_SunCol, &WorldEnv_SunXSide,
|
||||
&WorldEnv_SunZSide, &WorldEnv_SunYBottom);
|
||||
PackedCol_GetShaded(WorldEnv_SunCol, &WorldEnv_SunXSide,
|
||||
&WorldEnv_SunZSide, &WorldEnv_SunYBottom);
|
||||
}
|
||||
|
||||
|
||||
@ -110,32 +110,32 @@ void WorldEnv_SetExpFog(bool expFog) {
|
||||
}
|
||||
|
||||
|
||||
void WorldEnv_SetSkyCol(FastColour col) {
|
||||
void WorldEnv_SetSkyCol(PackedCol col) {
|
||||
WorldEnv_SetCol(col, WorldEnv_SkyCol, EnvVar_SkyCol);
|
||||
}
|
||||
|
||||
void WorldEnv_SetFogCol(FastColour col) {
|
||||
void WorldEnv_SetFogCol(PackedCol col) {
|
||||
WorldEnv_SetCol(col, WorldEnv_FogCol, EnvVar_FogCol);
|
||||
}
|
||||
|
||||
void WorldEnv_SetCloudsCol(FastColour col) {
|
||||
void WorldEnv_SetCloudsCol(PackedCol col) {
|
||||
WorldEnv_SetCol(col, WorldEnv_CloudsCol, EnvVar_CloudsCol);
|
||||
}
|
||||
|
||||
void WorldEnv_SetSunCol(FastColour col) {
|
||||
if (FastColour_Equals(col, WorldEnv_SunCol)) return;
|
||||
void WorldEnv_SetSunCol(PackedCol col) {
|
||||
if (PackedCol_Equals(col, WorldEnv_SunCol)) return;
|
||||
|
||||
WorldEnv_SunCol = col;
|
||||
FastColour_GetShaded(WorldEnv_SunCol, &WorldEnv_SunXSide,
|
||||
&WorldEnv_SunZSide, &WorldEnv_SunYBottom);
|
||||
PackedCol_GetShaded(WorldEnv_SunCol, &WorldEnv_SunXSide,
|
||||
&WorldEnv_SunZSide, &WorldEnv_SunYBottom);
|
||||
WorldEvents_RaiseEnvVariableChanged(EnvVar_SunCol);
|
||||
}
|
||||
|
||||
void WorldEnv_SetShadowCol(FastColour col) {
|
||||
if (FastColour_Equals(col, WorldEnv_ShadowCol)) return;
|
||||
void WorldEnv_SetShadowCol(PackedCol col) {
|
||||
if (PackedCol_Equals(col, WorldEnv_ShadowCol)) return;
|
||||
|
||||
WorldEnv_ShadowCol = col;
|
||||
FastColour_GetShaded(WorldEnv_ShadowCol, &WorldEnv_ShadowXSide,
|
||||
PackedCol_GetShaded(WorldEnv_ShadowCol, &WorldEnv_ShadowXSide,
|
||||
&WorldEnv_ShadowZSide, &WorldEnv_ShadowYBottom);
|
||||
WorldEvents_RaiseEnvVariableChanged(EnvVar_ShadowCol);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#ifndef CS_WORLDENV_H
|
||||
#define CS_WORLDENV_H
|
||||
#include "Typedefs.h"
|
||||
#include "FastColour.h"
|
||||
#include "PackedCol.h"
|
||||
#include "BlockID.h"
|
||||
/* Contains environment metadata for a world.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
@ -47,27 +47,27 @@ extern bool WorldEnv_ExpFog;
|
||||
|
||||
|
||||
/* Colour of the sky located behind / above clouds. */
|
||||
FastColour WorldEnv_SkyCol;
|
||||
FastColour WorldEnv_DefaultSkyCol;
|
||||
PackedCol WorldEnv_SkyCol;
|
||||
PackedCol WorldEnv_DefaultSkyCol;
|
||||
|
||||
/* Colour applied to the fog/horizon looking out horizontally.
|
||||
Note the true horizon colour is a blend of this and sky colour. */
|
||||
FastColour WorldEnv_FogCol;
|
||||
FastColour WorldEnv_DefaultFogCol;
|
||||
PackedCol WorldEnv_FogCol;
|
||||
PackedCol WorldEnv_DefaultFogCol;
|
||||
|
||||
/* Colour applied to the clouds. */
|
||||
FastColour WorldEnv_CloudsCol;
|
||||
FastColour WorldEnv_DefaultCloudsCol;
|
||||
PackedCol WorldEnv_CloudsCol;
|
||||
PackedCol WorldEnv_DefaultCloudsCol;
|
||||
|
||||
/* Colour applied to blocks located in direct sunlight. */
|
||||
FastColour WorldEnv_SunCol;
|
||||
FastColour WorldEnv_SunXSide, WorldEnv_SunZSide, WorldEnv_SunYBottom;
|
||||
FastColour WorldEnv_DefaultSunCol;
|
||||
PackedCol WorldEnv_SunCol;
|
||||
PackedCol WorldEnv_SunXSide, WorldEnv_SunZSide, WorldEnv_SunYBottom;
|
||||
PackedCol WorldEnv_DefaultSunCol;
|
||||
|
||||
/* Colour applied to blocks located in shadow / hidden from direct sunlight. */
|
||||
FastColour WorldEnv_ShadowCol;
|
||||
FastColour WorldEnv_ShadowXSide, WorldEnv_ShadowZSide, WorldEnv_ShadowYBottom;
|
||||
FastColour WorldEnv_DefaultShadowCol;
|
||||
PackedCol WorldEnv_ShadowCol;
|
||||
PackedCol WorldEnv_ShadowXSide, WorldEnv_ShadowZSide, WorldEnv_ShadowYBottom;
|
||||
PackedCol WorldEnv_DefaultShadowCol;
|
||||
|
||||
|
||||
/* Resets all of the environment properties to their defaults. */
|
||||
@ -110,17 +110,17 @@ void WorldEnv_SetExpFog(bool expFog);
|
||||
|
||||
|
||||
/* Sets sky colour, raises event with variable 'SkyCol'. */
|
||||
void WorldEnv_SetSkyCol(FastColour col);
|
||||
void WorldEnv_SetSkyCol(PackedCol col);
|
||||
|
||||
/* Sets fog colour, raises event with variable 'FogCol'. */
|
||||
void WorldEnv_SetFogCol(FastColour col);
|
||||
void WorldEnv_SetFogCol(PackedCol col);
|
||||
|
||||
/* Sets clouds colour, and raises event with variable 'CloudsCol'. */
|
||||
void WorldEnv_SetCloudsCol(FastColour col);
|
||||
void WorldEnv_SetCloudsCol(PackedCol col);
|
||||
|
||||
/* Sets sun colour, and raises event with variable 'SunCol'. */
|
||||
void WorldEnv_SetSunCol(FastColour col);
|
||||
void WorldEnv_SetSunCol(PackedCol col);
|
||||
|
||||
/* Sets shadow colour, and raises event with variable 'ShadowCol'. */
|
||||
void WorldEnv_SetShadowCol(FastColour col);
|
||||
void WorldEnv_SetShadowCol(PackedCol col);
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user