Added isValid check function for handles.

This commit is contained in:
bkaradzic 2013-09-29 21:33:50 -07:00
parent 9f2faf8c06
commit df1dfdc872
12 changed files with 132 additions and 117 deletions

View file

@ -237,7 +237,7 @@ struct Mesh
const Group& group = *it; const Group& group = *it;
bgfx::destroyVertexBuffer(group.m_vbh); bgfx::destroyVertexBuffer(group.m_vbh);
if (bgfx::invalidHandle != group.m_ibh.idx) if (bgfx::isValid(group.m_ibh) )
{ {
bgfx::destroyIndexBuffer(group.m_ibh); bgfx::destroyIndexBuffer(group.m_ibh);
} }

View file

@ -232,7 +232,7 @@ struct Mesh
const Group& group = *it; const Group& group = *it;
bgfx::destroyVertexBuffer(group.m_vbh); bgfx::destroyVertexBuffer(group.m_vbh);
if (bgfx::invalidHandle != group.m_ibh.idx) if (bgfx::isValid(group.m_ibh) )
{ {
bgfx::destroyIndexBuffer(group.m_ibh); bgfx::destroyIndexBuffer(group.m_ibh);
} }

View file

@ -259,7 +259,7 @@ struct Mesh
const Group& group = *it; const Group& group = *it;
bgfx::destroyVertexBuffer(group.m_vbh); bgfx::destroyVertexBuffer(group.m_vbh);
if (bgfx::invalidHandle != group.m_ibh.idx) if (bgfx::isValid(group.m_ibh) )
{ {
bgfx::destroyIndexBuffer(group.m_ibh); bgfx::destroyIndexBuffer(group.m_ibh);
} }

View file

@ -489,7 +489,7 @@ TrueTypeHandle FontManager::createTtf(const uint8_t* _buffer, uint32_t _size)
void FontManager::destroyTtf(TrueTypeHandle _handle) void FontManager::destroyTtf(TrueTypeHandle _handle)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
delete m_cachedFiles[_handle.idx].buffer; delete m_cachedFiles[_handle.idx].buffer;
m_cachedFiles[_handle.idx].bufferSize = 0; m_cachedFiles[_handle.idx].bufferSize = 0;
m_cachedFiles[_handle.idx].buffer = NULL; m_cachedFiles[_handle.idx].buffer = NULL;
@ -498,7 +498,7 @@ void FontManager::destroyTtf(TrueTypeHandle _handle)
FontHandle FontManager::createFontByPixelSize(TrueTypeHandle _ttfHandle, uint32_t _typefaceIndex, uint32_t _pixelSize, uint32_t _fontType) FontHandle FontManager::createFontByPixelSize(TrueTypeHandle _ttfHandle, uint32_t _typefaceIndex, uint32_t _pixelSize, uint32_t _fontType)
{ {
BX_CHECK(bgfx::invalidHandle != _ttfHandle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_ttfHandle), "Invalid handle used");
TrueTypeFont* ttf = new TrueTypeFont(); TrueTypeFont* ttf = new TrueTypeFont();
if (!ttf->init(m_cachedFiles[_ttfHandle.idx].buffer, m_cachedFiles[_ttfHandle.idx].bufferSize, _typefaceIndex, _pixelSize) ) if (!ttf->init(m_cachedFiles[_ttfHandle.idx].buffer, m_cachedFiles[_ttfHandle.idx].bufferSize, _typefaceIndex, _pixelSize) )
@ -525,7 +525,7 @@ FontHandle FontManager::createFontByPixelSize(TrueTypeHandle _ttfHandle, uint32_
FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle, uint32_t _pixelSize) FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle, uint32_t _pixelSize)
{ {
BX_CHECK(bgfx::invalidHandle != _baseFontHandle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_baseFontHandle), "Invalid handle used");
CachedFont& baseFont = m_cachedFonts[_baseFontHandle.idx]; CachedFont& baseFont = m_cachedFonts[_baseFontHandle.idx];
FontInfo& fontInfo = baseFont.fontInfo; FontInfo& fontInfo = baseFont.fontInfo;
@ -554,7 +554,7 @@ FontHandle FontManager::createScaledFontToPixelSize(FontHandle _baseFontHandle,
void FontManager::destroyFont(FontHandle _handle) void FontManager::destroyFont(FontHandle _handle)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx]; CachedFont& font = m_cachedFonts[_handle.idx];
@ -570,7 +570,7 @@ void FontManager::destroyFont(FontHandle _handle)
bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string) bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx]; CachedFont& font = m_cachedFonts[_handle.idx];
if (NULL == font.trueTypeFont) if (NULL == font.trueTypeFont)
@ -592,7 +592,7 @@ bool FontManager::preloadGlyph(FontHandle _handle, const wchar_t* _string)
bool FontManager::preloadGlyph(FontHandle _handle, CodePoint _codePoint) bool FontManager::preloadGlyph(FontHandle _handle, CodePoint _codePoint)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
CachedFont& font = m_cachedFonts[_handle.idx]; CachedFont& font = m_cachedFonts[_handle.idx];
FontInfo& fontInfo = font.fontInfo; FontInfo& fontInfo = font.fontInfo;
@ -640,7 +640,7 @@ bool FontManager::preloadGlyph(FontHandle _handle, CodePoint _codePoint)
return true; return true;
} }
if (font.masterFontHandle.idx != bgfx::invalidHandle if (isValid(font.masterFontHandle)
&& preloadGlyph(font.masterFontHandle, _codePoint) ) && preloadGlyph(font.masterFontHandle, _codePoint) )
{ {
const GlyphInfo* glyph = getGlyphInfo(font.masterFontHandle, _codePoint); const GlyphInfo* glyph = getGlyphInfo(font.masterFontHandle, _codePoint);
@ -662,7 +662,7 @@ bool FontManager::preloadGlyph(FontHandle _handle, CodePoint _codePoint)
const FontInfo& FontManager::getFontInfo(FontHandle _handle) const const FontInfo& FontManager::getFontInfo(FontHandle _handle) const
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
return m_cachedFonts[_handle.idx].fontInfo; return m_cachedFonts[_handle.idx].fontInfo;
} }

