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
/*
   Copyright (c) 2016 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:
    explicit glShaderProgram(GFXDevice& context,
                             const stringImpl& name,
                             const stringImpl& resourceLocation,
                             bool asyncLoad);
    ~glShaderProgram();

    /// 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 vectorImplAligned<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 vectorImplAligned<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 vectorImplAligned<vec4<F32>>& values) override;
    void Uniform(I32 location,
                 const vectorImpl<mat3<F32>>& values,
                 bool transpose = false) override;
    void Uniform(I32 location,
                 const vectorImplAligned<mat4<F32>>& values,
                 bool transpose = false) override;

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

    void SetMemoryBarrier(MemoryBarrierType type) override;

   protected:
    /// Creation of a new shader program. Pass in a shader token and use glsw to
    /// load the corresponding effects
    bool load() 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();
    /// 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, const bool refresh = false);
    /// Remove a shader stage from this program
    void detachShader(glShader* const shader);

   private:
    typedef hashMapImpl<ULL, 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_const_uint(ShaderType::COUNT)> _lineOffset;
    std::array<glShader*, to_const_uint(ShaderType::COUNT)> _shaderStage;
    /// ID<->shaders pair
    typedef hashMapImpl<U32, glShader*> ShaderIDMap;
    ShaderIDMap _shaderIDMap;

    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_uint(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
727 Diff Diff IonutCava picture IonutCava Tue 14 Jun, 2016 16:01:38 +0000

[IonutCava]
- Remove node and cmd buffers from GFXDevice and add them as a new BufferData struct to RenderPass class.
— Each render pass holds its own buffers
- Improvements / fixes to the CSM code
- Added a global toggle to enable/disable custom memory allocators

718 Diff Diff IonutCava picture IonutCava Thu 02 Jun, 2016 16:02:48 +0000

[IonutCava]
- Code cleanup:
— Rename Framebuffer to RenderTarget. Only OpenGL uses the Framebuffer nomenclature.
— Remove base Shader class as only OpenGL will have separate shaders (and eventually move to pipeline objects) as Direct3D uses FX files and may end up with different structure
— Remove drawBox3D, drawSphere3D and drawLines from GFXDevice class and add them as member functions to the IMPrimitive class (renamed to fromXYZ)
— Pull some elements from SceneManager and move them to standalone classes (W.I.P.)

716 Diff Diff IonutCava picture IonutCava Tue 31 May, 2016 16:08:29 +0000

[IonutCava]
- Multithreaded scene load/unload fixes:
— Added postLoadMainThread call for scenes for thread sensitive loading steps
— GUI element adding is a thread sensitive loading step (a fast one) because CEGUI doesn’t handle threading
- Added REALTIME_WITH_CALLBACK task priority for tasks that need an immediate callback when they complete instead of using the flushCallbackQueue system.
- Some work on shadow mapping for getting it to work again
- ShaderPrograms that fail to load can cause a LockManager infinite wait. Delete the lockManager if the shader didn’t load to avoid waiting on commands that never get called.

713 Diff Diff IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;

692 Diff Diff IonutCava picture IonutCava Wed 27 Apr, 2016 16:24:26 +0000

[IonutCava]
- Resource system cleanup:
— Resource name and resource file location (if any) is now passed only via explicit constructors! (ResourceDescriptors already contain this data, so why use setters?)
- Fix a bug with ortho projection matrix calculation (set m[3][3] to 1. this was skipped when the identity() call was changed to zero() in the ortho() function)
— This also fixed text rendering

671 Diff Diff IonutCava picture IonutCava Fri 08 Apr, 2016 16:26:49 +0000

[Ionut]
- Custom memory allocation system part 1:
— Add http://www.codeproject.com/Articles/1089905/A-Custom-STL-std-allocator-Replacement-Improves-Pe
— Add custom allocators to strings and vectors
— Add custom allocators to a few test classes
— No support for aligned memory yet, so vec4<F32> and mat4<F32> vectors use the old allocation system
- Replace more std::async call with our custom task system

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

622 Diff Diff IonutCava picture IonutCava Thu 14 Jan, 2016 17:18:49 +0000

[IonutCava]
- Remove onCameraUpdate call from LightManager and SceneGraph as it’s not needed
- Remove special threading handlers from Resource class as very few derived classes use them for now
— Use ResourceState to check current loading state
- Use insertion sort for particles as most entries should already be sorted from the previous frame
- Use async RenderBin sorting system

619 Diff Diff IonutCava picture IonutCava Fri 08 Jan, 2016 16:23:28 +0000

[IonutCava]
- Memory allocation optimizations
- Large VBO allocation system
- More terrain fixes
- Temporarily disable water and vegetation systems

591 IonutCava picture IonutCava Wed 02 Dec, 2015 17:17:23 +0000

[IonutCava]
- More work on the ForwardPlus renderer
- Singleton cleanup
- First steps for reducing scope of GFXDevice class