mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-24 16:48:18 -05:00
Added preserve state flag.
This commit is contained in:
parent
d8ce84f338
commit
c691521563
7 changed files with 60 additions and 49 deletions
|
@ -540,17 +540,16 @@ struct Mesh
|
|||
;
|
||||
}
|
||||
|
||||
uint32_t cached = bgfx::setTransform(_mtx);
|
||||
bgfx::setTransform(_mtx);
|
||||
bgfx::setState(_state);
|
||||
|
||||
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
const Group& group = *it;
|
||||
|
||||
bgfx::setTransform(cached);
|
||||
bgfx::setIndexBuffer(group.m_ibh);
|
||||
bgfx::setVertexBuffer(group.m_vbh);
|
||||
bgfx::setState(_state);
|
||||
bgfx::submit(_id, _program);
|
||||
bgfx::submit(_id, _program, 0, it != itEnd-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,26 +559,28 @@ struct Mesh
|
|||
|
||||
for (uint32_t pass = 0; pass < _numPasses; ++pass)
|
||||
{
|
||||
bgfx::setTransform(cached, _numMatrices);
|
||||
|
||||
const MeshState& state = *_state[pass];
|
||||
bgfx::setState(state.m_state);
|
||||
|
||||
for (uint8_t tex = 0; tex < state.m_numTextures; ++tex)
|
||||
{
|
||||
const MeshState::Texture& texture = state.m_textures[tex];
|
||||
bgfx::setTexture(texture.m_stage
|
||||
, texture.m_sampler
|
||||
, texture.m_texture
|
||||
, texture.m_flags
|
||||
);
|
||||
}
|
||||
|
||||
for (GroupArray::const_iterator it = m_groups.begin(), itEnd = m_groups.end(); it != itEnd; ++it)
|
||||
{
|
||||
const Group& group = *it;
|
||||
|
||||
bgfx::setTransform(cached, _numMatrices);
|
||||
for (uint8_t tex = 0; tex < state.m_numTextures; ++tex)
|
||||
{
|
||||
const MeshState::Texture& texture = state.m_textures[tex];
|
||||
bgfx::setTexture(texture.m_stage
|
||||
, texture.m_sampler
|
||||
, texture.m_texture
|
||||
, texture.m_flags
|
||||
);
|
||||
}
|
||||
bgfx::setIndexBuffer(group.m_ibh);
|
||||
bgfx::setVertexBuffer(group.m_vbh);
|
||||
bgfx::setState(state.m_state);
|
||||
bgfx::submit(state.m_viewId, state.m_program);
|
||||
bgfx::submit(state.m_viewId, state.m_program, 0, it != itEnd-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2074,11 +2074,13 @@ namespace bgfx
|
|||
/// @param[in] _id View id.
|
||||
/// @param[in] _program Program.
|
||||
/// @param[in] _depth Depth for sorting.
|
||||
/// @param[in] _preserveState Preserve internal draw state for next draw
|
||||
/// call submit.
|
||||
/// @returns Number of draw calls.
|
||||
///
|
||||
/// @attention C99 equivalent is `bgfx_submit`.
|
||||
///
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, int32_t _depth = 0);
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, int32_t _depth = 0, bool _preserveState = false);
|
||||
|
||||
/// Submit primitive with occlusion query for rendering.
|
||||
///
|
||||
|
@ -2086,11 +2088,13 @@ namespace bgfx
|
|||
/// @param[in] _program Program.
|
||||
/// @param[in] _occlusionQuery Occlusion query.
|
||||
/// @param[in] _depth Depth for sorting.
|
||||
/// @param[in] _preserveState Preserve internal draw state for next draw
|
||||
/// call submit.
|
||||
/// @returns Number of draw calls.
|
||||
///
|
||||
/// @attention C99 equivalent is `bgfx_submit_occlusion_query.
|
||||
///
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth = 0);
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth = 0, bool _preserveState = false);
|
||||
|
||||
/// Submit primitive for rendering with index and instance data info from
|
||||
/// indirect buffer.
|
||||
|
@ -2101,10 +2105,13 @@ namespace bgfx
|
|||
/// @param[in] _start First element in indirect buffer.
|
||||
/// @param[in] _num Number of dispatches.
|
||||
/// @param[in] _depth Depth for sorting.
|
||||
/// @param[in] _preserveState Preserve internal draw state for next draw
|
||||
/// call submit.
|
||||
/// @returns Number of draw calls.
|
||||
///
|
||||
/// @attention C99 equivalent is `bgfx_submit_indirect`.
|
||||
///
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, int32_t _depth = 0);
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start = 0, uint16_t _num = 1, int32_t _depth = 0, bool _preserveState = false);
|
||||
|
||||
/// Set compute index buffer.
|
||||
///
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#ifndef BGFX_DEFINES_H_HEADER_GUARD
|
||||
#define BGFX_DEFINES_H_HEADER_GUARD
|
||||
|
||||
#define BGFX_API_VERSION UINT32_C(10)
|
||||
#define BGFX_API_VERSION UINT32_C(11)
|
||||
|
||||
///
|
||||
#define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write.
|
||||
|
|
|
@ -792,13 +792,13 @@ BGFX_C_API void bgfx_set_texture_from_frame_buffer(uint8_t _stage, bgfx_uniform_
|
|||
BGFX_C_API uint32_t bgfx_touch(uint8_t _id);
|
||||
|
||||
/**/
|
||||
BGFX_C_API uint32_t bgfx_submit(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth);
|
||||
BGFX_C_API uint32_t bgfx_submit(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth, bool _preserveState);
|
||||
|
||||
/**/
|
||||
BGFX_C_API uint32_t bgfx_submit_occlusion_query(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth);
|
||||
BGFX_C_API uint32_t bgfx_submit_occlusion_query(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth, bool _preserveState);
|
||||
|
||||
/**/
|
||||
BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth);
|
||||
BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState);
|
||||
|
||||
/**/
|
||||
BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);
|
||||
|
|
|
@ -179,9 +179,9 @@ typedef struct bgfx_interface_vtbl
|
|||
void (*set_texture)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
|
||||
void (*set_texture_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, uint32_t _flags);
|
||||
uint32_t (*touch)(uint8_t _id);
|
||||
uint32_t (*submit)(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth);
|
||||
uint32_t (*submit_occlusion_query)(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth);
|
||||
uint32_t (*submit_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth);
|
||||
uint32_t (*submit)(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth, bool _preserveState);
|
||||
uint32_t (*submit_occlusion_query)(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth, bool _preserveState);
|
||||
uint32_t (*submit_indirect)(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState);
|
||||
void (*set_image)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format);
|
||||
void (*set_image_from_frame_buffer)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_frame_buffer_handle_t _handle, uint8_t _attachment, bgfx_access_t _access, bgfx_texture_format_t _format);
|
||||
void (*set_compute_index_buffer)(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access);
|
||||
|
|
35
src/bgfx.cpp
35
src/bgfx.cpp
|
@ -848,7 +848,7 @@ namespace bgfx
|
|||
return PredefinedUniform::Count;
|
||||
}
|
||||
|
||||
uint32_t Frame::submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth)
|
||||
uint32_t Frame::submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
if (m_discard)
|
||||
{
|
||||
|
@ -895,9 +895,12 @@ namespace bgfx
|
|||
m_renderItem[m_numRenderItems].draw = m_draw;
|
||||
++m_numRenderItems;
|
||||
|
||||
m_draw.clear();
|
||||
m_uniformBegin = m_uniformEnd;
|
||||
m_stateFlags = BGFX_STATE_NONE;
|
||||
if (!_preserveState)
|
||||
{
|
||||
m_draw.clear();
|
||||
m_uniformBegin = m_uniformEnd;
|
||||
m_stateFlags = BGFX_STATE_NONE;
|
||||
}
|
||||
|
||||
return m_num;
|
||||
}
|
||||
|
@ -3508,13 +3511,13 @@ again:
|
|||
return submit(_id, handle);
|
||||
}
|
||||
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, int32_t _depth)
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
OcclusionQueryHandle handle = BGFX_INVALID_HANDLE;
|
||||
return submit(_id, _program, handle, _depth);
|
||||
return submit(_id, _program, handle, _depth, _preserveState);
|
||||
}
|
||||
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth)
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
BGFX_CHECK_MAIN_THREAD();
|
||||
BX_CHECK(false
|
||||
|
@ -3522,13 +3525,13 @@ again:
|
|||
|| 0 != (g_caps.supported & BGFX_CAPS_OCCLUSION_QUERY)
|
||||
, "Occlusion query is not supported! Use bgfx::getCaps to check BGFX_CAPS_OCCLUSION_QUERY backend renderer capabilities."
|
||||
);
|
||||
return s_ctx->submit(_id, _program, _occlusionQuery, _depth);
|
||||
return s_ctx->submit(_id, _program, _occlusionQuery, _depth, _preserveState);
|
||||
}
|
||||
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth)
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
BGFX_CHECK_MAIN_THREAD();
|
||||
return s_ctx->submit(_id, _program, _indirectHandle, _start, _num, _depth);
|
||||
return s_ctx->submit(_id, _program, _indirectHandle, _start, _num, _depth, _preserveState);
|
||||
}
|
||||
|
||||
void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access)
|
||||
|
@ -4438,24 +4441,24 @@ BGFX_C_API uint32_t bgfx_touch(uint8_t _id)
|
|||
return bgfx::touch(_id);
|
||||
}
|
||||
|
||||
BGFX_C_API uint32_t bgfx_submit(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth)
|
||||
BGFX_C_API uint32_t bgfx_submit(uint8_t _id, bgfx_program_handle_t _handle, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle };
|
||||
return bgfx::submit(_id, handle.cpp, _depth);
|
||||
return bgfx::submit(_id, handle.cpp, _depth, _preserveState);
|
||||
}
|
||||
|
||||
BGFX_C_API uint32_t bgfx_submit_occlusion_query(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth)
|
||||
BGFX_C_API uint32_t bgfx_submit_occlusion_query(uint8_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program };
|
||||
union { bgfx_occlusion_query_handle c; bgfx::OcclusionQueryHandle cpp; } occlusionQuery = { _occlusionQuery };
|
||||
return bgfx::submit(_id, program.cpp, occlusionQuery.cpp, _depth);
|
||||
return bgfx::submit(_id, program.cpp, occlusionQuery.cpp, _depth, _preserveState);
|
||||
}
|
||||
|
||||
BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth)
|
||||
BGFX_C_API uint32_t bgfx_submit_indirect(uint8_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle };
|
||||
union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle };
|
||||
return bgfx::submit(_id, handle.cpp, indirectHandle.cpp, _start, _num, _depth);
|
||||
return bgfx::submit(_id, handle.cpp, indirectHandle.cpp, _start, _num, _depth, _preserveState);
|
||||
}
|
||||
|
||||
BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format)
|
||||
|
|
14
src/bgfx_p.h
14
src/bgfx_p.h
|
@ -1632,15 +1632,15 @@ namespace bgfx
|
|||
m_stateFlags = BGFX_STATE_NONE;
|
||||
}
|
||||
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth);
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth, bool _preserveState);
|
||||
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth)
|
||||
uint32_t submit(uint8_t _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState)
|
||||
{
|
||||
m_draw.m_startIndirect = _start;
|
||||
m_draw.m_numIndirect = _num;
|
||||
m_draw.m_indirectBuffer = _indirectHandle;
|
||||
OcclusionQueryHandle handle = BGFX_INVALID_HANDLE;
|
||||
return submit(_id, _program, handle, _depth);
|
||||
return submit(_id, _program, handle, _depth, _preserveState);
|
||||
}
|
||||
|
||||
uint32_t dispatch(uint8_t _id, ProgramHandle _handle, uint16_t _ngx, uint16_t _ngy, uint16_t _ngz, uint8_t _flags);
|
||||
|
@ -3713,7 +3713,7 @@ namespace bgfx
|
|||
m_submit->setTexture(_stage, _sampler, textureHandle, _flags);
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth) )
|
||||
BGFX_API_FUNC(uint32_t submit(uint8_t _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, int32_t _depth, bool _preserveState) )
|
||||
{
|
||||
BGFX_CHECK_HANDLE_INVALID_OK("submit", m_programHandle, _program);
|
||||
BGFX_CHECK_HANDLE_INVALID_OK("submit", m_occlusionQueryHandle, _occlusionQuery);
|
||||
|
@ -3732,10 +3732,10 @@ namespace bgfx
|
|||
m_occlusionQuerySet.insert(_occlusionQuery.idx);
|
||||
}
|
||||
|
||||
return m_submit->submit(_id, _program, _occlusionQuery, _depth);
|
||||
return m_submit->submit(_id, _program, _occlusionQuery, _depth, _preserveState);
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(uint32_t submit(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth) )
|
||||
BGFX_API_FUNC(uint32_t submit(uint8_t _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, int32_t _depth, bool _preserveState) )
|
||||
{
|
||||
BGFX_CHECK_HANDLE_INVALID_OK("submit", m_programHandle, _handle);
|
||||
BGFX_CHECK_HANDLE("submit", m_vertexBufferHandle, _indirectHandle);
|
||||
|
@ -3743,7 +3743,7 @@ namespace bgfx
|
|||
{
|
||||
m_uniformSet.clear();
|
||||
}
|
||||
return m_submit->submit(_id, _handle, _indirectHandle, _start, _num, _depth);
|
||||
return m_submit->submit(_id, _handle, _indirectHandle, _start, _num, _depth, _preserveState);
|
||||
}
|
||||
|
||||
BGFX_API_FUNC(void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) )
|
||||
|
|
Loading…
Reference in a new issue