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/GFXDevice.cpp

Diff revisions: vs.
  @@ -96,10 +96,10 @@
96 96 _GPUVendor = GPU_VENDOR_PLACEHOLDER;
97 97 _apiId = GFX_RENDER_API_PLACEHOLDER;
98 98 // Utility cameras
99 - _2DCamera = New FreeFlyCamera();
99 + _2DCamera = MemoryManager_NEW FreeFlyCamera();
100 100 _2DCamera->lockView(true);
101 101 _2DCamera->lockFrustum(true);
102 - _cubeCamera = New FreeFlyCamera();
102 + _cubeCamera = MemoryManager_NEW FreeFlyCamera();
103 103 // Clipping planes
104 104 _clippingPlanes.resize(Config::MAX_CLIP_PLANES, Plane<F32>(0,0,0,0));
105 105 // Render targets
  @@ -107,8 +107,8 @@
107 107 renderTarget = nullptr;
108 108 }
109 109 // Add our needed app-wide render passes. RenderPassManager is responsible for deleting these!
110 - RenderPassManager::getOrCreateInstance().addRenderPass(New RenderPass("diffusePass"), 1);
111 - //RenderPassManager::getInstance().addRenderPass(shadowPass,2);
110 + RenderPassManager::getOrCreateInstance().addRenderPass("diffusePass", 1);
111 + //RenderPassManager::getInstance().addRenderPass("shadowPass",2);
112 112 // Red X-axis
113 113 _axisLines.push_back(Line(VECTOR3_ZERO, WORLD_X_AXIS * 2, vec4<U8>(255, 0, 0, 255)));
114 114 // Green Y-axis
  @@ -124,12 +124,14 @@
