Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Hardware/Video/Headers/GFXDevice.h

Diff revisions: vs.
  @@ -20,12 +20,20 @@
20 20
21 21 */
22 22
23 - #ifndef _GFX_DEVICE_H
24 - #define _GFX_DEVICE_H
23 + #ifndef _HARDWARE_VIDEO_GFX_DEVICE_H_
24 + #define _HARDWARE_VIDEO_GFX_DEVICE_H_
25 25
26 26 #include "Hardware/Video/OpenGL/Headers/GLWrapper.h"
27 27 #include "Hardware/Video/Direct3D/Headers/DXWrapper.h"
28 28 #include "Managers/Headers/RenderPassManager.h" ///<For GFX_RENDER_BIN_SIZE
29 + #include "Rendering/Headers/Renderer.h"
30 +
31 + #ifdef FORCE_NV_OPTIMUS_HIGHPERFORMANCE
32 + extern "C" {
33 + _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
34 + }
35 + #endif
36 +
29 37 enum RenderStage;
30 38 enum SceneNodeType;
31 39
  @@ -33,7 +41,6 @@
33 41 class Camera;
34 42 class Object3D;
35 43 class Framerate;
36 - class Renderer;
37 44 class SceneRenderState;
38 45 ///Rough around the edges Adapter pattern
39 46 DEFINE_SINGLETON_EXT1(GFXDevice,RenderAPIWrapper)
  @@ -52,7 +59,7 @@
52 59 inline void registerKernel(Kernel* const kernel) {_kernel = kernel;}
53 60 inline void initDevice(U32 targetFrameRate) {_api.initDevice(targetFrameRate);}
54 61 inline void changeResolution(U16 w, U16 h) {_api.changeResolution(w,h);}
55 - inline void setWindowPos(U16 w, U16 h) {_api.setWindowPos(w,h);}
62 + inline void setWindowPos(U16 w, U16 h) const {_api.setWindowPos(w,h);}
56 63
57 64 inline void exitRenderLoop(const bool killCommand = false) {_api.exitRenderLoop(killCommand);}
58 65 void closeRenderingApi();
  @@ -79,11 +86,8 @@
79 86 void enableFog(FogMode mode, F32 density, const vec3<F32>& color, F32 startDist, F32 endDist);
80 87
81 88 inline void toggle2D(bool _2D) {_api.toggle2D(_2D);}
82 - inline void lookAt(const vec3<F32>& eye,
83 - const vec3<F32>& center,
84 - const vec3<F32>& up = vec3<F32>(0,1,0),
85 - const bool invertx = false,
86 - const bool inverty = false) { _api.lookAt(eye,center,up,invertx,inverty); }
89 + inline void lookAt(const mat4<F32>& viewMatrix, const vec3<F32>& viewDirection) { _api.lookAt(viewMatrix, viewDirection); }
90 + inline void lookAt(const vec3<F32>& eye, const vec3<F32>& target, const vec3<F32>& up = WORLD_Y_AXIS) {_api.lookAt(eye,target,up);}
87 91 ///Usually, after locking and releasing our matrices we want to revert to the View matrix to render geometry
88 92 inline void lockMatrices(const MATRIX_MODE& setCurrentMatrix = VIEW_MATRIX, bool lockView = true, bool lockProjection = true) {_api.lockMatrices(setCurrentMatrix,lockView,lockProjection);}
89 93 inline void releaseMatrices(const MATRIX_MODE& setCurrentMatrix = VIEW_MATRIX, bool releaseView = true, bool releaseProjection = true) {_api.releaseMatrices(setCurrentMatrix,releaseView,releaseProjection);}
  @@ -91,9 +95,11 @@
