1 // Copyright 2017 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "dawn_native/opengl/PersistentPipelineStateGL.h" 16 17 #include "dawn_native/opengl/OpenGLFunctions.h" 18 19 namespace dawn_native { namespace opengl { 20 SetDefaultState(const OpenGLFunctions & gl)21 void PersistentPipelineState::SetDefaultState(const OpenGLFunctions& gl) { 22 CallGLStencilFunc(gl); 23 } 24 SetStencilFuncsAndMask(const OpenGLFunctions & gl,GLenum stencilBackCompareFunction,GLenum stencilFrontCompareFunction,uint32_t stencilReadMask)25 void PersistentPipelineState::SetStencilFuncsAndMask(const OpenGLFunctions& gl, 26 GLenum stencilBackCompareFunction, 27 GLenum stencilFrontCompareFunction, 28 uint32_t stencilReadMask) { 29 if (mStencilBackCompareFunction == stencilBackCompareFunction && 30 mStencilFrontCompareFunction == stencilFrontCompareFunction && 31 mStencilReadMask == stencilReadMask) { 32 return; 33 } 34 35 mStencilBackCompareFunction = stencilBackCompareFunction; 36 mStencilFrontCompareFunction = stencilFrontCompareFunction; 37 mStencilReadMask = stencilReadMask; 38 CallGLStencilFunc(gl); 39 } 40 SetStencilReference(const OpenGLFunctions & gl,uint32_t stencilReference)41 void PersistentPipelineState::SetStencilReference(const OpenGLFunctions& gl, 42 uint32_t stencilReference) { 43 if (mStencilReference == stencilReference) { 44 return; 45 } 46 47 mStencilReference = stencilReference; 48 CallGLStencilFunc(gl); 49 } 50 CallGLStencilFunc(const OpenGLFunctions & gl)51 void PersistentPipelineState::CallGLStencilFunc(const OpenGLFunctions& gl) { 52 gl.StencilFuncSeparate(GL_BACK, mStencilBackCompareFunction, mStencilReference, 53 mStencilReadMask); 54 gl.StencilFuncSeparate(GL_FRONT, mStencilFrontCompareFunction, mStencilReference, 55 mStencilReadMask); 56 } 57 58 }} // namespace dawn_native::opengl 59