Skip to content

Commit

Permalink
gl: push constant small clean-up (#7841)
Browse files Browse the repository at this point in the history
  • Loading branch information
poweifeng committed May 10, 2024
1 parent 6f2c45c commit 7f8fbe5
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Expand Up @@ -212,7 +212,8 @@ OpenGLDriver::OpenGLDriver(OpenGLPlatform* platform, const Platform::DriverConfi
mHandleAllocator("Handles",
driverConfig.handleArenaSize,
driverConfig.disableHandleUseAfterFreeCheck),
mDriverConfig(driverConfig) {
mDriverConfig(driverConfig),
mCurrentPushConstants(new(std::nothrow) PushConstantBundle{}) {

std::fill(mSamplerBindings.begin(), mSamplerBindings.end(), nullptr);

Expand Down Expand Up @@ -269,9 +270,8 @@ void OpenGLDriver::terminate() {
assert_invariant(mGpuCommandCompleteOps.empty());
#endif

if (mCurrentPushConstants) {
delete mCurrentPushConstants;
}
delete mCurrentPushConstants;
mCurrentPushConstants = nullptr;

mContext.terminate();

Expand All @@ -295,9 +295,6 @@ void OpenGLDriver::bindSampler(GLuint unit, GLuint sampler) noexcept {

void OpenGLDriver::setPushConstant(backend::ShaderStage stage, uint8_t index,
backend::PushConstantVariant value) {
assert_invariant(mCurrentPushConstants &&
"Calling setPushConstant() before binding a pipeline");

assert_invariant(stage == ShaderStage::VERTEX || stage == ShaderStage::FRAGMENT);
utils::Slice<std::pair<GLint, ConstantType>> constants;
if (stage == ShaderStage::VERTEX) {
Expand Down Expand Up @@ -3848,12 +3845,7 @@ void OpenGLDriver::bindPipeline(PipelineState state) {
gl.polygonOffset(state.polygonOffset.slope, state.polygonOffset.constant);
OpenGLProgram* const p = handle_cast<OpenGLProgram*>(state.program);
mValidProgram = useProgram(p);

if (!mCurrentPushConstants) {
mCurrentPushConstants = new (std::nothrow) PushConstantBundle{p->getPushConstants()};
} else {
(*mCurrentPushConstants) = p->getPushConstants();
}
(*mCurrentPushConstants) = p->getPushConstants();
}

void OpenGLDriver::bindRenderPrimitive(Handle<HwRenderPrimitive> rph) {
Expand Down

0 comments on commit 7f8fbe5

Please sign in to comment.