91 95 inline void setOrthoProjection(const vec4<F32>& rect, const vec2<F32>& planes){_api.setOrthoProjection(rect,planes);}
92 96 ///sets a perspective projection, updating any listeners if needed
93 97 inline void setPerspectiveProjection(F32 FoV,F32 aspectRatio, const vec2<F32>& planes) { _api.setPerspectiveProjection(FoV,aspectRatio,planes);}
98 + ///sets the view frustum to either the left or right eye position for anaglyph rendering
99 + inline void setAnaglyphFrustum(F32 camIOD, bool rightFrustum = false) {_api.setAnaglyphFrustum(camIOD,rightFrustum);}
94 100 ///sets a new horizontal FoV
95 101 void setHorizontalFoV(I32 newFoV);
96 - inline void renderInViewport(const vec4<I32>& rect, boost::function0<void> callback) {_api.renderInViewport(rect,callback);}
102 + inline void renderInViewport(const vec4<U32>& rect, boost::function0<void> callback) {_api.renderInViewport(rect,callback);}
97 103 //returns an immediate mode emulation buffer that can be used to construct geometry in a vertex by vertex manner.
98 104 //allowPrimitiveRecycle = do not reause old primitives and do not delete it after x-frames. (Don't use the primitive zombie feature)
99 105 inline IMPrimitive* createPrimitive(bool allowPrimitiveRecycle = true) { return _api.createPrimitive(allowPrimitiveRecycle); }
  @@ -116,18 +122,18 @@
116 122 ///The render callback must update all visual information and populate the "RenderBin"'s!
117 123 ///Use the sceneGraph::update callback as default using the macro SCENE_GRAPH_UPDATE(pointer)
118 124 ///pointer = a pointer to the sceneGraph instance used for rendering
119 - void render(boost::function0<void> renderFunction,SceneRenderState* const sceneRenderState);
125 + void render(boost::function0<void> renderFunction, const SceneRenderState& sceneRenderState);
120 126 ///Update light properties internally in the Rendering API
121 127 inline void setLight(Light* const light) {_api.setLight(light);}
122 - ///Sets the current render state.
128 + ///Sets the current render stage.
123 129 ///@param stage Is used to inform the rendering pipeline what we are rendering. Shadows? reflections? etc
124 - inline void setRenderStage(RenderStage stage) {_renderStage = stage;}
130 + inline void setRenderStage(RenderStage stage) {_prevRenderStage = _renderStage; _renderStage = stage;}
131 + ///Restores the render stage to the previous one calling it multiple times will ping-pong between stages
132 + inline void setPreviousRenderStage() {setRenderStage(_prevRenderStage);}
125 133 ///Checks if the current rendering stage is any of the stages defined in renderStageMask
126 134 ///@param renderStageMask Is a bitmask of the stages we whish to check if active
127 - bool isCurrentRenderStage(U16 renderStageMask);
128 - bool getDeferredRendering();
129 -
130 - inline RenderStage getRenderStage() {return _renderStage;}
135 + bool isCurrentRenderStage(U16 renderStageMask);
136 + inline RenderStage getRenderStage() {return _renderStage;}
131 137 inline void setPrevShaderId(const U32& id) {_prevShaderId = id;}
132 138 inline U32 getPrevShaderId() {return _prevShaderId;}
133 139 inline void setPrevTextureId(const U32& id) {_prevTextureId = id;}
  @@ -135,14 +141,40 @@
135 141 inline Renderer* getRenderer() {assert(_renderer != NULL); return _renderer;}
136 142 void setRenderer(Renderer* const renderer);
137 143 void closeRenderer();
144 +
145 + /*
146 + /* Clipping plane management. All the clipping planes are handled by shader programs only!
147 + */
148 + ///enable-disable HW clipping
149 + inline void updateClipPlanes() {_api.updateClipPlanes(); }
150 + /// add a new clipping plane. This will be limited by the actual shaders (how many planes they use)
151 + /// this function returns the newly added clip plane's index in the vector
152 + inline I32 addClipPlane(const Plane<F32>& p);
153 + /// add a new clipping plane defined by it's equation's coefficients
154 + inline I32 addClipPlane(F32 A, F32 B, F32 C, F32 D);
155 + /// remove a clip plane by index
156 + inline bool removeClipPlane(U32 index);
157 + /// disable a clip plane by index
158 + inline bool disableClipPlane(U32 index);
159 + /// enable a clip plane by index
160 + inline bool enableClipPlane(U32 index);
161 + /// modify a single clip plane by index
162 + inline void setClipPlane(U32 index, const Plane<F32>& p);
163 + /// set a new list of clipping planes. The old one is discarded
164 + inline void setClipPlanes(const PlaneList& clipPlanes);
165 + /// clear all clipping planes
166 + inline void resetClipPlanes();
167 + /// have the clipping planes changed?
168 + inline bool clippingPlanesDirty() const {return _clippingPlanesDirty;}
169 + /// get the entire list of clipping planes
170 + inline const PlaneList& getClippingPlanes() const {return _clippingPlanes;}
138 171 ///Save a screenshot in TGA format
139 172 inline void Screenshot(char *filename, const vec4<F32>& rect){_api.Screenshot(filename,rect);}
140 173 /// Some Scene Node Types are excluded from certain operations (lights triggers, etc)
141 174 bool excludeFromStateChange(const SceneNodeType& currentType);
142 175 ///Creates a new API dependend stateblock based on the received description
143 176 ///Calls newRenderStateBlock and also saves the new block in the state block map
144 - RenderStateBlock* GFXDevice::createStateBlock(const RenderStateBlockDescriptor& descriptor);
145 -
177 + RenderStateBlock* createStateBlock(const RenderStateBlockDescriptor& descriptor);
146 178 ///Sets the current state block to the one passed as a param
147 179 ///It is not set immediately, but a call to "updateStates" is required
148 180 RenderStateBlock* setStateBlock(RenderStateBlock* block, bool forceUpdate = false);
  @@ -162,24 +194,29 @@
