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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include <stdarg.h>
#include "Headers/GUI.h"
#include <CEGUI/CEGUI.h>

#include "Headers/GUIFlash.h"
#include "Headers/GUIText.h"
#include "Headers/GUIButton.h"
#include "Headers/GUIConsole.h"
#include "GUIEditor/Headers/GUIEditor.h"
#include "Core/Headers/ParamHandler.h"
#include "Core/Resources/Headers/ResourceCache.h"

#include "Hardware/Video/Headers/GFXDevice.h"
#include "Hardware/Input/Headers/InputInterface.h"
#include "Hardware/Video/Headers/RenderStateBlock.h"

GUI::GUI() : _init(false),
             _enableCEGUIRendering(false),
             _rootSheet(nullptr),
             _console(New GUIConsole()),
             _textRenderInterval(getMsToUs(10))
{
    //500ms
    _input.setInitialDelay(0.500f);
    GUIEditor::createInstance();
}

GUI::~GUI()
{
    close();
}

void GUI::onResize(const vec2<U16>& newResolution){
    //CEGUI handles it's own init checks
    CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(newResolution.width, newResolution.height));

    if (!_init || _cachedResolution == newResolution)
        return;

    vec2<I32> difDimensions(_cachedResolution.width - newResolution.width,
                            _cachedResolution.height - newResolution.height);

    FOR_EACH(guiMap::value_type& guiStackIterator,_guiStack){
        guiStackIterator.second->onResize(difDimensions);
    }
    _cachedResolution = newResolution;
}

void GUI::draw2D(){
    if(!_init) return;

    GFXDevice& gfx = GFX_DEVICE;

    _guiShader->bind();

    //------------------------------------------------------------------------
    FOR_EACH(guiMap::value_type& guiStackIterator, _guiStack){
        gfx.drawGUIElement(guiStackIterator.second);
    }
    //------------------------------------------------------------------------
}

void GUI::draw(const U64 deltaTime, const D32 interpolationFactor){
    if(!_init) return;
    if(_console) _console->update(deltaTime);

    D32 deltaTimeSec = getUsToSec(deltaTime);

    _input.update(deltaTime);
    CEGUI::System::getSingleton().injectTimePulse(deltaTimeSec);

    GUIEditor::getInstance().update(deltaTime);

    if(_enableCEGUIRendering){
        CEGUI::System::getSingleton().renderAllGUIContexts();
    }
}

bool GUI::init(const vec2<U16>& resolution){
    if(_init) {
        D_ERROR_FN(Locale::get("ERROR_GUI_DOUBLE_INIT"));
        return false;
    }
    _cachedResolution = resolution;

#ifdef _DEBUG
    CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Insane);
#endif
    CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>( CEGUI::System::getSingleton().getResourceProvider() ) ;
    std::string CEGUIInstallSharePath = ParamHandler::getInstance().getParam<std::string>("assetsLocation");
    CEGUIInstallSharePath += "/GUI/" ;
    rp->setResourceGroupDirectory( "schemes",    CEGUIInstallSharePath + "schemes/" ) ;
    rp->setResourceGroupDirectory( "imagesets",  CEGUIInstallSharePath + "imagesets/" ) ;
    rp->setResourceGroupDirectory( "fonts",      CEGUIInstallSharePath + "fonts/" ) ;
    rp->setResourceGroupDirectory( "layouts",    CEGUIInstallSharePath + "layouts/" ) ;
    rp->setResourceGroupDirectory( "looknfeels", CEGUIInstallSharePath + "looknfeel/" ) ;
    rp->setResourceGroupDirectory( "lua_scripts",CEGUIInstallSharePath + "lua_scripts/" ) ;
    //rp->setResourceGroupDirectory( "schemas",    CEGUIInstallSharePath + "xml_schemas/" ) ;
    //rp->setResourceGroupDirectory( "animations", CEGUIInstallSharePath + "animations/" ) ;

    // set the default resource groups to be used
    CEGUI::ImageManager::setImagesetDefaultResourceGroup("imagesets");
    CEGUI::Font::setDefaultResourceGroup("fonts");
    CEGUI::Scheme::setDefaultResourceGroup("schemes");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
    CEGUI::WindowManager::setDefaultResourceGroup("layouts");
    CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
    // setup default group for validation schemas
    CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
    if (parser->isPropertyPresent("SchemaDefaultResourceGroup")){
        parser->setProperty("SchemaDefaultResourceGroup", "schemas");
    }

    _defaultGUIScheme = ParamHandler::getInstance().getParam<std::string>("GUI.defaultScheme");
    CEGUI::SchemeManager::getSingleton().createFromFile(  _defaultGUIScheme + ".scheme") ;

    _rootSheet = CEGUI::WindowManager::getSingleton().createWindow( "DefaultWindow","root_window");
    CEGUI_DEFAULT_CONTEXT.setRootWindow( _rootSheet );
    CEGUI_DEFAULT_CONTEXT.setDefaultTooltipType( _defaultGUIScheme + "/Tooltip" );

    assert(_console);
    //_console->CreateCEGUIWindow();
    GUIEditor::getInstance().init();

    ResourceDescriptor immediateModeShader("ImmediateModeEmulation.GUI");
    immediateModeShader.setThreadedLoading(false);
    _guiShader = CreateResource<ShaderProgram>(immediateModeShader);
    _guiShader->UniformTexture("tex", 0);
    GFX_DEVICE.add2DRenderFunction(DELEGATE_BIND(&GUI::draw2D, this), std::numeric_limits<U32>::max() - 1);

    _init = true;
    return true;
}

