Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed May 14, 2017
1 parent 0c04ae9 commit 52c28fa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
38 changes: 30 additions & 8 deletions examples/01-cubes/cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "common.h"
#include "bgfx_utils.h"

namespace bgfx
{
void setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle, uint32_t _startVertex = 0, uint32_t _numVertices = UINT32_MAX);
}

struct PosColorVertex
{
float m_x;
Expand All @@ -15,17 +20,25 @@ struct PosColorVertex

static void init()
{
ms_decl
ms_decl0
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.skip(4)
.end();

ms_decl1
.begin()
.skip(12)
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
.end();
};

static bgfx::VertexDecl ms_decl;
static bgfx::VertexDecl ms_decl0;
static bgfx::VertexDecl ms_decl1;
};

bgfx::VertexDecl PosColorVertex::ms_decl;
bgfx::VertexDecl PosColorVertex::ms_decl0;
bgfx::VertexDecl PosColorVertex::ms_decl1;

static PosColorVertex s_cubeVertices[] =
{
Expand Down Expand Up @@ -102,10 +115,16 @@ class ExampleCubes : public entry::AppI
PosColorVertex::init();

// Create static vertex buffer.
m_vbh = bgfx::createVertexBuffer(
m_vbh0 = bgfx::createVertexBuffer(
// Static data can be passed with bgfx::makeRef
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
, PosColorVertex::ms_decl0
);

m_vbh1 = bgfx::createVertexBuffer(
// Static data can be passed with bgfx::makeRef
bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) )
, PosColorVertex::ms_decl
, PosColorVertex::ms_decl1
);

// Create static index buffer.
Expand All @@ -124,7 +143,8 @@ class ExampleCubes : public entry::AppI
{
// Cleanup.
bgfx::destroyIndexBuffer(m_ibh);
bgfx::destroyVertexBuffer(m_vbh);
bgfx::destroyVertexBuffer(m_vbh0);
bgfx::destroyVertexBuffer(m_vbh1);
bgfx::destroyProgram(m_program);

// Shutdown bgfx.
Expand Down Expand Up @@ -201,7 +221,8 @@ class ExampleCubes : public entry::AppI
bgfx::setTransform(mtx);

// Set vertex and index buffer.
bgfx::setVertexBuffer(m_vbh);
bgfx::setVertexBuffer(0, m_vbh0);
bgfx::setVertexBuffer(1, m_vbh1);
bgfx::setIndexBuffer(m_ibh);

// Set render states.
Expand Down Expand Up @@ -229,7 +250,8 @@ class ExampleCubes : public entry::AppI
uint32_t m_height;
uint32_t m_debug;
uint32_t m_reset;
bgfx::VertexBufferHandle m_vbh;
bgfx::VertexBufferHandle m_vbh0;
bgfx::VertexBufferHandle m_vbh1;
bgfx::IndexBufferHandle m_ibh;
bgfx::ProgramHandle m_program;
int64_t m_timeOffset;
Expand Down
2 changes: 1 addition & 1 deletion src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,7 +2636,7 @@ namespace bgfx
g_caps.limits.maxTextures = BGFX_CONFIG_MAX_TEXTURES;
g_caps.limits.maxTextureSamplers = BGFX_CONFIG_MAX_TEXTURE_SAMPLERS;
g_caps.limits.maxVertexDecls = BGFX_CONFIG_MAX_VERTEX_DECLS;
g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS;
g_caps.limits.maxVertexStreams = 1;
g_caps.limits.maxIndexBuffers = BGFX_CONFIG_MAX_INDEX_BUFFERS;
g_caps.limits.maxVertexBuffers = BGFX_CONFIG_MAX_VERTEX_BUFFERS;
g_caps.limits.maxDynamicIndexBuffers = BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS;
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
#endif // BGFX_CONFIG_MAX_VERTEX_BUFFERS

#ifndef BGFX_CONFIG_MAX_VERTEX_STREAMS
# define BGFX_CONFIG_MAX_VERTEX_STREAMS 1
# define BGFX_CONFIG_MAX_VERTEX_STREAMS 4
#endif // BGFX_CONFIG_MAX_VERTEX_STREAMS

#ifndef BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS
Expand Down
11 changes: 7 additions & 4 deletions src/renderer_d3d9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ namespace bgfx { namespace d3d9
BX_TRACE("Max fragment shader 3.0 instr. slots: %d", m_caps.MaxPixelShader30InstructionSlots);
BX_TRACE("Num simultaneous render targets: %d", m_caps.NumSimultaneousRTs);
BX_TRACE("Max vertex index: %d", m_caps.MaxVertexIndex);
BX_TRACE("Max streams: %d", m_caps.MaxStreams);

g_caps.supported |= ( 0
| BGFX_CAPS_TEXTURE_3D
Expand All @@ -674,12 +675,14 @@ namespace bgfx { namespace d3d9
| BGFX_CAPS_TEXTURE_READ_BACK
| (m_occlusionQuerySupport ? BGFX_CAPS_OCCLUSION_QUERY : 0)
);
g_caps.limits.maxTextureSize = uint16_t(bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight) );

m_caps.NumSimultaneousRTs = uint8_t(bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) );
g_caps.limits.maxFBAttachments = uint8_t(m_caps.NumSimultaneousRTs);
m_caps.NumSimultaneousRTs = bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS);
m_caps.MaxStreams = bx::uint32_min(m_caps.MaxStreams, BGFX_CONFIG_MAX_VERTEX_STREAMS);
m_caps.MaxAnisotropy = bx::uint32_max(m_caps.MaxAnisotropy, 1);

m_caps.MaxAnisotropy = bx::uint32_max(m_caps.MaxAnisotropy, 1);
g_caps.limits.maxTextureSize = uint16_t(bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight) );
g_caps.limits.maxFBAttachments = uint8_t(m_caps.NumSimultaneousRTs);
g_caps.limits.maxVertexStreams = uint8_t(m_caps.MaxStreams);

if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) )
{
Expand Down

0 comments on commit 52c28fa

Please sign in to comment.