- made sky vertex buffer backend independent.

This commit is contained in:
Christoph Oelckers 2018-10-27 21:31:27 +02:00
parent b92b7ca0a7
commit 067716cefb
8 changed files with 53 additions and 57 deletions

View File

@ -91,28 +91,3 @@ void FSimpleVertexBuffer::set(FSimpleVertex *verts, int count)
glBufferData(GL_ARRAY_BUFFER, count * sizeof(*verts), verts, GL_STREAM_DRAW); glBufferData(GL_ARRAY_BUFFER, count * sizeof(*verts), verts, GL_STREAM_DRAW);
} }
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
FSkyVertexBuffer::FSkyVertexBuffer()
{
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
glBufferData(GL_ARRAY_BUFFER, mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], GL_STATIC_DRAW);
}
void FSkyVertexBuffer::BindVBO()
{
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->x);
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->u);
glVertexAttribPointer(VATTR_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(FSkyVertex), &VSO->color);
glEnableVertexAttribArray(VATTR_VERTEX);
glEnableVertexAttribArray(VATTR_TEXCOORD);
glEnableVertexAttribArray(VATTR_COLOR);
glDisableVertexAttribArray(VATTR_VERTEX2);
glDisableVertexAttribArray(VATTR_NORMAL);
}

View File

@ -86,16 +86,4 @@ public:
void EnableColorArray(bool on); void EnableColorArray(bool on);
}; };
class FSkyVertexBuffer : public FVertexBuffer, public FSkyDomeCreator
{
public:
FSkyVertexBuffer();
void BindVBO();
};
#define VSO ((FSkyVertex*)NULL)
#endif #endif

View File

@ -395,6 +395,6 @@ void FGLRenderState::ApplyBlendMode()
// Needs to be redone // Needs to be redone
void FGLRenderState::SetVertexBuffer(int which) void FGLRenderState::SetVertexBuffer(int which)
{ {
if (which == VB_Sky) SetVertexBuffer(GLRenderer->mSkyVBO); if (which == VB_Sky) GLRenderer->mSkyVBO->Bind(*this);
else GLRenderer->mVBO->Bind(*this); else GLRenderer->mVBO->Bind(*this);
} }

View File