void GUI::close(){
    PRINT_FN(Locale::get("STOP_GUI"));
    SAFE_DELETE(_console);
    RemoveResource(_guiShader);
    FOR_EACH(guiMap::value_type it, _guiStack) {
        SAFE_DELETE(it.second);
    }
    _guiStack.clear();
}

bool GUI::checkItem(const OIS::MouseEvent& arg ){
    if(!_init) return true;
    GUIEvent event;
    event.mousePoint.x = arg.state.X.abs;
    event.mousePoint.y = arg.state.Y.abs;

    FOR_EACH(guiMap::value_type& guiStackIterator,_guiStack) {
        guiStackIterator.second->onMouseMove(event);
    }
    CEGUI_DEFAULT_CONTEXT.injectMousePosition(arg.state.X.abs, arg.state.Y.abs);
    CEGUI_DEFAULT_CONTEXT.injectMouseWheelChange(arg.state.Z.abs);
    return true;
}

bool GUI::keyCheck(OIS::KeyEvent key, bool pressed) {
    if(!_init) return true;

    if(key.key == OIS::KC_GRAVE && !pressed){
        _console->setVisible(!_console->isVisible());
    }

#ifdef _DEBUG
    if(key.key == OIS::KC_F11 && !pressed){
        GUIEditor::getInstance().setVisible(!GUIEditor::getInstance().isVisible());
    }
#endif
    _input.injectOISKey(pressed,key);

    return (!_console->isVisible() && !GUIEditor::getInstance().isVisible());
}

bool GUI::clickCheck(OIS::MouseButtonID button, bool pressed) {
    if(!_init) return true;

    if(pressed){
        switch (button){
            case OIS::MB_Left:{
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonDown(CEGUI::LeftButton);
                GUIEvent event;
                event.mouseClickCount = 0;
                FOR_EACH(guiMap::value_type& guiStackIterator,_guiStack) {
                    guiStackIterator.second->onMouseDown(event);
                }
                }break;
            case OIS::MB_Middle:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonDown(CEGUI::MiddleButton);
                break;
            case OIS::MB_Right:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonDown(CEGUI::RightButton);
                break;
            case OIS::MB_Button3:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonDown(CEGUI::X1Button);
                break;
            case OIS::MB_Button4:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonDown(CEGUI::X2Button);
                break;
            default:
                break;
        }
    }else{
        switch (button){
            case OIS::MB_Left:{
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonUp(CEGUI::LeftButton);
                GUIEvent event;
                event.mouseClickCount = 1;
                FOR_EACH(guiMap::value_type& guiStackIterator,_guiStack) {
                    guiStackIterator.second->onMouseUp(event);
                }
                }break;
            case OIS::MB_Middle:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonUp(CEGUI::MiddleButton);
                break;
            case OIS::MB_Right:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonUp(CEGUI::RightButton);
                break;
            case OIS::MB_Button3:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonUp(CEGUI::X1Button);
                break;
            case OIS::MB_Button4:
                CEGUI_DEFAULT_CONTEXT.injectMouseButtonUp(CEGUI::X2Button);
                break;
            default:
                break;
        }
    }
    return !_console->isVisible() && !GUIEditor::getInstance().isVisible();
}

GUIButton* GUI::addButton(const std::string& id, const std::string& text,
                    const vec2<I32>& position,const vec2<U32>& dimensions,const vec3<F32>& color,
                    ButtonCallback callback,const std::string& rootSheetId){
    CEGUI::Window* parent = nullptr;
    if(!rootSheetId.empty()){
        parent = CEGUI_DEFAULT_CONTEXT.getRootWindow()->getChild(rootSheetId);
    }
    if(!parent) parent = _rootSheet;
    GUIButton* btn = New GUIButton(id,text,_defaultGUIScheme,position,dimensions,color,parent,callback);
    _guiStack[id] = btn;
    return btn;
}

GUIText* GUI::addText(const std::string& id,const vec2<I32> &position, const std::string& font,const vec3<F32> &color, char* format, ...){
    va_list args;
    std::string fmt_text;

    va_start(args, format);
    I32 len = _vscprintf(format, args) + 1;
    char *text = new char[len];
    vsprintf_s(text, len, format, args);
    fmt_text.append(text);
    SAFE_DELETE_ARRAY(text);
    va_end(args);

    GUIText *t = New GUIText(id,fmt_text,position,font,color,_rootSheet);
    _resultGuiElement = _guiStack.insert(make_pair(id,t));
    if(!_resultGuiElement.second) (_resultGuiElement.first)->second = t;
    fmt_text.empty();

    return t;
}

