Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 330 vs 331 for /trunk/Source Code/Hardware/Video/GFXDeviceState.cpp

Diff revisions: vs.
  @@ -27,13 +27,18 @@
27 27 _imShader = ShaderManager::getInstance().getDefaultShader();
28 28 DIVIDE_ASSERT(_imShader != nullptr, "GFXDevice error: No immediate mode emulation shader available!");
29 29 PostFX::createInstance();
30 - // Create a shader buffer to store the following info: ViewMatrix, ProjectionMatrix, ViewProjectionMatrix, CameraPositionVec, ViewportRec, zPlanesVec4 and ClipPlanes[MAX_CLIP_PLANES]
31 - // It should translate to (as seen by OpenGL) a uniform buffer without persistent mapping. (Many small updates with BufferSubData are recommended with the target usage of the buffer)
30 + // Create a shader buffer to store the following info:
31 + // ViewMatrix, ProjectionMatrix, ViewProjectionMatrix, CameraPositionVec,
32 + // ViewportRec, zPlanesVec4 and ClipPlanes[MAX_CLIP_PLANES]
33 + // It should translate to (as seen by OpenGL) a uniform buffer without persistent mapping.
34 + // (Many small updates with BufferSubData are recommended with the target usage of the buffer)
32 35 _gfxDataBuffer = newSB(false, false);
33 36 _gfxDataBuffer->Create(1, sizeof(GPUBlock));
34 37 _gfxDataBuffer->Bind(SHADER_BUFFER_GPU_BLOCK);
35 - // Every visible node will first update this buffer with required data (WorldMatrix, NormalMatrix, Material properties, Bone count, etc)
36 - // Due to it's potentially huge size, it translates to (as seen by OpenGL) a Shader Storage Buffer that's persistently and coherently mapped
38 + // Every visible node will first update this buffer with required data
39 + // (WorldMatrix, NormalMatrix, Material properties, Bone count, etc)
40 + // Due to it's potentially huge size, it translates to (as seen by OpenGL) a Shader Storage Buffer that's persistently
41 + // and coherently mapped
37 42 _nodeBuffer = newSB(true);
38 43 _nodeBuffer->Create(Config::MAX_VISIBLE_NODES, sizeof(NodeData));
39 44 _nodeBuffer->Bind(SHADER_BUFFER_NODE_INFO);
  @@ -56,12 +61,16 @@
56 61 // Block with hash 0 is null, and it's used to force a block update, bypassing state comparison with previous blocks
57 62 _stateBlockMap[0] = nullptr;
58 63 // The general purpose render state blocks are both mandatory and must differ from each other at a state hash level
59 - DIVIDE_ASSERT(_stateDepthOnlyRenderingHash != _state2DRenderingHash, "GFXDevice error: Invalid default state hash detected!");
60 - DIVIDE_ASSERT(_state2DRenderingHash != _defaultStateNoDepthHash, "GFXDevice error: Invalid default state hash detected!");
61 - DIVIDE_ASSERT(_defaultStateNoDepthHash != _defaultStateBlockHash, "GFXDevice error: Invalid default state hash detected!");
64 + DIVIDE_ASSERT(_stateDepthOnlyRenderingHash != _state2DRenderingHash,
65 + "GFXDevice error: Invalid default state hash detected!");
66 + DIVIDE_ASSERT(_state2DRenderingHash != _defaultStateNoDepthHash,
67 + "GFXDevice error: Invalid default state hash detected!");
68 + DIVIDE_ASSERT(_defaultStateNoDepthHash != _defaultStateBlockHash,
69 + "GFXDevice error: Invalid default state hash detected!");
62 70 // Activate the default render states
63 71 setStateBlock(_defaultStateBlockHash);
64 - // Our default render targets hold the screen buffer, depth buffer, and a special, on demand, down-sampled version of the depth buffer
72 + // Our default render targets hold the screen buffer, depth buffer, and a special, on demand,
73 + // down-sampled version of the depth buffer
65 74 // Screen FB should use MSAA if available
66 75 _renderTarget[RENDER_TARGET_SCREEN] = newFB(true);
67 76 // The depth buffer should probably be merged into the screen buffer
  @@ -92,42 +101,43 @@
