Skip to content

Commit 2cc8dc6

Browse files
authored
Merge pull request #158 from cortex-command-community/gpu-primitives
GPU Hotfix
2 parents afb20b7 + a39250d commit 2cc8dc6

File tree

16 files changed

+4536
-4479
lines changed

16 files changed

+4536
-4479
lines changed

Data/Base.rte/Shaders/PostProcess.frag

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#version 130
22

33
in vec2 textureUV;
4+
in vec4 vertexColor;
45

56
out vec4 FragColor;
67

@@ -18,5 +19,5 @@ vec4 texture2DAA(sampler2D tex, vec2 uv) {
1819
}
1920

2021
void main() {
21-
FragColor = texture2DAA(rteTexture, textureUV) * rteColor;
22+
FragColor = texture2DAA(rteTexture, textureUV) * rteColor * vertexColor;
2223
}

Data/Base.rte/Shaders/PostProcess.vert

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
in vec3 rteVertexPosition;
44
in vec2 rteVertexTexUV;
5+
in vec4 rteVertexColor;
56

67
out vec2 textureUV;
8+
out vec4 vertexColor;
79

810
uniform mat4 rteModel;
911
uniform mat4 rteProjection;
1012

1113
void main() {
1214
gl_Position = rteProjection * rteModel * vec4(rteVertexPosition, 1.0);
15+
vertexColor = rteVertexColor;
1316
textureUV = rteVertexTexUV;
1417
}

Source/Entities/PieMenu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ void PieMenu::Update() {
632632
}
633633

