MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / drawFrame

Method drawFrame

src/engine/GameEngine.cpp:100–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void GameEngine::drawFrame(uint16_t width, uint16_t height)
101{
102 Math::Matrix view;
103 if (getMainWorld().isValid())
104 view = Components::Actions::Position::makeViewMatrixFrom(getMainWorld().get().getComponentAllocator(), getMainWorld().get().getCamera());
105 else
106 view = Math::Matrix::CreateIdentity();
107
108 // Set view and projection matrix for view 0.
109 float farPlane = 600.0f;
110
111 float proj[16];
112 bx::mtxProj(proj, 60.0f, float(width) / float(height), 0.1f, farPlane, bgfx::getCaps()->homogeneousDepth);
113
114 // Set for every view
115 for (uint8_t i = 0; i < 255; i++)
116 {
117 bgfx::setViewTransform(i, view.mv, proj);
118
119 // Set view default viewport.
120 bgfx::setViewRect(i, 0, 0, uint16_t(width), uint16_t(height));
121 }
122
123 // Get draw-distance from config
124 float drawDistanceMod = atof(Flags::drawDistance.getParam(0).c_str());
125 float drawDistanceTotal = DRAW_DISTANCE * drawDistanceMod;
126
127 // Update the frame-config with the cameras world-matrix
128 if (getMainWorld().isValid())
129 m_DefaultRenderSystem.getConfig().state.cameraWorld = getMainWorld().get().getCameraComp<Components::PositionComponent>().m_WorldMatrix;
130 m_DefaultRenderSystem.getConfig().state.drawDistanceSquared = drawDistanceTotal * drawDistanceTotal;
131 m_DefaultRenderSystem.getConfig().state.farPlane = farPlane;
132 m_DefaultRenderSystem.getConfig().state.viewWidth = width;
133 m_DefaultRenderSystem.getConfig().state.viewHeight = height;
134 m_DefaultRenderSystem.getConfig().state.viewProj = Math::Matrix(proj) * view;
135
136
137 bgfx::touch(0);
138
139 // Draw only main world
140 if (getMainWorld().isValid())
141 Render::drawWorld(getMainWorld().get(), m_DefaultRenderSystem.getConfig(), m_DefaultRenderSystem);
142
143 //bgfx::frame();
144}
145
146void GameEngine::onWorldCreated(Handle::WorldHandle world)
147{

Callers

nothing calls this directly

Calls 6

makeViewMatrixFromFunction · 0.85
MatrixClass · 0.85
drawWorldFunction · 0.85
getMethod · 0.80
getCameraMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected