Skip to content

Commit c6dd33b

Browse files
committed
Fix invalid enum errors with OpenGL core profile and Storm
Point smooth and line width are only available with the compatibility profile. NVIDIA drivers report errors when trying to use these with the core profile.
1 parent 9746223 commit c6dd33b

File tree

9 files changed

+60
-16
lines changed

9 files changed

+60
-16
lines changed

pxr/imaging/hdSt/renderPassState.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,9 @@ HdStRenderPassState::Bind(HgiCapabilities const &hgiCapabilities)
769769
// If not using GL_MULTISAMPLE, use GL_POINT_SMOOTH to render points as
770770
// circles instead of square.
771771
// XXX Switch points rendering to emit quad with FS that draws circle.
772-
glEnable(GL_POINT_SMOOTH);
772+
if (!hgiCapabilities.GetCoreProfile()) {
773+
glEnable(GL_POINT_SMOOTH);
774+
}
773775
}
774776
}
775777

@@ -813,7 +815,9 @@ HdStRenderPassState::Unbind(HgiCapabilities const &hgiCapabilities)
813815
}
814816

815817
glEnable(GL_MULTISAMPLE);
816-
glDisable(GL_POINT_SMOOTH);
818+
if (!hgiCapabilities.GetCoreProfile()) {
819+
glDisable(GL_POINT_SMOOTH);
820+
}
817821
}
818822

819823
void

pxr/imaging/hgi/capabilities.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class HgiCapabilities
5252
HGI_API
5353
virtual int GetShaderVersion() const = 0;
5454

55+
HGI_API
56+
virtual bool GetCoreProfile() const {
57+
return false;
58+
}
59+
5560
HGI_API
5661
size_t GetMaxUniformBlockSize() const {
5762
return _maxUniformBlockSize;

pxr/imaging/hgiGL/blitCmds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ HgiGLBlitCmds::_Submit(Hgi* hgi, HgiSubmitWaitType wait)
136136
// Capture OpenGL state before executing the 'ops' and restore it when this
137137
// function ends. We do this defensively because parts of our pipeline may
138138
// not set and restore all relevant gl state.
139-
HgiGL_ScopedStateHolder openglStateGuard;
139+
HgiGL_ScopedStateHolder openglStateGuard(*hgi->GetCapabilities());
140140

141141
HgiGL* hgiGL = static_cast<HgiGL*>(hgi);
142142
HgiGLDevice* device = hgiGL->GetPrimaryDevice();

pxr/imaging/hgiGL/capabilities.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static const int _DefaultMaxClipDistances = 8;
5757
HgiGLCapabilities::HgiGLCapabilities()
5858
: _glVersion(0)
5959
, _glslVersion(_DefaultGLSLVersion)
60+
, _coreProfile(false)
6061
{
6162
_LoadCapabilities();
6263
}
@@ -131,6 +132,11 @@ HgiGLCapabilities::_LoadCapabilities()
131132
&uniformBufferOffsetAlignment);
132133
_uniformBufferOffsetAlignment = uniformBufferOffsetAlignment;
133134
}
135+
if (_glVersion >= 320) {
136+
GLint profileMask = 0;
137+
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profileMask);
138+
_coreProfile = (profileMask & GL_CONTEXT_CORE_PROFILE_BIT);
139+
}
134140
if (_glVersion >= 430) {
135141
GLint maxShaderStorageBlockSize = 0;
136142
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE,
@@ -259,4 +265,9 @@ HgiGLCapabilities::GetShaderVersion() const {
259265
return _glslVersion;
260266
}
261267

268+
bool
269+
HgiGLCapabilities::GetCoreProfile() const {
270+
return _coreProfile;
271+
}
272+
262273
PXR_NAMESPACE_CLOSE_SCOPE

pxr/imaging/hgiGL/capabilities.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class HgiGLCapabilities final : public HgiCapabilities
5252
HGIGL_API
5353
int GetShaderVersion() const override;
5454

55+
HGIGL_API
56+
bool GetCoreProfile() const override;
57+
5558
private:
5659
void _LoadCapabilities();
5760

@@ -60,6 +63,9 @@ class HgiGLCapabilities final : public HgiCapabilities
6063

6164
// GLSL version
6265
int _glslVersion; // 400, 410, ...
66+
67+
// Core Profile
68+
bool _coreProfile;
6369
};
6470

6571
PXR_NAMESPACE_CLOSE_SCOPE

pxr/imaging/hgiGL/graphicsCmds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ HgiGLGraphicsCmds::_Submit(Hgi* hgi, HgiSubmitWaitType wait)
249249
// Capture OpenGL state before executing the 'ops' and restore it when this
250250
// function ends. We do this defensively because parts of our pipeline may
251251
// not set and restore all relevant gl state.
252-
HgiGL_ScopedStateHolder openglStateGuard;
252+
HgiGL_ScopedStateHolder openglStateGuard(*hgi->GetCapabilities());
253253

254254
// Resolve multisample textures
255255
HgiGL* hgiGL = static_cast<HgiGL*>(hgi);

pxr/imaging/hgiGL/graphicsPipeline.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ HgiGLGraphicsPipeline::BindPipeline()
114114
glBindVertexArray(_vao);
115115
}
116116

