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 #ifndef DAWNNATIVE_OPENGL_PIPELINEGL_H_ 16 #define DAWNNATIVE_OPENGL_PIPELINEGL_H_ 17 18 #include "dawn_native/Pipeline.h" 19 20 #include "dawn_native/PerStage.h" 21 #include "dawn_native/opengl/opengl_platform.h" 22 23 #include <vector> 24 25 namespace dawn_native { 26 struct ProgrammableStage; 27 } // namespace dawn_native 28 29 namespace dawn_native { namespace opengl { 30 31 struct OpenGLFunctions; 32 class PipelineLayout; 33 class Sampler; 34 35 class PipelineGL { 36 public: 37 PipelineGL(); 38 ~PipelineGL(); 39 40 // For each unit a sampler is bound to we need to know if we should use filtering or not 41 // because int and uint texture are only complete without filtering. 42 struct SamplerUnit { 43 GLuint unit; 44 bool shouldUseFiltering; 45 }; 46 const std::vector<SamplerUnit>& GetTextureUnitsForSampler(GLuint index) const; 47 const std::vector<GLuint>& GetTextureUnitsForTextureView(GLuint index) const; 48 GLuint GetProgramHandle() const; 49 50 protected: 51 void ApplyNow(const OpenGLFunctions& gl); 52 MaybeError InitializeBase(const OpenGLFunctions& gl, 53 const PipelineLayout* layout, 54 const PerStage<ProgrammableStage>& stages); 55 void DeleteProgram(const OpenGLFunctions& gl); 56 57 private: 58 GLuint mProgram; 59 std::vector<std::vector<SamplerUnit>> mUnitsForSamplers; 60 std::vector<std::vector<GLuint>> mUnitsForTextures; 61 std::vector<GLuint> mDummySamplerUnits; 62 // TODO(enga): This could live on the Device, or elsewhere, but currently it makes Device 63 // destruction complex as it requires the sampler to be destroyed before the sampler cache. 64 Ref<Sampler> mDummySampler; 65 }; 66 67 }} // namespace dawn_native::opengl 68 69 #endif // DAWNNATIVE_OPENGL_PIPELINEGL_H_ 70