Skip to content

Commit

Permalink
Clean up API boundary for plGLDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Sep 9, 2023
1 parent 93e3299 commit dcfa61f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
7 changes: 7 additions & 0 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class plGLDeviceImpl

class plGLDevice
{
friend class plGLPipeline;

public:
typedef plGLVertexBufferRef VertexBufferRef;
typedef plGLIndexBufferRef IndexBufferRef;
Expand All @@ -93,6 +91,7 @@ class plGLDevice
public:
plGLDevice();

void Setup(plGLPipeline* pipe, hsWindowHndl window, hsWindowHndl device);
void Shutdown();

/**
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 14 additions & 16 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -742,7 +740,7 @@ void plGLPipeline::RenderSpans(plDrawableSpans* ice, const std::vector<int16_t>&
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;
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dcfa61f

Please sign in to comment.