GUIFlash* GUI::addFlash(const std::string& id, std::string movie, const vec2<U32>& position, const vec2<U32>& extent){
    GUIFlash *flash = New GUIFlash(_rootSheet);
    _resultGuiElement = _guiStack.insert(make_pair(id,flash));
    if(!_resultGuiElement.second) (_resultGuiElement.first)->second = flash;

    return flash;
}

GUIText* GUI::modifyText(const std::string& id, char* format, ...){
    if(_guiStack.find(id) == _guiStack.end()) return nullptr;

    va_list args;
    std::string fmt_text;

    va_start(args, format);
    I32 len = _vscprintf(format, args) + 1;
    char * text = new char[len];
    vsprintf_s(text, len, format, args);
    fmt_text.append(text);
    SAFE_DELETE_ARRAY(text);
    va_end(args);

    GUIElement* element = _guiStack[id];
    assert(element->getType() == GUI_TEXT);

    GUIText* textElement = dynamic_cast<GUIText*>(element);
    textElement->_text = fmt_text;
    fmt_text.empty();
    return textElement;
}

/*   void onRightMouseUp(const GuiEvent &event);
     void onRightMouseDown(const GuiEvent &event);
     bool onKeyUp(const GuiEvent &event);
     bool onKeyDown(const GuiEvent &event);
*/

bool GUI::bindRenderer(CEGUI::Renderer& renderer){
    CEGUI::System::create(renderer);
    _enableCEGUIRendering =  !(ParamHandler::getInstance().getParam<bool>("GUI.CEGUI.SkipRendering"));
    return true;
}

Commits for Divide-Framework/trunk/Source Code/GUI/GUI.cpp

Diff revisions: vs.
Revision Author Commited Message
286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

272 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 11:30:51 +0000

[Ionut] [[BR]]
- Added initial code for Forward+ rendering (grid based light culling) [[BR]]
- Simplified Light class [[BR]]
- Moved more light uniform data to ShaderBuffers [[BR]]
- Double buffered grass rendering [[BR]]
- Added a better attribute interface to GenericVertexData [[BR]]
- Fixed screenshot capture [[BR]]
- Fixed texture double-bind checks [[BR]]

270 Diff Diff IonutCava picture IonutCava Thu 05 Jun, 2014 19:08:07 +0000

[Ionut][[BR]]
- SubMeshes now use a single vertex buffer (owned by the parent mesh) with proper offsetting and querying [[BR]]
— Implementation not optimal yet [[BR]]
- Cleaned up VertexBuffer related classes [[BR]]

264 Diff Diff k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]

263 Diff Diff k1ngp1n picture k1ngp1n Fri 09 May, 2014 16:43:53 +0000

[Ionut] [[BR]]
- Fullscreen quads are now rendered via Geometry Shaders [[BR]]
- Implemented shader subroutines [[BR]]
- Improved CVSM’s quality [[BR]]
- Separated shadow only light properties from general light properties in separate UBOs to improve update performance [[BR]]
- Removed shader mask and instead try to load all available shaders from a given file [[BR]]
- Added a method (hackish) of changing projection properties at runtime (e.g. z planes) [[BR]]
- Fixed a comparison bug in RenderStateBlock class (forgot to clean it at last commit) [[BR]]
- Fixed clipping plane upload to shader programs [[BR]]

260 Diff Diff k1ngp1n picture k1ngp1n Sat 03 May, 2014 19:33:41 +0000

[Ionut] [[BR]]
- More work on CSM. Reverted back to VSM to allow easier blurring and filtering [[BR]]
- Rewrote FrameBuffer classes to fix MSAA and memory leaks that occurred on resize (double creation of textures) [[BR]]
— Removed FBType. FrameBuffer types depend only on attachment types and if it’s MSAA enabled or not [[BR]]
- Rewrote RenderState classes to be API agnostic [[BR]]
- Bug fixes in math classes [[BR]]
- Changed “resolution change” logic [[BR]]
- Simplified some options in config.xml [[BR]]
- Improved per-light shadow options [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

258 Diff Diff k1ngp1n picture k1ngp1n Tue 15 Apr, 2014 15:26:22 +0000

[Ionut]
- Bumped minimum OpenGL required version to 4.3 (any Fermi and GCN 1.1 GPU)
- Fixed an issue with opacity maps
- Improved loading times by optimizing console output system and various optimizations in DVDConverter
- Create GUIConsole when needed (not on load)
- Moved common control code to the Scene class

250 k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 12:36:36 +0000

[Ionut] [[BR]]
- More C++11 work [[BR]]
- Renamed “for_each” macro to “FOR_EACH” to avoid name conflicts with the C++11 function [[BR]]