mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-03-01 14:31:05 +00:00
- removed all direct OpenGL dependencies from gl_models.cpp.
This commit is contained in:
parent
ac37ff422a
commit
a62cd64138
9 changed files with 67 additions and 52 deletions
|
@ -44,7 +44,6 @@
|
||||||
#include "gl/renderer/gl_renderer.h"
|
#include "gl/renderer/gl_renderer.h"
|
||||||
#include "gl/scene/gl_drawinfo.h"
|
#include "gl/scene/gl_drawinfo.h"
|
||||||
#include "gl/models/gl_models.h"
|
#include "gl/models/gl_models.h"
|
||||||
#include "gl/renderer/gl_renderstate.h"
|
|
||||||
#include "gl/shaders/gl_shader.h"
|
#include "gl/shaders/gl_shader.h"
|
||||||
|
|
||||||
CVAR(Bool, gl_light_models, true, CVAR_ARCHIVE)
|
CVAR(Bool, gl_light_models, true, CVAR_ARCHIVE)
|
||||||
|
@ -58,55 +57,52 @@ VSMatrix FGLModelRenderer::GetViewToWorldMatrix()
|
||||||
|
|
||||||
void FGLModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
|
void FGLModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
|
||||||
{
|
{
|
||||||
glDepthFunc(GL_LEQUAL);
|
di->SetDepthFunc(DF_LEqual);
|
||||||
gl_RenderState.EnableTexture(true);
|
state.EnableTexture(true);
|
||||||
// [BB] In case the model should be rendered translucent, do back face culling.
|
// [BB] In case the model should be rendered translucent, do back face culling.
|
||||||
// This solves a few of the problems caused by the lack of depth sorting.
|
// This solves a few of the problems caused by the lack of depth sorting.
|
||||||
// [Nash] Don't do back face culling if explicitly specified in MODELDEF
|
// [Nash] Don't do back face culling if explicitly specified in MODELDEF
|
||||||
// TO-DO: Implement proper depth sorting.
|
// TO-DO: Implement proper depth sorting.
|
||||||
if (!(actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]) && !(smf->flags & MDL_DONTCULLBACKFACES))
|
if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
|
||||||
{
|
{
|
||||||
glEnable(GL_CULL_FACE);
|
di->SetCulling((mirrored ^ screen->mPortalState->isMirrored()) ? Cull_CCW : Cull_CW);
|
||||||
glFrontFace((mirrored ^ screen->mPortalState->isMirrored()) ? GL_CCW : GL_CW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_RenderState.mModelMatrix = objectToWorldMatrix;
|
state.mModelMatrix = objectToWorldMatrix;
|
||||||
gl_RenderState.EnableModelMatrix(true);
|
state.EnableModelMatrix(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
|
void FGLModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
|
||||||
{
|
{
|
||||||
gl_RenderState.EnableModelMatrix(false);
|
state.EnableModelMatrix(false);
|
||||||
|
di->SetDepthFunc(DF_Less);
|
||||||
glDepthFunc(GL_LESS);
|
if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
|
||||||
if (!(actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]) && !(smf->flags & MDL_DONTCULLBACKFACES))
|
di->SetCulling(Cull_None);
|
||||||
glDisable(GL_CULL_FACE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored)
|
void FGLModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored)
|
||||||
{
|
{
|
||||||
glDepthFunc(GL_LEQUAL);
|
di->SetDepthFunc(DF_LEqual);
|
||||||
|
|
||||||
// [BB] In case the model should be rendered translucent, do back face culling.
|
// [BB] In case the model should be rendered translucent, do back face culling.
|
||||||
// This solves a few of the problems caused by the lack of depth sorting.
|
// This solves a few of the problems caused by the lack of depth sorting.
|
||||||
// TO-DO: Implement proper depth sorting.
|
// TO-DO: Implement proper depth sorting.
|
||||||
if (!(actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]))
|
if (!(actor->RenderStyle == DefaultRenderStyle()))
|
||||||
{
|
{
|
||||||
glEnable(GL_CULL_FACE);
|
di->SetCulling((mirrored ^ screen->mPortalState->isMirrored()) ? Cull_CW : Cull_CCW);
|
||||||
glFrontFace((mirrored ^ screen->mPortalState->isMirrored()) ? GL_CW : GL_CCW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_RenderState.mModelMatrix = objectToWorldMatrix;
|
state.mModelMatrix = objectToWorldMatrix;
|
||||||
gl_RenderState.EnableModelMatrix(true);
|
state.EnableModelMatrix(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::EndDrawHUDModel(AActor *actor)
|
void FGLModelRenderer::EndDrawHUDModel(AActor *actor)
|
||||||
{
|
{
|
||||||
gl_RenderState.EnableModelMatrix(false);
|
state.EnableModelMatrix(false);
|
||||||
|
|
||||||
glDepthFunc(GL_LESS);
|
di->SetDepthFunc(DF_Less);
|
||||||
if (!(actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]))
|
if (!(actor->RenderStyle == DefaultRenderStyle()))
|
||||||
glDisable(GL_CULL_FACE);
|
di->SetCulling(Cull_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
IModelVertexBuffer *FGLModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe)
|
IModelVertexBuffer *FGLModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe)
|
||||||
|
@ -116,35 +112,34 @@ IModelVertexBuffer *FGLModelRenderer::CreateVertexBuffer(bool needindex, bool si
|
||||||
|
|
||||||
void FGLModelRenderer::SetVertexBuffer(IModelVertexBuffer *buffer)
|
void FGLModelRenderer::SetVertexBuffer(IModelVertexBuffer *buffer)
|
||||||
{
|
{
|
||||||
static_cast<FModelVertexBuffer*>(buffer)->Bind(gl_RenderState);
|
static_cast<FModelVertexBuffer*>(buffer)->Bind(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::ResetVertexBuffer()
|
void FGLModelRenderer::ResetVertexBuffer()
|
||||||
{
|
{
|
||||||
GLRenderer->mVBO->Bind(gl_RenderState);
|
GLRenderer->mVBO->Bind(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::SetInterpolation(double inter)
|
void FGLModelRenderer::SetInterpolation(double inter)
|
||||||
{
|
{
|
||||||
gl_RenderState.SetInterpolationFactor((float)inter);
|
state.SetInterpolationFactor((float)inter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::SetMaterial(FTexture *skin, bool clampNoFilter, int translation)
|
void FGLModelRenderer::SetMaterial(FTexture *skin, bool clampNoFilter, int translation)
|
||||||
{
|
{
|
||||||
FMaterial * tex = FMaterial::ValidateTexture(skin, false);
|
FMaterial * tex = FMaterial::ValidateTexture(skin, false);
|
||||||
gl_RenderState.ApplyMaterial(tex, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1);
|
state.SetMaterial(tex, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1);
|
||||||
/*if (modellightindex != -1)*/ gl_RenderState.SetLightIndex(modellightindex);
|
state.SetLightIndex(modellightindex);
|
||||||
gl_RenderState.Apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::DrawArrays(int start, int count)
|
void FGLModelRenderer::DrawArrays(int start, int count)
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_TRIANGLES, start, count);
|
di->Draw(DT_Triangles, state, start, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGLModelRenderer::DrawElements(int numIndices, size_t offset)
|
void FGLModelRenderer::DrawElements(int numIndices, size_t offset)
|
||||||
{
|
{
|
||||||
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, (void*)(intptr_t)offset);
|
di->DrawIndexed(DT_Triangles, state, offset / sizeof(unsigned int), numIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
@ -162,7 +157,7 @@ FModelVertexBuffer::FModelVertexBuffer(bool needindex, bool singleframe)
|
||||||
{ 0, VATTR_VERTEX, VFmt_Float3, myoffsetof(FModelVertex, x) },
|
{ 0, VATTR_VERTEX, VFmt_Float3, myoffsetof(FModelVertex, x) },
|
||||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, myoffsetof(FModelVertex, u) },
|
{ 0, VATTR_TEXCOORD, VFmt_Float2, myoffsetof(FModelVertex, u) },
|
||||||
{ 0, VATTR_NORMAL, VFmt_Packed_A2R10G10B10, myoffsetof(FModelVertex, packedNormal) },
|
{ 0, VATTR_NORMAL, VFmt_Packed_A2R10G10B10, myoffsetof(FModelVertex, packedNormal) },
|
||||||
{ 0, VATTR_VERTEX2, VFmt_Float3, myoffsetof(FModelVertex, x) }
|
{ 1, VATTR_VERTEX2, VFmt_Float3, myoffsetof(FModelVertex, x) }
|
||||||
};
|
};
|
||||||
mVertexBuffer->SetFormat(2, 4, sizeof(FModelVertex), format);
|
mVertexBuffer->SetFormat(2, 4, sizeof(FModelVertex), format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,9 @@ class FGLModelRenderer : public FModelRenderer
|
||||||
{
|
{
|
||||||
int modellightindex = -1;
|
int modellightindex = -1;
|
||||||
FDrawInfo *di;
|
FDrawInfo *di;
|
||||||
|
FRenderState &state;
|
||||||
public:
|
public:
|
||||||
FGLModelRenderer(FDrawInfo *d, int mli) : modellightindex(mli), di(d)
|
FGLModelRenderer(FDrawInfo *d, FRenderState &st, int mli) : modellightindex(mli), di(d), state(st)
|
||||||
{}
|
{}
|
||||||
ModelRendererType GetType() const override { return GLModelRendererType; }
|
ModelRendererType GetType() const override { return GLModelRendererType; }
|
||||||
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
|
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
|
||||||
|
|
|
@ -70,7 +70,6 @@ void FGLRenderState::Reset()
|
||||||
stBlendEquation = -1;
|
stBlendEquation = -1;
|
||||||
stAlphaTest = 0;
|
stAlphaTest = 0;
|
||||||
mLastDepthClamp = true;
|
mLastDepthClamp = true;
|
||||||
mInterpolationFactor = 0.0f;
|
|
||||||
|
|
||||||
mEffectState = 0;
|
mEffectState = 0;
|
||||||
activeShader = nullptr;
|
activeShader = nullptr;
|
||||||
|
|
|
@ -53,8 +53,6 @@ class FGLRenderState : public FRenderState
|
||||||
float mGlossiness, mSpecularLevel;
|
float mGlossiness, mSpecularLevel;
|
||||||
float mShaderTimer;
|
float mShaderTimer;
|
||||||
|
|
||||||
float mInterpolationFactor;
|
|
||||||
|
|
||||||
int mEffectState;
|
int mEffectState;
|
||||||
int mTempTM = TM_NORMAL;
|
int mTempTM = TM_NORMAL;
|
||||||
|
|
||||||
|
@ -127,16 +125,6 @@ public:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetInterpolationFactor(float fac)
|
|
||||||
{
|
|
||||||
mInterpolationFactor = fac;
|
|
||||||
}
|
|
||||||
|
|
||||||
float GetInterpolationFactor()
|
|
||||||
{
|
|
||||||
return mInterpolationFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetPassType(EPassType passType)
|
void SetPassType(EPassType passType)
|
||||||
{
|
{
|
||||||
mPassType = passType;
|
mPassType = passType;
|
||||||
|
|
|
@ -241,13 +241,13 @@ void FDrawInfo::DrawIndexed(EDrawType dt, FRenderState &state, int index, int co
|
||||||
|
|
||||||
void FDrawInfo::DrawModel(GLSprite *spr, FRenderState &state)
|
void FDrawInfo::DrawModel(GLSprite *spr, FRenderState &state)
|
||||||
{
|
{
|
||||||
FGLModelRenderer renderer(this, spr->dynlightindex);
|
FGLModelRenderer renderer(this, state, spr->dynlightindex);
|
||||||
renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor, Viewpoint.TicFrac);
|
renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor, Viewpoint.TicFrac);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FDrawInfo::DrawHUDModel(HUDSprite *huds, FRenderState &state)
|
void FDrawInfo::DrawHUDModel(HUDSprite *huds, FRenderState &state)
|
||||||
{
|
{
|
||||||
FGLModelRenderer renderer(this, huds->lightindex);
|
FGLModelRenderer renderer(this, state, huds->lightindex);
|
||||||
renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my);
|
renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,6 +305,19 @@ void FDrawInfo::SetStencil(int offs, int op, int flags)
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FDrawInfo::SetCulling(int mode)
|
||||||
|
{
|
||||||
|
if (mode != Cull_None)
|
||||||
|
{
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glFrontFace(mode == Cull_CCW ? GL_CCW : GL_CW);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
|
|
@ -53,6 +53,7 @@ struct FDrawInfo : public HWDrawInfo
|
||||||
void SetDepthRange(float min, float max) override;
|
void SetDepthRange(float min, float max) override;
|
||||||
void EnableDrawBufferAttachments(bool on) override;
|
void EnableDrawBufferAttachments(bool on) override;
|
||||||
void SetStencil(int offs, int op, int flags) override;
|
void SetStencil(int offs, int op, int flags) override;
|
||||||
|
void SetCulling(int mode) override;
|
||||||
|
|
||||||
void StartScene();
|
void StartScene();
|
||||||
|
|
||||||
|
|
|
@ -350,7 +350,7 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
||||||
|
|
||||||
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
|
FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli)
|
||||||
{
|
{
|
||||||
return new FGLModelRenderer(nullptr, mli);
|
return new FGLModelRenderer(nullptr, gl_RenderState, mli);
|
||||||
}
|
}
|
||||||
|
|
||||||
IUniformBuffer *OpenGLFrameBuffer::CreateUniformBuffer(size_t size, bool staticuse)
|
IUniformBuffer *OpenGLFrameBuffer::CreateUniformBuffer(size_t size, bool staticuse)
|
||||||
|
|
|
@ -49,7 +49,12 @@ enum EStencilOp
|
||||||
SOP_Decrement = 2
|
SOP_Decrement = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ECull
|
||||||
|
{
|
||||||
|
Cull_None,
|
||||||
|
Cull_CCW,
|
||||||
|
Cull_CW
|
||||||
|
};
|
||||||
|
|
||||||
struct FSectorPortalGroup;
|
struct FSectorPortalGroup;
|
||||||
struct FLinePortalSpan;
|
struct FLinePortalSpan;
|
||||||
|
@ -356,6 +361,7 @@ public:
|
||||||
virtual void SetDepthRange(float min, float max) = 0;
|
virtual void SetDepthRange(float min, float max) = 0;
|
||||||
virtual void EnableDrawBufferAttachments(bool on) = 0;
|
virtual void EnableDrawBufferAttachments(bool on) = 0;
|
||||||
virtual void SetStencil(int offs, int op, int flags) = 0;
|
virtual void SetStencil(int offs, int op, int flags) = 0;
|
||||||
|
virtual void SetCulling(int mode) = 0;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,6 +93,7 @@ protected:
|
||||||
|
|
||||||
float mAlphaThreshold;
|
float mAlphaThreshold;
|
||||||
float mClipSplit[2];
|
float mClipSplit[2];
|
||||||
|
float mInterpolationFactor;
|
||||||
|
|
||||||
FStateVec4 mNormal;
|
FStateVec4 mNormal;
|
||||||
FStateVec4 mColor;
|
FStateVec4 mColor;
|
||||||
|
@ -138,6 +139,7 @@ public:
|
||||||
mLightParms[3] = -1.f;
|
mLightParms[3] = -1.f;
|
||||||
mSpecialEffect = EFF_NONE;
|
mSpecialEffect = EFF_NONE;
|
||||||
mLightIndex = -1;
|
mLightIndex = -1;
|
||||||
|
mInterpolationFactor = 0;
|
||||||
mRenderStyle = DefaultRenderStyle();
|
mRenderStyle = DefaultRenderStyle();
|
||||||
mMaterial.Reset();
|
mMaterial.Reset();
|
||||||
mBias.Reset();
|
mBias.Reset();
|
||||||
|
@ -407,6 +409,16 @@ public:
|
||||||
mIndexBuffer = ib;
|
mIndexBuffer = ib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetInterpolationFactor(float fac)
|
||||||
|
{
|
||||||
|
mInterpolationFactor = fac;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetInterpolationFactor()
|
||||||
|
{
|
||||||
|
return mInterpolationFactor;
|
||||||
|
}
|
||||||
|
|
||||||
void SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false);
|
void SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false);
|
||||||
void SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);
|
void SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue