Navigation Menu

Skip to content

Commit

Permalink
#5623: Implement the shaders and adjust the sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 25, 2021
1 parent aead38f commit 74a75cf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 55 deletions.
3 changes: 3 additions & 0 deletions include/iglrender.h
Expand Up @@ -38,6 +38,9 @@ class OpenGLState
SORT_TRANSLUCENT = 1026, // used by blend-type editor passes
SORT_HIGHLIGHT = 1027, // used by the (red) selection system overlay
SORT_OVERLAY_FIRST = 1028, // used by decals
SORT_OVERLAY_SECOND = 1029, // used by merge actions
SORT_OVERLAY_THIRD = 1030, // used by merge actions
SORT_OVERLAY_ONE_BEFORE_LAST = 2046, // used by merge actions
SORT_OVERLAY_LAST = 2047,
SORT_POINT_FIRST = 2048, // used by POINT renderers
SORT_POINT_LAST = 3071,
Expand Down
1 change: 0 additions & 1 deletion libs/render/CamRenderer.h
Expand Up @@ -23,7 +23,6 @@ class CamRenderer :
ShaderPtr mergeActionShaderAdd;
ShaderPtr mergeActionShaderChange;
ShaderPtr mergeActionShaderRemove;
ShaderPtr nonMergeActionNodeShader;
};

private:
Expand Down
2 changes: 0 additions & 2 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -961,7 +961,6 @@ void CamWnd::captureStates()
_shaders.mergeActionShaderAdd = GlobalRenderSystem().capture("$MERGE_ACTION_ADD");
_shaders.mergeActionShaderChange = GlobalRenderSystem().capture("$MERGE_ACTION_CHANGE");
_shaders.mergeActionShaderRemove = GlobalRenderSystem().capture("$MERGE_ACTION_REMOVE");
_shaders.nonMergeActionNodeShader = GlobalRenderSystem().capture("$CAM_INACTIVE_NODE");
}

void CamWnd::releaseStates()
Expand All @@ -971,7 +970,6 @@ void CamWnd::releaseStates()
_shaders.mergeActionShaderAdd.reset();
_shaders.mergeActionShaderChange.reset();
_shaders.mergeActionShaderRemove.reset();
_shaders.nonMergeActionNodeShader.reset();
}

void CamWnd::queueDraw()
Expand Down
77 changes: 25 additions & 52 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -9,6 +9,7 @@
#include "ifilter.h"
#include "irender.h"
#include "texturelib.h"
#include "string/predicate.h"

#include <functional>

Expand Down Expand Up @@ -802,45 +803,28 @@ void OpenGLShader::construct()
hiddenLine.setDepthFunc(GL_GREATER);
hiddenLine.m_linestipple_factor = 2;
}
else if (_name == "$MERGE_ACTION_OVERLAY")
else if (string::starts_with(_name, "$MERGE_ACTION_"))
{
// This is the shader drawing a coloured overlay
// over faces/polys. Its colour is configurable,
// and it has depth test activated.
state.setRenderFlag(RENDER_FILL);
state.setRenderFlag(RENDER_DEPTHTEST);
state.setRenderFlag(RENDER_CULLFACE);
state.setRenderFlag(RENDER_BLEND);
Colour4 colour;
auto sortPosition = OpenGLState::SORT_OVERLAY_FIRST;
auto lineSortPosition = OpenGLState::SORT_OVERLAY_LAST;

state.setColour(Colour4(0, 0.4, 0.9, 0.5));
state.setSortPosition(OpenGLState::SORT_HIGHLIGHT);
state.polygonOffset = 0.5f;
state.setDepthFunc(GL_LEQUAL);
if (string::ends_with(_name, "_ADD"))
{
colour = Colour4(0, 0.9f, 0, 0.5f);
sortPosition = OpenGLState::SORT_OVERLAY_THIRD; // render additions over removals
}
else if (string::ends_with(_name, "_REMOVE"))
{
colour = Colour4(0.6f, 0.1f, 0, 0.5f);
lineSortPosition = OpenGLState::SORT_OVERLAY_ONE_BEFORE_LAST;
}
else if (string::ends_with(_name, "_CHANGE"))
{
colour = Colour4(0, 0.4f, 0.9f, 0.5f);
sortPosition = OpenGLState::SORT_OVERLAY_SECOND;
}

auto& linesOverlay = appendDefaultPass();
linesOverlay.setColour(0, 0.4, 0.9, 0.78);
// This is the shader drawing a solid line to outline
// a selected item. The first pass has its depth test
// activated using GL_LESS, whereas the second pass
// draws the hidden lines in stippled appearance
// with its depth test using GL_GREATER.
linesOverlay.setRenderFlags(RENDER_OFFSETLINE | RENDER_DEPTHTEST | RENDER_BLEND);
linesOverlay.setSortPosition(OpenGLState::SORT_OVERLAY_LAST);
#if 0
// Second pass for hidden lines
OpenGLState& hiddenLine = appendDefaultPass();
hiddenLine.setColour(0.6, 0.6, 0.6, 0.15);
hiddenLine.setRenderFlags(RENDER_CULLFACE
| RENDER_DEPTHTEST
| RENDER_OFFSETLINE
| RENDER_LINESTIPPLE | RENDER_BLEND);
hiddenLine.setSortPosition(OpenGLState::SORT_OVERLAY_FIRST);
hiddenLine.setDepthFunc(GL_GREATER);
hiddenLine.m_linestipple_factor = 2;
#endif
}
else if (_name == "$CAM_INACTIVE_NODE")
{
// This is the shader drawing a coloured overlay
// over faces/polys. Its colour is configurable,
// and it has depth test activated.
Expand All @@ -849,32 +833,21 @@ void OpenGLShader::construct()
state.setRenderFlag(RENDER_CULLFACE);
state.setRenderFlag(RENDER_BLEND);

state.setColour(Colour4(0.7, 0.7, 0.7, 0.15));
state.setSortPosition(OpenGLState::SORT_FULLBRIGHT);
state.setColour(colour);
state.setSortPosition(sortPosition);
state.polygonOffset = 0.5f;
state.setDepthFunc(GL_LEQUAL);

auto& linesOverlay = appendDefaultPass();
linesOverlay.setColour(0.6, 0.6, 0.6, 0.01);
colour[3] = 0.78f;
linesOverlay.setColour(colour);
// This is the shader drawing a solid line to outline
// a selected item. The first pass has its depth test
// activated using GL_LESS, whereas the second pass
// draws the hidden lines in stippled appearance
// with its depth test using GL_GREATER.
linesOverlay.setRenderFlags(RENDER_OFFSETLINE | RENDER_DEPTHTEST | RENDER_BLEND);
linesOverlay.setSortPosition(OpenGLState::SORT_OVERLAY_FIRST);
#if 0
// Second pass for hidden lines
OpenGLState& hiddenLine = appendDefaultPass();
hiddenLine.setColour(0.6, 0.6, 0.6, 0.05);
hiddenLine.setRenderFlags(RENDER_CULLFACE
| RENDER_DEPTHTEST
| RENDER_OFFSETLINE
| RENDER_LINESTIPPLE | RENDER_BLEND);
hiddenLine.setSortPosition(OpenGLState::SORT_OVERLAY_FIRST);
hiddenLine.setDepthFunc(GL_GREATER);
hiddenLine.m_linestipple_factor = 2;
#endif
linesOverlay.setSortPosition(lineSortPosition);
}
else if (_name == "$XY_OVERLAY")
{
Expand Down

0 comments on commit 74a75cf

Please sign in to comment.