View file

@ -635,8 +635,8 @@ TextBufferHandle TextBufferManager::createTextBuffer(uint32_t _type, BufferType:
bc.textBuffer = new TextBuffer(m_fontManager); bc.textBuffer = new TextBuffer(m_fontManager);
bc.fontType = _type; bc.fontType = _type;
bc.bufferType = _bufferType; bc.bufferType = _bufferType;
bc.indexBufferHandle = bgfx::invalidHandle; bc.indexBufferHandleIdx = bgfx::invalidHandle;
bc.vertexBufferHandle = bgfx::invalidHandle; bc.vertexBufferHandleIdx = bgfx::invalidHandle;
TextBufferHandle ret = {textIdx}; TextBufferHandle ret = {textIdx};
return ret; return ret;
@ -644,14 +644,14 @@ TextBufferHandle TextBufferManager::createTextBuffer(uint32_t _type, BufferType:
void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle) void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
m_textBufferHandles.free(_handle.idx); m_textBufferHandles.free(_handle.idx);
delete bc.textBuffer; delete bc.textBuffer;
bc.textBuffer = NULL; bc.textBuffer = NULL;
if (bc.vertexBufferHandle == bgfx::invalidHandle) if (bc.vertexBufferHandleIdx == bgfx::invalidHandle)
{ {
return; return;
} }
@ -662,8 +662,8 @@ void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle)
{ {
bgfx::IndexBufferHandle ibh; bgfx::IndexBufferHandle ibh;
bgfx::VertexBufferHandle vbh; bgfx::VertexBufferHandle vbh;
ibh.idx = bc.indexBufferHandle; ibh.idx = bc.indexBufferHandleIdx;
vbh.idx = bc.vertexBufferHandle; vbh.idx = bc.vertexBufferHandleIdx;
bgfx::destroyIndexBuffer(ibh); bgfx::destroyIndexBuffer(ibh);
bgfx::destroyVertexBuffer(vbh); bgfx::destroyVertexBuffer(vbh);
} }
@ -673,8 +673,8 @@ void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle)
case BufferType::Dynamic: case BufferType::Dynamic:
bgfx::DynamicIndexBufferHandle ibh; bgfx::DynamicIndexBufferHandle ibh;
bgfx::DynamicVertexBufferHandle vbh; bgfx::DynamicVertexBufferHandle vbh;
ibh.idx = bc.indexBufferHandle; ibh.idx = bc.indexBufferHandleIdx;
vbh.idx = bc.vertexBufferHandle; vbh.idx = bc.vertexBufferHandleIdx;
bgfx::destroyDynamicIndexBuffer(ibh); bgfx::destroyDynamicIndexBuffer(ibh);
bgfx::destroyDynamicVertexBuffer(vbh); bgfx::destroyDynamicVertexBuffer(vbh);
@ -687,7 +687,7 @@ void TextBufferManager::destroyTextBuffer(TextBufferHandle _handle)
void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id, int32_t _depth) void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id, int32_t _depth)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
@ -738,7 +738,7 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
bgfx::IndexBufferHandle ibh; bgfx::IndexBufferHandle ibh;
bgfx::VertexBufferHandle vbh; bgfx::VertexBufferHandle vbh;
if (bc.vertexBufferHandle == bgfx::invalidHandle) if (bgfx::invalidHandle == bc.vertexBufferHandleIdx)
{ {
mem = bgfx::alloc(indexSize); mem = bgfx::alloc(indexSize);
memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize); memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize);
@ -748,13 +748,13 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize); memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize);
vbh = bgfx::createVertexBuffer(mem, m_vertexDecl); vbh = bgfx::createVertexBuffer(mem, m_vertexDecl);
bc.indexBufferHandle = ibh.idx; bc.indexBufferHandleIdx = ibh.idx;
bc.vertexBufferHandle = vbh.idx; bc.vertexBufferHandleIdx = vbh.idx;
} }
else else
{ {
ibh.idx = bc.indexBufferHandle; ibh.idx = bc.indexBufferHandleIdx;
vbh.idx = bc.vertexBufferHandle; vbh.idx = bc.vertexBufferHandleIdx;
} }
bgfx::setVertexBuffer(vbh, bc.textBuffer->getVertexCount() ); bgfx::setVertexBuffer(vbh, bc.textBuffer->getVertexCount() );
@ -767,7 +767,7 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
bgfx::DynamicIndexBufferHandle ibh; bgfx::DynamicIndexBufferHandle ibh;
bgfx::DynamicVertexBufferHandle vbh; bgfx::DynamicVertexBufferHandle vbh;
if (bc.vertexBufferHandle == bgfx::invalidHandle) if (bgfx::invalidHandle == bc.vertexBufferHandleIdx )
{ {
mem = bgfx::alloc(indexSize); mem = bgfx::alloc(indexSize);
memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize); memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize);
@ -777,13 +777,13 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize); memcpy(mem->data, bc.textBuffer->getVertexBuffer(), vertexSize);
vbh = bgfx::createDynamicVertexBuffer(mem, m_vertexDecl); vbh = bgfx::createDynamicVertexBuffer(mem, m_vertexDecl);
bc.indexBufferHandle = ibh.idx; bc.indexBufferHandleIdx = ibh.idx;
bc.vertexBufferHandle = vbh.idx; bc.vertexBufferHandleIdx = vbh.idx;
} }
else else
{ {
ibh.idx = bc.indexBufferHandle; ibh.idx = bc.indexBufferHandleIdx;
vbh.idx = bc.vertexBufferHandle; vbh.idx = bc.vertexBufferHandleIdx;
mem = bgfx::alloc(indexSize); mem = bgfx::alloc(indexSize);
memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize); memcpy(mem->data, bc.textBuffer->getIndexBuffer(), indexSize);
@ -818,84 +818,84 @@ void TextBufferManager::submitTextBuffer(TextBufferHandle _handle, uint8_t _id,
void TextBufferManager::setStyle(TextBufferHandle _handle, uint32_t _flags) void TextBufferManager::setStyle(TextBufferHandle _handle, uint32_t _flags)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setStyle(_flags); bc.textBuffer->setStyle(_flags);
} }
void TextBufferManager::setTextColor(TextBufferHandle _handle, uint32_t _rgba) void TextBufferManager::setTextColor(TextBufferHandle _handle, uint32_t _rgba)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setTextColor(_rgba); bc.textBuffer->setTextColor(_rgba);
} }
void TextBufferManager::setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba) void TextBufferManager::setBackgroundColor(TextBufferHandle _handle, uint32_t _rgba)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setBackgroundColor(_rgba); bc.textBuffer->setBackgroundColor(_rgba);
} }
void TextBufferManager::setOverlineColor(TextBufferHandle _handle, uint32_t _rgba) void TextBufferManager::setOverlineColor(TextBufferHandle _handle, uint32_t _rgba)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setOverlineColor(_rgba); bc.textBuffer->setOverlineColor(_rgba);
} }
void TextBufferManager::setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba) void TextBufferManager::setUnderlineColor(TextBufferHandle _handle, uint32_t _rgba)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setUnderlineColor(_rgba); bc.textBuffer->setUnderlineColor(_rgba);
} }
void TextBufferManager::setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba) void TextBufferManager::setStrikeThroughColor(TextBufferHandle _handle, uint32_t _rgba)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setStrikeThroughColor(_rgba); bc.textBuffer->setStrikeThroughColor(_rgba);
} }
void TextBufferManager::setPenPosition(TextBufferHandle _handle, float _x, float _y) void TextBufferManager::setPenPosition(TextBufferHandle _handle, float _x, float _y)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->setPenPosition(_x, _y); bc.textBuffer->setPenPosition(_x, _y);
} }
void TextBufferManager::appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string, const char* _end) void TextBufferManager::appendText(TextBufferHandle _handle, FontHandle _fontHandle, const char* _string, const char* _end)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->appendText(_fontHandle, _string, _end); bc.textBuffer->appendText(_fontHandle, _string, _end);
} }
void TextBufferManager::appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string, const wchar_t* _end) void TextBufferManager::appendText(TextBufferHandle _handle, FontHandle _fontHandle, const wchar_t* _string, const wchar_t* _end)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->appendText(_fontHandle, _string, _end); bc.textBuffer->appendText(_fontHandle, _string, _end);
} }
void TextBufferManager::appendAtlasFace(TextBufferHandle _handle, uint16_t _faceIndex) void TextBufferManager::appendAtlasFace(TextBufferHandle _handle, uint16_t _faceIndex)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->appendAtlasFace(_faceIndex); bc.textBuffer->appendAtlasFace(_faceIndex);
} }
void TextBufferManager::clearTextBuffer(TextBufferHandle _handle) void TextBufferManager::clearTextBuffer(TextBufferHandle _handle)
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
bc.textBuffer->clearTextBuffer(); bc.textBuffer->clearTextBuffer();
} }
TextRectangle TextBufferManager::getRectangle(TextBufferHandle _handle) const TextRectangle TextBufferManager::getRectangle(TextBufferHandle _handle) const
{ {
BX_CHECK(bgfx::invalidHandle != _handle.idx, "Invalid handle used"); BX_CHECK(bgfx::isValid(_handle), "Invalid handle used");
BufferCache& bc = m_textBuffers[_handle.idx]; BufferCache& bc = m_textBuffers[_handle.idx];
return bc.textBuffer->getRectangle(); return bc.textBuffer->getRectangle();
} }

