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

Last change on this file since 288 was 237, checked in by epyon, 11 years ago
  • debug_draw module added
  • evil vertex descriptor and info added
  • fix for sampler objects
  • various fixes
File size: 2.2 KB
Line 
1// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7#include "nv/gfx/debug_draw.hh"
8
9#include "nv/interface/device.hh"
10
11static const char *nv_debug_draw_vertex_shader =
12        "#version 120\n"
13        "attribute vec3 nv_position;\n"
14        "attribute vec3 nv_color;\n"
15        "varying vec3 v_color;\n"
16        "uniform mat4 nv_m_mvp;\n"
17        "void main(void)\n"
18        "{\n"
19        "       gl_Position = nv_m_mvp * vec4 (nv_position, 1.0);\n"
20        "       v_color     = nv_color;\n"
21        "}\n";
22static const char *nv_debug_draw_fragment_shader =
23        "#version 120\n"
24        "varying vec3 v_color;\n"
25        "void main(void)\n"
26        "{\n"
27        "       gl_FragColor = vec4( v_color, 1.0 );\n"
28        "}\n";
29
30nv::debug_data::debug_data( device* a_device )
31        : m_device( a_device ), m_program( nullptr ), m_va( nullptr )
32{
33        m_program = m_device->create_program( nv_debug_draw_vertex_shader, nv_debug_draw_fragment_shader );
34}
35
36void nv::debug_data::update()
37{
38        delete m_va;
39        m_va = m_device->create_vertex_array( m_data, nv::STATIC_DRAW );
40}
41
42void nv::debug_data::reset()
43{
44        m_data.clear();
45}
46
47void nv::debug_data::push_line( const vec3& a, const vec3& b, const vec3& color )
48{
49        m_data.emplace_back( a, color );
50        m_data.emplace_back( b, color );
51}
52
53void nv::debug_data::push_aabox( const vec3& a, const vec3& b, const vec3& color )
54{
55        vec3 corners[8] =
56        {
57                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 ),
58                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 ),
59        };
60
61        push_line( corners[0], corners[1], color );
62        push_line( corners[1], corners[2], color );
63        push_line( corners[2], corners[3], color );
64        push_line( corners[3], corners[0], color );
65        push_line( corners[0], corners[4], color );
66        push_line( corners[1], corners[5], color );
67        push_line( corners[2], corners[6], color );
68        push_line( corners[3], corners[7], color );
69        push_line( corners[4], corners[5], color );
70        push_line( corners[5], corners[6], color );
71        push_line( corners[6], corners[7], color );
72        push_line( corners[7], corners[4], color );
73}
74
75nv::debug_data::~debug_data()
76{
77        delete m_va;
78        delete m_program;
79}
Note: See TracBrowser for help on using the repository browser.