File: ScreenViewport.cpp

package info (click to toggle)
jazz2-native 3.5.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites:
  • size: 16,836 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (105 lines) | stat: -rw-r--r-- 2,772 bytes parent folder | download | duplicates (2)
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
#include "ScreenViewport.h"
#include "RenderQueue.h"
#include "RenderCommandPool.h"
#include "RenderResources.h"
#include "RenderStatistics.h"
#include "../Application.h"
#include "DisplayMode.h"
#include "GL/GLClearColor.h"
#include "GL/GLViewport.h"
#include "GL/GLDebug.h"
#include "Camera.h"

namespace nCine
{
	ScreenViewport::ScreenViewport()
		: Viewport()
	{
		width_ = theApplication().GetWidth();
		height_ = theApplication().GetHeight();
		viewportRect_.Set(0, 0, width_, height_);

		const DisplayMode displayMode = theApplication().GetGfxDevice().displayMode();
		if (displayMode.depthBits() == 16) {
			depthStencilFormat_ = DepthStencilFormat::Depth16;
		} else if (displayMode.depthBits() == 24) {
			depthStencilFormat_ = (displayMode.stencilBits() == 8 ? DepthStencilFormat::Depth24_Stencil8 : DepthStencilFormat::Depth24);
		}
		rootNode_ = &theApplication().GetRootNode();
		type_ = Type::Screen;
	}

	void ScreenViewport::Resize(std::int32_t width, std::int32_t height)
	{
		if (width == width_ && height == height_) {
			return;
		}

		viewportRect_.Set(0, 0, width, height);

		if (camera_ != nullptr) {
			camera_->SetOrthoProjection(0.0f, float(width), 0.0f, float(height));
		}
		RenderResources::defaultCamera_->SetOrthoProjection(0.0f, float(width), 0.0f, float(height));

		width_ = width;
		height_ = height;
	}

	void ScreenViewport::Update()
	{
		for (std::int32_t i = std::int32_t(chain_.size()) - 1; i >= 0; i--) {
			if (chain_[i] && !chain_[i]->stateBits_.test(StateBitPositions::UpdatedBit)) {
				chain_[i]->Update();
			}
		}
		Viewport::Update();
	}

	void ScreenViewport::Visit()
	{
		for (std::int32_t i = std::int32_t(chain_.size()) - 1; i >= 0; i--) {
			if (chain_[i] && !chain_[i]->stateBits_.test(StateBitPositions::VisitedBit)) {
				chain_[i]->Visit();
			}
		}
		Viewport::Visit();
	}

	void ScreenViewport::SortAndCommitQueue()
	{
#if defined(NCINE_PROFILING)
		// Reset all rendering statistics
		RenderStatistics::Reset();
#endif

		for (std::int32_t i = std::int32_t(chain_.size()) - 1; i >= 0; i--) {
			if (chain_[i] && !chain_[i]->stateBits_.test(StateBitPositions::CommittedBit)) {
				chain_[i]->SortAndCommitQueue();
			}
		}
		Viewport::SortAndCommitQueue();

		// Now that UBOs and VBOs have been updated, they can be flushed and unmapped
		RenderResources::GetBuffersManager().FlushUnmap();
	}

	void ScreenViewport::Draw()
	{
		// Recursive calls into the chain
		Viewport::Draw(0);

		for (std::size_t i = 0; i < chain_.size(); i++) {
			if (chain_[i]) {
				chain_[i]->renderQueue_.Clear();
				chain_[i]->stateBits_.reset();
			}
		}
		renderQueue_.Clear();
		stateBits_.reset();

		RenderResources::GetBuffersManager().Remap();
		RenderResources::GetRenderCommandPool().Reset();
		GLDebug::Reset();
	}
}