View file

@ -77,8 +77,8 @@ public:
private: private:
struct BufferCache struct BufferCache
{ {
uint16_t indexBufferHandle; uint16_t indexBufferHandleIdx;
uint16_t vertexBufferHandle; uint16_t vertexBufferHandleIdx;
TextBuffer* textBuffer; TextBuffer* textBuffer;
BufferType::Enum bufferType; BufferType::Enum bufferType;
uint32_t fontType; uint32_t fontType;

View file

@ -227,7 +227,10 @@
#define BGFX_RESET_CAPTURE UINT32_C(0x00000100) #define BGFX_RESET_CAPTURE UINT32_C(0x00000100)
/// ///
#define BGFX_HANDLE(_name) struct _name { uint16_t idx; } #define BGFX_HANDLE(_name) \
struct _name { uint16_t idx; }; \
inline bool isValid(_name _handle) { return bgfx::invalidHandle != _handle.idx; }
#define BGFX_INVALID_HANDLE { bgfx::invalidHandle } #define BGFX_INVALID_HANDLE { bgfx::invalidHandle }
namespace bx { struct ReallocatorI; } namespace bx { struct ReallocatorI; }
@ -823,14 +826,24 @@ namespace bgfx
/// ///
/// Predefined uniforms: /// Predefined uniforms:
/// ///
/// u_viewRect vec4(x, y, width, height) - view rectangle for current view. /// u_viewRect vec4(x, y, width, height) - view rectangle for current
/// u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse width and height /// view.
/// u_view mat4 - view matrix ///
/// u_viewProj mat4 - view projection matrix /// u_viewTexel vec4(1.0/width, 1.0/height, undef, undef) - inverse
/// u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices. /// width and height
/// u_modelView mat4 - model view matrix, only first model matrix from array is used. ///
/// u_modelViewProj mat4 - concatinated model view projection matrix. /// u_view mat4 - view matrix
/// u_alphaRef float - alpha reference value for alpha test. ///
/// u_viewProj mat4 - concatenated view projection matrix
///
/// u_model mat4[BGFX_CONFIG_MAX_BONES] - array of model matrices.
///
/// u_modelView mat4 - concatenated model view matrix, only first
/// model matrix from array is used.
///
/// u_modelViewProj mat4 - concatenated model view projection matrix.
///
/// u_alphaRef float - alpha reference value for alpha test.
/// ///
UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1); UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num = 1);

