Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 279 vs 280 for /trunk/Source Code/Hardware/Video/GFXDevice.cpp

Diff revisions: vs.
  @@ -32,7 +32,7 @@
32 32
33 33 ShaderProgram* GFXDevice::_activeShaderProgram = nullptr;
34 34 ShaderProgram* GFXDevice::_HIZConstructProgram = nullptr;
35 - ShaderProgram* GFXDevice::_depthRangesConstrucProgram = nullptr;
35 + ShaderProgram* GFXDevice::_depthRangesConstructProgram = nullptr;
36 36
37 37 GFXDevice::GFXDevice() : _api(GL_API::getOrCreateInstance()),
38 38 _postFX(PostFX::getOrCreateInstance()),
  @@ -51,7 +51,6 @@
51 51 _enablePostProcessing = false;
52 52 _enableAnaglyph = false;
53 53 _enableHDR = false;
54 - _clippingPlanesDirty = true;
55 54 _isDepthPrePass = false;
56 55 _previewDepthBuffer = false;
57 56 _stateBlockDirty = true;
  @@ -63,6 +62,7 @@
63 62 _shadowDetailLevel = DETAIL_HIGH;
64 63 _renderStage = INVALID_STAGE;
65 64 _worldMatrices.push(mat4<F32>(/*identity*/));
65 + _clippingPlanes.resize(Config::MAX_CLIP_PLANES, Plane<F32>(0,0,0,0));
66 66 _isUniformedScaled = true;
67 67 _WDirty = _VDirty = _PDirty = true;
68 68 _WVCachedMatrix.identity();
  @@ -113,7 +113,8 @@
113 113
114 114 if(hardwareState == NO_ERR){
115 115 _matricesBuffer = newSB();
116 - _matricesBuffer->Create(true, false, 3 * 16 + 4, sizeof(F32)); //View, Projection, ViewProjection and Viewport 3 x 16 + 4 float values
116 + //View, Projection, ViewProjection, Viewport and ClipPlanes[MAX_CLIP_PLANES] 3 x 16 + 4 + 4 * MAX_CLIP_PLANES float values
117 + _matricesBuffer->Create(true, false, 3 * 16 + 4 + 4 * Config::MAX_CLIP_PLANES, sizeof(F32));
117 118 _matricesBuffer->Bind(Divide::SHADER_BUFFER_CAM_MATRICES);
118 119 changeResolution(resolution);
119 120
  @@ -205,8 +206,8 @@
205 206
206 207 ResourceDescriptor rangesDesc("DepthRangesConstruct");
207 208 rangesDesc.setPropertyList("LIGHT_GRID_TILE_DIM_X " + Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_X) + "," + "LIGHT_GRID_TILE_DIM_Y " + Util::toString(Config::Lighting::LIGHT_GRID_TILE_DIM_Y));
208 - _depthRangesConstrucProgram = CreateResource<ShaderProgram>(rangesDesc);
209 - _depthRangesConstrucProgram->UniformTexture("depthTex", 0);
209 + _depthRangesConstructProgram = CreateResource<ShaderProgram>(rangesDesc);
210 + _depthRangesConstructProgram->UniformTexture("depthTex", 0);
210 211 }
211 212
212 213 return hardwareState;
  @@ -235,7 +236,7 @@
235 236
236 237 void GFXDevice::closeRenderer(){
237 238 RemoveResource(_HIZConstructProgram);
238 - RemoveResource(_depthRangesConstrucProgram);
239 + RemoveResource(_depthRangesConstructProgram);
239 240 PRINT_FN(Locale::get("STOP_POST_FX"));
240 241 _postFX.destroyInstance();
241 242 _shaderManager.Destroy();
  @@ -252,11 +253,10 @@
252 253 }
253 254
254 255 void GFXDevice::drawPoints(U32 numPoints) {
255 - updateStates();
256 -
257 256 if (_activeShaderProgram)
258 257 _activeShaderProgram->uploadNodeMatrices();
259 258
259 + updateStates();
260 260 _api.drawPoints(numPoints);
261 261 }
262 262
  @@ -278,8 +278,6 @@
