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
/*
   Copyright (c) 2014 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 _IM_EMULATION_H_
#define _IM_EMULATION_H_

#include "Core/Math/Headers/MathClasses.h"
#include "Utility/Headers/GUIDWrapper.h"

namespace Divide {

class Texture;
class ShaderProgram;
enum PrimitiveType;
///IMPrimitive replaces immediate mode calls to VB based rendering
class IMPrimitive : public GUIDWrapper, private NonCopyable  {
public:
	inline void setRenderStates(const DELEGATE_CBK<>& setupStatesCallback, const DELEGATE_CBK<>& releaseStatesCallback){
        _setupStates = setupStatesCallback;
        _resetStates = releaseStatesCallback;
    }

    inline void clearRenderStates(){
        _setupStates = nullptr;
        _resetStates = nullptr;
    }

    inline void setupStates() {
		if (_setupStates) {
			_setupStates();
		}
    }

    inline void resetStates() {
		if (_resetStates) {
			_resetStates();
		}
    }

    inline void drawShader(ShaderProgram* const shaderProgram) {
        _drawShader = shaderProgram;
    }

    virtual void render(bool forceWireframe = false, U32 instanceCount = 1) = 0;

    virtual void beginBatch()  { _inUse = true; _zombieCounter = 0; }
    virtual void begin(PrimitiveType type) = 0;
    virtual void vertex(F32 x, F32 y, F32 z) = 0;
    inline  void vertex(const vec3<F32>& vert) { vertex(vert.x, vert.y, vert.z); }
    virtual void attribute1i(const stringImpl& attribName, I32 value) = 0;
    virtual void attribute4ub(const stringImpl& attribName, U8 x, U8 y, U8 z, U8 w) = 0;
    virtual void attribute4f(const stringImpl& attribName,  F32 x, F32 y, F32 z, F32 w) = 0;
    inline  void attribute4ub(const stringImpl& attribName, const vec4<U8>& value) {
        attribute4ub(attribName, value.x, value.y, value.z, value.w); 
    }
    inline  void attribute4f(const stringImpl& attribName, const vec4<F32>& value) { 
        attribute4f(attribName, value.x, value.y, value.z, value.w); 
    }
    virtual void end() = 0;
    virtual void endBatch() = 0;

    virtual void clear() {
        zombieCounter(0);
        stateHash(0);
        clearRenderStates();
        inUse(false);
        _worldMatrix.identity();
        _lineWidth = 1.0f;
        _canZombify = true;
        _texture = nullptr;
        _drawShader = nullptr;
    }

    inline void paused(bool state)                 {_paused = state;}
    inline bool paused()                     const {return _paused;}
    inline void inUse(bool state)                  {_inUse = state;}
    inline bool inUse()                      const {return _inUse;}
    inline void zombieCounter(U8 count)            {_zombieCounter = count;}
    inline U8   zombieCounter()              const {return _zombieCounter;}
    inline void forceWireframe(bool state)         {_forceWireframe = state;}
    inline bool forceWireframe()             const {return _forceWireframe; }
    inline bool hasRenderStates()            const {return (!_setupStates && !_resetStates);}

    ///State management
    inline size_t  stateHash()              const { return _stateHash; }
    inline void stateHash(size_t hashValue)       { _stateHash = hashValue;}

    inline const mat4<F32>& worldMatrix()                             const { return _worldMatrix;}
    inline void             worldMatrix(const mat4<F32>& worldMatrix)       { _worldMatrix.set(worldMatrix); }
    inline void             resetWorldMatrix()                              { _worldMatrix.identity(); }
protected:
    IMPrimitive();

public:
    virtual ~IMPrimitive();

    ShaderProgram* _drawShader;
    Texture*       _texture;
    bool           _hasLines;
    bool           _canZombify;
    F32            _lineWidth;

protected:
    //render in wireframe mode
    bool         _forceWireframe;

private:
    ///after rendering an IMPrimitive, it's "inUse" flag is set to false.
    ///If the API tries to render it again, we just increment the _zombieCounter
    ///If the _zombieCounter reaches 3, we remove it from the vector as it is not needed
    U8           _zombieCounter;
    ///After rendering the primitive, we se "inUse" to false but leave it in the vector
    ///If a new primitive is to be rendered, it first looks for a zombie primitive
    ///If none are found, it adds a new one
    bool         _inUse; //<For caching
    ///If _pause is true, rendering for the current primitive is skipped and nothing is modified (e.g. zombie counters)
    bool         _paused;
    ///2 functions used to setup or reset states
	DELEGATE_CBK<> _setupStates;
	DELEGATE_CBK<> _resetStates;
    ///The state hash associated with this render instance
    size_t       _stateHash;
    ///The transform matrix for this element
    mat4<F32> _worldMatrix;
   
};

}; //namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Hardware/Video/Headers/IMPrimitive.h

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

330 Diff Diff IonutCava picture IonutCava Fri 10 Oct, 2014 17:19:11 +0000

[Ionut]
- New rendering algorithm :
— Perform second pass for visible nodes gathering all render commands and uploading them to an indirect draw buffer
— Render geometry with indirect draw commands
— Removed per-node range binding of the node buffer. Instead, bind the entire buffer once and index data in shaders
— Use “baseInstance” parameter from IndirectDrawCommand as a node buffer index
— Prefer DSA extensions for updating buffer data where applicable
- Moved all rendering specific code from SceneGraphNode to a new RenderingComponent
- Optimized “toString” utility function

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

304 Diff Diff IonutCava picture IonutCava Sun 10 Aug, 2014 21:10:54 +0000

[Ionut]
- Redesigned the WorldEditor (dummy functions added for every button/option)
- Improved debug rendering performance by using static IMPrimitives for axis gizmo rendering
- Simplified skeleton rendering

302 Diff Diff IonutCava picture IonutCava Wed 06 Aug, 2014 22:09:55 +0000

[Ionut]
- GenericVertexData buffer size (for read/write buffering) is now configurable instead of a fixed 3x and also applies to non-persistently mapped buffers
- Moved OpenGL enum tables to Divide::GLUtil::GL_ENUM_TABLE
- More code cleanups (glResources, glError, glVertexArray, glGenericVertexData, glIMPrimitive)

295 k1ngp1n picture k1ngp1n Fri 01 Aug, 2014 20:10:44 +0000

[Ionut]
- If a shader fails to bind, skip draw call. A shader will fail to bind if it wasn’t linked properly, as well
- Moved ShaderManager to the Hardware project due to its tight coupling
- More code cleanup and comments:
— OpenGL wrapper code : GLWrapper.h, GLWrapper.cpp, GLStates.cpp, glShaderProgram.cpp
- Cleaned up Shader.cpp
- Binary shader dump also saves binary format in .fmt file for each binary shader
- Renamed immediate mode primitive files