Skip to content

Commit 8c81030

Browse files
committed
primitive gpu blend modes
1 parent 84aa93d commit 8c81030

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

Source/Managers/PrimitiveMan.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#include "SceneMan.h"
55
#include "ConsoleMan.h"
66
#include "MOSprite.h"
7+
#include "Shader.h"
78

89
#include "tracy/Tracy.hpp"
910

1011
#include <array>
12+
#include "Draw.h"
13+
#include "glad/gl.h"
1114

1215
using namespace RTE;
1316

@@ -230,29 +233,42 @@ void PrimitiveMan::DrawPrimitives(int player, BITMAP* targetBitmap, const Vector
230233
int lastDrawMode = DRAW_MODE_SOLID;
231234
DrawBlendMode lastBlendMode = DrawBlendMode::NoBlend;
232235
std::array<int, 4> lastBlendAmounts = {BlendAmountLimits::MinBlend, BlendAmountLimits::MinBlend, BlendAmountLimits::MinBlend, BlendAmountLimits::MinBlend};
233-
236+
GLint currentShader = rlGetShaderCurrent();
237+
rlDrawRenderBatchActive();
238+
glBlendBarrierKHR();
239+
rlEnableAdvancedColorBlend();
240+
rlEnableColorBlend();
234241
for (const std::unique_ptr<GraphicalPrimitive>& primitive: m_ScheduledPrimitives) {
235242
if (int playerToDrawFor = primitive->m_Player; playerToDrawFor == player || playerToDrawFor == -1) {
243+
rlDrawRenderBatchActive();
236244
if (DrawBlendMode blendMode = primitive->m_BlendMode; blendMode > DrawBlendMode::NoBlend) {
237245
if (const std::array<int, 4>& blendAmounts = primitive->m_ColorChannelBlendAmounts; blendMode != lastBlendMode || blendAmounts != lastBlendAmounts) {
238-
g_FrameMan.SetColorTable(blendMode, blendAmounts);
246+
rlEnableShader(rlGetShaderCurrent());
247+
g_FrameMan.SetBlendMode(blendMode);
248+
GLint colorUniform = glGetUniformLocation(rlGetShaderCurrent(), "rteColor");
249+
glUniform4f(colorUniform, blendAmounts[0] / static_cast<float>(MaxBlend), blendAmounts[1] / static_cast<float>(MaxBlend), blendAmounts[2] / static_cast<float>(MaxBlend), blendAmounts[3] / static_cast<float>(MaxBlend));
250+
//g_FrameMan.SetColorTable(blendMode, blendAmounts);
239251
lastBlendMode = blendMode;
240252
lastBlendAmounts = blendAmounts;
241253
}
242-
if (lastDrawMode != DRAW_MODE_TRANS) {
243-
// Drawing mode is set so blending effects apply to true primitives. For bitmap based primitives it has no effect.
244-
drawing_mode(DRAW_MODE_TRANS, nullptr, 0, 0);
245-
lastDrawMode = DRAW_MODE_TRANS;
246-
}
247254
} else {
248-
if (lastDrawMode != DRAW_MODE_SOLID) {
249-
drawing_mode(DRAW_MODE_SOLID, nullptr, 0, 0);
250-
lastDrawMode = DRAW_MODE_SOLID;
251-
}
255+
g_FrameMan.SetBlendMode(BlendTransparency);
256+
rlEnableShader(currentShader);
257+
GLint colorUniform = glGetUniformLocation(rlGetShaderCurrent(), "rteColor");
258+
glUniform4f(colorUniform, 1.0f, 1.0f, 1.0f, 1.0f);
252259
lastBlendMode = DrawBlendMode::NoBlend;
253260
}
261+
glBlendBarrierKHR();
262+
rlZDepth(primitive->m_Depth);
254263
primitive->DrawTiled(targetBitmap, targetPos);
255264
}
256265
}
266+
rlDrawRenderBatchActive();
267+
rlDisableAdvancedColorBlend();
268+
rlSetBlendMode(RL_BLEND_ALPHA);
269+
rlEnableShader(currentShader);
270+
GLint colorUniform = glGetUniformLocation(rlGetShaderCurrent(), "rteColor");
271+
glUniform4f(colorUniform, 1.0f, 1.0f, 1.0f, 1.0f);
272+
rlZDepth(c_DefaultDrawDepth);
257273
drawing_mode(DRAW_MODE_SOLID, nullptr, 0, 0);
258274
}

0 commit comments

Comments
 (0)