1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsGLPrerequisites.h" |
6 | |
7 | namespace bs { namespace ct |
8 | { |
9 | /** @addtogroup GL |
10 | * @{ |
11 | */ |
12 | |
13 | /** Wrapper around OpenGL pipeline object. */ |
14 | struct GLSLProgramPipeline |
15 | { |
16 | GLuint glHandle; |
17 | }; |
18 | |
19 | /** |
20 | * Managed OpenGL pipeline objects that are used for binding a certain combination of GPU programs to the render system. |
21 | * |
22 | * @note |
23 | * In OpenGL you cannot bind GPU programs to the pipeline manually. Instead as a preprocessing step you create a |
24 | * pipeline object containing the programs you plan on using, and then later you bind the previously created pipeline |
25 | * object. |
26 | */ |
27 | class GLSLProgramPipelineManager |
28 | { |
29 | public: |
30 | ~GLSLProgramPipelineManager(); |
31 | |
32 | /** |
33 | * Creates or returns an existing pipeline that uses the provided combination of GPU programs. Provide null for |
34 | * unused programs. |
35 | */ |
36 | const GLSLProgramPipeline* getPipeline(GLSLGpuProgram* vertexProgram, GLSLGpuProgram* fragmentProgram, |
37 | GLSLGpuProgram* geometryProgram, GLSLGpuProgram* hullProgram, GLSLGpuProgram* domainProgram); |
38 | |
39 | private: |
40 | /** Key that uniquely identifies a pipeline object. */ |
41 | struct ProgramPipelineKey |
42 | { |
43 | UINT32 vertexProgKey; |
44 | UINT32 fragmentProgKey; |
45 | UINT32 geometryProgKey; |
46 | UINT32 hullProgKey; |
47 | UINT32 domainProgKey; |
48 | }; |
49 | |
50 | /** Used for calculating a hash code from pipeline object key. */ |
51 | class ProgramPipelineKeyHashFunction |
52 | { |
53 | public: |
54 | ::std::size_t operator()(const ProgramPipelineKey &key) const; |
55 | }; |
56 | |
57 | /** Used for comparing two pipeline objects for equality. */ |
58 | class ProgramPipelineKeyEqual |
59 | { |
60 | public: |
61 | bool operator()(const ProgramPipelineKey &a, const ProgramPipelineKey &b) const; |
62 | }; |
63 | |
64 | typedef UnorderedMap<ProgramPipelineKey, GLSLProgramPipeline, ProgramPipelineKeyHashFunction, ProgramPipelineKeyEqual> ProgramPipelineMap; |
65 | ProgramPipelineMap mPipelines; |
66 | }; |
67 | |
68 | /** @} */ |
69 | }} |