View file

@ -46,6 +46,7 @@ namespace bgfx
} }
#endif // BX_PLATFORM_* #endif // BX_PLATFORM_*
#if BGFX_CONFIG_USE_TINYSTL
void* TinyStlAllocator::static_allocate(size_t _bytes) void* TinyStlAllocator::static_allocate(size_t _bytes)
{ {
return BX_ALLOC(g_allocator, _bytes); return BX_ALLOC(g_allocator, _bytes);
@ -55,6 +56,7 @@ namespace bgfx
{ {
BX_FREE(g_allocator, _ptr); BX_FREE(g_allocator, _ptr);
} }
#endif // BGFX_CONFIG_USE_TINYSTL
struct CallbackStub : public CallbackI struct CallbackStub : public CallbackI
{ {

View file

@ -1138,7 +1138,7 @@ namespace bgfx
void setProgram(ProgramHandle _handle) void setProgram(ProgramHandle _handle)
{ {
BX_CHECK(invalidHandle != _handle.idx, "Can't set program with invalid handle."); BX_CHECK(isValid(_handle), "Can't set program with invalid handle.");
m_key.m_program = _handle.idx; m_key.m_program = _handle.idx;
} }
@ -1152,7 +1152,7 @@ namespace bgfx
| ( (_flags&BGFX_SAMPLER_TYPE_MASK) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags) | ( (_flags&BGFX_SAMPLER_TYPE_MASK) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags)
; ;
if (invalidHandle != _sampler.idx) if (isValid(_sampler) )
{ {
uint32_t stage = _stage; uint32_t stage = _stage;
setUniform(_sampler, &stage); setUniform(_sampler, &stage);
@ -1169,7 +1169,7 @@ namespace bgfx
| ( (_flags&BGFX_SAMPLER_TYPE_MASK) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags) | ( (_flags&BGFX_SAMPLER_TYPE_MASK) ? BGFX_SAMPLER_DEFAULT_FLAGS : _flags)
; ;
if (invalidHandle != _sampler.idx) if (isValid(_sampler) )
{ {
uint32_t stage = _stage; uint32_t stage = _stage;
setUniform(_sampler, &stage); setUniform(_sampler, &stage);
@ -1611,8 +1611,8 @@ namespace bgfx
{ {
IndexBufferHandle handle = { m_indexBufferHandle.alloc() }; IndexBufferHandle handle = { m_indexBufferHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate index buffer handle."); BX_WARN(isValid(handle), "Failed to allocate index buffer handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateIndexBuffer); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateIndexBuffer);
cmdbuf.write(handle); cmdbuf.write(handle);
@ -1633,7 +1633,7 @@ namespace bgfx
{ {
VertexDeclHandle declHandle = m_declRef.find(_decl.m_hash); VertexDeclHandle declHandle = m_declRef.find(_decl.m_hash);
if (invalidHandle == declHandle.idx) if (!isValid(declHandle) )
{ {
VertexDeclHandle temp = { m_vertexDeclHandle.alloc() }; VertexDeclHandle temp = { m_vertexDeclHandle.alloc() };
declHandle = temp; declHandle = temp;
@ -1649,8 +1649,8 @@ namespace bgfx
{ {
VertexBufferHandle handle = { m_vertexBufferHandle.alloc() }; VertexBufferHandle handle = { m_vertexBufferHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate vertex buffer handle."); BX_WARN(isValid(handle), "Failed to allocate vertex buffer handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
VertexDeclHandle declHandle = findVertexDecl(_decl); VertexDeclHandle declHandle = findVertexDecl(_decl);
m_declRef.add(handle, declHandle, _decl.m_hash); m_declRef.add(handle, declHandle, _decl.m_hash);
@ -1667,7 +1667,7 @@ namespace bgfx
void destroyVertexBuffer(VertexBufferHandle _handle) void destroyVertexBuffer(VertexBufferHandle _handle)
{ {
VertexDeclHandle declHandle = m_declRef.release(_handle); VertexDeclHandle declHandle = m_declRef.release(_handle);
if (invalidHandle != declHandle.idx) if (isValid(declHandle) )
{ {
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexDecl); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexDecl);
cmdbuf.write(declHandle); cmdbuf.write(declHandle);
@ -1686,8 +1686,8 @@ namespace bgfx
if (ptr == NonLocalAllocator::invalidBlock) if (ptr == NonLocalAllocator::invalidBlock)
{ {
IndexBufferHandle indexBufferHandle = { m_indexBufferHandle.alloc() }; IndexBufferHandle indexBufferHandle = { m_indexBufferHandle.alloc() };
BX_WARN(invalidHandle != indexBufferHandle.idx, "Failed to allocate index buffer handle."); BX_WARN(isValid(indexBufferHandle), "Failed to allocate index buffer handle.");
if (indexBufferHandle.idx == invalidHandle) if (!isValid(indexBufferHandle) )
{ {
return handle; return handle;
} }
@ -1701,8 +1701,8 @@ namespace bgfx
} }
handle.idx = m_dynamicIndexBufferHandle.alloc(); handle.idx = m_dynamicIndexBufferHandle.alloc();
BX_WARN(invalidHandle != handle.idx, "Failed to allocate dynamic index buffer handle."); BX_WARN(isValid(handle), "Failed to allocate dynamic index buffer handle.");
if (handle.idx == invalidHandle) if (!isValid(handle) )
{ {
return handle; return handle;
} }
@ -1718,7 +1718,7 @@ namespace bgfx
DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem) DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem)
{ {
DynamicIndexBufferHandle handle = createDynamicIndexBuffer(_mem->size/2); DynamicIndexBufferHandle handle = createDynamicIndexBuffer(_mem->size/2);
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
updateDynamicIndexBuffer(handle, _mem); updateDynamicIndexBuffer(handle, _mem);
} }
@ -1756,8 +1756,8 @@ namespace bgfx
{ {
VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate dynamic vertex buffer handle."); BX_WARN(isValid(handle), "Failed to allocate dynamic vertex buffer handle.");
if (vertexBufferHandle.idx == invalidHandle) if (!isValid(vertexBufferHandle) )
{ {
return handle; return handle;
} }
@ -1788,7 +1788,7 @@ namespace bgfx
DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl) DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl)
{ {
DynamicVertexBufferHandle handle = createDynamicVertexBuffer(_mem->size/_decl.m_stride, _decl); DynamicVertexBufferHandle handle = createDynamicVertexBuffer(_mem->size/_decl.m_stride, _decl);
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
updateDynamicVertexBuffer(handle, _mem); updateDynamicVertexBuffer(handle, _mem);
} }
@ -1830,8 +1830,8 @@ namespace bgfx
TransientIndexBuffer* ib = NULL; TransientIndexBuffer* ib = NULL;
IndexBufferHandle handle = { m_indexBufferHandle.alloc() }; IndexBufferHandle handle = { m_indexBufferHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate transient index buffer handle."); BX_WARN(isValid(handle), "Failed to allocate transient index buffer handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicIndexBuffer); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicIndexBuffer);
cmdbuf.write(handle); cmdbuf.write(handle);
@ -1873,8 +1873,8 @@ namespace bgfx
VertexBufferHandle handle = { m_vertexBufferHandle.alloc() }; VertexBufferHandle handle = { m_vertexBufferHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate transient vertex buffer handle."); BX_WARN(isValid(handle), "Failed to allocate transient vertex buffer handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
uint16_t stride = 0; uint16_t stride = 0;
VertexDeclHandle declHandle = BGFX_INVALID_HANDLE; VertexDeclHandle declHandle = BGFX_INVALID_HANDLE;
@ -1918,7 +1918,7 @@ namespace bgfx
TransientVertexBuffer& dvb = *m_submit->m_transientVb; TransientVertexBuffer& dvb = *m_submit->m_transientVb;
if (invalidHandle == declHandle.idx) if (!isValid(declHandle) )
{ {
VertexDeclHandle temp = { m_vertexDeclHandle.alloc() }; VertexDeclHandle temp = { m_vertexDeclHandle.alloc() };
declHandle = temp; declHandle = temp;
@ -1971,8 +1971,8 @@ namespace bgfx
VertexShaderHandle handle = { m_vertexShaderHandle.alloc() }; VertexShaderHandle handle = { m_vertexShaderHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate vertex shader handle."); BX_WARN(isValid(handle), "Failed to allocate vertex shader handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
VertexShaderRef& vsr = m_vertexShaderRef[handle.idx]; VertexShaderRef& vsr = m_vertexShaderRef[handle.idx];
vsr.m_refCount = 1; vsr.m_refCount = 1;
@ -1988,7 +1988,7 @@ namespace bgfx
void destroyVertexShader(VertexShaderHandle _handle) void destroyVertexShader(VertexShaderHandle _handle)
{ {
if (invalidHandle == _handle.idx) if (!isValid(_handle) )
{ {
BX_WARN(false, "Passing invalid vertex shader handle to bgfx::destroyVertexShader"); BX_WARN(false, "Passing invalid vertex shader handle to bgfx::destroyVertexShader");
return; return;
@ -2031,8 +2031,8 @@ namespace bgfx
FragmentShaderHandle handle = { m_fragmentShaderHandle.alloc() }; FragmentShaderHandle handle = { m_fragmentShaderHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate fragment shader handle."); BX_WARN(isValid(handle), "Failed to allocate fragment shader handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
FragmentShaderRef& fsr = m_fragmentShaderRef[handle.idx]; FragmentShaderRef& fsr = m_fragmentShaderRef[handle.idx];
fsr.m_refCount = 1; fsr.m_refCount = 1;
@ -2048,7 +2048,7 @@ namespace bgfx
void destroyFragmentShader(FragmentShaderHandle _handle) void destroyFragmentShader(FragmentShaderHandle _handle)
{ {
if (invalidHandle == _handle.idx) if (!isValid(_handle) )
{ {
BX_WARN(false, "Passing invalid fragment shader handle to bgfx::destroyFragmentShader"); BX_WARN(false, "Passing invalid fragment shader handle to bgfx::destroyFragmentShader");
return; return;
@ -2077,8 +2077,8 @@ namespace bgfx
ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh) ProgramHandle createProgram(VertexShaderHandle _vsh, FragmentShaderHandle _fsh)
{ {
if (invalidHandle == _vsh.idx if (!isValid(_vsh)
|| invalidHandle == _fsh.idx) || !isValid(_fsh) )
{ {
BX_WARN(false, "Vertex/fragment shader is invalid (vsh %d, fsh %d).", _vsh.idx, _fsh.idx); BX_WARN(false, "Vertex/fragment shader is invalid (vsh %d, fsh %d).", _vsh.idx, _fsh.idx);
ProgramHandle invalid = BGFX_INVALID_HANDLE; ProgramHandle invalid = BGFX_INVALID_HANDLE;
@ -2097,8 +2097,8 @@ namespace bgfx
ProgramHandle handle; ProgramHandle handle;
handle.idx = m_programHandle.alloc(); handle.idx = m_programHandle.alloc();
BX_WARN(invalidHandle != handle.idx, "Failed to allocate program handle."); BX_WARN(isValid(handle), "Failed to allocate program handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
vertexShaderIncRef(_vsh); vertexShaderIncRef(_vsh);
fragmentShaderIncRef(_fsh); fragmentShaderIncRef(_fsh);
@ -2152,8 +2152,8 @@ namespace bgfx
} }
TextureHandle handle = { m_textureHandle.alloc() }; TextureHandle handle = { m_textureHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate texture handle."); BX_WARN(isValid(handle), "Failed to allocate texture handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture);
cmdbuf.write(handle); cmdbuf.write(handle);
@ -2191,9 +2191,9 @@ namespace bgfx
RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags) RenderTargetHandle createRenderTarget(uint16_t _width, uint16_t _height, uint32_t _flags, uint32_t _textureFlags)
{ {
RenderTargetHandle handle = { m_renderTargetHandle.alloc() }; RenderTargetHandle handle = { m_renderTargetHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate render target handle."); BX_WARN(isValid(handle), "Failed to allocate render target handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateRenderTarget); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateRenderTarget);
cmdbuf.write(handle); cmdbuf.write(handle);
@ -2224,8 +2224,8 @@ namespace bgfx
UniformHandle handle = { m_uniformHandle.alloc() }; UniformHandle handle = { m_uniformHandle.alloc() };
BX_WARN(invalidHandle != handle.idx, "Failed to allocate uniform handle."); BX_WARN(isValid(handle), "Failed to allocate uniform handle.");
if (invalidHandle != handle.idx) if (isValid(handle) )
{ {
Uniform& uniform = m_uniform[handle.idx]; Uniform& uniform = m_uniform[handle.idx];
uniform.m_type = _type; uniform.m_type = _type;

View file

@ -703,7 +703,7 @@ namespace bgfx
void setRenderTarget(RenderTargetHandle _rt, bool _msaa = true) void setRenderTarget(RenderTargetHandle _rt, bool _msaa = true)
{ {
BX_UNUSED(_msaa); BX_UNUSED(_msaa);
if (_rt.idx == invalidHandle) if (!isValid(_rt) )
{ {
m_deviceCtx->OMSetRenderTargets(1, &m_backBufferColor, m_backBufferDepthStencil); m_deviceCtx->OMSetRenderTargets(1, &m_backBufferColor, m_backBufferDepthStencil);
@ -2575,13 +2575,13 @@ namespace bgfx
{ {
const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[handle]; const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[handle];
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
const VertexDecl& vertexDecl = s_renderCtx->m_vertexDecls[decl]; const VertexDecl& vertexDecl = s_renderCtx->m_vertexDecls[decl];
uint32_t stride = vertexDecl.m_stride; uint32_t stride = vertexDecl.m_stride;
uint32_t offset = 0; uint32_t offset = 0;
deviceCtx->IASetVertexBuffers(0, 1, &vb.m_ptr, &stride, &offset); deviceCtx->IASetVertexBuffers(0, 1, &vb.m_ptr, &stride, &offset);
if (invalidHandle != state.m_instanceDataBuffer.idx) if (isValid(state.m_instanceDataBuffer) )
{ {
const VertexBuffer& inst = s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx]; const VertexBuffer& inst = s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx];
uint32_t instStride = state.m_instanceDataStride; uint32_t instStride = state.m_instanceDataStride;
@ -2616,13 +2616,13 @@ namespace bgfx
} }
} }
if (invalidHandle != currentState.m_vertexBuffer.idx) if (isValid(currentState.m_vertexBuffer) )
{ {
uint32_t numVertices = state.m_numVertices; uint32_t numVertices = state.m_numVertices;
if (UINT32_MAX == numVertices) if (UINT32_MAX == numVertices)
{ {
const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[currentState.m_vertexBuffer.idx]; const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[currentState.m_vertexBuffer.idx];
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
const VertexDecl& vertexDecl = s_renderCtx->m_vertexDecls[decl]; const VertexDecl& vertexDecl = s_renderCtx->m_vertexDecls[decl];
numVertices = vb.m_size/vertexDecl.m_stride; numVertices = vb.m_size/vertexDecl.m_stride;
} }
@ -2632,7 +2632,7 @@ namespace bgfx
uint32_t numInstances = 0; uint32_t numInstances = 0;
uint32_t numPrimsRendered = 0; uint32_t numPrimsRendered = 0;
if (invalidHandle != state.m_indexBuffer.idx) if (isValid(state.m_indexBuffer) )
{ {
if (UINT32_MAX == state.m_numIndices) if (UINT32_MAX == state.m_numIndices)
{ {

View file

@ -618,7 +618,7 @@ namespace bgfx
void setRenderTarget(RenderTargetHandle _rt, bool _msaa = true) void setRenderTarget(RenderTargetHandle _rt, bool _msaa = true)
{ {
if (_rt.idx == invalidHandle) if (!isValid(_rt) )
{ {
DX_CHECK(m_device->SetRenderTarget(0, m_backBufferColor) ); DX_CHECK(m_device->SetRenderTarget(0, m_backBufferColor) );
DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) ); DX_CHECK(m_device->SetDepthStencilSurface(m_backBufferDepthStencil) );
@ -638,7 +638,7 @@ namespace bgfx
DX_CHECK(m_device->SetDepthStencilSurface(NULL != renderTarget.m_depth ? renderTarget.m_depth : m_backBufferDepthStencil) ); DX_CHECK(m_device->SetDepthStencilSurface(NULL != renderTarget.m_depth ? renderTarget.m_depth : m_backBufferDepthStencil) );
} }
if (m_rt.idx != invalidHandle if (isValid(m_rt)
&& m_rt.idx != _rt.idx && m_rt.idx != _rt.idx
&& m_rtMsaa) && m_rtMsaa)
{ {
@ -2719,11 +2719,11 @@ namespace bgfx
{ {
const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[handle]; const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[handle];
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
const VertexDeclaration& vertexDecl = s_renderCtx->m_vertexDecls[decl]; const VertexDeclaration& vertexDecl = s_renderCtx->m_vertexDecls[decl];
DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, vertexDecl.m_decl.m_stride) ); DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, vertexDecl.m_decl.m_stride) );
if (invalidHandle != state.m_instanceDataBuffer.idx if (isValid(state.m_instanceDataBuffer)
&& s_renderCtx->m_instancing) && s_renderCtx->m_instancing)
{ {
const VertexBuffer& inst = s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx]; const VertexBuffer& inst = s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx];
@ -2765,13 +2765,13 @@ namespace bgfx
} }
} }
if (invalidHandle != currentState.m_vertexBuffer.idx) if (isValid(currentState.m_vertexBuffer) )
{ {
uint32_t numVertices = state.m_numVertices; uint32_t numVertices = state.m_numVertices;
if (UINT32_MAX == numVertices) if (UINT32_MAX == numVertices)
{ {
const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[currentState.m_vertexBuffer.idx]; const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[currentState.m_vertexBuffer.idx];
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
const VertexDeclaration& vertexDecl = s_renderCtx->m_vertexDecls[decl]; const VertexDeclaration& vertexDecl = s_renderCtx->m_vertexDecls[decl];
numVertices = vb.m_size/vertexDecl.m_decl.m_stride; numVertices = vb.m_size/vertexDecl.m_decl.m_stride;
} }
@ -2781,7 +2781,7 @@ namespace bgfx
uint32_t numInstances = 0; uint32_t numInstances = 0;
uint32_t numPrimsRendered = 0; uint32_t numPrimsRendered = 0;
if (invalidHandle != state.m_indexBuffer.idx) if (isValid(state.m_indexBuffer) )
{ {
if (UINT32_MAX == state.m_numIndices) if (UINT32_MAX == state.m_numIndices)
{ {

View file

@ -543,7 +543,7 @@ namespace bgfx
uint32_t setRenderTarget(RenderTargetHandle _rt, uint32_t _height, bool _msaa = true) uint32_t setRenderTarget(RenderTargetHandle _rt, uint32_t _height, bool _msaa = true)
{ {
if (m_rt.idx != invalidHandle if (isValid(m_rt)
&& m_rt.idx != _rt.idx && m_rt.idx != _rt.idx
&& m_rtMsaa) && m_rtMsaa)
{ {
@ -554,7 +554,7 @@ namespace bgfx
} }
} }
if (_rt.idx == invalidHandle) if (!isValid(_rt) )
{ {
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) );
} }
@ -2299,7 +2299,7 @@ namespace bgfx
uint32_t fmt = uint32_t(TextureFormat::Unknown); uint32_t fmt = uint32_t(TextureFormat::Unknown);
for (uint32_t jj = 0; jj < fmt; ++jj) for (uint32_t jj = 0; jj < fmt; ++jj)
{ {
if (s_textureFormat[jj].m_internalFmt == internalFmt) if (s_textureFormat[jj].m_internalFmt == (GLenum)internalFmt)
{ {
fmt = jj; fmt = jj;
} }
@ -3318,16 +3318,16 @@ namespace bgfx
Program& program = s_renderCtx->m_program[programIdx]; Program& program = s_renderCtx->m_program[programIdx];
program.add(hash); program.add(hash);
if (invalidHandle != state.m_vertexBuffer.idx) if (isValid(state.m_vertexBuffer) )
{ {
VertexBuffer& vb = s_renderCtx->m_vertexBuffers[state.m_vertexBuffer.idx]; VertexBuffer& vb = s_renderCtx->m_vertexBuffers[state.m_vertexBuffer.idx];
vb.add(hash); vb.add(hash);
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) );
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
program.bindAttributes(s_renderCtx->m_vertexDecls[decl], state.m_startVertex); program.bindAttributes(s_renderCtx->m_vertexDecls[decl], state.m_startVertex);
if (invalidHandle != state.m_instanceDataBuffer.idx) if (isValid(state.m_instanceDataBuffer) )
{ {
VertexBuffer& instanceVb = s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx]; VertexBuffer& instanceVb = s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx];
instanceVb.add(hash); instanceVb.add(hash);
@ -3340,7 +3340,7 @@ namespace bgfx
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) );
} }
if (invalidHandle != state.m_indexBuffer.idx) if (isValid(state.m_indexBuffer) )
{ {
IndexBuffer& ib = s_renderCtx->m_indexBuffers[state.m_indexBuffer.idx]; IndexBuffer& ib = s_renderCtx->m_indexBuffers[state.m_indexBuffer.idx];
ib.add(hash); ib.add(hash);
@ -3405,18 +3405,18 @@ namespace bgfx
} }
} }
if (invalidHandle != currentState.m_vertexBuffer.idx) if (isValid(currentState.m_vertexBuffer) )
{ {
if (baseVertex != state.m_startVertex if (baseVertex != state.m_startVertex
|| bindAttribs) || bindAttribs)
{ {
baseVertex = state.m_startVertex; baseVertex = state.m_startVertex;
const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[state.m_vertexBuffer.idx]; const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[state.m_vertexBuffer.idx];
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
const Program& program = s_renderCtx->m_program[programIdx]; const Program& program = s_renderCtx->m_program[programIdx];
program.bindAttributes(s_renderCtx->m_vertexDecls[decl], state.m_startVertex); program.bindAttributes(s_renderCtx->m_vertexDecls[decl], state.m_startVertex);
if (invalidHandle != state.m_instanceDataBuffer.idx) if (isValid(state.m_instanceDataBuffer) )
{ {
GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx].m_id) ); GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, s_renderCtx->m_vertexBuffers[state.m_instanceDataBuffer.idx].m_id) );
program.bindInstanceData(state.m_instanceDataStride, state.m_instanceDataOffset); program.bindInstanceData(state.m_instanceDataStride, state.m_instanceDataOffset);
@ -3425,13 +3425,13 @@ namespace bgfx
} }
} }
if (invalidHandle != currentState.m_vertexBuffer.idx) if (isValid(currentState.m_vertexBuffer) )
{ {
uint32_t numVertices = state.m_numVertices; uint32_t numVertices = state.m_numVertices;
if (UINT32_MAX == numVertices) if (UINT32_MAX == numVertices)
{ {
const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[currentState.m_vertexBuffer.idx]; const VertexBuffer& vb = s_renderCtx->m_vertexBuffers[currentState.m_vertexBuffer.idx];
uint16_t decl = vb.m_decl.idx == invalidHandle ? state.m_vertexDecl.idx : vb.m_decl.idx; uint16_t decl = !isValid(vb.m_decl) ? state.m_vertexDecl.idx : vb.m_decl.idx;
const VertexDecl& vertexDecl = s_renderCtx->m_vertexDecls[decl]; const VertexDecl& vertexDecl = s_renderCtx->m_vertexDecls[decl];
numVertices = vb.m_size/vertexDecl.m_stride; numVertices = vb.m_size/vertexDecl.m_stride;
} }
@ -3441,7 +3441,7 @@ namespace bgfx
uint32_t numInstances = 0; uint32_t numInstances = 0;
uint32_t numPrimsRendered = 0; uint32_t numPrimsRendered = 0;
if (invalidHandle != state.m_indexBuffer.idx) if (isValid(state.m_indexBuffer) )
{ {
if (UINT32_MAX == state.m_numIndices) if (UINT32_MAX == state.m_numIndices)
{ {