fix opengl 1.1 backend to semi show map properly again

This commit is contained in:
UnknownShadow200 2018-05-31 15:59:38 +10:00
parent 7a7c5f1586
commit 3a8c3d1f99
9 changed files with 86 additions and 26 deletions

View File

@ -60,7 +60,7 @@ namespace ClassicalSharp.GraphicsAPI {
} else {
throw new InvalidOperationException(
"Only OpenGL 1.1 supported\r\n\r\n" +
"Compile the game with CC_BUILD_GL11, or ask on the classicube forums for it");
"Compile the game with GL11, or ask on the classicube forums for it");
}
}
@ -269,7 +269,6 @@ namespace ClassicalSharp.GraphicsAPI {
SetBatchFormat(format);
int list = GL.GenLists(1);
GL.NewList(list, 0x1300);
count &= ~0x01; // Need to get rid of the 1 extra element, see comment in chunk mesh builder for why
const int maxIndices = 65536 / 4 * 6;
ushort* indicesPtr = stackalloc ushort[maxIndices];

View File

@ -165,10 +165,12 @@ namespace ClassicalSharp {
int totalVerts = TotalVerticesCount();
if (totalVerts == 0) return;
#if !GL11
fixed (VertexP3fT2fC4b* ptr = vertices) {
// add an extra element to fix crashing on some GPUs
info.VbId = game.Graphics.CreateVb((IntPtr)ptr, VertexFormat.P3fT2fC4b, totalVerts + 1);
info.Vb = game.Graphics.CreateVb((IntPtr)ptr, VertexFormat.P3fT2fC4b, totalVerts + 1);
}
#endif
int offset = 0;
for (int i = 0; i < arraysCount; i++) {
@ -190,6 +192,13 @@ namespace ClassicalSharp {
info.Offset = offset;
offset += vertCount;
#if GL11
fixed (VertexP3fT2fC4b* ptr = vertices) {
VertexP3fT2fC4b* ptr2 = ptr + info.Offset;
info.Vb = game.Graphics.CreateVb((IntPtr)ptr, VertexFormat.P3fT2fC4b, vertCount);
}
#endif
info.LeftCount = (ushort)part.vCount[Side.Left];
info.RightCount = (ushort)part.vCount[Side.Right];
info.FrontCount = (ushort)part.vCount[Side.Front];

View File

@ -231,13 +231,18 @@ namespace ClassicalSharp.Renderers {
info.OcclusionFlags = 0;
info.OccludedFlags = 0;
#endif
game.Graphics.DeleteVb(ref info.VbId);
#if !GL11
game.Graphics.DeleteVb(ref info.Vb);
#endif
if (info.NormalParts != null) {
ChunkPartInfo[] parts = info.NormalParts;
for (int i = 0; i < parts.Length; i++) {
if (parts[i].Offset < 0) continue;
renderer.normalPartsCount[i]--;
#if GL11
game.Graphics.DeleteVb(ref parts[i].Vb);
#endif
}
info.NormalParts = null;
}
@ -247,6 +252,9 @@ namespace ClassicalSharp.Renderers {
for (int i = 0; i < parts.Length; i++) {
if (parts[i].Offset < 0) continue;
renderer.translucentPartsCount[i]--;
#if GL11
game.Graphics.DeleteVb(ref parts[i].Vb);
#endif
}
info.TranslucentParts = null;
}

View File

@ -11,6 +11,9 @@ using BlockID = System.UInt16;
namespace ClassicalSharp.Renderers {
public struct ChunkPartInfo {
#if GL11
public int Vb;
#endif
public int Offset, SpriteCount;
public ushort LeftCount, RightCount, FrontCount, BackCount, BottomCount, TopCount;
}
@ -25,7 +28,9 @@ namespace ClassicalSharp.Renderers {
public bool Visited = false, Occluded = false;
public byte OcclusionFlags, OccludedFlags, DistanceFlags;
#endif
public int VbId;
#if !GL11
public int Vb;
#endif
public ChunkPartInfo[] NormalParts;
public ChunkPartInfo[] TranslucentParts;
@ -181,13 +186,17 @@ namespace ClassicalSharp.Renderers {
if (part.Offset < 0) continue;
usedNormal[batch] = true;
gfx.BindVb(info.VbId);
bool drawLeft = info.DrawLeft && part.LeftCount > 0;
bool drawRight = info.DrawRight && part.RightCount > 0;
#if !GL11
gfx.BindVb(info.Vb);
#else
gfx.BindVb(part.Vb);
#endif
bool drawLeft = info.DrawLeft && part.LeftCount > 0;
bool drawRight = info.DrawRight && part.RightCount > 0;
bool drawBottom = info.DrawBottom && part.BottomCount > 0;
bool drawTop = info.DrawTop && part.TopCount > 0;
bool drawFront = info.DrawFront && part.FrontCount > 0;
bool drawBack = info.DrawBack && part.BackCount > 0;
bool drawTop = info.DrawTop && part.TopCount > 0;
bool drawFront = info.DrawFront && part.FrontCount > 0;
bool drawBack = info.DrawBack && part.BackCount > 0;
int offset = part.Offset + part.SpriteCount;
if (drawLeft && drawRight) {
@ -265,13 +274,17 @@ namespace ClassicalSharp.Renderers {
if (part.Offset < 0) continue;
usedTranslucent[batch] = true;
gfx.BindVb(info.VbId);
bool drawLeft = (inTranslucent || info.DrawLeft) && part.LeftCount > 0;
bool drawRight = (inTranslucent || info.DrawRight) && part.RightCount > 0;
#if !GL11
gfx.BindVb(info.Vb);
#else
gfx.BindVb(part.Vb);
#endif
bool drawLeft = (inTranslucent || info.DrawLeft) && part.LeftCount > 0;
bool drawRight = (inTranslucent || info.DrawRight) && part.RightCount > 0;
bool drawBottom = (inTranslucent || info.DrawBottom) && part.BottomCount > 0;
bool drawTop = (inTranslucent || info.DrawTop) && part.TopCount > 0;
bool drawFront = (inTranslucent || info.DrawFront) && part.FrontCount > 0;
bool drawBack = (inTranslucent || info.DrawBack) && part.BackCount > 0;
bool drawTop = (inTranslucent || info.DrawTop) && part.TopCount > 0;
bool drawFront = (inTranslucent || info.DrawFront) && part.FrontCount > 0;
bool drawBack = (inTranslucent || info.DrawBack) && part.BackCount > 0;
int offset = part.Offset;
if (drawLeft && drawRight) {

View File

@ -98,6 +98,10 @@ static void Builder_SetPartInfo(Builder1DPart* part, Int32* offset, ChunkPartInf
*offset += vCount;
*hasParts = true;
#if CC_BUILD_GL11
info->Vb = Gfx_CreateVb(&Builder_Vertices[info->Offset], VERTEX_FORMAT_P3FT2FC4B, vCount);
#endif
info->Counts[FACE_XMIN] = part->fCount[FACE_XMIN];
info->Counts[FACE_XMAX] = part->fCount[FACE_XMAX];
info->Counts[FACE_ZMIN] = part->fCount[FACE_ZMIN];
@ -316,8 +320,10 @@ void Builder_MakeChunk(ChunkInfo* info) {
Int32 totalVerts = Builder_TotalVerticesCount();
if (totalVerts == 0) return;
#if !CC_BUILD_GL11
/* add an extra element to fix crashing on some GPUs */
info->VbId = Gfx_CreateVb(Builder_Vertices, VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1);
info->Vb = Gfx_CreateVb(Builder_Vertices, VERTEX_FORMAT_P3FT2FC4B, totalVerts + 1);
#endif
Int32 i, offset = 0, partsIndex = MapRenderer_Pack(x >> CHUNK_SHIFT, y >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
bool hasNormal = false, hasTranslucent = false;

View File

@ -22,7 +22,9 @@ void ChunkInfo_Reset(ChunkInfo* chunk, Int32 x, Int32 y, Int32 z) {
chunk->CentreX = (UInt16)(x + 8);
chunk->CentreY = (UInt16)(y + 8);
chunk->CentreZ = (UInt16)(z + 8);
chunk->VbId = NULL;
#if !CC_BUILD_GL11
chunk->Vb = NULL;
#endif
chunk->Visible = true; chunk->Empty = false;
chunk->PendingDelete = false; chunk->AllAir = false;
@ -351,13 +353,19 @@ void ChunkUpdater_DeleteChunk(ChunkInfo* info) {
info.OcclusionFlags = 0;
info.OccludedFlags = 0;
#endif
Gfx_DeleteVb(&info->VbId);
#if !CC_BUILD_GL11
Gfx_DeleteVb(&info->Vb);
#endif
Int32 i;
if (info->NormalParts != NULL) {
ChunkPartInfo* ptr = info->NormalParts;
for (i = 0; i < MapRenderer_1DUsedCount; i++, ptr += MapRenderer_ChunksCount) {
if (ptr->Offset >= 0) { MapRenderer_NormalPartsCount[i]--; }
if (ptr->Offset < 0) continue;
MapRenderer_NormalPartsCount[i]--;
#if CC_BUILD_GL11
Gfx_DeleteVb(&ptr->Vb);
#endif
}
info->NormalParts = NULL;
}
@ -365,7 +373,11 @@ void ChunkUpdater_DeleteChunk(ChunkInfo* info) {
if (info->TranslucentParts != NULL) {
ChunkPartInfo* ptr = info->TranslucentParts;
for (i = 0; i < MapRenderer_1DUsedCount; i++, ptr += MapRenderer_ChunksCount) {
if (ptr->Offset >= 0) { MapRenderer_TranslucentPartsCount[i]--; }
if (ptr->Offset < 0) continue;
MapRenderer_TranslucentPartsCount[i]--;
#if CC_BUILD_GL11
Gfx_DeleteVb(&ptr->Vb);
#endif
}
info->TranslucentParts = NULL;
}

View File

@ -9,6 +9,9 @@
/* Describes a portion of the data needed for rendering a chunk. */
typedef struct ChunkPartInfo_ {
#if CC_BUILD_GL11
GfxResourceID Vb;
#endif
Int32 Offset; /* -1 if no vertices at all */
Int32 SpriteCount; /* Sprite vertices count */
UInt16 Counts[FACE_COUNT]; /* Counts per face */
@ -35,7 +38,9 @@ typedef struct ChunkInfo_ {
public bool Visited = false, Occluded = false;
public byte OcclusionFlags, OccludedFlags, DistanceFlags;
#endif
GfxResourceID VbId;
#if !CC_BUILD_GL11
GfxResourceID Vb;
#endif
ChunkPartInfo* NormalParts;
ChunkPartInfo* TranslucentParts;
} ChunkInfo;

View File

@ -48,7 +48,11 @@ static void MapRenderer_RenderNormalBatch(UInt32 batch) {
if (part.Offset < 0) continue;
MapRenderer_HasNormalParts[batch] = true;
Gfx_BindVb(info->VbId);
#if !CC_BUILD_GL11
Gfx_BindVb(info->Vb);
#else
Gfx_BindVb(part.Vb);
#endif
bool drawXMin = info->DrawXMin && part.Counts[FACE_XMIN];
bool drawXMax = info->DrawXMax && part.Counts[FACE_XMAX];
bool drawYMin = info->DrawYMin && part.Counts[FACE_YMIN];
@ -158,7 +162,11 @@ static void MapRenderer_RenderTranslucentBatch(UInt32 batch) {
if (part.Offset < 0) continue;
MapRenderer_HasTranslucentParts[batch] = true;
Gfx_BindVb(info->VbId);
#if !CC_BUILD_GL11
Gfx_BindVb(info->Vb);
#else
Gfx_BindVb(part.Vb);
#endif
bool drawXMin = (inTranslucent || info->DrawXMin) && part.Counts[FACE_XMIN];
bool drawXMax = (inTranslucent || info->DrawXMax) && part.Counts[FACE_XMAX];
bool drawYMin = (inTranslucent || info->DrawYMin) && part.Counts[FACE_YMIN];

View File

@ -57,7 +57,7 @@ typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
#define Int32_MaxValue ((Int32)2147483647L)
#define UInt32_MaxValue ((UInt32)4294967295UL)
#define CC_BUILD_GL11 false
#define CC_BUILD_GL11 true
#define CC_BUILD_D3D9 false
#if CC_BUILD_D3D9