634634
void PieMenu::Draw(BITMAP* targetBitmap, const Vector& targetPos) const {
635+
rlZDepth(c_GuiDepth);
635636
Vector drawPos;
636637
CalculateDrawPosition(targetBitmap, targetPos, drawPos);
637638

@@ -656,6 +657,7 @@ void PieMenu::Draw(BITMAP* targetBitmap, const Vector& targetPos) const {
656657
if (m_ActiveSubPieMenu) {
657658
m_ActiveSubPieMenu->Draw(targetBitmap, targetPos);
658659
}
660+
rlZDepth(c_DefaultDrawDepth);
659661
}
660662

661663
void PieMenu::UpdateWobbling() {

Source/Entities/SLBackground.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void SLBackground::Clear() {
3838
m_FillColorRight = ColorKeys::g_MaskColor;
3939
m_FillColorUp = ColorKeys::g_MaskColor;
4040
m_FillColorDown = ColorKeys::g_MaskColor;
41+
m_ZOrder = c_BackgroundDepth;
4142

4243
m_IgnoreAutoScale = false;
4344
}
@@ -222,6 +223,7 @@ void SLBackground::Draw(const Box& targetDimensions, Box& targetBox, bool offset
222223
int targetBoxWidth = static_cast<int>(targetBox.GetWidth());
223224
int targetBoxHeight = static_cast<int>(targetBox.GetHeight());
224225

226+
rlZDepth(m_ZOrder);
225227
// Detect if non-wrapping layer dimensions can't cover the whole target area with its main bitmap. If so, fill in the gap with appropriate solid color sampled from the hanging edge.
226228
if (!m_WrapX && bitmapWidth <= targetBoxWidth) {
227229
if (m_FillColorLeft != ColorKeys::g_MaskColor && m_Offset.GetFloorIntX() != 0) {
@@ -239,4 +241,5 @@ void SLBackground::Draw(const Box& targetDimensions, Box& targetBox, bool offset
239241
DrawRectangle(targetBoxCornerX, targetBoxCornerY + bitmapHeight - m_Offset.m_Y, targetBoxWidth, targetBoxHeight - bitmapHeight + m_Offset.m_Y, {static_cast<unsigned char>(m_FillColorDown), 0, 0, 255});
240242
}
241243
}
244+
rlZDepth(c_DefaultDrawDepth);
242245
}

Source/Entities/SLTerrain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ int SLTerrain::Create() {
4646

4747
if (!m_FGColorLayer.get()) {
4848
m_FGColorLayer = std::make_unique<SceneLayer>();
49+
m_FGColorLayer->SetZOrder(c_DefaultDrawDepth);
4950
}
5051
if (!m_BGColorLayer.get()) {
5152
m_BGColorLayer = std::make_unique<SceneLayer>();
53+
m_BGColorLayer->SetZOrder(c_TerrainBGDepth);
5254
}
5355

5456
return 0;
@@ -90,10 +92,12 @@ int SLTerrain::ReadProperty(const std::string_view& propName, Reader& reader) {
9092
MatchProperty("BackgroundTexture", { reader >> m_DefaultBGTextureFile; });
9193
MatchProperty("FGColorLayer", {
9294
m_FGColorLayer = std::make_unique<SceneLayer>();
95+
m_FGColorLayer->SetZOrder(c_DefaultDrawDepth);
9396
reader >> m_FGColorLayer.get();
9497
});
9598
MatchProperty("BGColorLayer", {
9699
m_BGColorLayer = std::make_unique<SceneLayer>();
100+
m_BGColorLayer->SetZOrder(c_TerrainBGDepth);
97101
reader >> m_BGColorLayer.get();
98102
});
99103
MatchProperty("AddTerrainFrosting", {

Source/Entities/SceneLayer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::Clear() {
4545
m_WrapY = true;
4646
m_OriginOffset.Reset();
4747
m_Offset.Reset();
48+
m_ZOrder = 0.0F;
4849
m_ScrollInfo.SetXY(1.0F, 1.0F);
4950
m_ScrollRatio.SetXY(1.0F, 1.0F);
5051
m_ScaleFactor.SetXY(1.0F, 1.0F);
@@ -510,6 +511,8 @@ void SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::DrawTiled(const Box& target
510511
glUniform1i(maskedUniformLocation, 0);
511512
}
512513

514+
rlZDepth(m_ZOrder);
515+
513516
for (int tiledOffsetX = 0; tiledOffsetX < areaToCoverX;) {
514517
float destX = targetBox.GetCorner().GetFloorIntX() + tiledOffsetX - m_Offset.GetFloorIntX();
515518

@@ -537,6 +540,8 @@ void SceneLayerImpl<TRACK_DRAWINGS, STATIC_TEXTURE>::DrawTiled(const Box& target
537540
tiledOffsetX += bitmapWidth;
538541
}
539542

543+
rlZDepth(c_DefaultDrawDepth);
544+
540545
if (!m_DrawMasked) {
541546
rlDrawRenderBatchActive();
542547
int drawMaskedUniform = rlGetLocationUniform(rlGetShaderCurrent(), "drawMasked");

Source/Entities/SceneLayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ namespace RTE {
100100
/// @param newOffset The new offset Vector.
101101
void SetOffset(const Vector& newOffset) { m_Offset = newOffset; }
102102

103+
/// Set the depth this scenelayer will be drawn at.
104+
/// @param z The depth to draw at, negative values are further to the front in the range c_NearDepth to c_FarDepth.
105+
void SetZOrder(float z) { m_ZOrder = z; }
106+
103107
/// Gets the scroll ratio that modifies the offset.
104108
/// @return A copy of the ratio.
105109
Vector GetScrollRatio() const { return m_ScrollRatio; }
@@ -222,6 +226,7 @@ namespace RTE {
222226

223227
Vector m_OriginOffset; //!< Offset of this SceneLayer off the top left edge of the screen.
224228
Vector m_Offset; //!< The current scrolled offset of this SceneLayer, before being adjusted with the origin offset.
229+
float m_ZOrder{0.0F}; //!< The depth this SceneLayer should be drawn at.
225230

226231
Vector m_ScrollInfo; //!< The initial scrolling ratio of this SceneLayer as set in INI. Used to calculate the actual scrolling ratios.
227232
Vector m_ScrollRatio; //!< The scrolling ratios of this SceneLayer, adjusted to the Scene, player screen dimensions and scaling factor as necessary.

Source/Managers/FrameMan.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,8 @@ void FrameMan::Draw() {
962962
if (IsInMultiplayerMode()) {
963963
PrepareFrameForNetwork();
964964
}
965-
rlDisableDepthTest();
965+
rlEnableDepthTest();
966+
rlZDepth(c_GuiDepth-1.0f);
966967
g_GLResourceMan.UpdateDynamicBitmap(m_BackBuffer8.get(), true);
967968
backgroundShader.Begin();
968969
backgroundShader.Enable();
@@ -972,6 +973,7 @@ void FrameMan::Draw() {
972973
DrawTexture(g_GLResourceMan.GetStaticTextureFromBitmap(m_BackBuffer8.get()), 0.0f, 0.0f, {255, 255, 255, 255});
973974
m_BackBuffer->End();
974975
backgroundShader.End();
976+
rlZDepth(0);
975977
if (g_ActivityMan.IsInActivity()) {
976978
g_PostProcessMan.PostProcess();
977979
}

Source/Managers/GLResourceMan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,9 @@ GLuint GLResourceMan::UpdateDynamicBitmap(BITMAP* bitmap, bool updated, const st
150150
}
151151
}
152152
return texture;
153+
}
154+
155+
void GLResourceMan::DestroyBitmapInfo(BITMAP* bitmap) {
156+
GLBitmapInfo* info = GetBitmapInfo(bitmap);
157+
glDeleteTextures(1, &info->m_Texture);
153158
}

Source/Managers/GLResourceMan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace RTE {
4545
GLuint GetDynamicUploadBuffer(BITMAP* bitmap);
4646
GLuint UpdateDynamicBitmap(BITMAP* bitmap, bool updated, const std::vector<Box>& = {});
4747

48+
void DestroyBitmapInfo(BITMAP* bitmap);
49+
4850
GLBitmapInfo* MakeBitmapInfo();
4951

5052

0 commit comments

Comments
 (0)