124 124 /// A draw command is composed of a target buffer and a command. The command part is processed here
125 125 bool GFXDevice::setBufferData(const GenericDrawCommand& cmd) {
126 126 // We also need a valid draw command ID so we can index the node buffer properly
127 - DIVIDE_ASSERT(cmd.drawID() < std::max((I32)_matricesData.size(), 1) && cmd.drawID() >= 0, "GFXDevice error: Invalid draw ID encountered!");
127 + DIVIDE_ASSERT(cmd.drawID() < std::max((I32)_matricesData.size(), 1) && cmd.drawID() >= 0,
128 + "GFXDevice error: Invalid draw ID encountered!");
128 129 if (cmd.instanceCount() == 0) {
129 130 return false;
130 131 }
131 132 // We need a valid shader as no fixed function pipeline is available
132 - DIVIDE_ASSERT(cmd.shaderProgram() != nullptr, "GFXDevice error: Draw shader state is not valid for the current draw operation!");
133 + DIVIDE_ASSERT(cmd.shaderProgram() != nullptr,
134 + "GFXDevice error: Draw shader state is not valid for the current draw operation!");
133 135 // Try to bind the shader program. If it failed to load, or isn't loaded yet, cancel the draw request for this frame
134 136 if (!cmd.shaderProgram()->bind()) {
135 137 return false;
  @@ -202,7 +204,8 @@
202 204
203 205 /// Submit multiple draw commands that use the same source buffer (e.g. terrain or batched meshes)
204 206 void GFXDevice::submitRenderCommand(const vectorImpl<GenericDrawCommand>& cmds) {
205 - // Ideally, we would merge all of the draw commands in a command buffer, sort by state, shader, etc, and submit a single render call
207 + // Ideally, we would merge all of the draw commands in a command buffer,
208 + // sort by state/shader/etc and submit a single render call
206 209 STUBBED("Batch by state hash and submit multiple draw calls! - Ionut");
207 210 // That feature will be added later, so, for now, submit each command manually
208 211 for(const GenericDrawCommand& cmd : cmds) {
  @@ -212,7 +215,11 @@
212 215 }
213 216
214 217 /// Generate a cube texture and store it in the provided framebuffer
215 - void GFXDevice::generateCubeMap(Framebuffer& cubeMap, const vec3<F32>& pos, const DELEGATE_CBK<>& renderFunction, const vec2<F32>& zPlanes, const RenderStage& renderStage) {
218 + void GFXDevice::generateCubeMap(Framebuffer& cubeMap,
219 + const vec3<F32>& pos,
220 + const DELEGATE_CBK<>& renderFunction,
221 + const vec2<F32>& zPlanes,
222 + const RenderStage& renderStage) {
216 223 // Only the first color attachment or the depth attachment is used for now and it must be a cube map texture
217 224 Texture* colorAttachment = cubeMap.GetAttachment(TextureDescriptor::Color0);
218 225 Texture* depthAttachment = cubeMap.GetAttachment(TextureDescriptor::Depth);
  @@ -291,7 +298,7 @@
291 298 // Find the corresponding render state block
292 299 if (_stateBlockMap.find(hashValue) == _stateBlockMap.end()) {
293 300 // Create a new one if none are found. The GFXDevice class is responsible for deleting these!
294 - hashAlg::emplace(_stateBlockMap, hashValue, New RenderStateBlock(descriptor));
301 + hashAlg::emplace(_stateBlockMap, hashValue, MemoryManager_NEW RenderStateBlock(descriptor));
295 302 }
296 303 // Return the descriptor's hash value
297 304 return hashValue;
  @@ -309,7 +316,8 @@
309 316 _currentStateBlockHash = stateBlockHash;
310 317 RenderStateMap::const_iterator currentStateIt = _stateBlockMap.find(_currentStateBlockHash);
311 318 RenderStateMap::const_iterator previousStateIt = _stateBlockMap.find(_previousStateBlockHash);
312 - DIVIDE_ASSERT(currentStateIt != _stateBlockMap.end() && previousStateIt != _stateBlockMap.end(), "GFXDevice error: Invalid state blocks detected on activation!");
319 + DIVIDE_ASSERT(currentStateIt != _stateBlockMap.end() && previousStateIt != _stateBlockMap.end(),
320 + "GFXDevice error: Invalid state blocks detected on activation!");
313 321 // Activate the new render state block in an rendering API dependent way
314 322 activateStateBlock(*currentStateIt->second, previousStateIt->second);
315 323 }
  @@ -317,12 +325,14 @@
317 325 return _previousStateBlockHash;
318 326 }
319 327
320 - /// Return the descriptor of the render state block defined by the specified hash value. The state block must be created prior to calling this!
328 + /// Return the descriptor of the render state block defined by the specified hash value.
329 + /// The state block must be created prior to calling this!
321 330 const RenderStateBlockDescriptor& GFXDevice::getStateBlockDescriptor(size_t renderStateBlockHash) const {
322 331 // Find the render state block associated with the received hash value
323 332 RenderStateMap ::const_iterator it = _stateBlockMap.find(renderStateBlockHash);
324 333 // Assert if it doesn't exist. Avoids programming errors.
325 - DIVIDE_ASSERT(it != _stateBlockMap.end(), "GFXDevice error: Invalid render state block hash specified for getStateBlockDescriptor!");
334 + DIVIDE_ASSERT(it != _stateBlockMap.end(),
335 + "GFXDevice error: Invalid render state block hash specified for getStateBlockDescriptor!");
326 336 // Return the state block's descriptor
327 337 return it->second->getDescriptor();
328 338 }
  @@ -331,7 +341,8 @@
331 341 void GFXDevice::changeResolution(U16 w, U16 h) {
332 342 // Make sure we are in a valid state that allows resolution updates
333 343 if(_renderTarget[RENDER_TARGET_SCREEN] != nullptr) {
334 - // Update resolution only if it's different from the current one. Avoid resolution change on minimize so we don't thrash render targets
344 + // Update resolution only if it's different from the current one.
345 + // Avoid resolution change on minimize so we don't thrash render targets
335 346 if (vec2<U16>(w, h) == _renderTarget[RENDER_TARGET_SCREEN]->getResolution() || !(w > 1 && h > 1)) {
336 347 return;
337 348 }
  @@ -499,7 +510,8 @@
499 510 // Remember the previous state hash
500 511 static size_t previousStateBlockHash = 0;
501 512 // Prevent double 2D toggle to the same state (e.g. in a loop)
502 - DIVIDE_ASSERT((state && !_2DRendering) || (!state && _2DRendering), "GFXDevice error: double toggle2D call with same value detected!");
513 + DIVIDE_ASSERT((state && !_2DRendering) || (!state && _2DRendering),
514 + "GFXDevice error: double toggle2D call with same value detected!");
503 515 Kernel* const kernel = Application::getInstance().getKernel();
504 516 _2DRendering = state;
505 517 // If we need to enable 2D rendering
  @@ -609,7 +621,9 @@
609 621 }
610 622 // Since the normal matrix is 3x3, we can use the extra row and column to store additional data
611 623 temp._matrix[1].element(3,2,true) = static_cast<F32>(LightManager::getInstance().getLights().size());
612 - temp._matrix[1].element(3,3,true) = static_cast<F32>(crtNode->getComponent<AnimationComponent>() ? crtNode->getComponent<AnimationComponent>()->boneCount() : 0);
624 + temp._matrix[1].element(3,3,true) = static_cast<F32>(crtNode->getComponent<AnimationComponent>() ?
625 + crtNode->getComponent<AnimationComponent>()->boneCount() :
626 + 0);
613 627 RenderingComponent* const renderable = crtNode->getComponent<RenderingComponent>();
614 628 if (renderable) {
615 629 // Get the color matrix (diffuse, ambient, specular, etc.)
  @@ -637,7 +651,9 @@
637 651 if (!renderable) {
638 652 continue;
639 653 }
640 - const vectorImpl<GenericDrawCommand>& nodeDrawCommands = renderable->getDrawCommands(1 + i, sceneRenderState, getRenderStage());
654 + const vectorImpl<GenericDrawCommand>& nodeDrawCommands = renderable->getDrawCommands(1 + i,
655 + sceneRenderState,
656 + getRenderStage());
641 657 for (const GenericDrawCommand& cmd : nodeDrawCommands) {
642 658 drawCommands[cmd.drawID()] = cmd.cmd();
643 659 }
  @@ -673,7 +689,8 @@
673 689 vec2<U16> resolution = _renderTarget[RENDER_TARGET_DEPTH]->getResolution();
674 690 // We use a special shader that downsamples the buffer
675 691 _HIZConstructProgram->bind();
676 - // We will use a state block that disables color writes as we will render only a depth image, disables depth testing but allows depth writes
692 + // We will use a state block that disables color writes as we will render only a depth image,
693 + // disables depth testing but allows depth writes
677 694 // Set the depth buffer as the currently active render target
678 695 _renderTarget[RENDER_TARGET_DEPTH]->Begin(hizTarget);
679 696 // Bind the depth texture to the first texture unit
  @@ -699,7 +716,8 @@
699 716 _renderTarget[RENDER_TARGET_DEPTH]->SetMipLevel(i - 1, i - 1, i, TextureDescriptor::Depth);
700 717 // Dummy draw command as the full screen quad is generated completely by a geometry shader
701 718 drawPoints(1, _stateDepthOnlyRenderingHash, _HIZConstructProgram);
702 - // Restore the viewport to it's original value (should only be called once outside the loop, but our stack based system is preventing us from doing that
719 + // Restore the viewport to it's original value
720 + // (should only be called once outside the loop, but our stack based system is preventing us from doing that
703 721 restoreViewport();
704 722 }
705 723 // Reset mipmap level range for the depth buffer
  @@ -776,7 +794,11 @@
776 794 }
777 795
778 796 /// Render a list of lines within the specified constraints
779 - void GFXDevice::drawLines(const vectorImpl<Line >& lines, const mat4<F32>& globalOffset, const vec4<I32>& viewport, const bool inViewport, const bool disableDepth) {
797 + void GFXDevice::drawLines(const vectorImpl<Line >& lines,
798 + const mat4<F32>& globalOffset,
799 + const vec4<I32>& viewport,
800 + const bool inViewport,
801 + const bool disableDepth) {
780 802 // Check if we have a valid list. The list can be programmatically generated, so this check is required
781 803 if (lines.empty()) {
782 804 return;
  @@ -789,7 +811,8 @@
789 811 priv->stateHash(getDefaultStateBlock(disableDepth));
790 812 // Set the world matrix
791 813 priv->worldMatrix(globalOffset);
792 - // If we need to render it into a specific viewport, set the pre and post draw functions to set up the needed viewport rendering (e.g. axis lines)
814 + // If we need to render it into a specific viewport, set the pre and post draw functions to set up the
815 + // needed viewport rendering (e.g. axis lines)
793 816 if (inViewport) {
794 817 priv->setRenderStates(DELEGATE_BIND(&GFXDevice::setViewport, this, viewport),
795 818 DELEGATE_BIND(&GFXDevice::restoreViewport, this));
  @@ -816,13 +839,13 @@
816 839 const vec2<U16>& resolution = _renderTarget[RENDER_TARGET_SCREEN]->getResolution();
817 840 // Allocate sufficiently large buffers to hold the pixel data
818 841 U32 bufferSize = resolution.width * resolution.height * 4;
819 - U8 *imageData = New U8[bufferSize];
842 + U8 *imageData = MemoryManager_NEW U8[bufferSize];
820 843 // Read the pixels from the main render target (RGBA16F)
821 844 _renderTarget[RENDER_TARGET_SCREEN]->ReadData(RGBA, UNSIGNED_BYTE, imageData);
822 845 // Save to file
823 846 ImageTools::SaveSeries(filename, vec2<U16>(resolution.width, resolution.height), 32, imageData);
824 847 // Delete local buffers
825 - MemoryManager::SAFE_DELETE_ARRAY( imageData );
848 + MemoryManager::DELETE_ARRAY( imageData );
826 849 }
827 850
828 851 };