Cogs.Core
EffectsGL20.h
1#pragma once
2
3#include "../Base/EffectsCommon.h"
4
5#include "AttributesGL20.h"
6
7namespace Cogs
8{
9 class GraphicsDeviceGL20;
10 struct CapabilitiesGL20;
11
13 {
14 std::string name;
15 GLuint uniformIndex;
16 GLint bufferIndex;
17 GLint bufferOffset;
18 };
19
21 {
22 GLint binding = -1;
23 GLint dataSize = 0;
24 BufferHandle backingBuffer;
25 };
26
28 {
29 EffectHandle effectHandle;
30 size_t name = (size_t)-1;
31 };
32
34 {
35 std::string shaderSource;
36
37 std::string vsSource;
38 std::string gsSource;
39 std::string psSource;
40 };
41
42 struct EffectGL20 : public Effect
43 {
44 GLuint programId;
45
46 unsigned char attributeMap[MaxVertexAttributesGL20];
47
48 unsigned unitsInUse = 0;
49 std::unordered_map<size_t, std::pair<uint32_t, uint32_t>> samplers;
50 std::unordered_map<size_t, uint32_t> textures;
51 std::unordered_map<size_t, std::vector<size_t>> real_sampler;
52 std::unordered_map<size_t, SamplerMapGL20*> sampler_map;
53
54 std::vector<AtomicCounterVariableGL20> atomicCounterVariables;
55 std::vector<AtomicCounterBufferGL20> atomicCounterBuffers;
56 };
57
59 {
60 void initialize(GraphicsDeviceGL20* device, CapabilitiesGL20 * capabilities, IBuffers * buffers);
61
62 EffectHandle loadComputeEffect(const StringView & fileName, EffectFlags::EEffectFlags effectFlags) override;
63 EffectHandle loadComputeEffect(const StringView & fileName, const PreprocessorDefinitions & definitions, EffectFlags::EEffectFlags effectFlags) override;
64
65 void releaseEffect(EffectHandle handle) override;
66 void releaseShader(ShaderHandle shaderHandle);
67
69 TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView & name, const unsigned int slot) override;
70 SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView & name, const unsigned int slot) override;
71
72 void releaseResources() override;
73
74 void annotate(EffectHandle handle, const StringView & name) override;
75 void annotateVS(EffectHandle handle, const StringView & name) override;
76 void annotateGS(EffectHandle handle, const StringView & name) override;
77 void annotatePS(EffectHandle handle, const StringView & name) override;
78 void annotateCS(EffectHandle handle, const StringView & name) override;
79
80 BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView & name) override;
81 void releaseBufferBinding(BufferBindingHandle bufferBindingHandle) override;
82
83 EffectHandle load(const ProcessedContent & vsSource,
84 const ProcessedContent & hsSource,
85 const ProcessedContent & dsSource,
86 const ProcessedContent & gsSource,
87 const ProcessedContent & psSource,
88 const StringView & vsEntryPoint,
89 const StringView & hsEntryPoint,
90 const StringView & dsEntryPoint,
91 const StringView & gsEntryPoint,
92 const StringView & psEntryPoint,
93 const EffectDescription & desc) override;
94 private:
95 ShaderHandle loadShader(GLenum shaderType, const char * pSource, EffectFlags::EEffectFlags effectFlags, PreprocessorDefinitions definitions = PreprocessorDefinitions());
96 EffectHandle loadProgram(ShaderHandle vsHandle, ShaderHandle hsHandle, ShaderHandle dsHandle, ShaderHandle gsHandle, ShaderHandle psHandle, EffectFlags::EEffectFlags effectFlags, bool hlsl = false);
97
98 CapabilitiesGL20 * capabilities = nullptr;
99 public:
103
104 AttributesGL20 attributes;
105 GraphicsDeviceGL20* graphicsDevice;
106 };
107}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
std::vector< PreprocessorDefinition > PreprocessorDefinitions
A set of preprocessor definitions.
Definition: IEffects.h:13
Contains an effect description used to load a single effect.
Definition: IEffects.h:55
EEffectFlags
Effect source flags.
Definition: IEffects.h:20
SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot) override
Get a handle to a sampler state object binding, mapping how to bind the sampler state to the given ef...
BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView &name) override
Get a handle to a buffer binding.
ConstantBufferBindingHandle getConstantBufferBinding(EffectHandle effectHandle, const StringView &name) override
Get a handle to a constant buffer binding, mapping how to bind a constant buffer to the given effect.
void annotate(EffectHandle handle, const StringView &name) override
Associate a name with an object for use in graphics debugging.
TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot) override
Get a handle to a texture object binding, mapping how to bind textures to the given effect.
void annotateGS(EffectHandle handle, const StringView &name) override
Associate a name with an object for use in graphics debugging.
void annotateVS(EffectHandle handle, const StringView &name) override
Associate a name with an object for use in graphics debugging.
void annotatePS(EffectHandle handle, const StringView &name) override
Associate a name with an object for use in graphics debugging.
void releaseResources() override
Release all allocated effect resources.
void annotateCS(EffectHandle handle, const StringView &name) override
Associate a name with an object for use in graphics debugging.
void releaseEffect(EffectHandle handle) override
Release the effect with the given handle, freeing all resources generated during program loading.
void releaseBufferBinding(BufferBindingHandle bufferBindingHandle) override
Release a handle to a buffer binding.
EffectHandle loadComputeEffect(const StringView &fileName, EffectFlags::EEffectFlags effectFlags) override
Load the compute shader with the given file name and create an effect.
Provides buffer management functionality.
Definition: IBuffers.h:13