From 45526c276953355074f845f4531a741ddc542e5e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 5 Apr 2015 18:55:21 +0200 Subject: [PATCH] - basics for using hardware clip planes to split translucent stuff by 3D floor planes. --- src/gl/renderer/gl_renderstate.cpp | 2 ++ src/gl/renderer/gl_renderstate.h | 23 +++++++++++++++++++++++ src/gl/shaders/gl_shader.cpp | 1 + src/gl/shaders/gl_shader.h | 23 +++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 358c9fe7f2..15b046349c 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -86,6 +86,7 @@ void FRenderState::Reset() mSpecialEffect = EFF_NONE; mClipHeightTop = 65536.f; mClipHeightBottom = -65536.f; + ClearClipSplit(); stSrcBlend = stDstBlend = -1; stBlendEquation = -1; @@ -141,6 +142,7 @@ bool FRenderState::ApplyShader() activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f); activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now + activeShader->muClipSplit.Set(mClipSplit); if (mGlowEnabled) { diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 8c3b60772a..74065fe4ce 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -73,6 +73,7 @@ class FRenderState PalEntry mFogColor; PalEntry mObjectColor; FStateVec4 mDynColor; + float mClipSplit[2]; int mEffectState; int mColormapState; @@ -279,6 +280,28 @@ public: return mFogColor; } + void SetClipSplit(float bottom, float top) + { + mClipSplit[0] = bottom; + mClipSplit[1] = top; + } + + void SetClipSplit(float *vals) + { + memcpy(mClipSplit, vals, 2 * sizeof(float)); + } + + void GetClipSplit(float *out) + { + memcpy(out, mClipSplit, 2 * sizeof(float)); + } + + void ClearClipSplit() + { + mClipSplit[0] = -1000000.f; + mClipSplit[1] = 1000000.f; + } + void BlendFunc(int src, int dst) { if (!gl_direct_state_change) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 7c04bdf454..2955cf7c89 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -205,6 +205,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muTextureMode.Init(hShader, "uTextureMode"); muCameraPos.Init(hShader, "uCameraPos"); muLightParms.Init(hShader, "uLightAttr"); + muClipSplit.Init(hShader, "uClipSplit"); muColormapStart.Init(hShader, "uFixedColormapStart"); muColormapRange.Init(hShader, "uFixedColormapRange"); muLightIndex.Init(hShader, "uLightIndex"); diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 8b6f7b4a6e..c5baceceb1 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -103,6 +103,28 @@ public: } }; +class FBufferedUniform2f +{ + float mBuffer[2]; + int mIndex; + +public: + void Init(GLuint hShader, const GLchar *name) + { + mIndex = glGetUniformLocation(hShader, name); + memset(mBuffer, 0, sizeof(mBuffer)); + } + + void Set(const float *newvalue) + { + if (memcmp(newvalue, mBuffer, sizeof(mBuffer))) + { + memcpy(mBuffer, newvalue, sizeof(mBuffer)); + glUniform2fv(mIndex, 1, newvalue); + } + } +}; + class FBufferedUniform4f { float mBuffer[4]; @@ -184,6 +206,7 @@ class FShader FBufferedUniform1i muTextureMode; FBufferedUniform4f muCameraPos; FBufferedUniform4f muLightParms; + FBufferedUniform2f muClipSplit; FUniform1i muFixedColormap; FUniform4f muColormapStart; FUniform4f muColormapRange;