Skip to content

Commit a16b01e

Browse files
committed
Add plGLVersion helper function for testing
1 parent 361fdbd commit a16b01e

5 files changed

Lines changed: 33 additions & 21 deletions

File tree

Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool plGLDevice::InitDevice()
368368
plStatusLog::AddLineSF("pipeline.log", "Initialized with OpenGL {}", reinterpret_cast<const char*>(glGetString(GL_VERSION)));
369369

370370
#ifdef HS_DEBUGGING
371-
if (epoxy_gl_version() >= 43) {
371+
if (plGLVersion() >= 43) {
372372
glEnable(GL_DEBUG_OUTPUT);
373373

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

546546
if (!vRef->fRef) {
547-
if (epoxy_gl_version() >= 45) {
547+
if (plGLVersion() >= 45) {
548548
glCreateBuffers(1, &vRef->fRef);
549549
} else {
550550
glGenBuffers(1, &vRef->fRef);
@@ -573,7 +573,7 @@ void plGLDevice::FillStaticVertexBufferRef(VertexBufferRef* ref, plGBufferGroup*
573573

574574

575575
if (ref->fData) {
576-
if (epoxy_gl_version() >= 45) {
576+
if (plGLVersion() >= 45) {
577577
glNamedBufferData(ref->fRef, size, ref->fData + vertStart, GL_STATIC_DRAW);
578578
} else {
579579
glBindBuffer(GL_ARRAY_BUFFER, ref->fRef);
@@ -624,7 +624,7 @@ void plGLDevice::FillStaticVertexBufferRef(VertexBufferRef* ref, plGBufferGroup*
624624
}
625625

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

697-
if (epoxy_gl_version() >= 45) {
697+
if (plGLVersion() >= 45) {
698698
glCreateBuffers(1, &iRef->fRef);
699699
} else {
700700
glGenBuffers(1, &iRef->fRef);
@@ -713,7 +713,7 @@ void plGLDevice::FillIndexBufferRef(IndexBufferRef* iRef, plGBufferGroup* owner,
713713
if (!size)
714714
return;
715715

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

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

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

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

Sources/Plasma/FeatureLib/pfGLPipeline/plGLDeviceRef.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
4747

4848
#include <epoxy/gl.h>
4949

50+
inline int plGLVersion() {
51+
// This exists for testing purposes to force the pipeline to behave as if a
52+
// specific version of OpenGL were present, mainly for ensuring
53+
// compatibility with older GL API versions on machines where newer
54+
// versions are available by default. To pretend to be limited to a
55+
// specific version, just return the GL version with the decimal removed as
56+
// an integer:
57+
58+
// return 42; // Pretend we only support OpenGL 4.2
59+
return epoxy_gl_version();
60+
}
61+
5062
// Helper macro for logging GL Errors
5163
#ifdef HS_DEBUGGING
5264
# include "plStatusLog/plStatusLog.h"

Sources/Plasma/FeatureLib/pfGLPipeline/plGLMaterialShaderRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void plGLMaterialShaderRef::ICompile()
411411
fRef = glCreateProgram();
412412
LOG_GL_ERROR_CHECK("Create Program failed");
413413

414-
if (epoxy_gl_version() >= 43) {
414+
if (plGLVersion() >= 43) {
415415
const char* name = ST::format("hsGMaterial::{}", fMaterial->GetKeyName()).c_str();
416416
glObjectLabel(GL_PROGRAM, fRef, strlen(name), name);
417417
}

Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ hsGDeviceRef* plGLPipeline::MakeRenderTargetRef(plRenderTarget* owner)
375375
// since we only render one face at a time. If we were rendering part of face X, then part
376376
// of face Y, then more of face X, then they would all need their own depth buffers.
377377
if (owner->GetZDepth() && (owner->GetFlags() & (plRenderTarget::kIsTexture | plRenderTarget::kIsOffscreen))) {
378-
if (epoxy_gl_version() >= 45) {
378+
if (plGLVersion() >= 45) {
379379
glCreateRenderbuffers(1, &depthBuffer);
380380
glNamedRenderbufferStorage(depthBuffer, GL_DEPTH24_STENCIL8, owner->GetWidth(), owner->GetHeight());
381381
} else {
@@ -409,7 +409,7 @@ hsGDeviceRef* plGLPipeline::MakeRenderTargetRef(plRenderTarget* owner)
409409
ref->fDepthBuffer = depthBuffer;
410410
ref->fMapping = GL_TEXTURE_2D;
411411

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

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

707-
if (epoxy_gl_version() >= 30)
707+
if (plGLVersion() >= 30)
708708
glDeleteVertexArrays(1, &vao);
709709
}
710710

Sources/Plasma/FeatureLib/pfGLPipeline/plGLPlateManager.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void plGLPlateManager::ICreateGeometry()
8282

8383
GLuint vbo, ibo, vao = 0;
8484

85-
if (epoxy_gl_version() >= 45) {
85+
if (plGLVersion() >= 45) {
8686
glCreateBuffers(1, &vbo);
8787
glObjectLabel(GL_BUFFER, vbo, -1, "plPlate/VBO");
8888
glNamedBufferStorage(vbo, sizeof(verts), verts, 0);
@@ -112,7 +112,7 @@ void plGLPlateManager::ICreateGeometry()
112112
glVertexArrayAttribBinding(vao, kVtxColor, 0);
113113
glVertexArrayAttribBinding(vao, kVtxUVWSrc, 0);
114114
} else {
115-
if (epoxy_gl_version() >= 30) {
115+
if (plGLVersion() >= 30) {
116116
glGenVertexArrays(1, &vao);
117117
glBindVertexArray(vao);
118118
}
@@ -125,9 +125,9 @@ void plGLPlateManager::ICreateGeometry()
125125
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
126126
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
127127

128-
if (epoxy_gl_version() >= 30) {
128+
if (plGLVersion() >= 30) {
129129
glEnableVertexAttribArray(kVtxPosition);
130-
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), 0);
130+
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), (void*)(sizeof(float) * 0));
131131

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

148148
void plGLPlateManager::IReleaseGeometry()
149149
{
150-
if (epoxy_gl_version() >= 30 && fBuffers.ARef) {
151-
if (epoxy_gl_version() >= 45) {
150+
if (plGLVersion() >= 30 && fBuffers.ARef) {
151+
if (plGLVersion() >= 45) {
152152
glDisableVertexArrayAttrib(fBuffers.ARef, kVtxPosition);
153153
glDisableVertexArrayAttrib(fBuffers.ARef, kVtxNormal);
154154
glDisableVertexArrayAttrib(fBuffers.ARef, kVtxColor);
@@ -184,15 +184,15 @@ void plGLPlateManager::IDrawToDevice(plPipeline* pipe)
184184
return;
185185
}
186186

187-
if (epoxy_gl_version() >= 30) {
187+
if (plGLVersion() >= 30) {
188188
if (fBuffers.ARef == 0)
189189
return;
190190

191191
glBindVertexArray(fBuffers.ARef);
192192
} else {
193193
glBindBuffer(GL_ARRAY_BUFFER, fBuffers.VRef);
194194

195-
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), 0);
195+
glVertexAttribPointer(kVtxPosition, 3, GL_FLOAT, GL_FALSE, sizeof(plPlateVertex), (void*)(sizeof(float) * 0));
196196
glEnableVertexAttribArray(kVtxPosition);
197197

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

0 commit comments

Comments
 (0)