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
/*
   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 _KERNEL_H_
#define _KERNEL_H_

#include "core.h"
#include <boost/noncopyable.hpp>
#include "Hardware/Platform/Headers/Task.h"
#include <boost/lockfree/queue.hpp>
#include "Managers/Headers/CameraManager.h"

class GUI;
class Scene;
class PXDevice;
class GFXDevice;
class SFXDevice;
class Application;
class LightManager;
class SceneManager;
class ShaderManager;
class InputInterface;
class SceneRenderState;
class FrameListenerManager;

enum RenderStage;

///Input
namespace OIS {
    class KeyEvent;
    class MouseEvent;
    class JoyStickEvent;
    enum MouseButtonID;
}
struct FrameEvent;

///The kernel is the main interface to our engine components:
///-video
///-audio
///-physx
///-scene manager
///-etc
class Kernel : private boost::noncopyable {
public:
    Kernel(I32 argc, char **argv, Application& parentApp);
    ~Kernel();

    I8 initialize(const std::string& entryPoint);
    void shutdown();

    ///This sets the _mainLoopCallback and starts the main loop
    void beginLogicLoop();
    ///Our main loop entry function. The actual callback can be changed at runtime (i.e. pausing rendering in some menus, or pre-rendering a frame offscreen)
    inline  static void mainLoopStatic() {_mainLoopCallback();}
    ///Our main application rendering loop. Call input requests, physics calculations, pre-rendering, rendering,post-rendering etc
            static void mainLoopApp();
    ///Called after a swap-buffer call and before a clear-buffer call.
    ///In a GPU-bound application, the CPU will wait on the GPU to finish processing the frame so this should keep it busy (old-GLUT heritage)
            static void idle();
    ///Update all engine components that depend on the current resolution
            static void updateResolutionCallback(I32 w, I32 h);

public:

    GFXDevice& getGFXDevice() const {return _GFX;}
    SFXDevice& getSFXDevice() const {return _SFX;}
    PXDevice&  getPXDevice()  const {return _PFX;}
    /// get elapsed time since kernel initialization
    inline U64 getCurrentTime()      const {return _currentTime;}
    inline U64 getCurrentTimeDelta() const {return _currentTimeDelta;}
    /// get a pointer to the kernel's threadpool to add,remove,pause or stop tasks
    inline boost::threadpool::pool* const getThreadPool() {assert(_mainTaskPool != nullptr); return _mainTaskPool;}

    CameraManager& getCameraMgr() { return *_cameraMgr; }

public: ///Input
    ///Key pressed
    bool onKeyDown(const OIS::KeyEvent& key);
    ///Key released
    bool onKeyUp(const OIS::KeyEvent& key);
    ///Joystic axis change
    bool onJoystickMoveAxis(const OIS::JoyStickEvent& arg,I8 axis,I32 deadZone);
    ///Joystick direction change
    bool onJoystickMovePOV(const OIS::JoyStickEvent& arg,I8 pov);
    ///Joystick button pressed
    bool onJoystickButtonDown(const OIS::JoyStickEvent& arg,I8 button);
    ///Joystick button released
    bool onJoystickButtonUp(const OIS::JoyStickEvent& arg, I8 button);
    bool sliderMoved( const OIS::JoyStickEvent &arg, I8 index);
    bool vector3Moved( const OIS::JoyStickEvent &arg, I8 index);
    ///Mouse moved
    bool onMouseMove(const OIS::MouseEvent& arg);
    ///Mouse button pressed
    bool onMouseClickDown(const OIS::MouseEvent& arg,OIS::MouseButtonID button);
    ///Mouse button released
    bool onMouseClickUp(const OIS::MouseEvent& arg,OIS::MouseButtonID button);

    inline Task* AddTask(D32 tickInterval, bool startOnCreate, I32 numberOfTicks, const DELEGATE_CBK& threadedFunction, const DELEGATE_CBK& onCompletionFunction = DELEGATE_CBK()) {
         Task* taskPtr = New Task(getThreadPool(), tickInterval, startOnCreate, numberOfTicks, threadedFunction);
         taskPtr->connect(DELEGATE_BIND(&Kernel::threadPoolCompleted, this, _1));
         if (!onCompletionFunction.empty()){
             _threadedCallbackFunctions.insert(std::make_pair(taskPtr->getGUID(), onCompletionFunction));
         }
         return taskPtr;
    }

    inline Task* AddTask(D32 tickInterval, bool startOnCreate, bool runOnce, const DELEGATE_CBK& threadedFunction, const DELEGATE_CBK& onCompletionFunction = DELEGATE_CBK()) {
        Task* taskPtr = New Task(getThreadPool(), tickInterval, startOnCreate, runOnce, threadedFunction);
        taskPtr->connect(DELEGATE_BIND(&Kernel::threadPoolCompleted, this, _1));
        if (!onCompletionFunction.empty()){
            _threadedCallbackFunctions.insert(std::make_pair(taskPtr->getGUID(), onCompletionFunction));
        }
        return taskPtr;
    }

private:
   static void firstLoop();
   void renderScene();
   void renderSceneAnaglyph();
   bool mainLoopScene(FrameEvent& evt);
   bool presentToScreen(FrameEvent& evt, const D32 interpolationFactor);
   void threadPoolCompleted(U64 onExitTaskID);

private:
    friend class SceneManager;
    void submitRenderCall(const RenderStage& stage, const SceneRenderState& sceneRenderState, const DELEGATE_CBK& sceneRenderCallback) const;
    
private:
    Application&    _APP;
    ///Access to the GPU
    GFXDevice&		_GFX;
    ///Access to the audio device
    SFXDevice&		_SFX;
    ///Access to the physics system
    PXDevice&		_PFX;
    ///The graphical user interface
    GUI&			_GUI;
    ///The input interface
    InputInterface& _input;
    ///The SceneManager/ Scene Pool
    SceneManager&	_sceneMgr;
    ///Keep track of all active cameras used by the engine
    CameraManager* _cameraMgr;

    static bool   _keepAlive;
    static bool   _renderingPaused;
    static bool   _freezeLoopTime;
    static bool   _freezeGUITime;
   static DELEGATE_CBK      _mainLoopCallback;
   boost::threadpool::pool* _mainTaskPool;
   // both are in ms
   static U64 _currentTime;
   static U64 _currentTimeFrozen;
   static U64 _currentTimeDelta;
   static U64 _previousTime;
   static D32 _nextGameTick;

   static Unordered_map<U64, DELEGATE_CBK > _threadedCallbackFunctions;
   static boost::lockfree::queue<U64, boost::lockfree::capacity<Config::THREAD_LIMIT + 1> >  _callbackBuffer;
   U8 _loops;
   //Command line arguments
   I32    _argc;
   char **_argv;
};

#endif

Commits for Divide-Framework/trunk/Source Code/Core/Headers/Kernel.h

Diff revisions: vs.
Revision Author Commited Message
268 Diff Diff IonutCava picture IonutCava Wed 04 Jun, 2014 10:20:27 +0000

[IonutCava] [[BR]]
- Terrain and vegetation updates: [[BR]]
— Use standard phong lighting model [[BR]]
— Separate grass patches per chunk [[BR]]
— Reduce number of required texture bind points for terrain by adding both textures and normal maps in a single texture array [[BR]]
— Draw terrain with 2 drawcalls (using glMultiDrawElements twice, once for LoD == 0 and once for LoD > 0) [[BR]]
[[BR]]
- Buffer management updates: [[BR]]
— Unified buffer binding system [[BR]]
— Made Uniform buffer objects visible to all classes and moved lightUBO to LightManager, matricesUBO to GFXDevice etc [[BR]]
— Added initial support for Shader Buffer Objects [[BR]]
— Moved viewport management to GFXDevice class [[BR]]
[[BR]]
- Rendering improvements: [[BR]]
— Added Hi-Z occlusion culling to instanceCull shader (using Hi-Z depth buffer constructed in GFXDevice class) [[BR]]
— Resolved issues with shadow maps overriding texture bind locations [[[BR]]
— Improved shader and shader program loading [[BR]]
— Improved material transparency support [[BR]]
— Added buffer lock manager class from “Approaching Zero Driver Overhead in OpenGL (Presented by NVIDIA)” speech at GDC14 [[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]]

249 Diff Diff k1ngp1n picture k1ngp1n Mon 31 Mar, 2014 20:42:31 +0000

[Ionut] [[BR]]
- Migrated to platform toolset v100 [[BR]]
- Updated boost to 1.55 [[BR]]
- Moved from “NULL” to “nullptr” [[BR]]
- DevIL is now linked dynamically [[BR]]

239 Diff Diff k1ngp1n picture k1ngp1n Sat 01 Feb, 2014 18:07:03 +0000

- decoupled some classes and moved rebalanced responsibilities around [[BR]]
— e.g. GFX class is now responsible for creating and destroying PostFX and ShaderManager instances [[BR]]
— e.g. Kernel should not do any GUI queries [[BR]]

221 Diff Diff k1ngp1n picture k1ngp1n Wed 08 Jan, 2014 18:50:02 +0000

[Ionut] [[BR]]
- Merged branch “Shadows And Animations” back into trunk [[BR]]
- Added DoxygenGUI project file [[BR]]

  • Buggy *
186 Diff Diff k1ngp1n picture k1ngp1n Sun 24 Nov, 2013 19:14:54 +0000

[Ionut] [[BR]]
- Increased precision of internal timers (delta time stored as double and computed by the kernel) [[BR]]
- Some thread sync fixes [[BR]]
- More work on the profile timers. Added a main loop timer as an example (Kernel.cpp -> mainLoopApp) [[BR]]
- Physics update <-> SceneGraphNode transform update sync (rather primitive, but it works) [[BR]]
— Setting a position or rotation manually was overridden by the physics engine. Now, manual transform updates have a higher priority [[BR]]

178 k1ngp1n picture k1ngp1n Sat 16 Nov, 2013 16:42:20 +0000

[Ionut][[BR]]
- Path generation between 2 points using a specified NavMesh (Part 1 / 3 - “Base Code”) [[BR]]