117+
const bool coreProfile = _hgi->GetCapabilities()->GetCoreProfile();
118+
117119
//
118120
// Depth Stencil State
119121
//
@@ -178,7 +180,9 @@ HgiGLGraphicsPipeline::BindPipeline()
178180
// If not using GL_MULTISAMPLE, use GL_POINT_SMOOTH to render points as
179181
// circles instead of square.
180182
// XXX Switch points rendering to emit quad with FS that draws circle.
181-
glEnable(GL_POINT_SMOOTH);
183+
if (!coreProfile) {
184+
glEnable(GL_POINT_SMOOTH);
185+
}
182186
}
183187
if (_descriptor.multiSampleState.alphaToCoverageEnable) {
184188
glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
@@ -213,7 +217,7 @@ HgiGLGraphicsPipeline::BindPipeline()
213217
glFrontFace(GL_CCW);
214218
}
215219

216-
if (_descriptor.rasterizationState.lineWidth != 1.0f) {
220+
if (!coreProfile && _descriptor.rasterizationState.lineWidth != 1.0f) {
217221
glLineWidth(_descriptor.rasterizationState.lineWidth);
218222
}
219223

pxr/imaging/hgiGL/scopedStateHolder.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@
2626
#include "pxr/imaging/hgiGL/scopedStateHolder.h"
2727
#include "pxr/imaging/hgiGL/conversions.h"
2828
#include "pxr/imaging/hgiGL/diagnostic.h"
29+
#include "pxr/imaging/hgiGL/hgi.h"
2930

3031
#include "pxr/base/trace/trace.h"
3132
#include "pxr/base/tf/diagnostic.h"
3233
#include "pxr/base/tf/iterator.h"
3334

3435
PXR_NAMESPACE_OPEN_SCOPE
3536

36-
HgiGL_ScopedStateHolder::HgiGL_ScopedStateHolder()
37-
: _restoreRenderBuffer(0)
37+
HgiGL_ScopedStateHolder::HgiGL_ScopedStateHolder(
38+
HgiCapabilities const& capabilities)
39+
: _coreProfile(capabilities.GetCoreProfile())
40+
, _restoreRenderBuffer(0)
3841
, _restoreVao(0)
3942
, _restoreDepthTest(false)
4043
, _restoreDepthWriteMask(false)
@@ -115,7 +118,9 @@ HgiGL_ScopedStateHolder::HgiGL_ScopedStateHolder()
115118
glGetBooleanv(
116119
GL_SAMPLE_ALPHA_TO_ONE,
117120
(GLboolean*)&_restoreSampleAlphaToOne);
118-
glGetFloatv(GL_LINE_WIDTH, &_lineWidth);
121+
if (!_coreProfile) {
122+
glGetFloatv(GL_LINE_WIDTH, &_lineWidth);
123+
}
119124
glGetBooleanv(GL_CULL_FACE, (GLboolean*)&_cullFace);
120125
glGetIntegerv(GL_CULL_FACE_MODE, &_cullMode);
121126
glGetIntegerv(GL_FRONT_FACE, &_frontFace);
@@ -139,7 +144,9 @@ HgiGL_ScopedStateHolder::HgiGL_ScopedStateHolder()
139144
}
140145

141146
glGetBooleanv(GL_MULTISAMPLE, (GLboolean*)&_restoreMultiSample);
142-
glGetBooleanv(GL_POINT_SMOOTH, (GLboolean*)&_restorePointSmooth);
147+
if (!_coreProfile) {
148+
glGetBooleanv(GL_POINT_SMOOTH, (GLboolean*)&_restorePointSmooth);
149+
}
143150

144151
HGIGL_POST_PENDING_GL_ERRORS();
145152
#if defined(GL_KHR_debug)
@@ -235,7 +242,9 @@ HgiGL_ScopedStateHolder::~HgiGL_ScopedStateHolder()
235242
_restoreViewport[2], _restoreViewport[3]);
236243
glBindVertexArray(_restoreVao);
237244
glBindRenderbuffer(GL_RENDERBUFFER, _restoreRenderBuffer);
238-
glLineWidth(_lineWidth);
245+
if (!_coreProfile) {
246+
glLineWidth(_lineWidth);
247+
}
239248
if (_cullFace) {
240249
glEnable(GL_CULL_FACE);
241250
} else {
@@ -285,10 +294,12 @@ HgiGL_ScopedStateHolder::~HgiGL_ScopedStateHolder()
285294
glDisable(GL_MULTISAMPLE);
286295
}
287296

288-
if (_restorePointSmooth) {
289-
glEnable(GL_POINT_SMOOTH);
290-
} else {
291-
glDisable(GL_POINT_SMOOTH);
297+
if (!_coreProfile) {
298+
if (_restorePointSmooth) {
299+
glEnable(GL_POINT_SMOOTH);
300+
} else {
301+
glDisable(GL_POINT_SMOOTH);
302+
}
292303
}
293304

294305
static const GLuint samplers[8] = {0};

pxr/imaging/hgiGL/scopedStateHolder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
PXR_NAMESPACE_OPEN_SCOPE
3434

35+
class HgiCapabilities;
3536

3637
/// \class HgiGLScopedStateHolder
3738
///
@@ -50,7 +51,7 @@ class HgiGL_ScopedStateHolder final
5051
{
5152
public:
5253
HGIGL_API
53-
HgiGL_ScopedStateHolder();
54+
HgiGL_ScopedStateHolder(HgiCapabilities const& capabilities);
5455

5556
HGIGL_API
5657
~HgiGL_ScopedStateHolder();
@@ -59,6 +60,8 @@ class HgiGL_ScopedStateHolder final
5960
HgiGL_ScopedStateHolder& operator=(const HgiGL_ScopedStateHolder&) = delete;
6061
HgiGL_ScopedStateHolder(const HgiGL_ScopedStateHolder&) = delete;
6162

63+
bool _coreProfile;
64+
6265
int32_t _restoreRenderBuffer;
6366
int32_t _restoreVao;
6467

0 commit comments

Comments
 (0)