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
/*
   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 {
    USE_CUSTOM_ALLOCATOR
    friend class Attorney::GLAPIShaderProgram;
   public:
       struct glShaderProgramLoadInfo {
           stringImpl _resourcePath;
           stringImpl _header;
           stringImpl _programName;
           stringImpl _programProperties;
           stringImpl _vertexStageProperties;
       };

   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;
    /// Set an uniform value
    inline void Uniform(const char* ext, U32 value) override;
    inline void Uniform(const char* ext, I32 value) override;
    inline void Uniform(const char* ext, F32 value) override;
    inline void Uniform(const char* ext, const vec2<F32>& value) override;
    inline void Uniform(const char* ext, const vec2<I32>& value) override;
    inline void Uniform(const char* ext, const vec3<F32>& value) override;
    inline void Uniform(const char* ext, const vec3<I32>& value) override;
    inline void Uniform(const char* ext, const vec4<F32>& value) override;
    inline void Uniform(const char* ext, const vec4<I32>& value) override;
    inline void Uniform(const char* ext, const mat3<F32>& value, bool transpose = false) override;
    inline void Uniform(const char* ext, const mat4<F32>& value, bool transpose = false) override;
    inline void Uniform(const char* ext, const vectorImpl<I32>& values) override;
    inline void Uniform(const char* ext, const vectorImpl<F32>& values) override;
    inline void Uniform(const char* ext, const vectorImpl<vec2<F32>>& values) override;
    inline void Uniform(const char* ext, const vectorImpl<vec3<F32>>& values) override;
    inline void Uniform(const char* ext, const vectorImplBest<vec4<F32>>& values) override;
    inline void Uniform(const char* ext, const vectorImpl<mat3<F32>>& values, bool transpose = false) override;
    inline void Uniform(const char* ext, const vectorImplBest<mat4<F32>>& values, bool transpose = false) override;

    void Uniform(I32 location, U32 value) override;
    void Uniform(I32 location, I32 value) override;
    void Uniform(I32 location, F32 value) override;
    void Uniform(I32 location, const vec2<F32>& value) override;
    void Uniform(I32 location, const vec2<I32>& value) override;
    void Uniform(I32 location, const vec3<F32>& value) override;
    void Uniform(I32 location, const vec3<I32>& value) override;
    void Uniform(I32 location, const vec4<F32>& value) override;
    void Uniform(I32 location, const vec4<I32>& value) override;
    void Uniform(I32 location, const mat3<F32>& value, bool transpose = false) override;
    void Uniform(I32 location, const mat4<F32>& value, bool transpose = false) override;
    void Uniform(I32 location, const vectorImpl<I32>& values) override;
    void Uniform(I32 location, const vectorImpl<F32>& values) override;
    void Uniform(I32 location, const vectorImpl<vec2<F32>>& values) override;
    void Uniform(I32 location, const vectorImpl<vec3<F32>>& values) override;
    void Uniform(I32 location, const vectorImplBest<vec4<F32>>& values) override;
    void Uniform(I32 location,
                 const vectorImpl<mat3<F32>>& values,
                 bool transpose = false) override;
    void Uniform(I32 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);
    /// Cache uniform/attribute locations for shader programs
    I32 getUniformLocation(const char* name) override;

    struct fake_dependency: public std::false_type {};
    template <typename T>
    bool cachedValueUpdate(I32 location, const T& value) {
        static_assert(
                fake_dependency::value,
            "glShaderProgram::cachedValue error: unsupported data type!");
        return false;
    }
    /// 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);

   private:
    typedef hashMapImpl<U64, I32> ShaderVarMap;
    typedef hashMapImpl<I32, U32> ShaderVarU32Map;
    typedef hashMapImpl<I32, I32> ShaderVarI32Map;
    typedef hashMapImpl<I32, F32> ShaderVarF32Map;
    typedef hashMapImpl<I32, vec2<F32>> ShaderVarVec2F32Map;
    typedef hashMapImpl<I32, vec2<I32>> ShaderVarvec2I32Map;
    typedef hashMapImpl<I32, vec3<F32>> ShaderVarVec3F32Map;
    typedef hashMapImpl<I32, vec3<I32>> ShaderVarVec3I32Map;
    typedef hashMapImpl<I32, vec4<F32>> ShaderVarVec4F32Map;
    typedef hashMapImpl<I32, vec4<I32>> ShaderVarVec4I32Map;
    typedef hashMapImpl<I32, mat3<F32>> ShaderVarMat3Map;
    typedef hashMapImpl<I32, mat4<F32>> ShaderVarMat4Map;

    ShaderVarU32Map _shaderVarsU32;
    ShaderVarI32Map _shaderVarsI32;
    ShaderVarF32Map _shaderVarsF32;
    ShaderVarVec2F32Map _shaderVarsVec2F32;
    ShaderVarvec2I32Map _shaderVarsVec2I32;
    ShaderVarVec3F32Map _shaderVarsVec3F32;
    ShaderVarVec3I32Map _shaderVarsVec3I32;
    ShaderVarVec4F32Map _shaderVarsVec4F32;
    ShaderVarVec4I32Map _shaderVarsVec4I32;
    ShaderVarMat3Map _shaderVarsMat3;
    ShaderVarMat4Map _shaderVarsMat4;

    ShaderVarMap _shaderVarLocation;
    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
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 Diff Diff IonutCava picture IonutCava Mon 13 Feb, 2017 21:07:59 +0000

[IonutCava]
- Fix shared_ptr leak in resource loading callbacks

858 Diff Diff IonutCava picture IonutCava Sun 12 Feb, 2017 20:55:05 +0000

[IonutCava]
- More resource loading updates

856 Diff Diff IonutCava picture IonutCava Fri 10 Feb, 2017 17:19:06 +0000

[IonutCava]
- Attempt to improve resource creation mechanism by adding a callback for when the resource finishes loading
— This is useful for multi-threaded loading: shaders, textures, terrain, etc

840 Diff Diff IonutCava picture IonutCava Wed 01 Feb, 2017 14:06:06 +0000

[IonutCava]
- Fix a bug with hot shader reloading and atom file caching
- Add hot language file reloading.
— Changes made to the current language file will be immediately applied

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

833 IonutCava picture IonutCava Thu 26 Jan, 2017 22:04:33 +0000

[IonutCava]
- Fix most build errors. Divide-Server does not build for now.