blob: be6c1dd5538b7640081f0afc3a86a9301589aa85 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Corentin Wallezf07e3bd2017-04-20 14:38:20 -04002//
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
Corentin Wallez30965a72018-07-24 16:42:33 +020015#ifndef DAWNNATIVE_OPENGL_PIPELINEGL_H_
16#define DAWNNATIVE_OPENGL_PIPELINEGL_H_
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040017
Corentin Wallezd37523f2018-07-24 13:53:51 +020018#include "dawn_native/Pipeline.h"
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040019
Corentin Wallez28efed12020-09-09 22:51:37 +000020#include "dawn_native/PerStage.h"
Corentin Wallez8f4046b2019-06-17 09:17:29 +000021#include "dawn_native/opengl/opengl_platform.h"
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040022
23#include <vector>
24
Corentin Wallez28efed12020-09-09 22:51:37 +000025namespace dawn_native {
26 struct ProgrammableStage;
27} // namespace dawn_native
28
Corentin Wallez49a65d02018-07-24 16:45:45 +020029namespace dawn_native { namespace opengl {
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040030
Corentin Wallezdf69f242019-06-13 10:22:32 +000031 struct OpenGLFunctions;
Corentin Wallez8e335a52018-08-27 23:12:56 +020032 class PipelineLayout;
Austin Eng2395ff52020-12-02 16:51:19 +000033 class Sampler;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040034
Corentin Wallezb085eec2017-07-14 14:04:52 -040035 class PipelineGL {
Corentin Wallezc7807ab2017-11-24 14:16:15 -050036 public:
Corentin Wallez8e335a52018-08-27 23:12:56 +020037 PipelineGL();
Austin Eng2395ff52020-12-02 16:51:19 +000038 ~PipelineGL();
Corentin Wallez8e335a52018-08-27 23:12:56 +020039
Corentin Wallezba9f3a82019-08-21 13:01:23 +000040 // 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;
Jiawei Shaoc72ab8c2018-10-29 09:07:25 +000047 const std::vector<GLuint>& GetTextureUnitsForTextureView(GLuint index) const;
Corentin Wallezc7807ab2017-11-24 14:16:15 -050048 GLuint GetProgramHandle() const;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040049
Corentin Wallezcac3e7e2021-09-29 09:15:02 +000050 protected:
Jiawei Shaoafe91382021-10-04 12:31:22 +000051 void ApplyNow(const OpenGLFunctions& gl);
Austin Eng8e957162021-08-03 19:07:29 +000052 MaybeError InitializeBase(const OpenGLFunctions& gl,
53 const PipelineLayout* layout,
54 const PerStage<ProgrammableStage>& stages);
Jiawei Shaoafe91382021-10-04 12:31:22 +000055 void DeleteProgram(const OpenGLFunctions& gl);
Austin Eng8e957162021-08-03 19:07:29 +000056
Corentin Wallezc7807ab2017-11-24 14:16:15 -050057 private:
58 GLuint mProgram;
Corentin Wallezba9f3a82019-08-21 13:01:23 +000059 std::vector<std::vector<SamplerUnit>> mUnitsForSamplers;
Corentin Wallezc7807ab2017-11-24 14:16:15 -050060 std::vector<std::vector<GLuint>> mUnitsForTextures;
Austin Eng2395ff52020-12-02 16:51:19 +000061 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;
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040065 };
66
Corentin Wallez49a65d02018-07-24 16:45:45 +020067}} // namespace dawn_native::opengl
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040068
Corentin Wallez30965a72018-07-24 16:42:33 +020069#endif // DAWNNATIVE_OPENGL_PIPELINEGL_H_