162 194 ///It renders the entire scene graph (with culling) as default
163 195 ///use the callback param to override the draw function
164 196 void generateCubeMap(FrameBufferObject& cubeMap,
165 - Camera* const activeCamera,
166 197 const vec3<F32>& pos,
167 - boost::function0<void> callback = 0);
198 + boost::function0<void> callback = 0,
199 + const RenderStage& renderStage = ENVIRONMENT_MAPPING_STAGE);
168 200
169 201 inline bool loadInContext(const CurrentContext& context, boost::function0<void> callback) {return _api.loadInContext(context, callback);}
170 202 inline void getMatrix(const MATRIX_MODE& mode, mat4<F32>& mat) {_api.getMatrix(mode, mat);}
171 203 inline void getMatrix(const EXTENDED_MATRIX& mode, mat4<F32>& mat) {_api.getMatrix(mode, mat);}
172 204 inline void getMatrix(const EXTENDED_MATRIX& mode, mat3<F32>& mat) {_api.getMatrix(mode, mat);}
173 205
174 - #if defined( __WIN32__ ) || defined( _WIN32 )
206 + #if defined(OS_WINDOWS)
175 207 HWND getHWND() {return _api.getHWND();}
176 - #elif defined( __APPLE_CC__ ) // Apple OS X
208 + #elif defined(OS_APPLE)
177 209 ??
178 210 #else //Linux
179 211 Display* getDisplay() {return _api.getDisplay();}
180 212 GLXDrawable getDrawSurface() {return _api.getDrawSurface();}
181 213 #endif
182 214
215 + protected:
216 + friend class Kernel;
217 + friend class Application;
218 + inline void setMousePosition(D32 x, D32 y) const {_api.setMousePosition(x,y);}
219 +
183 220 private:
184 221
185 222 GFXDevice();
  @@ -193,7 +230,7 @@
193 230 private:
194 231 RenderAPIWrapper& _api;
195 232 bool _deviceStateDirty;
196 - RenderStage _renderStage;
233 + RenderStage _renderStage, _prevRenderStage;
197 234 U32 _prevShaderId, _prevTextureId;
198 235 bool _drawDebugAxis;
199 236
  @@ -212,21 +249,11 @@
212 249 RenderStateBlock* _defaultStateBlock;
213 250 ///Pointer to current kernel
214 251 Kernel* _kernel;
252 + PlaneList _clippingPlanes;
253 + bool _clippingPlanesDirty;
215 254
216 255 END_SINGLETON
217 256
218 - #define GFX_DEVICE GFXDevice::getInstance()
219 - #define GFX_RENDER_BIN_SIZE RenderPassManager::getInstance().getLastTotalBinSize(0)
220 -
221 - inline RenderStateBlock* SET_STATE_BLOCK(RenderStateBlock* const block, bool forceUpdate = false){
222 - return GFX_DEVICE.setStateBlock(block,forceUpdate);
223 - }
257 + #include "GFXDevice-Inl.h"
224 258
225 - inline RenderStateBlock* SET_DEFAULT_STATE_BLOCK(bool forceUpdate = false){
226 - return GFX_DEVICE.setDefaultStateBlock(forceUpdate);
227 - }
228 -
229 - inline RenderStateBlock* SET_PREVIOUS_STATE_BLOCK(bool forceUpdate = false){
230 - return GFX_DEVICE.setPreviousStateBlock(forceUpdate);
231 - }
232 259 #endif