Skip to content

Commit

Permalink
Add plGLVersion helper function for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Feb 5, 2023
1 parent 361fdbd commit a16b01e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
16 changes: 8 additions & 8 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ bool plGLDevice::InitDevice()
plStatusLog::AddLineSF("pipeline.log", "Initialized with OpenGL {}", reinterpret_cast<const char*>(glGetString(GL_VERSION)));

#ifdef HS_DEBUGGING
if (epoxy_gl_version() >= 43) {
if (plGLVersion() >= 43) {
glEnable(GL_DEBUG_OUTPUT);

// Turn off low-severity messages
Expand Down Expand Up @@ -544,7 +544,7 @@ void plGLDevice::CheckStaticVertexBuffer(VertexBufferRef* vRef, plGBufferGroup*
hsAssert(!vRef->Volatile(), "Creating a managed vertex buffer for a volatile buffer ref");

if (!vRef->fRef) {
if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glCreateBuffers(1, &vRef->fRef);
} else {
glGenBuffers(1, &vRef->fRef);
Expand Down Expand Up @@ -573,7 +573,7 @@ void plGLDevice::FillStaticVertexBufferRef(VertexBufferRef* ref, plGBufferGroup*


if (ref->fData) {
if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glNamedBufferData(ref->fRef, size, ref->fData + vertStart, GL_STATIC_DRAW);
} else {
glBindBuffer(GL_ARRAY_BUFFER, ref->fRef);
Expand Down Expand Up @@ -624,7 +624,7 @@ void plGLDevice::FillStaticVertexBufferRef(VertexBufferRef* ref, plGBufferGroup*
}

hsAssert((ptr - buffer) == size, "Didn't fill the buffer?");
if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glNamedBufferData(ref->fRef, size, buffer, GL_STATIC_DRAW);
} else {
glBindBuffer(GL_ARRAY_BUFFER, ref->fRef);
Expand Down Expand Up @@ -694,7 +694,7 @@ void plGLDevice::CheckIndexBuffer(IndexBufferRef* iRef)
if (!iRef->fRef && iRef->fCount) {
iRef->SetVolatile(false);

if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glCreateBuffers(1, &iRef->fRef);
} else {
glGenBuffers(1, &iRef->fRef);
Expand All @@ -713,7 +713,7 @@ void plGLDevice::FillIndexBufferRef(IndexBufferRef* iRef, plGBufferGroup* owner,
if (!size)
return;

if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glNamedBufferData(iRef->fRef, size, owner->GetIndexBufferData(idx) + startIdx, GL_STATIC_DRAW);
} else {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iRef->fRef);
Expand Down Expand Up @@ -824,7 +824,7 @@ void plGLDevice::MakeTextureRef(TextureRef* tRef, plLayerInterface* layer, plMip
glBindTexture(tRef->fMapping, tRef->fRef);
BindTexture(tRef, img, tRef->fMapping);

if (epoxy_gl_version() >= 43) {
if (plGLVersion() >= 43) {
glObjectLabel(GL_TEXTURE, tRef->fRef, -1, img->GetKeyName().c_str());
}

Expand Down Expand Up @@ -860,7 +860,7 @@ void plGLDevice::MakeCubicTextureRef(TextureRef* tRef, plLayerInterface* layer,
BindTexture(tRef, img->GetFace(i), kFaceMapping[i]);
}

if (epoxy_gl_version() >= 43) {
if (plGLVersion() >= 43) {
glObjectLabel(GL_TEXTURE, tRef->fRef, -1, img->GetKeyName().c_str());
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDeviceRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include <epoxy/gl.h>

inline int plGLVersion() {
// This exists for testing purposes to force the pipeline to behave as if a
// specific version of OpenGL were present, mainly for ensuring
// compatibility with older GL API versions on machines where newer
// versions are available by default. To pretend to be limited to a
// specific version, just return the GL version with the decimal removed as
// an integer:

// return 42; // Pretend we only support OpenGL 4.2
return epoxy_gl_version();
}

// Helper macro for logging GL Errors
#ifdef HS_DEBUGGING
# include "plStatusLog/plStatusLog.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void plGLMaterialShaderRef::ICompile()
fRef = glCreateProgram();
LOG_GL_ERROR_CHECK("Create Program failed");

if (epoxy_gl_version() >= 43) {
if (plGLVersion() >= 43) {
const char* name = ST::format("hsGMaterial::{}", fMaterial->GetKeyName()).c_str();
glObjectLabel(GL_PROGRAM, fRef, strlen(name), name);
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ hsGDeviceRef* plGLPipeline::MakeRenderTargetRef(plRenderTarget* owner)
// since we only render one face at a time. If we were rendering part of face X, then part
// of face Y, then more of face X, then they would all need their own depth buffers.
if (owner->GetZDepth() && (owner->GetFlags() & (plRenderTarget::kIsTexture | plRenderTarget::kIsOffscreen))) {
if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glCreateRenderbuffers(1, &depthBuffer);
glNamedRenderbufferStorage(depthBuffer, GL_DEPTH24_STENCIL8, owner->GetWidth(), owner->GetHeight());
} else {
Expand Down Expand Up @@ -409,7 +409,7 @@ hsGDeviceRef* plGLPipeline::MakeRenderTargetRef(plRenderTarget* owner)
ref->fDepthBuffer = depthBuffer;
ref->fMapping = GL_TEXTURE_2D;

if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glCreateTextures(GL_TEXTURE_2D, 1, &ref->fRef);
glTextureStorage2D(ref->fRef, 1, GL_RGBA8, owner->GetWidth(), owner->GetHeight());
glTextureParameteri(ref->fRef, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Expand Down Expand Up @@ -673,7 +673,7 @@ void plGLPipeline::RenderSpans(plDrawableSpans* ice, const std::vector<int16_t>&
LOG_GL_ERROR_CHECK(ST::format("Use Program with material \"{}\" failed", material->GetKeyName()));

GLuint vao = 0;
if (epoxy_gl_version() >= 30) {
if (plGLVersion() >= 30) {
// TODO: Figure out how to use VAOs properly :(
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
Expand Down Expand Up @@ -704,7 +704,7 @@ void plGLPipeline::RenderSpans(plDrawableSpans* ice, const std::vector<int16_t>&
tempIce.fVStartIdx, tempIce.fVLength, // These are used as our accumulated range
tempIce.fIPackedIdx, tempIce.fILength );

if (epoxy_gl_version() >= 30)
if (plGLVersion() >= 30)
glDeleteVertexArrays(1, &vao);
}

Expand Down
16 changes: 8 additions & 8 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLPlateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void plGLPlateManager::ICreateGeometry()

GLuint vbo, ibo, vao = 0;

if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 45) {
glCreateBuffers(1, &vbo);
glObjectLabel(GL_BUFFER, vbo, -1, "plPlate/VBO");
glNamedBufferStorage(vbo, sizeof(verts), verts, 0);
Expand Down Expand Up @@ -112,7 +112,7 @@ void plGLPlateManager::ICreateGeometry()
glVertexArrayAttribBinding(vao, kVtxColor, 0);
glVertexArrayAttribBinding(vao, kVtxUVWSrc, 0);
} else {
if (epoxy_gl_version() >= 30) {
if (plGLVersion() >= 30) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
}
Expand All @@ -125,9 +125,9 @@ void plGLPlateManager::ICreateGeometry()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

if (epoxy_gl_version() >= 30) {
if (plGLVersion() >= 30) {
glEnableVertexAttribArray(kVtxPosition);
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), 0);
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), (void*)(sizeof(float) * 0));

glEnableVertexAttribArray(kVtxNormal);
glVertexAttribPointer(kVtxNormal, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), (void*)(sizeof(float) * 3));
Expand All @@ -147,8 +147,8 @@ void plGLPlateManager::ICreateGeometry()

void plGLPlateManager::IReleaseGeometry()
{
if (epoxy_gl_version() >= 30 && fBuffers.ARef) {
if (epoxy_gl_version() >= 45) {
if (plGLVersion() >= 30 && fBuffers.ARef) {
if (plGLVersion() >= 45) {
glDisableVertexArrayAttrib(fBuffers.ARef, kVtxPosition);
glDisableVertexArrayAttrib(fBuffers.ARef, kVtxNormal);
glDisableVertexArrayAttrib(fBuffers.ARef, kVtxColor);
Expand Down Expand Up @@ -184,15 +184,15 @@ void plGLPlateManager::IDrawToDevice(plPipeline* pipe)
return;
}

if (epoxy_gl_version() >= 30) {
if (plGLVersion() >= 30) {
if (fBuffers.ARef == 0)
return;

glBindVertexArray(fBuffers.ARef);
} else {
glBindBuffer(GL_ARRAY_BUFFER, fBuffers.VRef);

glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), 0);
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), (void*)(sizeof(float) * 0));
glEnableVertexAttribArray(kVtxPosition);

glVertexAttribPointer(kVtxNormal, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), (void*)(sizeof(float) * 3));
Expand Down

0 comments on commit a16b01e

Please sign in to comment.