2016-02-26 09:20:24 +03:00
|
|
|
/*
|
2018-01-01 22:16:06 +03:00
|
|
|
* Copyright 2011-2018 Branimir Karadzic. All rights reserved.
|
2017-01-01 11:18:41 +03:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2016-02-26 09:20:24 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bgfx/bgfx.h>
|
2016-12-05 06:43:07 +03:00
|
|
|
#include <bgfx/embedded_shader.h>
|
2016-02-26 09:20:24 +03:00
|
|
|
#include "debugdraw.h"
|
2016-12-23 03:18:44 +03:00
|
|
|
#include "../bgfx_utils.h"
|
2016-12-21 08:20:55 +03:00
|
|
|
#include "../packrect.h"
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
#include <bx/mutex.h>
|
2017-07-16 07:01:08 +03:00
|
|
|
#include <bx/math.h>
|
2017-02-11 20:12:16 +03:00
|
|
|
#include <bx/sort.h>
|
2016-02-26 09:20:24 +03:00
|
|
|
#include <bx/uint32_t.h>
|
2016-12-21 08:20:55 +03:00
|
|
|
#include <bx/handlealloc.h>
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
#ifndef DEBUG_DRAW_CONFIG_MAX_GEOMETRY
|
|
|
|
# define DEBUG_DRAW_CONFIG_MAX_GEOMETRY 256
|
|
|
|
#endif // DEBUG_DRAW_CONFIG_MAX_GEOMETRY
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
struct DebugVertex
|
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
|
|
|
float m_len;
|
|
|
|
uint32_t m_abgr;
|
|
|
|
|
|
|
|
static void init()
|
|
|
|
{
|
|
|
|
ms_decl
|
|
|
|
.begin()
|
|
|
|
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
|
|
|
.add(bgfx::Attrib::TexCoord0, 1, bgfx::AttribType::Float)
|
|
|
|
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
|
|
|
.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bgfx::VertexDecl ms_decl;
|
|
|
|
};
|
|
|
|
|
|
|
|
bgfx::VertexDecl DebugVertex::ms_decl;
|
|
|
|
|
2016-12-20 09:13:15 +03:00
|
|
|
struct DebugUvVertex
|
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
|
|
|
float m_u;
|
|
|
|
float m_v;
|
|
|
|
uint32_t m_abgr;
|
|
|
|
|
|
|
|
static void init()
|
|
|
|
{
|
|
|
|
ms_decl
|
|
|
|
.begin()
|
|
|
|
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
|
|
|
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
|
|
|
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
|
|
|
.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bgfx::VertexDecl ms_decl;
|
|
|
|
};
|
|
|
|
|
|
|
|
bgfx::VertexDecl DebugUvVertex::ms_decl;
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
struct DebugShapeVertex
|
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
2016-06-15 08:33:37 +03:00
|
|
|
uint8_t m_indices[4];
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
static void init()
|
|
|
|
{
|
|
|
|
ms_decl
|
|
|
|
.begin()
|
2016-06-15 08:33:37 +03:00
|
|
|
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
|
|
|
.add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Uint8)
|
2016-02-26 09:20:24 +03:00
|
|
|
.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bgfx::VertexDecl ms_decl;
|
|
|
|
};
|
|
|
|
|
|
|
|
bgfx::VertexDecl DebugShapeVertex::ms_decl;
|
|
|
|
|
2018-01-09 04:54:15 +03:00
|
|
|
struct DebugMeshVertex
|
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
|
|
|
|
|
|
|
static void init()
|
|
|
|
{
|
|
|
|
ms_decl
|
|
|
|
.begin()
|
|
|
|
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
|
|
|
.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bgfx::VertexDecl ms_decl;
|
|
|
|
};
|
|
|
|
|
|
|
|
bgfx::VertexDecl DebugMeshVertex::ms_decl;
|
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
static DebugShapeVertex s_quadVertices[4] =
|
|
|
|
{
|
|
|
|
{-1.0f, 0.0f, 1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{ 1.0f, 0.0f, 1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{-1.0f, 0.0f, -1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{ 1.0f, 0.0f, -1.0f, { 0, 0, 0, 0 } },
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint16_t s_quadIndices[6] =
|
|
|
|
{
|
|
|
|
0, 1, 2,
|
|
|
|
1, 3, 2,
|
|
|
|
};
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
static DebugShapeVertex s_cubeVertices[8] =
|
|
|
|
{
|
2016-06-15 08:33:37 +03:00
|
|
|
{-1.0f, 1.0f, 1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{ 1.0f, 1.0f, 1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{-1.0f, -1.0f, 1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{ 1.0f, -1.0f, 1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{-1.0f, 1.0f, -1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{ 1.0f, 1.0f, -1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{-1.0f, -1.0f, -1.0f, { 0, 0, 0, 0 } },
|
|
|
|
{ 1.0f, -1.0f, -1.0f, { 0, 0, 0, 0 } },
|
2016-02-26 09:20:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint16_t s_cubeIndices[36] =
|
|
|
|
{
|
|
|
|
0, 1, 2, // 0
|
|
|
|
1, 3, 2,
|
|
|
|
4, 6, 5, // 2
|
|
|
|
5, 6, 7,
|
|
|
|
0, 2, 4, // 4
|
|
|
|
4, 2, 6,
|
|
|
|
1, 5, 3, // 6
|
|
|
|
5, 7, 3,
|
|
|
|
0, 4, 1, // 8
|
|
|
|
4, 5, 1,
|
|
|
|
2, 3, 6, // 10
|
|
|
|
6, 3, 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t s_circleLod[] =
|
|
|
|
{
|
|
|
|
37,
|
|
|
|
29,
|
|
|
|
23,
|
|
|
|
17,
|
|
|
|
11,
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint8_t getCircleLod(uint8_t _lod)
|
|
|
|
{
|
|
|
|
_lod = _lod > BX_COUNTOF(s_circleLod)-1 ? BX_COUNTOF(s_circleLod)-1 : _lod;
|
|
|
|
return s_circleLod[_lod];
|
|
|
|
}
|
|
|
|
|
2016-03-06 11:07:20 +03:00
|
|
|
static void circle(float* _out, float _angle)
|
|
|
|
{
|
2018-01-14 02:33:50 +03:00
|
|
|
float sa = bx::sin(_angle);
|
|
|
|
float ca = bx::cos(_angle);
|
2016-03-06 11:07:20 +03:00
|
|
|
_out[0] = sa;
|
|
|
|
_out[1] = ca;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void squircle(float* _out, float _angle)
|
|
|
|
{
|
2018-01-14 02:33:50 +03:00
|
|
|
float sa = bx::sin(_angle);
|
|
|
|
float ca = bx::cos(_angle);
|
|
|
|
_out[0] = bx::sqrt(bx::abs(sa) ) * bx::sign(sa);
|
|
|
|
_out[1] = bx::sqrt(bx::abs(ca) ) * bx::sign(ca);
|
2016-03-06 11:07:20 +03:00
|
|
|
}
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
uint32_t genSphere(uint8_t _subdiv0, void* _pos0 = NULL, uint16_t _posStride0 = 0, void* _normals0 = NULL, uint16_t _normalStride0 = 0)
|
|
|
|
{
|
|
|
|
if (NULL != _pos0)
|
|
|
|
{
|
|
|
|
struct Gen
|
|
|
|
{
|
|
|
|
Gen(void* _pos, uint16_t _posStride, void* _normals, uint16_t _normalStride, uint8_t _subdiv)
|
|
|
|
: m_pos( (uint8_t*)_pos)
|
|
|
|
, m_normals( (uint8_t*)_normals)
|
|
|
|
, m_posStride(_posStride)
|
|
|
|
, m_normalStride(_normalStride)
|
|
|
|
{
|
|
|
|
static const float scale = 1.0f;
|
|
|
|
static const float golden = 1.6180339887f;
|
2018-01-14 02:33:50 +03:00
|
|
|
static const float len = bx::sqrt(golden*golden + 1.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
static const float ss = 1.0f/len * scale;
|
|
|
|
static const float ll = ss*golden;
|
|
|
|
|
|
|
|
static const float vv[12][4] =
|
|
|
|
{
|
|
|
|
{ -ll, 0.0f, -ss, 0.0f },
|
|
|
|
{ ll, 0.0f, -ss, 0.0f },
|
|
|
|
{ ll, 0.0f, ss, 0.0f },
|
|
|
|
{ -ll, 0.0f, ss, 0.0f },
|
|
|
|
|
|
|
|
{ -ss, ll, 0.0f, 0.0f },
|
|
|
|
{ ss, ll, 0.0f, 0.0f },
|
|
|
|
{ ss, -ll, 0.0f, 0.0f },
|
|
|
|
{ -ss, -ll, 0.0f, 0.0f },
|
|
|
|
|
|
|
|
{ 0.0f, -ss, ll, 0.0f },
|
|
|
|
{ 0.0f, ss, ll, 0.0f },
|
|
|
|
{ 0.0f, ss, -ll, 0.0f },
|
|
|
|
{ 0.0f, -ss, -ll, 0.0f },
|
|
|
|
};
|
|
|
|
|
|
|
|
m_numVertices = 0;
|
|
|
|
|
|
|
|
triangle(vv[ 0], vv[ 4], vv[ 3], scale, _subdiv);
|
|
|
|
triangle(vv[ 0], vv[10], vv[ 4], scale, _subdiv);
|
|
|
|
triangle(vv[ 4], vv[10], vv[ 5], scale, _subdiv);
|
|
|
|
triangle(vv[ 5], vv[10], vv[ 1], scale, _subdiv);
|
|
|
|
triangle(vv[ 5], vv[ 1], vv[ 2], scale, _subdiv);
|
|
|
|
triangle(vv[ 5], vv[ 2], vv[ 9], scale, _subdiv);
|
|
|
|
triangle(vv[ 5], vv[ 9], vv[ 4], scale, _subdiv);
|
|
|
|
triangle(vv[ 3], vv[ 4], vv[ 9], scale, _subdiv);
|
|
|
|
|
|
|
|
triangle(vv[ 0], vv[ 3], vv[ 7], scale, _subdiv);
|
|
|
|
triangle(vv[ 0], vv[ 7], vv[11], scale, _subdiv);
|
|
|
|
triangle(vv[11], vv[ 7], vv[ 6], scale, _subdiv);
|
|
|
|
triangle(vv[11], vv[ 6], vv[ 1], scale, _subdiv);
|
|
|
|
triangle(vv[ 1], vv[ 6], vv[ 2], scale, _subdiv);
|
|
|
|
triangle(vv[ 2], vv[ 6], vv[ 8], scale, _subdiv);
|
|
|
|
triangle(vv[ 8], vv[ 6], vv[ 7], scale, _subdiv);
|
|
|
|
triangle(vv[ 8], vv[ 7], vv[ 3], scale, _subdiv);
|
|
|
|
|
|
|
|
triangle(vv[ 0], vv[11], vv[10], scale, _subdiv);
|
|
|
|
triangle(vv[ 1], vv[10], vv[11], scale, _subdiv);
|
|
|
|
triangle(vv[ 2], vv[ 8], vv[ 9], scale, _subdiv);
|
|
|
|
triangle(vv[ 3], vv[ 9], vv[ 8], scale, _subdiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addVert(const float* _v)
|
|
|
|
{
|
|
|
|
float* verts = (float*)m_pos;
|
|
|
|
verts[0] = _v[0];
|
|
|
|
verts[1] = _v[1];
|
|
|
|
verts[2] = _v[2];
|
|
|
|
m_pos += m_posStride;
|
|
|
|
|
|
|
|
if (NULL != m_normals)
|
|
|
|
{
|
|
|
|
float* normals = (float*)m_normals;
|
|
|
|
bx::vec3Norm(normals, _v);
|
|
|
|
m_normals += m_normalStride;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_numVertices++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void triangle(const float* _v0, const float* _v1, const float* _v2, float _scale, uint8_t _subdiv)
|
|
|
|
{
|
|
|
|
if (0 == _subdiv)
|
|
|
|
{
|
|
|
|
addVert(_v0);
|
|
|
|
addVert(_v1);
|
|
|
|
addVert(_v2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float tmp0[4];
|
|
|
|
float tmp1[4];
|
|
|
|
|
|
|
|
float v01[4];
|
|
|
|
bx::vec3Add(tmp0, _v0, _v1);
|
|
|
|
bx::vec3Norm(tmp1, tmp0);
|
|
|
|
bx::vec3Mul(v01, tmp1, _scale);
|
|
|
|
|
|
|
|
float v12[4];
|
|
|
|
bx::vec3Add(tmp0, _v1, _v2);
|
|
|
|
bx::vec3Norm(tmp1, tmp0);
|
|
|
|
bx::vec3Mul(v12, tmp1, _scale);
|
|
|
|
|
|
|
|
float v20[4];
|
|
|
|
bx::vec3Add(tmp0, _v2, _v0);
|
|
|
|
bx::vec3Norm(tmp1, tmp0);
|
|
|
|
bx::vec3Mul(v20, tmp1, _scale);
|
|
|
|
|
|
|
|
--_subdiv;
|
|
|
|
triangle(_v0, v01, v20, _scale, _subdiv);
|
|
|
|
triangle(_v1, v12, v01, _scale, _subdiv);
|
|
|
|
triangle(_v2, v20, v12, _scale, _subdiv);
|
|
|
|
triangle(v01, v12, v20, _scale, _subdiv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* m_pos;
|
|
|
|
uint8_t* m_normals;
|
|
|
|
uint16_t m_posStride;
|
|
|
|
uint16_t m_normalStride;
|
|
|
|
uint32_t m_numVertices;
|
|
|
|
|
|
|
|
} gen(_pos0, _posStride0, _normals0, _normalStride0, _subdiv0);
|
|
|
|
}
|
|
|
|
|
2018-01-14 02:33:50 +03:00
|
|
|
uint32_t numVertices = 20*3*bx::uint32_max(1, (uint32_t)bx::pow(4.0f, _subdiv0) );
|
2016-02-26 09:20:24 +03:00
|
|
|
return numVertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void getPoint(float* _result, Axis::Enum _axis, float _x, float _y)
|
|
|
|
{
|
|
|
|
switch (_axis)
|
|
|
|
{
|
|
|
|
case Axis::X:
|
|
|
|
_result[0] = 0.0f;
|
|
|
|
_result[1] = _x;
|
|
|
|
_result[2] = _y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Axis::Y:
|
|
|
|
_result[0] = _y;
|
|
|
|
_result[1] = 0.0f;
|
|
|
|
_result[2] = _x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_result[0] = _x;
|
|
|
|
_result[1] = _y;
|
|
|
|
_result[2] = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "vs_debugdraw_lines.bin.h"
|
|
|
|
#include "fs_debugdraw_lines.bin.h"
|
|
|
|
#include "vs_debugdraw_lines_stipple.bin.h"
|
|
|
|
#include "fs_debugdraw_lines_stipple.bin.h"
|
|
|
|
#include "vs_debugdraw_fill.bin.h"
|
2018-01-09 04:54:15 +03:00
|
|
|
#include "vs_debugdraw_fill_mesh.bin.h"
|
2016-02-26 09:20:24 +03:00
|
|
|
#include "fs_debugdraw_fill.bin.h"
|
|
|
|
#include "vs_debugdraw_fill_lit.bin.h"
|
2018-01-09 04:54:15 +03:00
|
|
|
#include "vs_debugdraw_fill_lit_mesh.bin.h"
|
2016-02-26 09:20:24 +03:00
|
|
|
#include "fs_debugdraw_fill_lit.bin.h"
|
2016-12-20 09:13:15 +03:00
|
|
|
#include "vs_debugdraw_fill_texture.bin.h"
|
|
|
|
#include "fs_debugdraw_fill_texture.bin.h"
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2016-12-05 06:43:07 +03:00
|
|
|
static const bgfx::EmbeddedShader s_embeddedShaders[] =
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2016-12-05 06:43:07 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_lines),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_debugdraw_lines),
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_lines_stipple),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_debugdraw_lines_stipple),
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_fill),
|
2018-01-09 04:54:15 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_fill_mesh),
|
2016-12-05 06:43:07 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(fs_debugdraw_fill),
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_fill_lit),
|
2018-01-09 04:54:15 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_fill_lit_mesh),
|
2016-12-05 06:43:07 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(fs_debugdraw_fill_lit),
|
2016-12-20 09:13:15 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(vs_debugdraw_fill_texture),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_debugdraw_fill_texture),
|
2016-12-06 03:55:49 +03:00
|
|
|
|
2016-12-05 06:43:07 +03:00
|
|
|
BGFX_EMBEDDED_SHADER_END()
|
2016-02-26 09:20:24 +03:00
|
|
|
};
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
#define SPRITE_TEXTURE_SIZE 1024
|
|
|
|
|
|
|
|
template<uint16_t MaxHandlesT = 256, uint16_t TextureSizeT = 1024>
|
|
|
|
struct SpriteT
|
|
|
|
{
|
|
|
|
SpriteT()
|
|
|
|
: m_ra(TextureSizeT, TextureSizeT)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteHandle create(uint16_t _width, uint16_t _height)
|
|
|
|
{
|
2018-09-11 03:45:23 +03:00
|
|
|
bx::MutexScope lock(m_lock);
|
|
|
|
|
2017-06-10 07:57:08 +03:00
|
|
|
SpriteHandle handle = { bx::kInvalidHandle };
|
2016-12-21 08:20:55 +03:00
|
|
|
|
|
|
|
if (m_handleAlloc.getNumHandles() < m_handleAlloc.getMaxHandles() )
|
|
|
|
{
|
|
|
|
Pack2D pack;
|
|
|
|
if (m_ra.find(_width, _height, pack) )
|
|
|
|
{
|
|
|
|
handle.idx = m_handleAlloc.alloc();
|
2018-01-11 11:14:36 +03:00
|
|
|
|
|
|
|
if (isValid(handle) )
|
|
|
|
{
|
|
|
|
m_pack[handle.idx] = pack;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ra.clear(pack);
|
|
|
|
}
|
2016-12-21 08:20:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy(SpriteHandle _sprite)
|
|
|
|
{
|
|
|
|
const Pack2D& pack = m_pack[_sprite.idx];
|
|
|
|
m_ra.clear(pack);
|
|
|
|
m_handleAlloc.free(_sprite.idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Pack2D& get(SpriteHandle _sprite) const
|
|
|
|
{
|
|
|
|
return m_pack[_sprite.idx];
|
|
|
|
}
|
|
|
|
|
2018-09-11 03:45:23 +03:00
|
|
|
bx::Mutex m_lock;
|
2016-12-21 08:20:55 +03:00
|
|
|
bx::HandleAllocT<MaxHandlesT> m_handleAlloc;
|
|
|
|
Pack2D m_pack[MaxHandlesT];
|
|
|
|
RectPack2DT<256> m_ra;
|
|
|
|
};
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
template<uint16_t MaxHandlesT = DEBUG_DRAW_CONFIG_MAX_GEOMETRY>
|
2018-01-11 11:14:36 +03:00
|
|
|
struct GeometryT
|
|
|
|
{
|
|
|
|
GeometryT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
GeometryHandle create(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices, const void* _indices, bool _index32)
|
2018-01-11 11:14:36 +03:00
|
|
|
{
|
2018-09-05 03:27:35 +03:00
|
|
|
BX_UNUSED(_numVertices, _vertices, _numIndices, _indices, _index32);
|
2018-01-11 11:14:36 +03:00
|
|
|
|
2018-09-11 03:45:23 +03:00
|
|
|
GeometryHandle handle;
|
|
|
|
{
|
|
|
|
bx::MutexScope lock(m_lock);
|
|
|
|
handle = { m_handleAlloc.alloc() };
|
|
|
|
}
|
2018-01-11 11:14:36 +03:00
|
|
|
|
|
|
|
if (isValid(handle) )
|
|
|
|
{
|
|
|
|
Geometry& geometry = m_geometry[handle.idx];
|
|
|
|
geometry.m_vbh = bgfx::createVertexBuffer(
|
|
|
|
bgfx::copy(_vertices, _numVertices*sizeof(DdVertex) )
|
|
|
|
, DebugMeshVertex::ms_decl
|
|
|
|
);
|
|
|
|
|
|
|
|
geometry.m_topologyNumIndices[0] = _numIndices;
|
|
|
|
geometry.m_topologyNumIndices[1] = bgfx::topologyConvert(
|
|
|
|
bgfx::TopologyConvert::TriListToLineList
|
|
|
|
, NULL
|
|
|
|
, 0
|
|
|
|
, _indices
|
|
|
|
, _numIndices
|
2018-09-05 03:27:35 +03:00
|
|
|
, _index32
|
2018-01-11 11:14:36 +03:00
|
|
|
);
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
const uint32_t indexSize = _index32 ? sizeof(uint32_t) : sizeof(uint16_t);
|
|
|
|
|
2018-01-11 11:14:36 +03:00
|
|
|
const uint32_t numIndices = 0
|
|
|
|
+ geometry.m_topologyNumIndices[0]
|
|
|
|
+ geometry.m_topologyNumIndices[1]
|
|
|
|
;
|
2018-09-05 03:27:35 +03:00
|
|
|
const bgfx::Memory* mem = bgfx::alloc(numIndices*indexSize );
|
|
|
|
uint8_t* indexData = mem->data;
|
2018-01-11 11:14:36 +03:00
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
bx::memCopy(indexData, _indices, _numIndices*indexSize );
|
2018-01-11 11:14:36 +03:00
|
|
|
bgfx::topologyConvert(
|
|
|
|
bgfx::TopologyConvert::TriListToLineList
|
2018-09-05 03:27:35 +03:00
|
|
|
, &indexData[geometry.m_topologyNumIndices[0]*indexSize ]
|
|
|
|
, geometry.m_topologyNumIndices[1]*indexSize
|
2018-01-11 11:14:36 +03:00
|
|
|
, _indices
|
|
|
|
, _numIndices
|
2018-09-05 03:27:35 +03:00
|
|
|
, _index32
|
2018-01-11 11:14:36 +03:00
|
|
|
);
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
geometry.m_ibh = bgfx::createIndexBuffer(
|
|
|
|
mem
|
|
|
|
, _index32 ? BGFX_BUFFER_INDEX32 : BGFX_BUFFER_NONE
|
|
|
|
);
|
2018-01-11 11:14:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy(GeometryHandle _handle)
|
|
|
|
{
|
2018-09-11 03:45:23 +03:00
|
|
|
bx::MutexScope lock(m_lock);
|
2018-01-11 11:14:36 +03:00
|
|
|
Geometry& geometry = m_geometry[_handle.idx];
|
|
|
|
bgfx::destroy(geometry.m_vbh);
|
|
|
|
bgfx::destroy(geometry.m_ibh);
|
|
|
|
|
|
|
|
m_handleAlloc.free(_handle.idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Geometry
|
|
|
|
{
|
|
|
|
Geometry()
|
|
|
|
{
|
|
|
|
m_vbh.idx = bx::kInvalidHandle;
|
|
|
|
m_ibh.idx = bx::kInvalidHandle;
|
|
|
|
m_topologyNumIndices[0] = 0;
|
|
|
|
m_topologyNumIndices[1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bgfx::VertexBufferHandle m_vbh;
|
|
|
|
bgfx::IndexBufferHandle m_ibh;
|
|
|
|
uint32_t m_topologyNumIndices[2];
|
|
|
|
};
|
|
|
|
|
2018-09-11 03:45:23 +03:00
|
|
|
bx::Mutex m_lock;
|
2018-01-11 11:14:36 +03:00
|
|
|
bx::HandleAllocT<MaxHandlesT> m_handleAlloc;
|
|
|
|
Geometry m_geometry[MaxHandlesT];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Attrib
|
|
|
|
{
|
|
|
|
uint64_t m_state;
|
|
|
|
float m_offset;
|
|
|
|
float m_scale;
|
|
|
|
float m_spin;
|
|
|
|
uint32_t m_abgr;
|
|
|
|
bool m_stipple;
|
|
|
|
bool m_wireframe;
|
|
|
|
uint8_t m_lod;
|
|
|
|
};
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
struct Program
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
enum Enum
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
Lines,
|
|
|
|
LinesStipple,
|
|
|
|
Fill,
|
|
|
|
FillMesh,
|
|
|
|
FillLit,
|
|
|
|
FillLitMesh,
|
|
|
|
FillTexture,
|
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
struct Mesh
|
|
|
|
{
|
|
|
|
enum Enum
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
Sphere0,
|
|
|
|
Sphere1,
|
|
|
|
Sphere2,
|
|
|
|
Sphere3,
|
|
|
|
|
|
|
|
Cone0,
|
|
|
|
Cone1,
|
|
|
|
Cone2,
|
|
|
|
Cone3,
|
|
|
|
|
|
|
|
Cylinder0,
|
|
|
|
Cylinder1,
|
|
|
|
Cylinder2,
|
|
|
|
Cylinder3,
|
|
|
|
|
|
|
|
Capsule0,
|
|
|
|
Capsule1,
|
|
|
|
Capsule2,
|
|
|
|
Capsule3,
|
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
Quad,
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
Cube,
|
|
|
|
|
|
|
|
Count,
|
|
|
|
|
|
|
|
SphereMaxLod = Sphere3 - Sphere0,
|
|
|
|
ConeMaxLod = Cone3 - Cone0,
|
|
|
|
CylinderMaxLod = Cylinder3 - Cylinder0,
|
|
|
|
CapsuleMaxLod = Capsule3 - Capsule0,
|
|
|
|
};
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
uint32_t m_startVertex;
|
|
|
|
uint32_t m_numVertices;
|
|
|
|
uint32_t m_startIndex[2];
|
|
|
|
uint32_t m_numIndices[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SpriteT<256, SPRITE_TEXTURE_SIZE> Sprite;
|
2018-09-05 03:27:35 +03:00
|
|
|
typedef GeometryT<DEBUG_DRAW_CONFIG_MAX_GEOMETRY> Geometry;
|
2018-04-12 03:26:55 +03:00
|
|
|
|
|
|
|
struct DebugDrawShared
|
|
|
|
{
|
|
|
|
void init(bx::AllocatorI* _allocator)
|
|
|
|
{
|
2016-02-26 09:20:24 +03:00
|
|
|
if (NULL == _allocator)
|
|
|
|
{
|
2017-06-11 08:31:59 +03:00
|
|
|
static bx::DefaultAllocator allocator;
|
2016-02-26 09:20:24 +03:00
|
|
|
m_allocator = &allocator;
|
|
|
|
}
|
2018-04-12 03:26:55 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_allocator = _allocator;
|
|
|
|
}
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
DebugVertex::init();
|
2016-12-20 09:13:15 +03:00
|
|
|
DebugUvVertex::init();
|
2016-02-26 09:20:24 +03:00
|
|
|
DebugShapeVertex::init();
|
2018-01-09 04:54:15 +03:00
|
|
|
DebugMeshVertex::init();
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
bgfx::RendererType::Enum type = bgfx::getRendererType();
|
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
m_program[Program::Lines] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_lines")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_lines")
|
|
|
|
, true
|
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
m_program[Program::LinesStipple] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_lines_stipple")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_lines_stipple")
|
|
|
|
, true
|
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
m_program[Program::Fill] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill")
|
|
|
|
, true
|
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-01-09 04:54:15 +03:00
|
|
|
m_program[Program::FillMesh] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill_mesh")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill")
|
|
|
|
, true
|
|
|
|
);
|
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
m_program[Program::FillLit] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill_lit")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill_lit")
|
|
|
|
, true
|
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-01-09 04:54:15 +03:00
|
|
|
m_program[Program::FillLitMesh] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill_lit_mesh")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill_lit")
|
|
|
|
, true
|
|
|
|
);
|
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
m_program[Program::FillTexture] = bgfx::createProgram(
|
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_debugdraw_fill_texture")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_debugdraw_fill_texture")
|
|
|
|
, true
|
|
|
|
);
|
2016-12-20 09:13:15 +03:00
|
|
|
|
|
|
|
u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, 4);
|
|
|
|
s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
|
2016-12-21 08:20:55 +03:00
|
|
|
m_texture = bgfx::createTexture2D(SPRITE_TEXTURE_SIZE, SPRITE_TEXTURE_SIZE, false, 1, bgfx::TextureFormat::BGRA8);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
void* vertices[Mesh::Count] = {};
|
|
|
|
uint16_t* indices[Mesh::Count] = {};
|
|
|
|
uint16_t stride = DebugShapeVertex::ms_decl.getStride();
|
|
|
|
|
|
|
|
uint32_t startVertex = 0;
|
|
|
|
uint32_t startIndex = 0;
|
|
|
|
|
|
|
|
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
|
|
|
{
|
|
|
|
Mesh::Enum id = Mesh::Enum(Mesh::Sphere0+mesh);
|
|
|
|
|
2016-03-03 05:09:36 +03:00
|
|
|
const uint8_t tess = uint8_t(3-mesh);
|
2016-02-26 09:20:24 +03:00
|
|
|
const uint32_t numVertices = genSphere(tess);
|
|
|
|
const uint32_t numIndices = numVertices;
|
2016-02-26 09:41:28 +03:00
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memSet(vertices[id], 0, numVertices*stride);
|
2016-02-26 09:20:24 +03:00
|
|
|
genSphere(tess, vertices[id], stride);
|
|
|
|
|
|
|
|
uint16_t* trilist = (uint16_t*)BX_ALLOC(m_allocator, numIndices*sizeof(uint16_t) );
|
|
|
|
for (uint32_t ii = 0; ii < numIndices; ++ii)
|
|
|
|
{
|
|
|
|
trilist[ii] = uint16_t(ii);
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
uint32_t numLineListIndices = bgfx::topologyConvert(
|
|
|
|
bgfx::TopologyConvert::TriListToLineList
|
|
|
|
, NULL
|
|
|
|
, 0
|
|
|
|
, trilist
|
|
|
|
, numIndices
|
|
|
|
, false
|
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
|
|
|
uint16_t* indicesOut = indices[id];
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(indicesOut, trilist, numIndices*sizeof(uint16_t) );
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2017-07-24 07:22:21 +03:00
|
|
|
bgfx::topologyConvert(
|
|
|
|
bgfx::TopologyConvert::TriListToLineList
|
|
|
|
, &indicesOut[numIndices]
|
|
|
|
, numLineListIndices*sizeof(uint16_t)
|
|
|
|
, trilist
|
|
|
|
, numIndices
|
|
|
|
, false
|
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
m_mesh[id].m_startVertex = startVertex;
|
|
|
|
m_mesh[id].m_numVertices = numVertices;
|
|
|
|
m_mesh[id].m_startIndex[0] = startIndex;
|
|
|
|
m_mesh[id].m_numIndices[0] = numIndices;
|
|
|
|
m_mesh[id].m_startIndex[1] = startIndex+numIndices;
|
|
|
|
m_mesh[id].m_numIndices[1] = numLineListIndices;
|
|
|
|
|
|
|
|
startVertex += numVertices;
|
|
|
|
startIndex += numIndices + numLineListIndices;
|
|
|
|
|
|
|
|
BX_FREE(m_allocator, trilist);
|
|
|
|
}
|
2016-02-26 09:41:28 +03:00
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
|
|
|
{
|
|
|
|
Mesh::Enum id = Mesh::Enum(Mesh::Cone0+mesh);
|
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
const uint32_t num = getCircleLod(uint8_t(mesh) );
|
2017-06-10 06:08:52 +03:00
|
|
|
const float step = bx::kPi * 2.0f / num;
|
2016-06-15 08:33:37 +03:00
|
|
|
|
|
|
|
const uint32_t numVertices = num+1;
|
|
|
|
const uint32_t numIndices = num*6;
|
|
|
|
const uint32_t numLineListIndices = num*4;
|
|
|
|
|
|
|
|
vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
|
|
|
|
indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memSet(indices[id], 0, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
2016-06-15 08:33:37 +03:00
|
|
|
|
|
|
|
DebugShapeVertex* vertex = (DebugShapeVertex*)vertices[id];
|
|
|
|
uint16_t* index = indices[id];
|
|
|
|
|
|
|
|
vertex[num].m_x = 0.0f;
|
|
|
|
vertex[num].m_y = 0.0f;
|
|
|
|
vertex[num].m_z = 0.0f;
|
|
|
|
vertex[num].m_indices[0] = 1;
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
const float angle = step * ii;
|
|
|
|
|
|
|
|
float xy[2];
|
|
|
|
circle(xy, angle);
|
|
|
|
|
|
|
|
vertex[ii].m_x = xy[1];
|
|
|
|
vertex[ii].m_y = 0.0f;
|
|
|
|
vertex[ii].m_z = xy[0];
|
|
|
|
vertex[ii].m_indices[0] = 0;
|
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[ii*3+0] = uint16_t(num);
|
|
|
|
index[ii*3+1] = uint16_t( (ii+1)%num);
|
|
|
|
index[ii*3+2] = uint16_t(ii);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
|
|
|
index[num*3+ii*3+0] = 0;
|
2016-06-15 22:58:36 +03:00
|
|
|
index[num*3+ii*3+1] = uint16_t(ii);
|
|
|
|
index[num*3+ii*3+2] = uint16_t( (ii+1)%num);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[numIndices+ii*2+0] = uint16_t(ii);
|
|
|
|
index[numIndices+ii*2+1] = uint16_t(num);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[numIndices+num*2+ii*2+0] = uint16_t(ii);
|
|
|
|
index[numIndices+num*2+ii*2+1] = uint16_t( (ii+1)%num);
|
2016-06-15 08:33:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_mesh[id].m_startVertex = startVertex;
|
|
|
|
m_mesh[id].m_numVertices = numVertices;
|
|
|
|
m_mesh[id].m_startIndex[0] = startIndex;
|
|
|
|
m_mesh[id].m_numIndices[0] = numIndices;
|
|
|
|
m_mesh[id].m_startIndex[1] = startIndex+numIndices;
|
|
|
|
m_mesh[id].m_numIndices[1] = numLineListIndices;
|
|
|
|
|
|
|
|
startVertex += numVertices;
|
|
|
|
startIndex += numIndices + numLineListIndices;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
|
|
|
{
|
|
|
|
Mesh::Enum id = Mesh::Enum(Mesh::Cylinder0+mesh);
|
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
const uint32_t num = getCircleLod(uint8_t(mesh) );
|
2017-06-10 06:08:52 +03:00
|
|
|
const float step = bx::kPi * 2.0f / num;
|
2016-06-15 08:33:37 +03:00
|
|
|
|
|
|
|
const uint32_t numVertices = num*2;
|
|
|
|
const uint32_t numIndices = num*12;
|
|
|
|
const uint32_t numLineListIndices = num*6;
|
|
|
|
|
|
|
|
vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
|
|
|
|
indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memSet(indices[id], 0, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
2016-06-15 08:33:37 +03:00
|
|
|
|
|
|
|
DebugShapeVertex* vertex = (DebugShapeVertex*)vertices[id];
|
|
|
|
uint16_t* index = indices[id];
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
const float angle = step * ii;
|
|
|
|
|
|
|
|
float xy[2];
|
|
|
|
circle(xy, angle);
|
|
|
|
|
|
|
|
vertex[ii].m_x = xy[1];
|
|
|
|
vertex[ii].m_y = 0.0f;
|
|
|
|
vertex[ii].m_z = xy[0];
|
|
|
|
vertex[ii].m_indices[0] = 0;
|
|
|
|
|
|
|
|
vertex[ii+num].m_x = xy[1];
|
|
|
|
vertex[ii+num].m_y = 0.0f;
|
|
|
|
vertex[ii+num].m_z = xy[0];
|
|
|
|
vertex[ii+num].m_indices[0] = 1;
|
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[ii*6+0] = uint16_t(ii+num);
|
|
|
|
index[ii*6+1] = uint16_t( (ii+1)%num);
|
|
|
|
index[ii*6+2] = uint16_t(ii);
|
|
|
|
index[ii*6+3] = uint16_t(ii+num);
|
|
|
|
index[ii*6+4] = uint16_t( (ii+1)%num+num);
|
|
|
|
index[ii*6+5] = uint16_t( (ii+1)%num);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[num*6+ii*6+0] = uint16_t(0);
|
|
|
|
index[num*6+ii*6+1] = uint16_t(ii);
|
|
|
|
index[num*6+ii*6+2] = uint16_t( (ii+1)%num);
|
|
|
|
index[num*6+ii*6+3] = uint16_t(num);
|
|
|
|
index[num*6+ii*6+4] = uint16_t( (ii+1)%num+num);
|
|
|
|
index[num*6+ii*6+5] = uint16_t(ii+num);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[numIndices+ii*2+0] = uint16_t(ii);
|
|
|
|
index[numIndices+ii*2+1] = uint16_t(ii+num);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[numIndices+num*2+ii*2+0] = uint16_t(ii);
|
|
|
|
index[numIndices+num*2+ii*2+1] = uint16_t( (ii+1)%num);
|
2016-06-15 08:33:37 +03:00
|
|
|
|
2016-06-15 22:58:36 +03:00
|
|
|
index[numIndices+num*4+ii*2+0] = uint16_t(num + ii);
|
|
|
|
index[numIndices+num*4+ii*2+1] = uint16_t(num + (ii+1)%num);
|
2016-06-15 08:33:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_mesh[id].m_startVertex = startVertex;
|
|
|
|
m_mesh[id].m_numVertices = numVertices;
|
|
|
|
m_mesh[id].m_startIndex[0] = startIndex;
|
|
|
|
m_mesh[id].m_numIndices[0] = numIndices;
|
|
|
|
m_mesh[id].m_startIndex[1] = startIndex+numIndices;
|
|
|
|
m_mesh[id].m_numIndices[1] = numLineListIndices;
|
|
|
|
|
|
|
|
startVertex += numVertices;
|
|
|
|
startIndex += numIndices + numLineListIndices;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t mesh = 0; mesh < 4; ++mesh)
|
|
|
|
{
|
|
|
|
Mesh::Enum id = Mesh::Enum(Mesh::Capsule0+mesh);
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
const uint32_t num = getCircleLod(uint8_t(mesh) );
|
2017-06-10 06:08:52 +03:00
|
|
|
const float step = bx::kPi * 2.0f / num;
|
2016-06-20 08:00:24 +03:00
|
|
|
|
|
|
|
const uint32_t numVertices = num*2;
|
|
|
|
const uint32_t numIndices = num*6;
|
|
|
|
const uint32_t numLineListIndices = num*6;
|
|
|
|
|
|
|
|
vertices[id] = BX_ALLOC(m_allocator, numVertices*stride);
|
|
|
|
indices[id] = (uint16_t*)BX_ALLOC(m_allocator, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memSet(indices[id], 0, (numIndices + numLineListIndices)*sizeof(uint16_t) );
|
2016-06-20 08:00:24 +03:00
|
|
|
|
|
|
|
DebugShapeVertex* vertex = (DebugShapeVertex*)vertices[id];
|
|
|
|
uint16_t* index = indices[id];
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
const float angle = step * ii;
|
|
|
|
|
|
|
|
float xy[2];
|
|
|
|
circle(xy, angle);
|
|
|
|
|
|
|
|
vertex[ii].m_x = xy[1];
|
|
|
|
vertex[ii].m_y = 0.0f;
|
|
|
|
vertex[ii].m_z = xy[0];
|
|
|
|
vertex[ii].m_indices[0] = 0;
|
|
|
|
|
|
|
|
vertex[ii+num].m_x = xy[1];
|
|
|
|
vertex[ii+num].m_y = 0.0f;
|
|
|
|
vertex[ii+num].m_z = xy[0];
|
|
|
|
vertex[ii+num].m_indices[0] = 1;
|
|
|
|
|
|
|
|
index[ii*6+0] = uint16_t(ii+num);
|
|
|
|
index[ii*6+1] = uint16_t( (ii+1)%num);
|
|
|
|
index[ii*6+2] = uint16_t(ii);
|
|
|
|
index[ii*6+3] = uint16_t(ii+num);
|
|
|
|
index[ii*6+4] = uint16_t( (ii+1)%num+num);
|
|
|
|
index[ii*6+5] = uint16_t( (ii+1)%num);
|
|
|
|
|
|
|
|
// index[num*6+ii*6+0] = uint16_t(0);
|
|
|
|
// index[num*6+ii*6+1] = uint16_t(ii);
|
|
|
|
// index[num*6+ii*6+2] = uint16_t( (ii+1)%num);
|
|
|
|
// index[num*6+ii*6+3] = uint16_t(num);
|
|
|
|
// index[num*6+ii*6+4] = uint16_t( (ii+1)%num+num);
|
|
|
|
// index[num*6+ii*6+5] = uint16_t(ii+num);
|
|
|
|
|
|
|
|
index[numIndices+ii*2+0] = uint16_t(ii);
|
|
|
|
index[numIndices+ii*2+1] = uint16_t(ii+num);
|
|
|
|
|
|
|
|
index[numIndices+num*2+ii*2+0] = uint16_t(ii);
|
|
|
|
index[numIndices+num*2+ii*2+1] = uint16_t( (ii+1)%num);
|
|
|
|
|
|
|
|
index[numIndices+num*4+ii*2+0] = uint16_t(num + ii);
|
|
|
|
index[numIndices+num*4+ii*2+1] = uint16_t(num + (ii+1)%num);
|
|
|
|
}
|
2016-06-15 08:33:37 +03:00
|
|
|
|
|
|
|
m_mesh[id].m_startVertex = startVertex;
|
|
|
|
m_mesh[id].m_numVertices = numVertices;
|
|
|
|
m_mesh[id].m_startIndex[0] = startIndex;
|
|
|
|
m_mesh[id].m_numIndices[0] = numIndices;
|
|
|
|
m_mesh[id].m_startIndex[1] = startIndex+numIndices;
|
|
|
|
m_mesh[id].m_numIndices[1] = numLineListIndices;
|
|
|
|
|
|
|
|
startVertex += numVertices;
|
|
|
|
startIndex += numIndices + numLineListIndices;
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
m_mesh[Mesh::Quad].m_startVertex = startVertex;
|
|
|
|
m_mesh[Mesh::Quad].m_numVertices = BX_COUNTOF(s_quadVertices);
|
|
|
|
m_mesh[Mesh::Quad].m_startIndex[0] = startIndex;
|
|
|
|
m_mesh[Mesh::Quad].m_numIndices[0] = BX_COUNTOF(s_quadIndices);
|
|
|
|
m_mesh[Mesh::Quad].m_startIndex[1] = 0;
|
|
|
|
m_mesh[Mesh::Quad].m_numIndices[1] = 0;
|
|
|
|
startVertex += BX_COUNTOF(s_quadVertices);
|
|
|
|
startIndex += BX_COUNTOF(s_quadIndices);
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
m_mesh[Mesh::Cube].m_startVertex = startVertex;
|
|
|
|
m_mesh[Mesh::Cube].m_numVertices = BX_COUNTOF(s_cubeVertices);
|
|
|
|
m_mesh[Mesh::Cube].m_startIndex[0] = startIndex;
|
|
|
|
m_mesh[Mesh::Cube].m_numIndices[0] = BX_COUNTOF(s_cubeIndices);
|
|
|
|
m_mesh[Mesh::Cube].m_startIndex[1] = 0;
|
|
|
|
m_mesh[Mesh::Cube].m_numIndices[1] = 0;
|
|
|
|
startVertex += m_mesh[Mesh::Cube].m_numVertices;
|
|
|
|
startIndex += m_mesh[Mesh::Cube].m_numIndices[0];
|
|
|
|
|
|
|
|
const bgfx::Memory* vb = bgfx::alloc(startVertex*stride);
|
|
|
|
const bgfx::Memory* ib = bgfx::alloc(startIndex*sizeof(uint16_t) );
|
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
for (uint32_t mesh = Mesh::Sphere0; mesh < Mesh::Quad; ++mesh)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2016-06-15 08:33:37 +03:00
|
|
|
Mesh::Enum id = Mesh::Enum(mesh);
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(&vb->data[m_mesh[id].m_startVertex * stride]
|
2016-02-26 09:20:24 +03:00
|
|
|
, vertices[id]
|
|
|
|
, m_mesh[id].m_numVertices*stride
|
|
|
|
);
|
|
|
|
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(&ib->data[m_mesh[id].m_startIndex[0] * sizeof(uint16_t)]
|
2016-02-26 09:20:24 +03:00
|
|
|
, indices[id]
|
|
|
|
, (m_mesh[id].m_numIndices[0]+m_mesh[id].m_numIndices[1])*sizeof(uint16_t)
|
|
|
|
);
|
|
|
|
|
|
|
|
BX_FREE(m_allocator, vertices[id]);
|
|
|
|
BX_FREE(m_allocator, indices[id]);
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
bx::memCopy(&vb->data[m_mesh[Mesh::Quad].m_startVertex * stride]
|
|
|
|
, s_quadVertices
|
|
|
|
, sizeof(s_quadVertices)
|
|
|
|
);
|
|
|
|
|
|
|
|
bx::memCopy(&ib->data[m_mesh[Mesh::Quad].m_startIndex[0] * sizeof(uint16_t)]
|
|
|
|
, s_quadIndices
|
|
|
|
, sizeof(s_quadIndices)
|
|
|
|
);
|
|
|
|
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(&vb->data[m_mesh[Mesh::Cube].m_startVertex * stride]
|
2016-02-26 09:20:24 +03:00
|
|
|
, s_cubeVertices
|
|
|
|
, sizeof(s_cubeVertices)
|
|
|
|
);
|
|
|
|
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(&ib->data[m_mesh[Mesh::Cube].m_startIndex[0] * sizeof(uint16_t)]
|
2016-02-26 09:20:24 +03:00
|
|
|
, s_cubeIndices
|
|
|
|
, sizeof(s_cubeIndices)
|
|
|
|
);
|
|
|
|
|
|
|
|
m_vbh = bgfx::createVertexBuffer(vb, DebugShapeVertex::ms_decl);
|
|
|
|
m_ibh = bgfx::createIndexBuffer(ib);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shutdown()
|
|
|
|
{
|
2017-07-18 08:29:43 +03:00
|
|
|
bgfx::destroy(m_ibh);
|
|
|
|
bgfx::destroy(m_vbh);
|
2016-02-27 07:09:13 +03:00
|
|
|
for (uint32_t ii = 0; ii < Program::Count; ++ii)
|
|
|
|
{
|
2017-07-18 08:29:43 +03:00
|
|
|
bgfx::destroy(m_program[ii]);
|
2016-02-27 07:09:13 +03:00
|
|
|
}
|
2017-07-18 08:29:43 +03:00
|
|
|
bgfx::destroy(u_params);
|
|
|
|
bgfx::destroy(s_texColor);
|
|
|
|
bgfx::destroy(m_texture);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
SpriteHandle createSprite(uint16_t _width, uint16_t _height, const void* _data)
|
|
|
|
{
|
|
|
|
SpriteHandle handle = m_sprite.create(_width, _height);
|
|
|
|
|
|
|
|
if (isValid(handle) )
|
|
|
|
{
|
|
|
|
const Pack2D& pack = m_sprite.get(handle);
|
|
|
|
bgfx::updateTexture2D(
|
|
|
|
m_texture
|
|
|
|
, 0
|
|
|
|
, 0
|
|
|
|
, pack.m_x
|
|
|
|
, pack.m_y
|
|
|
|
, pack.m_width
|
|
|
|
, pack.m_height
|
|
|
|
, bgfx::copy(_data, pack.m_width*pack.m_height*4)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy(SpriteHandle _handle)
|
|
|
|
{
|
|
|
|
m_sprite.destroy(_handle);
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
GeometryHandle createGeometry(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices, const void* _indices, bool _index32)
|
2018-01-11 11:14:36 +03:00
|
|
|
{
|
2018-09-05 03:27:35 +03:00
|
|
|
return m_geometry.create(_numVertices, _vertices, _numIndices, _indices, _index32);
|
2018-01-11 11:14:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void destroy(GeometryHandle _handle)
|
|
|
|
{
|
|
|
|
m_geometry.destroy(_handle);
|
|
|
|
}
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
bx::AllocatorI* m_allocator;
|
|
|
|
|
|
|
|
Sprite m_sprite;
|
|
|
|
Geometry m_geometry;
|
|
|
|
|
|
|
|
Mesh m_mesh[Mesh::Count];
|
|
|
|
|
|
|
|
bgfx::UniformHandle s_texColor;
|
|
|
|
bgfx::TextureHandle m_texture;
|
|
|
|
bgfx::ProgramHandle m_program[Program::Count];
|
|
|
|
bgfx::UniformHandle u_params;
|
|
|
|
|
|
|
|
bgfx::VertexBufferHandle m_vbh;
|
|
|
|
bgfx::IndexBufferHandle m_ibh;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DebugDrawShared s_dds;
|
|
|
|
|
|
|
|
struct DebugDrawEncoderImpl
|
|
|
|
{
|
|
|
|
DebugDrawEncoderImpl()
|
|
|
|
: m_depthTestLess(true)
|
|
|
|
, m_state(State::Count)
|
|
|
|
, m_defaultEncoder(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
void init(bgfx::Encoder* _encoder)
|
2018-04-12 03:26:55 +03:00
|
|
|
{
|
|
|
|
m_defaultEncoder = _encoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
void begin(bgfx::ViewId _viewId, bool _depthTestLess, bgfx::Encoder* _encoder)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
BX_CHECK(State::Count == m_state);
|
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
m_viewId = _viewId;
|
|
|
|
m_encoder = _encoder == NULL ? m_defaultEncoder : _encoder;
|
|
|
|
m_state = State::None;
|
|
|
|
m_stack = 0;
|
|
|
|
m_depthTestLess = _depthTestLess;
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
m_pos = 0;
|
|
|
|
m_indexPos = 0;
|
|
|
|
m_vertexPos = 0;
|
|
|
|
m_posQuad = 0;
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
Attrib& attrib = m_attrib[0];
|
2016-03-03 10:09:45 +03:00
|
|
|
attrib.m_state = 0
|
2018-02-13 23:35:23 +03:00
|
|
|
| BGFX_STATE_WRITE_RGB
|
2016-03-25 02:16:56 +03:00
|
|
|
| (m_depthTestLess ? BGFX_STATE_DEPTH_TEST_LESS : BGFX_STATE_DEPTH_TEST_GREATER)
|
2016-03-03 10:09:45 +03:00
|
|
|
| BGFX_STATE_CULL_CW
|
2018-02-13 23:35:23 +03:00
|
|
|
| BGFX_STATE_WRITE_Z
|
2016-03-03 10:09:45 +03:00
|
|
|
;
|
2016-02-26 09:20:24 +03:00
|
|
|
attrib.m_scale = 1.0f;
|
2016-12-14 08:58:18 +03:00
|
|
|
attrib.m_spin = 0.0f;
|
2016-02-26 09:20:24 +03:00
|
|
|
attrib.m_offset = 0.0f;
|
|
|
|
attrib.m_abgr = UINT32_MAX;
|
|
|
|
attrib.m_stipple = false;
|
|
|
|
attrib.m_wireframe = false;
|
|
|
|
attrib.m_lod = 0;
|
2017-09-13 03:58:36 +03:00
|
|
|
|
|
|
|
m_mtxStackCurrent = 0;
|
|
|
|
m_mtxStack[m_mtxStackCurrent].reset();
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void end()
|
|
|
|
{
|
|
|
|
BX_CHECK(0 == m_stack, "Invalid stack %d.", m_stack);
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
flushQuad();
|
2016-02-26 09:20:24 +03:00
|
|
|
flush();
|
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder = NULL;
|
|
|
|
m_state = State::Count;
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void push()
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
++m_stack;
|
|
|
|
m_attrib[m_stack] = m_attrib[m_stack-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void pop()
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
2016-03-25 02:16:56 +03:00
|
|
|
const Attrib& curr = m_attrib[m_stack];
|
|
|
|
const Attrib& prev = m_attrib[m_stack-1];
|
|
|
|
if (curr.m_stipple != prev.m_stipple
|
|
|
|
|| curr.m_state != prev.m_state)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
--m_stack;
|
|
|
|
}
|
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
void setDepthTestLess(bool _depthTestLess)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
if (m_depthTestLess != _depthTestLess)
|
|
|
|
{
|
|
|
|
m_depthTestLess = _depthTestLess;
|
|
|
|
Attrib& attrib = m_attrib[m_stack];
|
2018-04-17 08:04:49 +03:00
|
|
|
if (attrib.m_state & BGFX_STATE_DEPTH_TEST_MASK)
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
attrib.m_state &= ~BGFX_STATE_DEPTH_TEST_MASK;
|
|
|
|
attrib.m_state |= _depthTestLess ? BGFX_STATE_DEPTH_TEST_LESS : BGFX_STATE_DEPTH_TEST_GREATER;
|
|
|
|
}
|
2018-04-17 03:58:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
void setTransform(const void* _mtx, uint16_t _num = 1, bool _flush = true)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
2018-09-05 03:27:35 +03:00
|
|
|
if (_flush)
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2017-09-13 03:58:36 +03:00
|
|
|
MatrixStack& stack = m_mtxStack[m_mtxStackCurrent];
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
if (NULL == _mtx)
|
|
|
|
{
|
2017-09-13 03:58:36 +03:00
|
|
|
stack.reset();
|
2016-02-26 09:20:24 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bgfx::Transform transform;
|
2018-05-25 04:03:51 +03:00
|
|
|
stack.mtx = m_encoder->allocTransform(&transform, _num);
|
2017-09-13 03:58:36 +03:00
|
|
|
stack.num = _num;
|
|
|
|
stack.data = transform.data;
|
|
|
|
bx::memCopy(transform.data, _mtx, _num*64);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void setTranslate(float _x, float _y, float _z)
|
|
|
|
{
|
|
|
|
float mtx[16];
|
|
|
|
bx::mtxTranslate(mtx, _x, _y, _z);
|
|
|
|
setTransform(mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTranslate(const float* _pos)
|
|
|
|
{
|
|
|
|
setTranslate(_pos[0], _pos[1], _pos[2]);
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
void pushTransform(const void* _mtx, uint16_t _num, bool _flush = true)
|
2017-09-13 03:58:36 +03:00
|
|
|
{
|
|
|
|
BX_CHECK(m_mtxStackCurrent < BX_COUNTOF(m_mtxStack), "Out of matrix stack!");
|
|
|
|
BX_CHECK(State::Count != m_state);
|
2018-09-05 03:27:35 +03:00
|
|
|
if (_flush)
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
2017-09-13 03:58:36 +03:00
|
|
|
|
|
|
|
float* mtx = NULL;
|
|
|
|
|
|
|
|
const MatrixStack& stack = m_mtxStack[m_mtxStackCurrent];
|
|
|
|
|
|
|
|
if (NULL == stack.data)
|
|
|
|
{
|
|
|
|
mtx = (float*)_mtx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mtx = (float*)alloca(_num*64);
|
|
|
|
for (uint16_t ii = 0; ii < _num; ++ii)
|
|
|
|
{
|
|
|
|
const float* mtxTransform = (const float*)_mtx;
|
|
|
|
bx::mtxMul(&mtx[ii*16], &mtxTransform[ii*16], stack.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mtxStackCurrent++;
|
2018-09-05 03:27:35 +03:00
|
|
|
setTransform(mtx, _num, _flush);
|
2017-09-13 03:58:36 +03:00
|
|
|
}
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
void popTransform(bool _flush = true)
|
2017-09-13 03:58:36 +03:00
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
2018-09-05 03:27:35 +03:00
|
|
|
if (_flush)
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
2017-09-13 03:58:36 +03:00
|
|
|
|
|
|
|
m_mtxStackCurrent--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushTranslate(float _x, float _y, float _z)
|
|
|
|
{
|
|
|
|
float mtx[16];
|
|
|
|
bx::mtxTranslate(mtx, _x, _y, _z);
|
|
|
|
pushTransform(mtx, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushTranslate(const float* _pos)
|
|
|
|
{
|
|
|
|
pushTranslate(_pos[0], _pos[1], _pos[2]);
|
|
|
|
}
|
|
|
|
|
2016-03-03 10:09:45 +03:00
|
|
|
void setState(bool _depthTest, bool _depthWrite, bool _clockwise)
|
|
|
|
{
|
2016-03-25 02:16:56 +03:00
|
|
|
const uint64_t depthTest = m_depthTestLess
|
|
|
|
? BGFX_STATE_DEPTH_TEST_LESS
|
|
|
|
: BGFX_STATE_DEPTH_TEST_GREATER
|
|
|
|
;
|
|
|
|
|
2016-12-02 23:10:09 +03:00
|
|
|
uint64_t state = m_attrib[m_stack].m_state & ~(0
|
2016-03-25 02:16:56 +03:00
|
|
|
| BGFX_STATE_DEPTH_TEST_MASK
|
2018-02-13 23:35:23 +03:00
|
|
|
| BGFX_STATE_WRITE_Z
|
2016-03-03 10:09:45 +03:00
|
|
|
| BGFX_STATE_CULL_CW
|
|
|
|
| BGFX_STATE_CULL_CCW
|
|
|
|
);
|
|
|
|
|
2016-12-02 23:10:09 +03:00
|
|
|
state |= _depthTest
|
2016-03-25 02:16:56 +03:00
|
|
|
? depthTest
|
2016-03-03 10:09:45 +03:00
|
|
|
: 0
|
|
|
|
;
|
|
|
|
|
2016-12-02 23:10:09 +03:00
|
|
|
state |= _depthWrite
|
2018-02-13 23:35:23 +03:00
|
|
|
? BGFX_STATE_WRITE_Z
|
2016-03-03 10:09:45 +03:00
|
|
|
: 0
|
|
|
|
;
|
|
|
|
|
2016-12-02 23:10:09 +03:00
|
|
|
state |= _clockwise
|
2016-03-03 10:09:45 +03:00
|
|
|
? BGFX_STATE_CULL_CW
|
|
|
|
: BGFX_STATE_CULL_CCW
|
|
|
|
;
|
2016-12-02 23:10:09 +03:00
|
|
|
|
|
|
|
if (m_attrib[m_stack].m_state != state)
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_attrib[m_stack].m_state = state;
|
2016-03-03 10:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
void setColor(uint32_t _abgr)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
m_attrib[m_stack].m_abgr = _abgr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLod(uint8_t _lod)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
m_attrib[m_stack].m_lod = _lod;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWireframe(bool _wireframe)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
m_attrib[m_stack].m_wireframe = _wireframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStipple(bool _stipple, float _scale = 1.0f, float _offset = 0.0f)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
|
|
|
|
Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
|
|
|
if (attrib.m_stipple != _stipple)
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
attrib.m_stipple = _stipple;
|
|
|
|
attrib.m_offset = _offset;
|
|
|
|
attrib.m_scale = _scale;
|
|
|
|
}
|
|
|
|
|
2016-12-14 08:58:18 +03:00
|
|
|
void setSpin(float _spin)
|
|
|
|
{
|
|
|
|
Attrib& attrib = m_attrib[m_stack];
|
|
|
|
attrib.m_spin = _spin;
|
|
|
|
}
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
void moveTo(float _x, float _y, float _z = 0.0f)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
|
|
|
|
softFlush();
|
|
|
|
|
|
|
|
m_state = State::MoveTo;
|
|
|
|
|
|
|
|
DebugVertex& vertex = m_cache[m_pos];
|
|
|
|
vertex.m_x = _x;
|
|
|
|
vertex.m_y = _y;
|
|
|
|
vertex.m_z = _z;
|
|
|
|
|
|
|
|
Attrib& attrib = m_attrib[m_stack];
|
|
|
|
vertex.m_abgr = attrib.m_abgr;
|
|
|
|
vertex.m_len = attrib.m_offset;
|
|
|
|
|
|
|
|
m_vertexPos = m_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveTo(const void* _pos)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
|
|
|
|
const float* pos = (const float*)_pos;
|
|
|
|
moveTo(pos[0], pos[1], pos[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveTo(Axis::Enum _axis, float _x, float _y)
|
|
|
|
{
|
|
|
|
float pos[3];
|
|
|
|
getPoint(pos, _axis, _x, _y);
|
|
|
|
moveTo(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lineTo(float _x, float _y, float _z = 0.0f)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
if (State::None == m_state)
|
|
|
|
{
|
|
|
|
moveTo(_x, _y, _z);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_pos+2 > uint16_t(BX_COUNTOF(m_cache) ) )
|
|
|
|
{
|
|
|
|
uint32_t pos = m_pos;
|
|
|
|
uint32_t vertexPos = m_vertexPos;
|
|
|
|
|
|
|
|
flush();
|
|
|
|
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(&m_cache[0], &m_cache[vertexPos], sizeof(DebugVertex) );
|
2016-02-26 09:20:24 +03:00
|
|
|
if (vertexPos == pos)
|
|
|
|
{
|
|
|
|
m_pos = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(&m_cache[1], &m_cache[pos - 1], sizeof(DebugVertex) );
|
2016-02-26 09:20:24 +03:00
|
|
|
m_pos = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_state = State::LineTo;
|
|
|
|
}
|
|
|
|
else if (State::MoveTo == m_state)
|
|
|
|
{
|
|
|
|
++m_pos;
|
|
|
|
m_state = State::LineTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t prev = m_pos-1;
|
|
|
|
uint16_t curr = m_pos++;
|
|
|
|
DebugVertex& vertex = m_cache[curr];
|
|
|
|
vertex.m_x = _x;
|
|
|
|
vertex.m_y = _y;
|
|
|
|
vertex.m_z = _z;
|
|
|
|
|
|
|
|
Attrib& attrib = m_attrib[m_stack];
|
|
|
|
vertex.m_abgr = attrib.m_abgr;
|
|
|
|
vertex.m_len = attrib.m_offset;
|
|
|
|
|
|
|
|
float tmp[3];
|
|
|
|
bx::vec3Sub(tmp, &vertex.m_x, &m_cache[prev].m_x);
|
|
|
|
float len = bx::vec3Length(tmp) * attrib.m_scale;
|
|
|
|
vertex.m_len = m_cache[prev].m_len + len;
|
|
|
|
|
|
|
|
m_indices[m_indexPos++] = prev;
|
|
|
|
m_indices[m_indexPos++] = curr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lineTo(const void* _pos)
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
|
|
|
|
const float* pos = (const float*)_pos;
|
|
|
|
lineTo(pos[0], pos[1], pos[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lineTo(Axis::Enum _axis, float _x, float _y)
|
|
|
|
{
|
|
|
|
float pos[3];
|
|
|
|
getPoint(pos, _axis, _x, _y);
|
|
|
|
lineTo(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void close()
|
|
|
|
{
|
|
|
|
BX_CHECK(State::Count != m_state);
|
|
|
|
DebugVertex& vertex = m_cache[m_vertexPos];
|
|
|
|
lineTo(vertex.m_x, vertex.m_y, vertex.m_z);
|
|
|
|
|
|
|
|
m_state = State::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw(const Aabb& _aabb)
|
|
|
|
{
|
2017-09-29 07:50:11 +03:00
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
if (attrib.m_wireframe)
|
|
|
|
{
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_min.z);
|
2017-09-29 07:50:11 +03:00
|
|
|
close();
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_max.z);
|
|
|
|
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_max.z);
|
|
|
|
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_max.z);
|
|
|
|
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_max.z);
|
2017-09-29 07:50:11 +03:00
|
|
|
close();
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_max.z);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_max.z);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_max.z);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_min.z);
|
|
|
|
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_max.z);
|
2017-09-29 07:50:11 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Obb obb;
|
|
|
|
aabbToObb(obb, _aabb);
|
|
|
|
draw(Mesh::Cube, obb.m_mtx, 1, false);
|
|
|
|
}
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw(const Cylinder& _cylinder, bool _capsule)
|
|
|
|
{
|
2018-11-14 09:38:41 +03:00
|
|
|
drawCylinder(&_cylinder.m_pos.x, &_cylinder.m_end.x, _cylinder.m_radius, _capsule);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw(const Disk& _disk)
|
|
|
|
{
|
2018-11-14 09:38:41 +03:00
|
|
|
drawCircle(&_disk.m_normal.x, &_disk.m_center.x, _disk.m_radius, 0.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw(const Obb& _obb)
|
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
if (attrib.m_wireframe)
|
|
|
|
{
|
2017-09-13 03:58:36 +03:00
|
|
|
pushTransform(_obb.m_mtx, 1);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
moveTo(-1.0f, -1.0f, -1.0f);
|
|
|
|
lineTo( 1.0f, -1.0f, -1.0f);
|
|
|
|
lineTo( 1.0f, 1.0f, -1.0f);
|
|
|
|
lineTo(-1.0f, 1.0f, -1.0f);
|
|
|
|
close();
|
|
|
|
|
|
|
|
moveTo(-1.0f, 1.0f, 1.0f);
|
|
|
|
lineTo( 1.0f, 1.0f, 1.0f);
|
|
|
|
lineTo( 1.0f, -1.0f, 1.0f);
|
|
|
|
lineTo(-1.0f, -1.0f, 1.0f);
|
|
|
|
close();
|
|
|
|
|
|
|
|
moveTo( 1.0f, -1.0f, -1.0f);
|
|
|
|
lineTo( 1.0f, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
moveTo( 1.0f, 1.0f, -1.0f);
|
|
|
|
lineTo( 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
moveTo(-1.0f, 1.0f, -1.0f);
|
|
|
|
lineTo(-1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
moveTo(-1.0f, -1.0f, -1.0f);
|
|
|
|
lineTo(-1.0f, -1.0f, 1.0f);
|
|
|
|
|
2017-09-13 03:58:36 +03:00
|
|
|
popTransform();
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-15 08:33:37 +03:00
|
|
|
draw(Mesh::Cube, _obb.m_mtx, 1, false);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw(const Sphere& _sphere)
|
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
float mtx[16];
|
|
|
|
bx::mtxSRT(mtx
|
2017-07-24 07:22:21 +03:00
|
|
|
, _sphere.m_radius
|
|
|
|
, _sphere.m_radius
|
|
|
|
, _sphere.m_radius
|
|
|
|
, 0.0f
|
|
|
|
, 0.0f
|
|
|
|
, 0.0f
|
2018-11-14 09:38:41 +03:00
|
|
|
, _sphere.m_center.x
|
|
|
|
, _sphere.m_center.y
|
|
|
|
, _sphere.m_center.z
|
2017-07-24 07:22:21 +03:00
|
|
|
);
|
2016-02-26 09:41:28 +03:00
|
|
|
uint8_t lod = attrib.m_lod > Mesh::SphereMaxLod
|
2018-01-11 11:14:36 +03:00
|
|
|
? uint8_t(Mesh::SphereMaxLod)
|
|
|
|
: attrib.m_lod
|
|
|
|
;
|
2016-06-15 08:33:37 +03:00
|
|
|
draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, 1, attrib.m_wireframe);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 11:14:36 +03:00
|
|
|
void setUParams(const Attrib& _attrib, bool _wireframe)
|
|
|
|
{
|
|
|
|
const float flip = 0 == (_attrib.m_state & BGFX_STATE_CULL_CCW) ? 1.0f : -1.0f;
|
|
|
|
const uint8_t alpha = _attrib.m_abgr >> 24;
|
|
|
|
|
|
|
|
float params[4][4] =
|
|
|
|
{
|
|
|
|
{ // lightDir
|
|
|
|
0.0f * flip,
|
|
|
|
-1.0f * flip,
|
|
|
|
0.0f * flip,
|
|
|
|
3.0f, // shininess
|
|
|
|
},
|
|
|
|
{ // skyColor
|
|
|
|
1.0f,
|
|
|
|
0.9f,
|
|
|
|
0.8f,
|
|
|
|
0.0f, // unused
|
|
|
|
},
|
|
|
|
{ // groundColor.xyz0
|
|
|
|
0.2f,
|
|
|
|
0.22f,
|
|
|
|
0.5f,
|
|
|
|
0.0f, // unused
|
|
|
|
},
|
|
|
|
{ // matColor
|
|
|
|
( (_attrib.m_abgr) & 0xff) / 255.0f,
|
|
|
|
( (_attrib.m_abgr >> 8) & 0xff) / 255.0f,
|
|
|
|
( (_attrib.m_abgr >> 16) & 0xff) / 255.0f,
|
|
|
|
(alpha) / 255.0f,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
bx::vec3Norm(params[0], params[0]);
|
2018-04-12 03:26:55 +03:00
|
|
|
m_encoder->setUniform(s_dds.u_params, params, 4);
|
2018-01-11 11:14:36 +03:00
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setState(0
|
2018-01-11 11:14:36 +03:00
|
|
|
| _attrib.m_state
|
|
|
|
| (_wireframe ? BGFX_STATE_PT_LINES | BGFX_STATE_LINEAA | BGFX_STATE_BLEND_ALPHA
|
|
|
|
: (alpha < 0xff) ? BGFX_STATE_BLEND_ALPHA : 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw(GeometryHandle _handle)
|
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
const Geometry::Geometry& geometry = s_dds.m_geometry.m_geometry[_handle.idx];
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setVertexBuffer(0, geometry.m_vbh);
|
2018-01-11 11:14:36 +03:00
|
|
|
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
const bool wireframe = attrib.m_wireframe;
|
|
|
|
setUParams(attrib, wireframe);
|
|
|
|
|
|
|
|
if (wireframe)
|
|
|
|
{
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setIndexBuffer(
|
2018-01-11 11:14:36 +03:00
|
|
|
geometry.m_ibh
|
|
|
|
, geometry.m_topologyNumIndices[0]
|
|
|
|
, geometry.m_topologyNumIndices[1]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (0 != geometry.m_topologyNumIndices[0])
|
|
|
|
{
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setIndexBuffer(
|
2018-01-11 11:14:36 +03:00
|
|
|
geometry.m_ibh
|
|
|
|
, 0
|
|
|
|
, geometry.m_topologyNumIndices[0]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setTransform(m_mtxStack[m_mtxStackCurrent].mtx);
|
2018-04-12 03:26:55 +03:00
|
|
|
bgfx::ProgramHandle program = s_dds.m_program[wireframe ? Program::FillMesh : Program::FillLitMesh];
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->submit(m_viewId, program);
|
2018-01-11 11:14:36 +03:00
|
|
|
}
|
|
|
|
|
2018-01-10 04:14:27 +03:00
|
|
|
void draw(bool _lineList, uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices, const uint16_t* _indices)
|
2018-01-09 04:54:15 +03:00
|
|
|
{
|
|
|
|
flush();
|
|
|
|
|
|
|
|
if (_numVertices == bgfx::getAvailTransientVertexBuffer(_numVertices, DebugMeshVertex::ms_decl) )
|
|
|
|
{
|
|
|
|
bgfx::TransientVertexBuffer tvb;
|
|
|
|
bgfx::allocTransientVertexBuffer(&tvb, _numVertices, DebugMeshVertex::ms_decl);
|
|
|
|
bx::memCopy(tvb.data, _vertices, _numVertices * DebugMeshVertex::ms_decl.m_stride);
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setVertexBuffer(0, &tvb);
|
2018-01-09 04:54:15 +03:00
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
const bool wireframe = _lineList || attrib.m_wireframe;
|
|
|
|
setUParams(attrib, wireframe);
|
|
|
|
|
2018-01-09 04:54:15 +03:00
|
|
|
if (0 < _numIndices)
|
|
|
|
{
|
2018-09-05 03:27:35 +03:00
|
|
|
uint32_t numIndices = _numIndices;
|
2018-01-09 04:54:15 +03:00
|
|
|
bgfx::TransientIndexBuffer tib;
|
2018-09-05 03:27:35 +03:00
|
|
|
if (!_lineList && wireframe)
|
|
|
|
{
|
|
|
|
numIndices = bgfx::topologyConvert(
|
|
|
|
bgfx::TopologyConvert::TriListToLineList
|
|
|
|
, NULL
|
|
|
|
, 0
|
|
|
|
, _indices
|
|
|
|
, _numIndices
|
|
|
|
, false
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
|
|
|
bgfx::topologyConvert(
|
|
|
|
bgfx::TopologyConvert::TriListToLineList
|
|
|
|
, tib.data
|
|
|
|
, numIndices * sizeof(uint16_t)
|
|
|
|
, _indices
|
|
|
|
, _numIndices
|
|
|
|
, false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
|
|
|
bx::memCopy(tib.data, _indices, numIndices * sizeof(uint16_t) );
|
|
|
|
}
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setIndexBuffer(&tib);
|
2018-01-09 04:54:15 +03:00
|
|
|
}
|
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setTransform(m_mtxStack[m_mtxStackCurrent].mtx);
|
2018-04-12 03:26:55 +03:00
|
|
|
bgfx::ProgramHandle program = s_dds.m_program[wireframe ? Program::FillMesh : Program::FillLitMesh];
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->submit(m_viewId, program);
|
2018-01-09 04:54:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-03 10:09:45 +03:00
|
|
|
void drawFrustum(const float* _viewProj)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
Plane planes[6];
|
|
|
|
buildFrustumPlanes(planes, _viewProj);
|
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
bx::Vec3 points[8];
|
|
|
|
points[0] = intersectPlanes(planes[0], planes[2], planes[4]);
|
|
|
|
points[1] = intersectPlanes(planes[0], planes[3], planes[4]);
|
|
|
|
points[2] = intersectPlanes(planes[0], planes[3], planes[5]);
|
|
|
|
points[3] = intersectPlanes(planes[0], planes[2], planes[5]);
|
|
|
|
points[4] = intersectPlanes(planes[1], planes[2], planes[4]);
|
|
|
|
points[5] = intersectPlanes(planes[1], planes[3], planes[4]);
|
|
|
|
points[6] = intersectPlanes(planes[1], planes[3], planes[5]);
|
|
|
|
points[7] = intersectPlanes(planes[1], planes[2], planes[5]);
|
|
|
|
|
|
|
|
moveTo(&points[0].x);
|
|
|
|
lineTo(&points[1].x);
|
|
|
|
lineTo(&points[2].x);
|
|
|
|
lineTo(&points[3].x);
|
2016-02-26 09:20:24 +03:00
|
|
|
close();
|
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(&points[4].x);
|
|
|
|
lineTo(&points[5].x);
|
|
|
|
lineTo(&points[6].x);
|
|
|
|
lineTo(&points[7].x);
|
2016-02-26 09:20:24 +03:00
|
|
|
close();
|
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(&points[0].x);
|
|
|
|
lineTo(&points[4].x);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(&points[1].x);
|
|
|
|
lineTo(&points[5].x);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(&points[2].x);
|
|
|
|
lineTo(&points[6].x);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
moveTo(&points[3].x);
|
|
|
|
lineTo(&points[7].x);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
2016-03-03 10:09:45 +03:00
|
|
|
void drawFrustum(const void* _viewProj)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2016-03-03 10:09:45 +03:00
|
|
|
drawFrustum( (const float*)_viewProj);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
|
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
const uint32_t num = getCircleLod(attrib.m_lod);
|
2017-06-10 06:08:52 +03:00
|
|
|
const float step = bx::kPi * 2.0f / num;
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-01-14 02:33:50 +03:00
|
|
|
_degrees = bx::wrap(_degrees, 360.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
float pos[3];
|
|
|
|
getPoint(pos, _axis
|
2018-01-14 02:33:50 +03:00
|
|
|
, bx::sin(step * 0)*_radius
|
|
|
|
, bx::cos(step * 0)*_radius
|
2016-02-26 09:20:24 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
|
|
|
|
|
|
|
|
uint32_t n = uint32_t(num*_degrees/360.0f);
|
|
|
|
|
|
|
|
for (uint32_t ii = 1; ii < n+1; ++ii)
|
|
|
|
{
|
|
|
|
getPoint(pos, _axis
|
2018-01-14 02:33:50 +03:00
|
|
|
, bx::sin(step * ii)*_radius
|
|
|
|
, bx::cos(step * ii)*_radius
|
2017-07-24 07:22:21 +03:00
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
|
|
|
|
}
|
|
|
|
|
|
|
|
moveTo(_x, _y, _z);
|
|
|
|
getPoint(pos, _axis
|
2018-01-14 02:33:50 +03:00
|
|
|
, bx::sin(step * 0)*_radius
|
|
|
|
, bx::cos(step * 0)*_radius
|
2017-07-24 07:22:21 +03:00
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
|
|
|
|
|
|
|
|
getPoint(pos, _axis
|
2018-01-14 02:33:50 +03:00
|
|
|
, bx::sin(step * n)*_radius
|
|
|
|
, bx::cos(step * n)*_radius
|
2017-07-24 07:22:21 +03:00
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
|
|
|
|
lineTo(_x, _y, _z);
|
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCircle(const float* _normal, const float* _center, float _radius, float _weight)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
const uint32_t num = getCircleLod(attrib.m_lod);
|
2017-06-10 06:08:52 +03:00
|
|
|
const float step = bx::kPi * 2.0f / num;
|
2017-12-03 05:15:31 +03:00
|
|
|
_weight = bx::clamp(_weight, 0.0f, 2.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
float udir[3];
|
|
|
|
float vdir[3];
|
2016-12-14 08:58:18 +03:00
|
|
|
bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
float pos[3];
|
2016-03-06 11:07:20 +03:00
|
|
|
float tmp0[3];
|
|
|
|
float tmp1[3];
|
|
|
|
|
|
|
|
float xy0[2];
|
|
|
|
float xy1[2];
|
|
|
|
circle(xy0, 0.0f);
|
|
|
|
squircle(xy1, 0.0f);
|
|
|
|
|
2018-01-14 02:33:50 +03:00
|
|
|
bx::vec3Mul(pos, udir, bx::lerp(xy0[0], xy1[0], _weight)*_radius);
|
|
|
|
bx::vec3Mul(tmp0, vdir, bx::lerp(xy0[1], xy1[1], _weight)*_radius);
|
2016-03-06 11:07:20 +03:00
|
|
|
bx::vec3Add(tmp1, pos, tmp0);
|
|
|
|
bx::vec3Add(pos, tmp1, _center);
|
2016-02-26 09:20:24 +03:00
|
|
|
moveTo(pos);
|
|
|
|
|
|
|
|
for (uint32_t ii = 1; ii < num; ++ii)
|
|
|
|
{
|
2016-03-06 11:07:20 +03:00
|
|
|
float angle = step * ii;
|
|
|
|
circle(xy0, angle);
|
|
|
|
squircle(xy1, angle);
|
|
|
|
|
2018-01-14 02:33:50 +03:00
|
|
|
bx::vec3Mul(pos, udir, bx::lerp(xy0[0], xy1[0], _weight)*_radius);
|
|
|
|
bx::vec3Mul(tmp0, vdir, bx::lerp(xy0[1], xy1[1], _weight)*_radius);
|
2016-02-26 09:20:24 +03:00
|
|
|
bx::vec3Add(tmp1, pos, tmp0);
|
|
|
|
bx::vec3Add(pos, tmp1, _center);
|
|
|
|
lineTo(pos);
|
|
|
|
}
|
2016-03-06 11:07:20 +03:00
|
|
|
|
|
|
|
close();
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCircle(const void* _normal, const void* _center, float _radius, float _weight)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2016-03-06 11:07:20 +03:00
|
|
|
drawCircle( (const float*)_normal, (const float*)_center, _radius, _weight);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
const uint32_t num = getCircleLod(attrib.m_lod);
|
2017-06-10 06:08:52 +03:00
|
|
|
const float step = bx::kPi * 2.0f / num;
|
2017-12-03 05:15:31 +03:00
|
|
|
_weight = bx::clamp(_weight, 0.0f, 2.0f);
|
2016-03-06 11:07:20 +03:00
|
|
|
|
|
|
|
float xy0[2];
|
|
|
|
float xy1[2];
|
|
|
|
circle(xy0, 0.0f);
|
|
|
|
squircle(xy1, 0.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
float pos[3];
|
|
|
|
getPoint(pos, _axis
|
2018-01-14 02:33:50 +03:00
|
|
|
, bx::lerp(xy0[0], xy1[0], _weight)*_radius
|
|
|
|
, bx::lerp(xy0[1], xy1[1], _weight)*_radius
|
2016-02-26 09:20:24 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
moveTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
|
|
|
|
for (uint32_t ii = 1; ii < num; ++ii)
|
|
|
|
{
|
2016-03-06 11:07:20 +03:00
|
|
|
float angle = step * ii;
|
|
|
|
circle(xy0, angle);
|
|
|
|
squircle(xy1, angle);
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
getPoint(pos, _axis
|
2018-01-14 02:33:50 +03:00
|
|
|
, bx::lerp(xy0[0], xy1[0], _weight)*_radius
|
|
|
|
, bx::lerp(xy0[1], xy1[1], _weight)*_radius
|
2016-03-06 11:07:20 +03:00
|
|
|
);
|
2016-02-26 09:20:24 +03:00
|
|
|
lineTo(pos[0] + _x, pos[1] + _y, pos[2] + _z);
|
|
|
|
}
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2016-12-14 08:58:18 +03:00
|
|
|
void drawQuad(const float* _normal, const float* _center, float _size)
|
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
2018-09-18 03:25:14 +03:00
|
|
|
if (attrib.m_wireframe)
|
|
|
|
{
|
|
|
|
float udir[3];
|
|
|
|
float vdir[3];
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
const float halfExtent = _size*0.5f;
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
float umin[3];
|
|
|
|
bx::vec3Mul(umin, udir, -halfExtent);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
float umax[3];
|
|
|
|
bx::vec3Mul(umax, udir, halfExtent);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
float vmin[3];
|
|
|
|
bx::vec3Mul(vmin, vdir, -halfExtent);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
float vmax[3];
|
|
|
|
bx::vec3Mul(vmax, vdir, halfExtent);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
float pt[3];
|
|
|
|
float tmp[3];
|
|
|
|
bx::vec3Add(tmp, umin, vmin);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
moveTo(pt);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
bx::vec3Add(tmp, umax, vmin);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
lineTo(pt);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
bx::vec3Add(tmp, umax, vmax);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
lineTo(pt);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
bx::vec3Add(tmp, umin, vmax);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
lineTo(pt);
|
2016-12-14 08:58:18 +03:00
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float mtx[16];
|
2018-09-18 06:51:21 +03:00
|
|
|
bx::mtxFromNormal(mtx, _normal, _size*0.5f, _center, attrib.m_spin);
|
2018-09-18 03:25:14 +03:00
|
|
|
draw(Mesh::Quad, mtx, 1, false);
|
|
|
|
}
|
2016-12-14 08:58:18 +03:00
|
|
|
}
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
void drawQuad(SpriteHandle _handle, const float* _normal, const float* _center, float _size)
|
|
|
|
{
|
2018-09-18 06:51:21 +03:00
|
|
|
if (!isValid(_handle) )
|
|
|
|
{
|
|
|
|
drawQuad(_normal, _center, _size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
if (m_posQuad == BX_COUNTOF(m_cacheQuad) )
|
|
|
|
{
|
|
|
|
flushQuad();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
|
|
|
float udir[3];
|
|
|
|
float vdir[3];
|
|
|
|
|
|
|
|
bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
const Pack2D& pack = s_dds.m_sprite.get(_handle);
|
2016-12-21 08:20:55 +03:00
|
|
|
const float invTextureSize = 1.0f/SPRITE_TEXTURE_SIZE;
|
|
|
|
const float us = pack.m_x * invTextureSize;
|
|
|
|
const float vs = pack.m_y * invTextureSize;
|
|
|
|
const float ue = (pack.m_x + pack.m_width ) * invTextureSize;
|
|
|
|
const float ve = (pack.m_y + pack.m_height) * invTextureSize;
|
|
|
|
|
|
|
|
const float aspectRatio = float(pack.m_width)/float(pack.m_height);
|
|
|
|
const float halfExtentU = aspectRatio*_size*0.5f;
|
|
|
|
const float halfExtentV = 1.0f/aspectRatio*_size*0.5f;
|
|
|
|
|
|
|
|
float umin[3];
|
|
|
|
bx::vec3Mul(umin, udir, -halfExtentU);
|
|
|
|
|
|
|
|
float umax[3];
|
|
|
|
bx::vec3Mul(umax, udir, halfExtentU);
|
|
|
|
|
|
|
|
float vmin[3];
|
|
|
|
bx::vec3Mul(vmin, vdir, -halfExtentV);
|
|
|
|
|
|
|
|
float vmax[3];
|
|
|
|
bx::vec3Mul(vmax, vdir, halfExtentV);
|
|
|
|
|
|
|
|
DebugUvVertex* vertex = &m_cacheQuad[m_posQuad];
|
|
|
|
m_posQuad += 4;
|
|
|
|
|
|
|
|
float pt[3];
|
|
|
|
float tmp[3];
|
|
|
|
bx::vec3Add(tmp, umin, vmin);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
vertex->m_x = pt[0];
|
|
|
|
vertex->m_y = pt[1];
|
|
|
|
vertex->m_z = pt[2];
|
|
|
|
vertex->m_u = us;
|
|
|
|
vertex->m_v = vs;
|
|
|
|
vertex->m_abgr = attrib.m_abgr;
|
|
|
|
++vertex;
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umax, vmin);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
vertex->m_x = pt[0];
|
|
|
|
vertex->m_y = pt[1];
|
|
|
|
vertex->m_z = pt[2];
|
|
|
|
vertex->m_u = ue;
|
|
|
|
vertex->m_v = vs;
|
|
|
|
vertex->m_abgr = attrib.m_abgr;
|
|
|
|
++vertex;
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umin, vmax);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
vertex->m_x = pt[0];
|
|
|
|
vertex->m_y = pt[1];
|
|
|
|
vertex->m_z = pt[2];
|
|
|
|
vertex->m_u = us;
|
|
|
|
vertex->m_v = ve;
|
|
|
|
vertex->m_abgr = attrib.m_abgr;
|
|
|
|
++vertex;
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umax, vmax);
|
|
|
|
bx::vec3Add(pt, _center, tmp);
|
|
|
|
vertex->m_x = pt[0];
|
|
|
|
vertex->m_y = pt[1];
|
|
|
|
vertex->m_z = pt[2];
|
|
|
|
vertex->m_u = ue;
|
|
|
|
vertex->m_v = ve;
|
|
|
|
vertex->m_abgr = attrib.m_abgr;
|
|
|
|
++vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawQuad(bgfx::TextureHandle _handle, const float* _normal, const float* _center, float _size)
|
|
|
|
{
|
|
|
|
BX_UNUSED(_handle, _normal, _center, _size);
|
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCone(const float* _from, const float* _to, float _radius)
|
2016-04-06 03:10:48 +03:00
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
|
|
|
float tmp0[3];
|
|
|
|
bx::vec3Sub(tmp0, _from, _to);
|
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
float normal[3];
|
|
|
|
bx::vec3Norm(normal, tmp0);
|
2016-04-06 03:10:48 +03:00
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
float mtx[2][16];
|
2016-12-14 08:58:18 +03:00
|
|
|
bx::mtxFromNormal(mtx[0], normal, _radius, _from, attrib.m_spin);
|
2016-04-06 03:10:48 +03:00
|
|
|
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(mtx[1], mtx[0], 64);
|
2016-06-15 08:33:37 +03:00
|
|
|
mtx[1][12] = _to[0];
|
|
|
|
mtx[1][13] = _to[1];
|
|
|
|
mtx[1][14] = _to[2];
|
2016-04-06 03:10:48 +03:00
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
uint8_t lod = attrib.m_lod > Mesh::ConeMaxLod
|
|
|
|
? uint8_t(Mesh::ConeMaxLod)
|
|
|
|
: attrib.m_lod
|
|
|
|
;
|
|
|
|
draw(Mesh::Enum(Mesh::Cone0 + lod), mtx[0], 2, attrib.m_wireframe);
|
2016-04-06 03:10:48 +03:00
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCone(const void* _from, const void* _to, float _radius)
|
2016-04-06 03:10:48 +03:00
|
|
|
{
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCone( (const float*)_from, (const float*)_to, _radius);
|
2016-04-06 03:10:48 +03:00
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCylinder(const float* _from, const float* _to, float _radius, bool _capsule)
|
2016-04-07 08:21:46 +03:00
|
|
|
{
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
float tmp0[3];
|
2016-04-07 08:21:46 +03:00
|
|
|
bx::vec3Sub(tmp0, _from, _to);
|
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
float normal[3];
|
|
|
|
bx::vec3Norm(normal, tmp0);
|
2016-04-07 08:21:46 +03:00
|
|
|
|
2016-06-15 08:33:37 +03:00
|
|
|
float mtx[2][16];
|
2016-12-14 08:58:18 +03:00
|
|
|
bx::mtxFromNormal(mtx[0], normal, _radius, _from, attrib.m_spin);
|
2016-04-07 08:21:46 +03:00
|
|
|
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(mtx[1], mtx[0], 64);
|
2016-06-15 08:33:37 +03:00
|
|
|
mtx[1][12] = _to[0];
|
|
|
|
mtx[1][13] = _to[1];
|
|
|
|
mtx[1][14] = _to[2];
|
2016-04-07 08:21:46 +03:00
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
if (_capsule)
|
|
|
|
{
|
|
|
|
uint8_t lod = attrib.m_lod > Mesh::CapsuleMaxLod
|
2018-01-11 11:14:36 +03:00
|
|
|
? uint8_t(Mesh::CapsuleMaxLod)
|
|
|
|
: attrib.m_lod
|
|
|
|
;
|
2016-06-20 08:00:24 +03:00
|
|
|
draw(Mesh::Enum(Mesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
|
|
|
|
|
|
|
|
Sphere sphere;
|
2018-11-14 09:38:41 +03:00
|
|
|
sphere.m_center.x = _from[0];
|
|
|
|
sphere.m_center.y = _from[1];
|
|
|
|
sphere.m_center.z = _from[2];
|
|
|
|
sphere.m_radius = _radius;
|
2016-06-20 08:00:24 +03:00
|
|
|
draw(sphere);
|
|
|
|
|
2018-11-14 09:38:41 +03:00
|
|
|
sphere.m_center.x = _to[0];
|
|
|
|
sphere.m_center.y = _to[1];
|
|
|
|
sphere.m_center.z = _to[2];
|
2016-06-20 08:00:24 +03:00
|
|
|
draw(sphere);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint8_t lod = attrib.m_lod > Mesh::CylinderMaxLod
|
2018-01-11 11:14:36 +03:00
|
|
|
? uint8_t(Mesh::CylinderMaxLod)
|
|
|
|
: attrib.m_lod
|
|
|
|
;
|
2018-09-05 03:27:35 +03:00
|
|
|
draw(Mesh::Enum(Mesh::Cylinder0 + lod), mtx[0], 2, attrib.m_wireframe);
|
2016-06-20 08:00:24 +03:00
|
|
|
}
|
2016-04-07 08:21:46 +03:00
|
|
|
}
|
|
|
|
|
2016-06-20 08:00:24 +03:00
|
|
|
void drawCylinder(const void* _from, const void* _to, float _radius, bool _capsule)
|
2016-04-07 08:21:46 +03:00
|
|
|
{
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCylinder( (const float*)_from, (const float*)_to, _radius, _capsule);
|
2016-04-07 08:21:46 +03:00
|
|
|
}
|
|
|
|
|
2016-06-16 06:28:54 +03:00
|
|
|
void drawAxis(float _x, float _y, float _z, float _len, Axis::Enum _highlight, float _thickness)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
push();
|
|
|
|
|
2016-06-16 06:28:54 +03:00
|
|
|
if (_thickness > 0.0f)
|
|
|
|
{
|
|
|
|
float from[3] = { _x, _y, _z };
|
|
|
|
float mid[3];
|
|
|
|
float to[3];
|
|
|
|
|
|
|
|
setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff);
|
|
|
|
mid[0] = _x + _len - _thickness;
|
|
|
|
mid[1] = _y;
|
|
|
|
mid[2] = _z;
|
2017-07-24 07:22:21 +03:00
|
|
|
to[0] = _x + _len;
|
|
|
|
to[1] = _y;
|
|
|
|
to[2] = _z;
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCylinder(from, mid, _thickness, false);
|
2016-06-16 06:28:54 +03:00
|
|
|
drawCone(mid, to, _thickness);
|
|
|
|
|
|
|
|
setColor(Axis::Y == _highlight ? 0xff00ffff : 0xff00ff00);
|
|
|
|
mid[0] = _x;
|
|
|
|
mid[1] = _y + _len - _thickness;
|
|
|
|
mid[2] = _z;
|
2017-07-24 07:22:21 +03:00
|
|
|
to[0] = _x;
|
|
|
|
to[1] = _y + _len;
|
|
|
|
to[2] = _z;
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCylinder(from, mid, _thickness, false);
|
2016-06-16 06:28:54 +03:00
|
|
|
drawCone(mid, to, _thickness);
|
|
|
|
|
|
|
|
setColor(Axis::Z == _highlight ? 0xff00ffff : 0xffff0000);
|
|
|
|
mid[0] = _x;
|
|
|
|
mid[1] = _y;
|
|
|
|
mid[2] = _z + _len - _thickness;
|
2017-07-24 07:22:21 +03:00
|
|
|
to[0] = _x;
|
|
|
|
to[1] = _y;
|
|
|
|
to[2] = _z + _len;
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCylinder(from, mid, _thickness, false);
|
2016-06-16 06:28:54 +03:00
|
|
|
drawCone(mid, to, _thickness);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff);
|
|
|
|
moveTo(_x, _y, _z);
|
|
|
|
lineTo(_x + _len, _y, _z);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2016-06-16 06:28:54 +03:00
|
|
|
setColor(Axis::Y == _highlight ? 0xff00ffff : 0xff00ff00);
|
|
|
|
moveTo(_x, _y, _z);
|
|
|
|
lineTo(_x, _y + _len, _z);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2016-06-16 06:28:54 +03:00
|
|
|
setColor(Axis::Z == _highlight ? 0xff00ffff : 0xffff0000);
|
|
|
|
moveTo(_x, _y, _z);
|
|
|
|
lineTo(_x, _y, _z + _len);
|
|
|
|
}
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGrid(const float* _normal, const float* _center, uint32_t _size, float _step)
|
|
|
|
{
|
2016-12-14 08:58:18 +03:00
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
float udir[3];
|
|
|
|
float vdir[3];
|
2016-12-14 08:58:18 +03:00
|
|
|
bx::vec3TangentFrame(_normal, udir, vdir, attrib.m_spin);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
bx::vec3Mul(udir, udir, _step);
|
|
|
|
bx::vec3Mul(vdir, vdir, _step);
|
|
|
|
|
|
|
|
const uint32_t num = (_size/2)*2+1;
|
|
|
|
const float halfExtent = float(_size/2);
|
|
|
|
|
|
|
|
float umin[3];
|
|
|
|
bx::vec3Mul(umin, udir, -halfExtent);
|
|
|
|
|
|
|
|
float umax[3];
|
|
|
|
bx::vec3Mul(umax, udir, halfExtent);
|
|
|
|
|
|
|
|
float vmin[3];
|
|
|
|
bx::vec3Mul(vmin, vdir, -halfExtent);
|
|
|
|
|
|
|
|
float vmax[3];
|
|
|
|
bx::vec3Mul(vmax, vdir, halfExtent);
|
|
|
|
|
|
|
|
float tmp[3];
|
|
|
|
|
|
|
|
float xs[3];
|
|
|
|
float xe[3];
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umin, vmin);
|
|
|
|
bx::vec3Add(xs, _center, tmp);
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umax, vmin);
|
|
|
|
bx::vec3Add(xe, _center, tmp);
|
|
|
|
|
|
|
|
float ys[3];
|
|
|
|
float ye[3];
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umin, vmin);
|
|
|
|
bx::vec3Add(ys, _center, tmp);
|
|
|
|
|
|
|
|
bx::vec3Add(tmp, umin, vmax);
|
|
|
|
bx::vec3Add(ye, _center, tmp);
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
moveTo(xs);
|
|
|
|
lineTo(xe);
|
|
|
|
bx::vec3Add(xs, xs, vdir);
|
|
|
|
bx::vec3Add(xe, xe, vdir);
|
|
|
|
|
|
|
|
moveTo(ys);
|
|
|
|
lineTo(ye);
|
|
|
|
bx::vec3Add(ys, ys, udir);
|
|
|
|
bx::vec3Add(ye, ye, udir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGrid(const void* _normal, const void* _center, uint32_t _size, float _step)
|
|
|
|
{
|
|
|
|
drawGrid( (const float*)_normal, (const float*)_center, _size, _step);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGrid(Axis::Enum _axis, const float* _center, uint32_t _size, float _step)
|
|
|
|
{
|
|
|
|
push();
|
2017-09-13 03:58:36 +03:00
|
|
|
pushTranslate(_center);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
const uint32_t num = (_size/2)*2-1;
|
|
|
|
const float halfExtent = float(_size/2) * _step;
|
|
|
|
|
|
|
|
setColor(0xff606060);
|
|
|
|
float yy = -halfExtent + _step;
|
|
|
|
for (uint32_t ii = 0; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
moveTo(_axis, -halfExtent, yy);
|
|
|
|
lineTo(_axis, halfExtent, yy);
|
|
|
|
|
|
|
|
moveTo(_axis, yy, -halfExtent);
|
|
|
|
lineTo(_axis, yy, halfExtent);
|
|
|
|
|
|
|
|
yy += _step;
|
|
|
|
}
|
|
|
|
|
|
|
|
setColor(0xff101010);
|
|
|
|
moveTo(_axis, -halfExtent, -halfExtent);
|
|
|
|
lineTo(_axis, -halfExtent, halfExtent);
|
|
|
|
lineTo(_axis, halfExtent, halfExtent);
|
|
|
|
lineTo(_axis, halfExtent, -halfExtent);
|
|
|
|
close();
|
|
|
|
|
|
|
|
moveTo(_axis, -halfExtent, 0.0f);
|
|
|
|
lineTo(_axis, halfExtent, 0.0f);
|
|
|
|
|
|
|
|
moveTo(_axis, 0.0f, -halfExtent);
|
|
|
|
lineTo(_axis, 0.0f, halfExtent);
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
popTransform();
|
2016-02-26 09:20:24 +03:00
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGrid(Axis::Enum _axis, const void* _center, uint32_t _size, float _step)
|
|
|
|
{
|
|
|
|
drawGrid(_axis, (const float*)_center, _size, _step);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _hightlight)
|
|
|
|
{
|
|
|
|
push();
|
|
|
|
|
|
|
|
setColor(Axis::X == _hightlight ? 0xff00ffff : 0xff0000ff);
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCircle(Axis::X, _x, _y, _z, _radius, 0.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
setColor(Axis::Y == _hightlight ? 0xff00ffff : 0xff00ff00);
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCircle(Axis::Y, _x, _y, _z, _radius, 0.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
setColor(Axis::Z == _hightlight ? 0xff00ffff : 0xffff0000);
|
2016-06-20 08:00:24 +03:00
|
|
|
drawCircle(Axis::Z, _x, _y, _z, _radius, 0.0f);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
2017-09-13 03:58:36 +03:00
|
|
|
void draw(Mesh::Enum _mesh, const float* _mtx, uint16_t _num, bool _wireframe)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2018-09-05 03:27:35 +03:00
|
|
|
pushTransform(_mtx, _num, false /* flush */);
|
2017-09-13 03:58:36 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
const Mesh& mesh = s_dds.m_mesh[_mesh];
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
if (0 != mesh.m_numIndices[_wireframe])
|
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
m_encoder->setIndexBuffer(s_dds.m_ibh
|
2016-02-26 09:20:24 +03:00
|
|
|
, mesh.m_startIndex[_wireframe]
|
|
|
|
, mesh.m_numIndices[_wireframe]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-11 11:14:36 +03:00
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
setUParams(attrib, _wireframe);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2017-09-13 03:58:36 +03:00
|
|
|
MatrixStack& stack = m_mtxStack[m_mtxStackCurrent];
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setTransform(stack.mtx, stack.num);
|
2017-09-13 03:58:36 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
m_encoder->setVertexBuffer(0, s_dds.m_vbh, mesh.m_startVertex, mesh.m_numVertices);
|
|
|
|
m_encoder->submit(m_viewId, s_dds.m_program[_wireframe ? Program::Fill : Program::FillLit]);
|
2017-09-13 03:58:36 +03:00
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
popTransform(false /* flush */);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void softFlush()
|
|
|
|
{
|
|
|
|
if (m_pos == uint16_t(BX_COUNTOF(m_cache) ) )
|
|
|
|
{
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush()
|
|
|
|
{
|
|
|
|
if (0 != m_pos)
|
|
|
|
{
|
2016-12-23 03:18:44 +03:00
|
|
|
if (checkAvailTransientBuffers(m_pos, DebugVertex::ms_decl, m_indexPos) )
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
|
|
|
bgfx::TransientVertexBuffer tvb;
|
|
|
|
bgfx::allocTransientVertexBuffer(&tvb, m_pos, DebugVertex::ms_decl);
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(tvb.data, m_cache, m_pos * DebugVertex::ms_decl.m_stride);
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
bgfx::TransientIndexBuffer tib;
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, m_indexPos);
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(tib.data, m_indices, m_indexPos * sizeof(uint16_t) );
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2016-04-06 03:40:03 +03:00
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setVertexBuffer(0, &tvb);
|
|
|
|
m_encoder->setIndexBuffer(&tib);
|
|
|
|
m_encoder->setState(0
|
2018-02-13 23:35:23 +03:00
|
|
|
| BGFX_STATE_WRITE_RGB
|
2017-07-24 07:22:21 +03:00
|
|
|
| BGFX_STATE_PT_LINES
|
|
|
|
| attrib.m_state
|
|
|
|
| BGFX_STATE_LINEAA
|
|
|
|
| BGFX_STATE_BLEND_ALPHA
|
|
|
|
);
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setTransform(m_mtxStack[m_mtxStackCurrent].mtx);
|
2018-04-12 03:26:55 +03:00
|
|
|
bgfx::ProgramHandle program = s_dds.m_program[attrib.m_stipple ? 1 : 0];
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->submit(m_viewId, program);
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_state = State::None;
|
|
|
|
m_pos = 0;
|
|
|
|
m_indexPos = 0;
|
|
|
|
m_vertexPos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
void flushQuad()
|
|
|
|
{
|
|
|
|
if (0 != m_posQuad)
|
|
|
|
{
|
|
|
|
const uint32_t numIndices = m_posQuad/4*6;
|
2016-12-23 03:18:44 +03:00
|
|
|
if (checkAvailTransientBuffers(m_posQuad, DebugUvVertex::ms_decl, numIndices) )
|
2016-12-21 08:20:55 +03:00
|
|
|
{
|
|
|
|
bgfx::TransientVertexBuffer tvb;
|
|
|
|
bgfx::allocTransientVertexBuffer(&tvb, m_posQuad, DebugUvVertex::ms_decl);
|
2017-02-07 03:22:08 +03:00
|
|
|
bx::memCopy(tvb.data, m_cacheQuad, m_posQuad * DebugUvVertex::ms_decl.m_stride);
|
2016-12-21 08:20:55 +03:00
|
|
|
|
|
|
|
bgfx::TransientIndexBuffer tib;
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
|
|
|
uint16_t* indices = (uint16_t*)tib.data;
|
|
|
|
for (uint16_t ii = 0, num = m_posQuad/4; ii < num; ++ii)
|
|
|
|
{
|
|
|
|
uint16_t startVertex = ii*4;
|
|
|
|
indices[0] = startVertex+0;
|
|
|
|
indices[1] = startVertex+1;
|
|
|
|
indices[2] = startVertex+2;
|
|
|
|
indices[3] = startVertex+1;
|
|
|
|
indices[4] = startVertex+3;
|
|
|
|
indices[5] = startVertex+2;
|
|
|
|
indices += 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Attrib& attrib = m_attrib[m_stack];
|
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setVertexBuffer(0, &tvb);
|
|
|
|
m_encoder->setIndexBuffer(&tib);
|
|
|
|
m_encoder->setState(0
|
2017-07-24 07:22:21 +03:00
|
|
|
| (attrib.m_state & ~BGFX_STATE_CULL_MASK)
|
|
|
|
);
|
2018-04-11 03:15:24 +03:00
|
|
|
m_encoder->setTransform(m_mtxStack[m_mtxStackCurrent].mtx);
|
2018-04-12 03:26:55 +03:00
|
|
|
m_encoder->setTexture(0, s_dds.s_texColor, s_dds.m_texture);
|
|
|
|
m_encoder->submit(m_viewId, s_dds.m_program[Program::FillTexture]);
|
2016-12-21 08:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
m_posQuad = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-26 09:20:24 +03:00
|
|
|
struct State
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
MoveTo,
|
|
|
|
LineTo,
|
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
static const uint32_t kCacheSize = 1024;
|
|
|
|
static const uint32_t kStackSize = 16;
|
|
|
|
static const uint32_t kCacheQuadSize = 1024;
|
|
|
|
BX_STATIC_ASSERT(kCacheSize >= 3, "Cache must be at least 3 elements.");
|
|
|
|
|
|
|
|
DebugVertex m_cache[kCacheSize+1];
|
|
|
|
DebugUvVertex m_cacheQuad[kCacheQuadSize];
|
|
|
|
uint16_t m_indices[kCacheSize*2];
|
2016-02-26 09:20:24 +03:00
|
|
|
uint16_t m_pos;
|
2018-04-12 03:26:55 +03:00
|
|
|
uint16_t m_posQuad;
|
2016-02-26 09:20:24 +03:00
|
|
|
uint16_t m_indexPos;
|
|
|
|
uint16_t m_vertexPos;
|
2017-09-13 03:58:36 +03:00
|
|
|
uint32_t m_mtxStackCurrent;
|
|
|
|
|
|
|
|
struct MatrixStack
|
|
|
|
{
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
mtx = 0;
|
|
|
|
num = 1;
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t mtx;
|
|
|
|
uint16_t num;
|
|
|
|
float* data;
|
|
|
|
};
|
|
|
|
|
|
|
|
MatrixStack m_mtxStack[32];
|
|
|
|
|
2018-01-18 04:34:20 +03:00
|
|
|
bgfx::ViewId m_viewId;
|
|
|
|
uint8_t m_stack;
|
|
|
|
bool m_depthTestLess;
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
Attrib m_attrib[kStackSize];
|
2016-02-26 09:20:24 +03:00
|
|
|
|
|
|
|
State::Enum m_state;
|
|
|
|
|
2018-04-11 03:15:24 +03:00
|
|
|
bgfx::Encoder* m_encoder;
|
|
|
|
bgfx::Encoder* m_defaultEncoder;
|
2016-02-26 09:20:24 +03:00
|
|
|
};
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
static DebugDrawEncoderImpl s_dde;
|
|
|
|
BX_STATIC_ASSERT(sizeof(DebugDrawEncoderImpl) <= sizeof(DebugDrawEncoder), "Size must match");
|
2016-02-26 09:20:24 +03:00
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
void ddInit(bx::AllocatorI* _allocator)
|
2016-02-26 09:20:24 +03:00
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
s_dds.init(_allocator);
|
2018-04-17 03:58:17 +03:00
|
|
|
s_dde.init(bgfx::begin() );
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ddShutdown()
|
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
s_dde.shutdown();
|
|
|
|
s_dds.shutdown();
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|
|
|
|
|
2016-12-21 08:20:55 +03:00
|
|
|
SpriteHandle ddCreateSprite(uint16_t _width, uint16_t _height, const void* _data)
|
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
return s_dds.createSprite(_width, _height, _data);
|
2016-12-21 08:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ddDestroy(SpriteHandle _handle)
|
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
s_dds.destroy(_handle);
|
2016-12-21 08:20:55 +03:00
|
|
|
}
|
|
|
|
|
2018-09-05 03:27:35 +03:00
|
|
|
GeometryHandle ddCreateGeometry(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices, const void* _indices, bool _index32)
|
2018-01-11 11:14:36 +03:00
|
|
|
{
|
2018-09-05 03:27:35 +03:00
|
|
|
return s_dds.createGeometry(_numVertices, _vertices, _numIndices, _indices, _index32);
|
2018-01-11 11:14:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ddDestroy(GeometryHandle _handle)
|
|
|
|
{
|
2018-04-12 03:26:55 +03:00
|
|
|
s_dds.destroy(_handle);
|
2018-01-11 11:14:36 +03:00
|
|
|
}
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
#define DEBUG_DRAW_ENCODER(_func) reinterpret_cast<DebugDrawEncoderImpl*>(this)->_func
|
|
|
|
|
|
|
|
DebugDrawEncoder::DebugDrawEncoder()
|
|
|
|
{
|
2018-04-17 03:58:17 +03:00
|
|
|
DEBUG_DRAW_ENCODER(init(s_dde.m_defaultEncoder) );
|
2018-04-12 03:26:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DebugDrawEncoder::~DebugDrawEncoder()
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(shutdown() );
|
|
|
|
}
|
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
void DebugDrawEncoder::begin(uint16_t _viewId, bool _depthTestLess, bgfx::Encoder* _encoder)
|
2018-04-12 03:26:55 +03:00
|
|
|
{
|
2018-04-17 03:58:17 +03:00
|
|
|
DEBUG_DRAW_ENCODER(begin(_viewId, _depthTestLess, _encoder) );
|
2018-04-12 03:26:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::end()
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::push()
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(push() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::pop()
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(pop() );
|
|
|
|
}
|
|
|
|
|
2018-04-17 03:58:17 +03:00
|
|
|
void DebugDrawEncoder::setDepthTestLess(bool _depthTestLess)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setDepthTestLess(_depthTestLess) );
|
|
|
|
}
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
void DebugDrawEncoder::setState(bool _depthTest, bool _depthWrite, bool _clockwise)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setState(_depthTest, _depthWrite, _clockwise) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setColor(uint32_t _abgr)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setColor(_abgr) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setLod(uint8_t _lod)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setLod(_lod) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setWireframe(bool _wireframe)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setWireframe(_wireframe) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setStipple(bool _stipple, float _scale, float _offset)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setStipple(_stipple, _scale, _offset) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setSpin(float _spin)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setSpin(_spin) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setTransform(const void* _mtx)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setTransform(_mtx) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::setTranslate(float _x, float _y, float _z)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(setTranslate(_x, _y, _z) );
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:25:14 +03:00
|
|
|
void DebugDrawEncoder::pushTransform(const void* _mtx)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(pushTransform(_mtx, 1) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::popTransform()
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(popTransform() );
|
|
|
|
}
|
|
|
|
|
2018-04-12 03:26:55 +03:00
|
|
|
void DebugDrawEncoder::moveTo(float _x, float _y, float _z)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(moveTo(_x, _y, _z) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::moveTo(const void* _pos)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(moveTo(_pos) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::lineTo(float _x, float _y, float _z)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(lineTo(_x, _y, _z) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::lineTo(const void* _pos)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(lineTo(_pos) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::close()
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(close() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Aabb& _aabb)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(_aabb) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Cylinder& _cylinder)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(_cylinder, false) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Capsule& _capsule)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(*( (const Cylinder*)&_capsule), true) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Disk& _disk)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(_disk) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Obb& _obb)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(_obb) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Sphere& _sphere)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(_sphere) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(const Cone& _cone)
|
|
|
|
{
|
2018-11-14 09:38:41 +03:00
|
|
|
DEBUG_DRAW_ENCODER(drawCone(&_cone.m_pos.x, &_cone.m_end.x, _cone.m_radius) );
|
2018-04-12 03:26:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::draw(GeometryHandle _handle)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(_handle) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawLineList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices, const uint16_t* _indices)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(true, _numVertices, _vertices, _numIndices, _indices) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawTriList(uint32_t _numVertices, const DdVertex* _vertices, uint32_t _numIndices, const uint16_t* _indices)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(draw(false, _numVertices, _vertices, _numIndices, _indices) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawFrustum(const void* _viewProj)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawFrustum(_viewProj) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawArc(_axis, _x, _y, _z, _radius, _degrees) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawCircle(const void* _normal, const void* _center, float _radius, float _weight)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawCircle(_normal, _center, _radius, _weight) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawCircle(_axis, _x, _y, _z, _radius, _weight) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawQuad(const float* _normal, const float* _center, float _size)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawQuad(_normal, _center, _size) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawQuad(SpriteHandle _handle, const float* _normal, const float* _center, float _size)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawQuad(_handle, _normal, _center, _size) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawQuad(bgfx::TextureHandle _handle, const float* _normal, const float* _center, float _size)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawQuad(_handle, _normal, _center, _size) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawCone(const void* _from, const void* _to, float _radius)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawCone(_from, _to, _radius) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawCylinder(const void* _from, const void* _to, float _radius)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawCylinder(_from, _to, _radius, false) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawCapsule(const void* _from, const void* _to, float _radius)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawCylinder(_from, _to, _radius, true) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawAxis(float _x, float _y, float _z, float _len, Axis::Enum _highlight, float _thickness)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawAxis(_x, _y, _z, _len, _highlight, _thickness) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawGrid(const void* _normal, const void* _center, uint32_t _size, float _step)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawGrid(_normal, _center, _size, _step) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawGrid(Axis::Enum _axis, const void* _center, uint32_t _size, float _step)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawGrid(_axis, _center, _size, _step) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugDrawEncoder::drawOrb(float _x, float _y, float _z, float _radius, Axis::Enum _highlight)
|
|
|
|
{
|
|
|
|
DEBUG_DRAW_ENCODER(drawOrb(_x, _y, _z, _radius, _highlight) );
|
2016-02-26 09:20:24 +03:00
|
|
|
}
|