Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _PLATFORM_VIDEO_OPENGLS_PROGRAM_H_
#define _PLATFORM_VIDEO_OPENGLS_PROGRAM_H_

#include "Platform/Video/OpenGL/Headers/glResources.h"
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"

namespace Divide {
class GL_API;
class glShader;
class glLockManager;
namespace Attorney {
    class GLAPIShaderProgram;
};
/// OpenGL implementation of the ShaderProgram entity
class glShaderProgram final : public ShaderProgram, public glObject {
    USE_CUSTOM_ALLOCATOR
    friend class Attorney::GLAPIShaderProgram;
   public:
       struct glShaderProgramLoadInfo {
           stringImpl _resourcePath;
           stringImpl _header;
           stringImpl _programName;
           stringImpl _programProperties;
           stringImpl _vertexStageProperties;
       };

  private:
    template<typename T>
    struct UniformCache {
        typedef hashMapImpl<T, U32> ShaderVarU32Map;
        typedef hashMapImpl<T, I32> ShaderVarI32Map;
        typedef hashMapImpl<T, F32> ShaderVarF32Map;
        typedef hashMapImpl<T, vec2<F32>> ShaderVarVec2F32Map;
        typedef hashMapImpl<T, vec2<I32>> ShaderVarvec2I32Map;
        typedef hashMapImpl<T, vec3<F32>> ShaderVarVec3F32Map;
        typedef hashMapImpl<T, vec3<I32>> ShaderVarVec3I32Map;
        typedef hashMapImpl<T, vec4<F32>> ShaderVarVec4F32Map;
        typedef hashMapImpl<T, vec4<I32>> ShaderVarVec4I32Map;
        typedef hashMapImpl<T, mat3<F32>> ShaderVarMat3Map;
        typedef hashMapImpl<T, mat4<F32>> ShaderVarMat4Map;
        typedef hashMapImpl<T, vectorImpl<I32>> ShaderVarVectorI32Map;
        typedef hashMapImpl<T, vectorImpl<F32>> ShaderVarVectorF32Map;
        typedef hashMapImpl<T, vectorImpl<vec2<F32>>> ShaderVarVectorVec2F32Map;
        typedef hashMapImpl<T, vectorImpl<vec3<F32>>> ShaderVarVectorVec3F32Map;
        typedef hashMapImpl<T, vectorImpl<vec4<F32>>> ShaderVarVectorVec4F32Map;
        typedef hashMapImpl<T, vectorImpl<mat3<F32>>> ShaderVarVectorMat3Map;
        typedef hashMapImpl<T, vectorImpl<mat4<F32>>> ShaderVarVectorMat4Map;

        void clear() {
            _shaderVarsU32.clear();
            _shaderVarsI32.clear();
            _shaderVarsF32.clear();
            _shaderVarsVec2F32.clear();
            _shaderVarsVec2I32.clear();
            _shaderVarsVec3F32.clear();
            _shaderVarsVec4F32.clear();
            _shaderVarsMat3.clear();
            _shaderVarsMat4.clear();
            _shaderVarsVectorI32.clear();
            _shaderVarsVectorF32.clear();
            _shaderVarsVectorVec2F32.clear();
            _shaderVarsVectorVec3F32.clear();
            _shaderVarsVectorVec4F32.clear();
            _shaderVarsVectorMat3.clear();
            _shaderVarsVectorMat4.clear();
        }