278 278 return;
279 279 }
280 280
281 - updateStates();
282 -
283 281 Transform* transform = instance->transform();
284 282 if (transform) {
285 283 Transform* prevTransform = instance->prevTransform();
  @@ -391,23 +389,13 @@
391 389 return prevStateHash;
392 390 }
393 391
394 - void GFXDevice::updateStates(bool force) {
395 - I64 oldStateBlockHash = 0;
396 - //Verify render states
397 - if(force){
398 - _stateBlockDirty = true;
399 - }else{
400 - oldStateBlockHash = _currentStateBlockHash;
401 - }
402 -
392 + void GFXDevice::updateStates() {
403 393 if (_newStateBlockHash && _stateBlockDirty){
404 - activateStateBlock(*_stateBlockMap[_newStateBlockHash], _stateBlockMap[oldStateBlockHash]);
394 + activateStateBlock(*_stateBlockMap[_newStateBlockHash], _stateBlockMap[_currentStateBlockHash]);
405 395 _stateBlockDirty = false;
406 396 }
407 397
408 398 _currentStateBlockHash = _newStateBlockHash;
409 -
410 - updateClipPlanes();
411 399 }
412 400
413 401 const RenderStateBlockDescriptor& GFXDevice::getStateBlockDescriptor(I64 renderStateBlockHash) const {
  @@ -525,6 +513,15 @@
525 513 _PDirty = true;
526 514 }
527 515
516 + void GFXDevice::updateClipPlanes(){
517 + const size_t mat4Size = 16 * sizeof(F32);
518 + const size_t vec4Size = 4 * sizeof(F32);
519 + vectorImpl<vec4<F32> > clipPlanes; clipPlanes.resize(Config::MAX_CLIP_PLANES, vec4<F32>());
520 + for(U8 i = 0 ; i < Config::MAX_CLIP_PLANES; ++i)
521 + clipPlanes[i] = _clippingPlanes[i].getEquation();
522 + _matricesBuffer->UpdateData(3 * mat4Size + vec4Size, Config::MAX_CLIP_PLANES * vec4Size, &clipPlanes.front());
523 + }
524 +
528 525 void GFXDevice::updateViewMatrix(){
529 526 const size_t mat4Size = 16 * sizeof(F32);
530 527
  @@ -658,15 +655,6 @@
658 655 renderInViewport(vec4<I32>(Application::getInstance().getResolution().width-256,0,256,256), DELEGATE_BIND(&GFXDevice::drawPoints, this, 1));
659 656 }
660 657
661 - void GFXDevice::updateClipPlanes() {
662 - if (!_clippingPlanesDirty)
663 - return;
664 -
665 - _api.updateClipPlanes();
666 - _clippingPlanesDirty = false;
667 - _shaderManager.updateClipPlanes();
668 - }
669 -
670 658 void GFXDevice::postProcessingEnabled(const bool state) {
671 659 if (_enablePostProcessing != state){
672 660 _enablePostProcessing = state;
  @@ -762,8 +750,8 @@
762 750
763 751 _depthRanges->Begin(FrameBuffer::defaultPolicy());
764 752 _renderTarget[RENDER_TARGET_DEPTH]->Bind(0, TextureDescriptor::Depth);
765 - SET_STATE_BLOCK(_defaultStateNoDepthHash, true);
766 - _depthRangesConstrucProgram->bind();
753 + SET_STATE_BLOCK(_defaultStateNoDepthHash);
754 + _depthRangesConstructProgram->bind();
767 755 drawPoints(1);
768 756 depthRanges.resize(_depthRanges->getWidth() * _depthRanges->getHeight());
769 757 _depthRanges->ReadData(RG, FLOAT_32, &depthRanges[0]);