@ -6,7 +6,7 @@
#include "hw_drawstructs.h" #include "hw_drawstructs.h"
#include "hwrenderer/textures/hw_material.h" #include "hwrenderer/textures/hw_material.h"
class FSkyDomeCreator; class FSkyVertexBuffer;
struct GLSkyInfo struct GLSkyInfo
{ {
@ -379,7 +379,7 @@ public:
struct HWSkyPortal : public HWPortal struct HWSkyPortal : public HWPortal
{ {
GLSkyInfo * origin; GLSkyInfo * origin;
FSkyDomeCreator *vertexBuffer; FSkyVertexBuffer *vertexBuffer;
friend struct HWEEHorizonPortal; friend struct HWEEHorizonPortal;
void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true); void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true);
@ -396,7 +396,7 @@ protected:
public: public:
HWSkyPortal(FSkyDomeCreator *vertexbuffer, FPortalSceneState *state, GLSkyInfo * pt, bool local = false) HWSkyPortal(FSkyVertexBuffer *vertexbuffer, FPortalSceneState *state, GLSkyInfo * pt, bool local = false)
: HWPortal(state, local) : HWPortal(state, local)
{ {
origin = pt; origin = pt;

View File

@ -23,7 +23,7 @@
** **
** Draws the sky. Loosely based on the JDoom sky and the ZDoomGL 0.66.2 sky. ** Draws the sky. Loosely based on the JDoom sky and the ZDoomGL 0.66.2 sky.
** **
** for FSkyDomeCreator::SkyVertex only: ** for FSkyVertexBuffer::SkyVertex only:
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** Copyright 2003 Tim Stump ** Copyright 2003 Tim Stump
** All rights reserved. ** All rights reserved.
@ -60,10 +60,13 @@
#include "r_utility.h" #include "r_utility.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "r_sky.h" #include "r_sky.h"
#include "cmdlib.h"
#include "textures/skyboxtexture.h" #include "textures/skyboxtexture.h"
#include "hwrenderer/textures/hw_material.h" #include "hwrenderer/textures/hw_material.h"
#include "hw_skydome.h" #include "hw_skydome.h"
#include "hw_renderstate.h"
#include "hwrenderer/data/vertexbuffer.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
@ -79,13 +82,28 @@ EXTERN_CVAR(Float, skyoffset)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
FSkyDomeCreator::FSkyDomeCreator() FSkyVertexBuffer::FSkyVertexBuffer()
{ {
screen->mSkyData = this; screen->mSkyData = this;
CreateDome(); CreateDome();
mVertexBuffer = screen->CreateVertexBuffer();
static const FVertexBufferAttribute format[] = {
{ 0, VATTR_VERTEX, VFmt_Float3, myoffsetof(FSkyVertex, x) },
{ 0, VATTR_TEXCOORD, VFmt_Float2, myoffsetof(FSkyVertex, u) },
{ 0, VATTR_COLOR, VFmt_Byte4, myoffsetof(FSkyVertex, color) }
};
mVertexBuffer->SetFormat(1, 3, sizeof(FSkyVertex), format);
mVertexBuffer->SetData(mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], true);
} }
FSkyDomeCreator::~FSkyDomeCreator() //-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
FSkyVertexBuffer::~FSkyVertexBuffer()
{ {
if (screen && screen->mSkyData) screen->mSkyData = nullptr; if (screen && screen->mSkyData) screen->mSkyData = nullptr;
} }
@ -96,7 +114,18 @@ FSkyDomeCreator::~FSkyDomeCreator()
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FSkyDomeCreator::SkyVertex(int r, int c, bool zflip) void FSkyVertexBuffer::Bind(FRenderState &state)
{
state.SetVertexBuffer(mVertexBuffer, 0, 0);
}
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void FSkyVertexBuffer::SkyVertex(int r, int c, bool zflip)
{ {
static const FAngle maxSideAngle = 60.f; static const FAngle maxSideAngle = 60.f;
static const float scale = 10000.; static const float scale = 10000.;
@ -140,7 +169,7 @@ void FSkyDomeCreator::SkyVertex(int r, int c, bool zflip)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FSkyDomeCreator::CreateSkyHemisphere(int hemi) void FSkyVertexBuffer::CreateSkyHemisphere(int hemi)
{ {
int r, c; int r, c;
bool zflip = !!(hemi & SKYHEMI_LOWER); bool zflip = !!(hemi & SKYHEMI_LOWER);
@ -171,7 +200,7 @@ void FSkyDomeCreator::CreateSkyHemisphere(int hemi)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FSkyDomeCreator::CreateDome() void FSkyVertexBuffer::CreateDome()
{ {
// the first thing we put into the buffer is the fog layer object which is just 4 triangles around the viewpoint. // the first thing we put into the buffer is the fog layer object which is just 4 triangles around the viewpoint.
@ -270,7 +299,7 @@ void FSkyDomeCreator::CreateDome()
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FSkyDomeCreator::SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) void FSkyVertexBuffer::SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix)
{ {
int texw = tex->TextureWidth(); int texw = tex->TextureWidth();
int texh = tex->TextureHeight(); int texh = tex->TextureHeight();

View File

@ -4,6 +4,8 @@
#include "r_data/matrix.h" #include "r_data/matrix.h"
class FMaterial; class FMaterial;
class FRenderState;
class IVertexBuffer;
struct FSkyVertex struct FSkyVertex
{ {
@ -33,7 +35,7 @@ struct FSkyVertex
}; };
struct HWSkyPortal; struct HWSkyPortal;
class FSkyDomeCreator class FSkyVertexBuffer
{ {
friend struct HWSkyPortal; friend struct HWSkyPortal;
public: public:
@ -47,7 +49,8 @@ public:
SKYMODE_FOGLAYER = 2 SKYMODE_FOGLAYER = 2
}; };
protected: IVertexBuffer *mVertexBuffer;
TArray<FSkyVertex> mVertices; TArray<FSkyVertex> mVertices;
TArray<unsigned int> mPrimStart; TArray<unsigned int> mPrimStart;
@ -63,9 +66,10 @@ protected:
public: public:
FSkyDomeCreator(); FSkyVertexBuffer();
virtual ~FSkyDomeCreator(); virtual ~FSkyVertexBuffer();
void SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix); void SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix);
void Bind(FRenderState &state);
int FaceStart(int i) int FaceStart(int i)
{ {

View File

@ -64,7 +64,7 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te
int rc = vertexBuffer->mRows + 1; int rc = vertexBuffer->mRows + 1;
// The caps only get drawn for the main layer but not for the overlay. // The caps only get drawn for the main layer but not for the overlay.
if (mode == FSkyDomeCreator::SKYMODE_MAINLAYER && tex != NULL) if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL)
{ {
PalEntry pe = tex->tex->GetSkyCapColor(false); PalEntry pe = tex->tex->GetSkyCapColor(false);
state.SetObjectColor(pe); state.SetObjectColor(pe);
@ -192,7 +192,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
if (origin->texture[0]) if (origin->texture[0])
{ {
state.SetTextureMode(TM_OPAQUE); state.SetTextureMode(TM_OPAQUE);
RenderDome(di, state, origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyDomeCreator::SKYMODE_MAINLAYER); RenderDome(di, state, origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyVertexBuffer::SKYMODE_MAINLAYER);
state.SetTextureMode(TM_NORMAL); state.SetTextureMode(TM_NORMAL);
} }
@ -200,7 +200,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
if (origin->doublesky && origin->texture[1]) if (origin->doublesky && origin->texture[1])
{ {
RenderDome(di, state, origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyDomeCreator::SKYMODE_SECONDLAYER); RenderDome(di, state, origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER);
} }
if (::level.skyfog>0 && !di->isFullbrightScene() && (origin->fadecolor & 0xffffff) != 0) if (::level.skyfog>0 && !di->isFullbrightScene() && (origin->fadecolor & 0xffffff) != 0)

View File

@ -49,7 +49,7 @@ struct sector_t;
class IShaderProgram; class IShaderProgram;
class FTexture; class FTexture;
struct FPortalSceneState; struct FPortalSceneState;
class FSkyDomeCreator; class FSkyVertexBuffer;
class IIndexBuffer; class IIndexBuffer;
class IVertexBuffer; class IVertexBuffer;
@ -371,7 +371,7 @@ public:
int stencilValue = 0; // Global stencil test value int stencilValue = 0; // Global stencil test value
bool enable_quadbuffered = false; bool enable_quadbuffered = false;
FPortalSceneState *mPortalState; // global portal state. FPortalSceneState *mPortalState; // global portal state.
FSkyDomeCreator *mSkyData; // we need access to this in the device independent part, but cannot depend on how the renderer manages it internally. FSkyVertexBuffer *mSkyData; // we need access to this in the device independent part, but cannot depend on how the renderer manages it internally.
IntRect mScreenViewport; IntRect mScreenViewport;
IntRect mSceneViewport; IntRect mSceneViewport;