        ShaderVarU32Map _shaderVarsU32;
        ShaderVarI32Map _shaderVarsI32;
        ShaderVarF32Map _shaderVarsF32;
        ShaderVarVec2F32Map _shaderVarsVec2F32;
        ShaderVarvec2I32Map _shaderVarsVec2I32;
        ShaderVarVec3F32Map _shaderVarsVec3F32;
        ShaderVarVec3I32Map _shaderVarsVec3I32;
        ShaderVarVec4F32Map _shaderVarsVec4F32;
        ShaderVarVec4I32Map _shaderVarsVec4I32;
        ShaderVarMat3Map _shaderVarsMat3;
        ShaderVarMat4Map _shaderVarsMat4;
        ShaderVarVectorI32Map _shaderVarsVectorI32;
        ShaderVarVectorF32Map _shaderVarsVectorF32;
        ShaderVarVectorVec2F32Map _shaderVarsVectorVec2F32;
        ShaderVarVectorVec3F32Map _shaderVarsVectorVec3F32;
        ShaderVarVectorVec4F32Map _shaderVarsVectorVec4F32;
        ShaderVarVectorMat3Map _shaderVarsVectorMat3;
        ShaderVarVectorMat4Map _shaderVarsVectorMat4;

    };

    typedef hashMapImpl<U64, I32> ShaderVarMap;
    typedef UniformCache<stringImplFast> UniformsByName;

   public:
    explicit glShaderProgram(GFXDevice& context,
                             size_t descriptorHash,
                             const stringImpl& name,
                             const stringImpl& resourceName,
                             const stringImpl& resourceLocation,
                             bool asyncLoad);
    ~glShaderProgram();

    static void initStaticData();
    static void destroyStaticData();

    /// Make sure this program is ready for deletion
    bool unload() override;
    /// Bind this shader program
    bool bind() override;
    /// Returns true if the shader is currently active
    bool isBound() const override;
    /// Check every possible combination of flags to make sure this program can
    /// be used for rendering
    bool isValid() const override;
    /// Called once per frame. Used to update internal state
    bool update(const U64 deltaTime) override;
    /// This is used to set all of the subroutine indices for the specified
    /// shader stage for this program
    void SetSubroutines(ShaderType type, const vectorImpl<U32>& indices) const override;
    /// This works exactly like SetSubroutines, but for a single index.
    void SetSubroutine(ShaderType type, U32 index) const override;
    /// Get the index of the specified subroutine name for the specified stage.
    /// Not cached!
    U32 GetSubroutineIndex(ShaderType type, const char* name) const override;
    /// Get the uniform location of the specified subroutine uniform for the
    /// specified stage. Not cached!
    U32 GetSubroutineUniformLocation(ShaderType type, const char* name) const override;
    U32 GetSubroutineUniformCount(ShaderType type) const override;

    /// Cache uniform/attribute locations for shader programs
    I32 Binding(const char* name) override;

    /// Set an uniform value
    void Uniform(const stringImplFast& location, U32 value) override;
    void Uniform(const stringImplFast& location, I32 value) override;
    void Uniform(const stringImplFast& location, F32 value) override;
    void Uniform(const stringImplFast& location, const vec2<F32>& value) override;
    void Uniform(const stringImplFast& location, const vec2<I32>& value) override;
    void Uniform(const stringImplFast& location, const vec3<F32>& value) override;
    void Uniform(const stringImplFast& location, const vec3<I32>& value) override;
    void Uniform(const stringImplFast& location, const vec4<F32>& value) override;
    void Uniform(const stringImplFast& location, const vec4<I32>& value) override;
    void Uniform(const stringImplFast& location, const mat3<F32>& value, bool transpose = false) override;
    void Uniform(const stringImplFast& location, const mat4<F32>& value, bool transpose = false) override;
    void Uniform(const stringImplFast& location, const vectorImpl<I32>& values) override;
    void Uniform(const stringImplFast& location, const vectorImpl<F32>& values) override;
    void Uniform(const stringImplFast& location, const vectorImpl<vec2<F32>>& values) override;
    void Uniform(const stringImplFast& location, const vectorImpl<vec3<F32>>& values) override;
    void Uniform(const stringImplFast& location, const vectorImplBest<vec4<F32>>& values) override;
    void Uniform(const stringImplFast& location, const vectorImpl<mat3<F32>>& values, bool transpose = false) override;
    void Uniform(const stringImplFast& location, const vectorImplBest<mat4<F32>>& values, bool transpose = false) override;

    void DispatchCompute(U32 xGroups, U32 yGroups, U32 zGroups) override;

    void SetMemoryBarrier(MemoryBarrierType type) override;

