- use the light buffer to handle dynamic lighting.

This commit is contained in:
Christoph Oelckers 2014-08-01 20:59:39 +02:00
commit 7967082e60
17 changed files with 189 additions and 192 deletions

View file

@ -67,6 +67,7 @@
#include "gl/utility/gl_clock.h"
#include "gl/utility/gl_templates.h"
#include "gl/models/gl_models.h"
#include "gl/dynlights/gl_lightbuffer.h"
//===========================================================================
//
@ -97,6 +98,7 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
gl_spriteindex = 0;
mShaderManager = NULL;
glpart2 = glpart = mirrortexture = NULL;
mLights = NULL;
}
void FGLRenderer::Initialize()
@ -108,6 +110,7 @@ void FGLRenderer::Initialize()
mVBO = new FFlatVertexBuffer;
mSkyVBO = new FSkyVertexBuffer;
mModelVBO = new FModelVertexBuffer;
mLights = new FLightBuffer;
gl_RenderState.SetVertexBuffer(mVBO);
mFBID = 0;
SetupLevel();
@ -124,6 +127,7 @@ FGLRenderer::~FGLRenderer()
if (mVBO != NULL) delete mVBO;
if (mModelVBO) delete mModelVBO;
if (mSkyVBO != NULL) delete mSkyVBO;
if (mLights != NULL) delete mLights;
if (glpart2) delete glpart2;
if (glpart) delete glpart;
if (mirrortexture) delete mirrortexture;

View file

@ -17,6 +17,7 @@ struct pspdef_t;
class FShaderManager;
class GLPortal;
class FGLThreadManager;
class FLightBuffer;
enum SectorRenderFlags
{
@ -72,6 +73,7 @@ public:
FFlatVertexBuffer *mVBO;
FSkyVertexBuffer *mSkyVBO;
FModelVertexBuffer *mModelVBO;
FLightBuffer *mLights;
FGLRenderer(OpenGLFrameBuffer *fb);

View file

@ -48,6 +48,7 @@
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderstate.h"
#include "gl/renderer/gl_colormap.h"
#include "gl/dynlights//gl_lightbuffer.h"
void gl_SetTextureMode(int type);
@ -68,9 +69,10 @@ TArray<VSMatrix> gl_MatrixStack;
void FRenderState::Reset()
{
mTextureEnabled = true;
mBrightmapEnabled = mFogEnabled = mGlowEnabled = mLightEnabled = false;
mBrightmapEnabled = mFogEnabled = mGlowEnabled = false;
mFogColor.d = -1;
mTextureMode = -1;
mLightIndex = -1;
mDesaturation = 0;
mSrcBlend = GL_SRC_ALPHA;
mDstBlend = GL_ONE_MINUS_SRC_ALPHA;
@ -98,7 +100,6 @@ void FRenderState::Reset()
bool FRenderState::ApplyShader()
{
FShader *activeShader;
if (mSpecialEffect > EFF_NONE)
{
activeShader = GLRenderer->mShaderManager->BindEffect(mSpecialEffect);
@ -139,6 +140,7 @@ bool FRenderState::ApplyShader()
activeShader->muClipHeightBottom.Set(mClipHeightBottom);
activeShader->muTimer.Set(gl_frameMS * mShaderTimer / 1000.f);
activeShader->muAlphaThreshold.Set(mAlphaThreshold);
activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now
if (mGlowEnabled)
{
@ -159,17 +161,6 @@ bool FRenderState::ApplyShader()
activeShader->currentglowstate = 0;
}
if (mLightEnabled)
{
activeShader->muLightRange.Set(mNumLights);
glUniform4fv(activeShader->lights_index, mNumLights[3], mLightData);
}
else
{
static const int nulint[] = { 0, 0, 0, 0 };
activeShader->muLightRange.Set(nulint);
}
if (mColormapState != activeShader->currentfixedcolormap)
{
float r, g, b;
@ -282,3 +273,12 @@ void FRenderState::ApplyMatrices()
GLRenderer->mShaderManager->ApplyMatrices(&mProjectionMatrix, &mViewMatrix);
}
}
void FRenderState::ApplyLightIndex(int index)
{
if (GLRenderer->mLights->GetBufferType() == GL_UNIFORM_BUFFER && index > -1)
{
index = GLRenderer->mLights->BindUBO(index);
}
activeShader->muLightIndex.Set(index);
}

View file

@ -9,6 +9,7 @@
#include "r_defs.h"
class FVertexBuffer;
class FShader;
extern TArray<VSMatrix> gl_MatrixStack;
EXTERN_CVAR(Bool, gl_direct_state_change)
@ -43,24 +44,22 @@ class FRenderState
bool mTextureEnabled;
bool mFogEnabled;
bool mGlowEnabled;
bool mLightEnabled;
bool mBrightmapEnabled;
int mLightIndex;
int mSpecialEffect;
int mTextureMode;
int mDesaturation;
int mSoftLight;
float mLightParms[4];
int mNumLights[4];
float *mLightData;
int mSrcBlend, mDstBlend;
float mAlphaThreshold;
bool mAlphaTest;
int mBlendEquation;
bool mAlphaTest;
bool m2D;
float mInterpolationFactor;
float mClipHeightTop, mClipHeightBottom;
bool mModelMatrixEnabled;
bool mTextureMatrixEnabled;
float mInterpolationFactor;
float mClipHeightTop, mClipHeightBottom;
float mShaderTimer;
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
@ -80,6 +79,8 @@ class FRenderState
bool stAlphaTest;
int stBlendEquation;
FShader *activeShader;
bool ApplyShader();
public:
@ -104,6 +105,7 @@ public:
void Apply();
void ApplyMatrices();
void ApplyLightIndex(int index);
void SetVertexBuffer(FVertexBuffer *vb)
{
@ -185,9 +187,9 @@ public:
mGlowEnabled = on;
}
void EnableLight(bool on)
void SetLightIndex(int n)
{
mLightEnabled = on;
mLightIndex = n;
}
void EnableBrightmap(bool on)
@ -251,15 +253,6 @@ public:
mLightParms[0] = d;
}
void SetLights(int *numlights, float *lightdata)
{
mNumLights[0] = 0;
mNumLights[1] = numlights[0];
mNumLights[2] = numlights[1];
mNumLights[3] = numlights[2];
mLightData = lightdata; // caution: the data must be preserved by the caller until the 'apply' call!
}
void SetFixedColormap(int cm)
{
mColormapState = cm;