properly freeing debug draw buffers, added drawing of axes

master
Martin Felis 2016-11-28 21:29:19 +01:00
parent 61d82c26c3
commit ef89ac43fc
3 changed files with 25 additions and 7 deletions

View File

@ -684,13 +684,13 @@ void Renderer::createGeometries() {
// Create dynamic debug line buffer
debug_lines_vbh = bgfx::createDynamicVertexBuffer(
(uint32_t) 10,
(uint32_t) 1,
PosColorVertex::ms_decl,
BGFX_BUFFER_ALLOW_RESIZE
);
debug_lines_ibh = bgfx::createDynamicIndexBuffer(
(uint32_t) 10,
(uint32_t) 1,
BGFX_BUFFER_ALLOW_RESIZE
);
@ -965,6 +965,9 @@ void Renderer::initialize(int width, int height) {
}
void Renderer::shutdown() {
bgfx::destroyDynamicVertexBuffer(debug_lines_vbh);
bgfx::destroyDynamicIndexBuffer(debug_lines_ibh);
bgfx::destroyIndexBuffer(cube_ibh);
bgfx::destroyIndexBuffer(cube_edges_ibh);
bgfx::destroyVertexBuffer(cube_vbh);
@ -1158,7 +1161,7 @@ void Renderer::paintGL() {
bx::mtxSRT(mtxFloor
, 10.0f, 10.0f, 10.0f
, 0.0f, 0.0f, 0.0f
, 0.0f, 0.0f, 0.0f
, 0.0f, -0.001f, 0.0f
);
float lightMtx[16];
@ -1473,4 +1476,14 @@ void Renderer::drawDebugLine (
debugCommands.push_back(cmd);
}
void Renderer::drawDebugAxes (
const SimpleMath::Vector3f &pos,
const SimpleMath::Matrix33f &orientation,
const float &scale) {
drawDebugLine (pos, pos + Vector3f (orientation.block<3,1>(0,0)) * scale, Vector3f (1.f, 0.f, 0.f));
drawDebugLine (pos, pos + Vector3f (orientation.block<3,1>(0,1)) * scale, Vector3f (0.f, 1.f, 0.f));
drawDebugLine (pos, pos + Vector3f (orientation.block<3,1>(0,2)) * scale, Vector3f (0.f, 0.f, 1.f));
}

View File

@ -179,6 +179,7 @@ struct LightProbe
struct DebugCommand {
enum CommandType {
Line,
Axes,
Arrow
};
@ -246,6 +247,11 @@ struct Renderer {
const SimpleMath::Vector3f &from,
const SimpleMath::Vector3f &to,
const SimpleMath::Vector3f &color);
void drawDebugAxes (
const SimpleMath::Vector3f &pos,
const SimpleMath::Matrix33f &orientation,
const float &scale);
};
struct RenderState {

View File

@ -389,11 +389,10 @@ static bool module_step(struct module_state *state, float dt) {
handle_keyboard(state, dt);
update_character(state, dt);
gRenderer->drawDebugLine (
gRenderer->drawDebugAxes (
Vector3f (0.f, 0.f, 0.f),
Vector3f (5.f, 3.f, 2.f),
Vector3f (0.f, 1.f, 0.f)
);
Matrix33f::Identity(),
1.0f);
return true;
}