   protected:
    glShaderProgramLoadInfo buildLoadInfo();
    std::pair<bool, stringImpl> loadSourceCode(ShaderType stage,
                                               const stringImpl& stageName,
                                               const stringImpl& header,
                                               bool forceReParse);
    bool loadFromBinary();
       
    bool recompileInternal() override;
    /// Creation of a new shader program. Pass in a shader token and use glsw to
    /// load the corresponding effects
    bool load(const DELEGATE_CBK<void, CachedResource_wptr>& onLoadCallback) override;
    /// Linking a shader program also sets up all pre-link properties for the
    /// shader (varying locations, attrib bindings, etc)
    void link();
    /// This should be called in the loading thread, but some issues are still
    /// present, and it's not recommended (yet)
    void threadedLoad(DELEGATE_CBK<void, CachedResource_wptr> onLoadCallback, bool skipRegister);

    struct fake_dependency: public std::false_type {};
    template <typename T>
    I32 cachedValueUpdate(const stringImplFast& location, const T& value) {
        static_assert(
                fake_dependency::value,
            "glShaderProgram::cachedValue error: unsupported data type!");
        return -1;
    }
    /// Basic OpenGL shader program validation (both in debug and in release)
    bool validateInternal();
    /// Retrieve the program's validation log if we need it
    stringImpl getLog() const;

    /// Add a new shader stage to this program
    void attachShader(glShader* const shader);
    /// Remove a shader stage from this program
    void detachShader(glShader* const shader);

    void reloadShaders(bool reparseShaderSource);

    void reuploadUniforms();

   private:

    ShaderVarMap _shaderVarLocation;
    UniformsByName _uniformsByName;
    
    bool _validationQueued;
    GLenum _binaryFormat;
    bool _validated;
    bool _loadedFromBinary;
    GLuint _shaderProgramIDTemp;
    static std::array<U32, to_base(ShaderType::COUNT)> _lineOffset;
    std::array<glShader*, to_base(ShaderType::COUNT)> _shaderStage;

    glLockManager* _lockManager;
};

namespace Attorney {
    class GLAPIShaderProgram {
    private:
        static void setGlobalLineOffset(U32 offset) {
            glShaderProgram::_lineOffset.fill(offset);
        }
        static void addLineOffset(ShaderType stage, U32 offset) {
            glShaderProgram::_lineOffset[to_U32(stage)] += offset;
        }

        friend class Divide::GL_API;
    };
};  // namespace Attorney
};  // namespace Divide

#endif  //_PLATFORM_VIDEO_OPENGLS_PROGRAM_H_

#include "glShaderProgram.inl"

Commits for Divide-Framework/trunk/Source Code/Platform/Video/OpenGL/Shaders/Headers/glShaderProgram.h

Diff revisions: vs.
Revision Author Commited Message
912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

897 Diff Diff IonutCava picture IonutCava Thu 22 Jun, 2017 18:26:20 +0000

[IonutCava]
- Fix multi-context GL object creation
- Add missing file

892 Diff Diff IonutCava picture IonutCava Mon 15 May, 2017 20:43:39 +0000

[Ionut]
- Miscellaneous bug fixes

889 Diff Diff IonutCava picture IonutCava Tue 04 Apr, 2017 16:01:34 +0000

[IonutCava]
- Rework uniform passing/caching to better work with shader recompilation
- Cleanup shaders a bit for better performance

886 Diff Diff IonutCava picture IonutCava Wed 29 Mar, 2017 23:36:51 +0000

[Ionut]
- Initial code for multiple water block support (position + length/width/depth)

879 Diff Diff IonutCava picture IonutCava Sun 19 Mar, 2017 19:29:46 +0000

[IonutCava]
- GLSL updates:
— Interface block correction to support tessellation shaders automatically
— Fixed line counting issues with the preprocessor

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

860 IonutCava picture IonutCava Mon 13 Feb, 2017 21:07:59 +0000

[IonutCava]
- Fix shared_ptr leak in resource loading callbacks