92 101 depthSamplerHiZ.toggleMipMaps(true);
93 102 TextureDescriptor depthDescriptorHiZ(TEXTURE_2D_MS, DEPTH_COMPONENT32F, FLOAT_32);
94 103 depthDescriptorHiZ.setSampler(depthSamplerHiZ);
95 - /// Add the attachments to the render targets
104 + // Add the attachments to the render targets
96 105 _renderTarget[RENDER_TARGET_SCREEN]->AddAttachment(screenDescriptor, TextureDescriptor::Color0);
97 106 _renderTarget[RENDER_TARGET_SCREEN]->AddAttachment(depthDescriptor, TextureDescriptor::Depth);
98 107 _renderTarget[RENDER_TARGET_SCREEN]->Create(resolution.width, resolution.height);
99 108 _renderTarget[RENDER_TARGET_DEPTH]->AddAttachment(depthDescriptorHiZ, TextureDescriptor::Depth);
100 109 _renderTarget[RENDER_TARGET_DEPTH]->toggleColorWrites(false);
101 110 _renderTarget[RENDER_TARGET_DEPTH]->Create(resolution.width, resolution.height);
102 - /// If we enabled anaglyph rendering, we need a second target, identical to the screen target used to render the scene at an offset
111 + // If we enabled anaglyph rendering, we need a second target, identical to the screen target
112 + // used to render the scene at an offset
103 113 if(_enableAnaglyph){
104 114 _renderTarget[RENDER_TARGET_ANAGLYPH] = newFB(true);
105 115 _renderTarget[RENDER_TARGET_ANAGLYPH]->AddAttachment(screenDescriptor, TextureDescriptor::Color0);
106 116 _renderTarget[RENDER_TARGET_ANAGLYPH]->AddAttachment(depthDescriptor, TextureDescriptor::Depth);
107 117 _renderTarget[RENDER_TARGET_ANAGLYPH]->Create(resolution.width, resolution.height);
108 118 }
109 - /// If render targets ready, we initialize our post processing system
119 + // If render targets ready, we initialize our post processing system
110 120 PostFX::getInstance().init(resolution);
111 - /// We also add a couple of useful cameras used by this class. One for rendering in 2D and one for generating cube maps
121 + // We also add a couple of useful cameras used by this class. One for rendering in 2D and one for generating cube maps
112 122
113 123 Application::getInstance().getKernel()->getCameraMgr().addNewCamera("2DRenderCamera", _2DCamera);
114 124 Application::getInstance().getKernel()->getCameraMgr().addNewCamera("_gfxCubeCamera", _cubeCamera);
115 - /// Initialized our HierarchicalZ construction shader (takes a depth attachment and down-samples it for every mip level)
125 + // Initialized our HierarchicalZ construction shader (takes a depth attachment and down-samples it for every mip level)
116 126 _HIZConstructProgram = CreateResource<ShaderProgram>(ResourceDescriptor("HiZConstruct"));
117 127 _HIZConstructProgram->UniformTexture("LastMip", 0);
118 - /// Store our target z distances
128 + // Store our target z distances
119 129 _gpuBlock._ZPlanesCombined.z = ParamHandler::getInstance().getParam<F32>("rendering.zNear");
120 130 _gpuBlock._ZPlanesCombined.w = ParamHandler::getInstance().getParam<F32>("rendering.zFar");
121 - /// Create a separate loading thread that shares resources with the main rendering context
122 - _loaderThread = New std::thread(&GFXDevice::createLoaderThread, this);
123 - /// Register a 2D function used for previewing the depth buffer.
131 + // Create a separate loading thread that shares resources with the main rendering context
132 + _loaderThread = MemoryManager_NEW std::thread(&GFXDevice::createLoaderThread, this);
133 + // Register a 2D function used for previewing the depth buffer.
124 134 # ifdef _DEBUG
125 135 add2DRenderFunction(DELEGATE_BIND(&GFXDevice::previewDepthBuffer, this), 0);
126 136 # endif
127 137 // We start of with a forward plus renderer
128 - setRenderer(New ForwardPlusRenderer());
138 + setRenderer(MemoryManager_NEW ForwardPlusRenderer());
129 139 ParamHandler::getInstance().setParam<bool>("rendering.previewDepthBuffer", false);
130 - /// Everything is ready from the rendering point of view
140 + // Everything is ready from the rendering point of view
131 141 return NO_ERR;
132 142 }
133 143
  @@ -140,26 +150,20 @@
140 150 PostFX::destroyInstance();
141 151 // Delete the renderer implementation
142 152 PRINT_FN(Locale::get("CLOSING_RENDERER"));
143 - MemoryManager::SAFE_DELETE( _renderer );
153 + MemoryManager::DELETE( _renderer );
144 154 // Delete our default render state blocks
145 - for (RenderStateMap::value_type& it : _stateBlockMap) {
146 - MemoryManager::SAFE_DELETE( it.second );
147 - }
148 - _stateBlockMap.clear();
155 + MemoryManager::DELETE_HASHMAP(_stateBlockMap);
149 156 // Destroy all of the immediate mode emulation primitives created during runtime
150 - for ( IMPrimitive*& priv : _imInterfaces ) {
151 - MemoryManager::SAFE_DELETE( priv );
152 - }
153 - _imInterfaces.clear();
157 + MemoryManager::DELETE_VECTOR(_imInterfaces);
154 158 // Destroy all rendering passes and rendering bins
155 159 RenderPassManager::destroyInstance();
156 160 // Delete all of our rendering targets
157 161 for ( Framebuffer*& renderTarget : _renderTarget ) {
158 - MemoryManager::SAFE_DELETE( renderTarget );
162 + MemoryManager::DELETE( renderTarget );
159 163 }
160 164 // Delete our shader buffers
161 - MemoryManager::SAFE_DELETE( _gfxDataBuffer );
162 - MemoryManager::SAFE_DELETE( _nodeBuffer );
165 + MemoryManager::DELETE( _gfxDataBuffer );
166 + MemoryManager::DELETE( _nodeBuffer );
163 167 // Close the shader manager
164 168 ShaderManager::getInstance().destroy();
165 169 // Close the rendering API
  @@ -167,7 +171,7 @@
167 171 // Wait for the loading thread to terminate
168 172 _loaderThread->join();
169 173 // And delete it
170 - MemoryManager::SAFE_DELETE( _loaderThread );
174 + MemoryManager::DELETE( _loaderThread );
171 175
172 176 switch ( _apiId ) {
173 177 case RenderAPI::OpenGL:
  @@ -223,7 +227,7 @@
223 227 });
224 228 //2) For every zombie object, free the memory it's using
225 229 for ( vectorImpl<IMPrimitive *>::iterator i = zombie ; i != _imInterfaces.end(); ++i ) {
226 - MemoryManager::SAFE_DELETE( *i );
230 + MemoryManager::DELETE( *i );
227 231 }
228 232 //3) Remove all the zombie objects once the memory is freed
229 233 _imInterfaces.erase(zombie, _imInterfaces.end());