diff --git a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp index b34a4b1306..6d3c8589b6 100644 --- a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp +++ b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp @@ -89,6 +89,13 @@ plGLDevice::plGLDevice() memcpy(fMatrixProj, kIdentityMatrix, sizeof(GLfloat) * 16); } +void plGLDevice::Setup(plGLPipeline* pipe, hsWindowHndl window, hsWindowHndl device) +{ + fPipeline = pipe; + fWindow = window; + fDevice = device; +} + bool plGLDevice::InitDevice() { #ifdef USE_EGL diff --git a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h index 2bd23550de..d648c78b32 100644 --- a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h +++ b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h @@ -69,8 +69,6 @@ class plGLDeviceImpl class plGLDevice { - friend class plGLPipeline; - public: typedef plGLVertexBufferRef VertexBufferRef; typedef plGLIndexBufferRef IndexBufferRef; @@ -93,6 +91,7 @@ class plGLDevice public: plGLDevice(); + void Setup(plGLPipeline* pipe, hsWindowHndl window, hsWindowHndl device); void Shutdown(); /** @@ -131,8 +130,18 @@ class plGLDevice void SetWorldToCameraMatrix(const hsMatrix44& src); void SetLocalToWorldMatrix(const hsMatrix44& src); + void SetCurrentProgram(GLuint program) { fCurrentProgram = program; } + const char* GetErrorString() const { return fErrorMsg; } + bool HasContext() const { return fImpl != nullptr; } + + const GLfloat* GetL2WMatrix() const { return fMatrixL2W; } + const GLfloat* GetW2LMatrix() const { return fMatrixW2L; } + const GLfloat* GetC2WMatrix() const { return fMatrixC2W; } + const GLfloat* GetW2CMatrix() const { return fMatrixW2C; } + const GLfloat* GetProjectionMatrix() const { return fMatrixProj; } + private: /** * Initializes the OpenGL rendering context. diff --git a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp index 986833a210..70a9c54a79 100644 --- a/Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp @@ -193,9 +193,7 @@ plGLPipeline::plGLPipeline(hsWindowHndl display, hsWindowHndl window, const hsG3 plStatusLog::AddLineS("pipeline.log", "Constructing plGLPipeline"); plStatusLog::AddLineSF("pipeline.log", "Driver vendor: {}", devMode->GetDevice()->GetDriverDesc()); - fDevice.fWindow = window; - fDevice.fDevice = display; - fDevice.fPipeline = this; + fDevice.Setup(this, window, display); fPlateMgr = new plGLPlateManager(this); } @@ -607,7 +605,7 @@ void plGLPipeline::LoadResources() IReleaseAvRTPool(); - if (!fDevice.fImpl) { + if (!fDevice.HasContext()) { // We can't create anything if the OpenGL context isn't initialized plProfile_IncCount(PipeReload, 1); @@ -742,7 +740,7 @@ void plGLPipeline::RenderSpans(plDrawableSpans* ice, const std::vector& mRef->Link(&fMatRefList); glUseProgram(mRef->fRef); - fDevice.fCurrentProgram = mRef->fRef; + fDevice.SetCurrentProgram(mRef->fRef); LOG_GL_ERROR_CHECK(ST::format("Use Program with material \"{}\" failed", material->GetKeyName())); GLuint vao = 0; @@ -821,13 +819,13 @@ void plGLPipeline::ISetupTransforms(plDrawableSpans* drawable, const plSpan& spa if (mRef) { /* Push the matrices into the GLSL shader now */ - glUniformMatrix4fv(mRef->uMatrixProj, 1, GL_TRUE, fDevice.fMatrixProj); - glUniformMatrix4fv(mRef->uMatrixW2C, 1, GL_TRUE, fDevice.fMatrixW2C); - glUniformMatrix4fv(mRef->uMatrixL2W, 1, GL_TRUE, fDevice.fMatrixL2W); - glUniformMatrix4fv(mRef->uMatrixW2L, 1, GL_TRUE, fDevice.fMatrixW2L); + glUniformMatrix4fv(mRef->uMatrixProj, 1, GL_TRUE, fDevice.GetProjectionMatrix()); + glUniformMatrix4fv(mRef->uMatrixW2C, 1, GL_TRUE, fDevice.GetW2CMatrix()); + glUniformMatrix4fv(mRef->uMatrixL2W, 1, GL_TRUE, fDevice.GetL2WMatrix()); + glUniformMatrix4fv(mRef->uMatrixW2L, 1, GL_TRUE, fDevice.GetW2LMatrix()); if (mRef->uMatrixC2W != -1) - glUniformMatrix4fv(mRef->uMatrixC2W, 1, GL_TRUE, fDevice.fMatrixC2W); + glUniformMatrix4fv(mRef->uMatrixC2W, 1, GL_TRUE, fDevice.GetC2WMatrix()); } } @@ -1488,7 +1486,7 @@ void plGLPipeline::IDrawPlate(plPlate* plate) mRef->Link(&fMatRefList); glUseProgram(mRef->fRef); - fDevice.fCurrentProgram = mRef->fRef; + fDevice.SetCurrentProgram(mRef->fRef); mRef->SetupTextureRefs(); @@ -1501,12 +1499,12 @@ void plGLPipeline::IDrawPlate(plPlate* plate) /* Push the matrices into the GLSL shader now */ glUniformMatrix4fv(mRef->uMatrixProj, 1, GL_TRUE, projMat); - glUniformMatrix4fv(mRef->uMatrixW2C, 1, GL_TRUE, fDevice.fMatrixW2C); - glUniformMatrix4fv(mRef->uMatrixC2W, 1, GL_TRUE, fDevice.fMatrixC2W); - glUniformMatrix4fv(mRef->uMatrixL2W, 1, GL_TRUE, fDevice.fMatrixL2W); + glUniformMatrix4fv(mRef->uMatrixW2C, 1, GL_TRUE, fDevice.GetW2CMatrix()); + glUniformMatrix4fv(mRef->uMatrixC2W, 1, GL_TRUE, fDevice.GetC2WMatrix()); + glUniformMatrix4fv(mRef->uMatrixL2W, 1, GL_TRUE, fDevice.GetL2WMatrix()); if (mRef->uMatrixW2L != -1) - glUniformMatrix4fv(mRef->uMatrixW2L, 1, GL_TRUE, fDevice.fMatrixW2L); + glUniformMatrix4fv(mRef->uMatrixW2L, 1, GL_TRUE, fDevice.GetW2LMatrix()); glUniform1f(mRef->uInvertVtxAlpha, 0.f); glUniform1f(mRef->uAlphaThreshold, 0.f); @@ -1655,7 +1653,7 @@ void plGLPipeline::IPreprocessAvatarTextures() glUseProgram(sProgram); LOG_GL_ERROR_CHECK("Use Program failed"); - fDevice.fCurrentProgram = sProgram; + fDevice.SetCurrentProgram(sProgram); glUniform1i(0, 0); glUniform4f(1, 1.f, 1.f, 1.f, 1.f);