source: trunk/src/gfx/debug_draw.cc @ 415

Last change on this file since 415 was 395, checked in by epyon, 10 years ago
  • bulk update copyright update include guards cleanup core/common.hh -> common.hh minor cleanups
File size: 2.2 KB
Line 
1// Copyright (C) 2014-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
6
7#include "nv/gfx/debug_draw.hh"
8
9#include "nv/interface/device.hh"
10
11static const char *nv_debug_draw_vertex_shader = R"(
12#version 120
13attribute vec3 nv_position;
14attribute vec3 nv_color;
15varying vec3 v_color;
16uniform mat4 nv_m_mvp;
17void main(void)
18{
19        gl_Position = nv_m_mvp * vec4 (nv_position, 1.0);
20        v_color     = nv_color;
21};
22)";
23static const char *nv_debug_draw_fragment_shader = R"(
24#version 120
25varying vec3 v_color;
26void main(void)
27{
28        gl_FragColor = vec4( v_color, 1.0 );
29}
30)";
31
32nv::debug_data::debug_data( context* a_context )
33        : m_context( a_context ), m_program(), m_va()
34{
35        m_program = m_context->get_device()->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
36}
37
38void nv::debug_data::update()
39{
40        m_context->release( m_va );
41        m_va = m_context->create_vertex_array( m_data, nv::STATIC_DRAW );
42}
43
44void nv::debug_data::reset()
45{
46        m_data.clear();
47}
48
49void nv::debug_data::push_line( const vec3& a, const vec3& b, const vec3& color )
50{
51        m_data.emplace_back( a, color );
52        m_data.emplace_back( b, color );
53}
54
55void nv::debug_data::push_aabox( const vec3& a, const vec3& b, const vec3& color )
56{
57        vec3 corners[8] =
58        {
59                vec3( a.x, a.y, a.z ), vec3( b.x, a.y, a.z ), vec3( b.x, a.y, b.z ), vec3( a.x, a.y, b.z ),
60                vec3( a.x, b.y, a.z ), vec3( b.x, b.y, a.z ), vec3( b.x, b.y, b.z ), vec3( a.x, b.y, b.z ),
61        };
62
63        push_line( corners[0], corners[1], color );
64        push_line( corners[1], corners[2], color );
65        push_line( corners[2], corners[3], color );
66        push_line( corners[3], corners[0], color );
67        push_line( corners[0], corners[4], color );
68        push_line( corners[1], corners[5], color );
69        push_line( corners[2], corners[6], color );
70        push_line( corners[3], corners[7], color );
71        push_line( corners[4], corners[5], color );
72        push_line( corners[5], corners[6], color );
73        push_line( corners[6], corners[7], color );
74        push_line( corners[7], corners[4], color );
75}
76
77nv::debug_data::~debug_data()
78{
79        m_context->release( m_va );
80        m_context->get_device()->release( m_program );
81}
Note: See TracBrowser for help on using the repository browser.