diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index c3d61b988..bf1302dcc 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -91,28 +91,3 @@ void FSimpleVertexBuffer::set(FSimpleVertex *verts, int count) 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); -} - diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index 3d6d16345..44d7ba35b 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -86,16 +86,4 @@ public: void EnableColorArray(bool on); }; -class FSkyVertexBuffer : public FVertexBuffer, public FSkyDomeCreator -{ - -public: - - FSkyVertexBuffer(); - void BindVBO(); -}; - - -#define VSO ((FSkyVertex*)NULL) - #endif \ No newline at end of file diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 49279375c..082a2e117 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -395,6 +395,6 @@ void FGLRenderState::ApplyBlendMode() // Needs to be redone 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); } diff --git a/src/hwrenderer/scene/hw_portal.h b/src/hwrenderer/scene/hw_portal.h index 99f69614c..099d09092 100644 --- a/src/hwrenderer/scene/hw_portal.h +++ b/src/hwrenderer/scene/hw_portal.h @@ -6,7 +6,7 @@ #include "hw_drawstructs.h" #include "hwrenderer/textures/hw_material.h" -class FSkyDomeCreator; +class FSkyVertexBuffer; struct GLSkyInfo { @@ -379,7 +379,7 @@ public: struct HWSkyPortal : public HWPortal { GLSkyInfo * origin; - FSkyDomeCreator *vertexBuffer; + FSkyVertexBuffer *vertexBuffer; friend struct HWEEHorizonPortal; void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true); @@ -396,7 +396,7 @@ protected: public: - HWSkyPortal(FSkyDomeCreator *vertexbuffer, FPortalSceneState *state, GLSkyInfo * pt, bool local = false) + HWSkyPortal(FSkyVertexBuffer *vertexbuffer, FPortalSceneState *state, GLSkyInfo * pt, bool local = false) : HWPortal(state, local) { origin = pt; diff --git a/src/hwrenderer/scene/hw_skydome.cpp b/src/hwrenderer/scene/hw_skydome.cpp index 449be72f6..e256391d7 100644 --- a/src/hwrenderer/scene/hw_skydome.cpp +++ b/src/hwrenderer/scene/hw_skydome.cpp @@ -23,7 +23,7 @@ ** ** 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 ** All rights reserved. @@ -60,10 +60,13 @@ #include "r_utility.h" #include "g_levellocals.h" #include "r_sky.h" +#include "cmdlib.h" #include "textures/skyboxtexture.h" #include "hwrenderer/textures/hw_material.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; 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; } @@ -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 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; 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. @@ -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 texh = tex->TextureHeight(); diff --git a/src/hwrenderer/scene/hw_skydome.h b/src/hwrenderer/scene/hw_skydome.h index 6d2bbff52..dd429b810 100644 --- a/src/hwrenderer/scene/hw_skydome.h +++ b/src/hwrenderer/scene/hw_skydome.h @@ -4,6 +4,8 @@ #include "r_data/matrix.h" class FMaterial; +class FRenderState; +class IVertexBuffer; struct FSkyVertex { @@ -33,7 +35,7 @@ struct FSkyVertex }; struct HWSkyPortal; -class FSkyDomeCreator +class FSkyVertexBuffer { friend struct HWSkyPortal; public: @@ -47,7 +49,8 @@ public: SKYMODE_FOGLAYER = 2 }; -protected: + IVertexBuffer *mVertexBuffer; + TArray mVertices; TArray mPrimStart; @@ -63,9 +66,10 @@ protected: public: - FSkyDomeCreator(); - virtual ~FSkyDomeCreator(); + FSkyVertexBuffer(); + virtual ~FSkyVertexBuffer(); 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) { diff --git a/src/hwrenderer/scene/hw_skyportal.cpp b/src/hwrenderer/scene/hw_skyportal.cpp index 6ead548e1..8f5332080 100644 --- a/src/hwrenderer/scene/hw_skyportal.cpp +++ b/src/hwrenderer/scene/hw_skyportal.cpp @@ -64,7 +64,7 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te int rc = vertexBuffer->mRows + 1; // 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); state.SetObjectColor(pe); @@ -192,7 +192,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) if (origin->texture[0]) { 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); } @@ -200,7 +200,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) 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) diff --git a/src/v_video.h b/src/v_video.h index 2087be8c6..d63c8cbaa 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -49,7 +49,7 @@ struct sector_t; class IShaderProgram; class FTexture; struct FPortalSceneState; -class FSkyDomeCreator; +class FSkyVertexBuffer; class IIndexBuffer; class IVertexBuffer; @@ -371,7 +371,7 @@ public: int stencilValue = 0; // Global stencil test value bool enable_quadbuffered = false; 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 mSceneViewport;