mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Fixed per view uniform order, and added more validation. (#3497)
This commit is contained in:
committed by
GitHub
parent
c18119bc41
commit
f888f9d9a4
14
src/bgfx.cpp
14
src/bgfx.cpp
@@ -5226,11 +5226,23 @@ namespace bgfx
|
||||
|
||||
UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num)
|
||||
{
|
||||
BX_ASSERT(UniformType::End != _type && UniformType::Count > _type
|
||||
, "UniformType argument is not valid (_type: %d)!"
|
||||
, _type
|
||||
);
|
||||
return s_ctx->createUniform(_name, UniformFreq::Draw, _type, _num);
|
||||
}
|
||||
|
||||
UniformHandle createUniform(const char* _name, UniformFreq::Enum _freq, UniformType::Enum _type, uint16_t _num)
|
||||
{
|
||||
BX_ASSERT(UniformType::End != _type && UniformType::Count > _type
|
||||
, "UniformType argument is not valid (_type: %d)!"
|
||||
, _type
|
||||
);
|
||||
BX_ASSERT(UniformFreq::Count > _freq
|
||||
, "UniformFreq argument is not valid (_freq: %d)!"
|
||||
, _freq
|
||||
);
|
||||
return s_ctx->createUniform(_name, _freq, _type, _num);
|
||||
}
|
||||
|
||||
@@ -5442,11 +5454,13 @@ namespace bgfx
|
||||
void setViewUniform(ViewId _id, UniformHandle _handle, const void* _value, uint16_t _num)
|
||||
{
|
||||
BX_ASSERT(checkView(_id), "Invalid view id: %d", _id);
|
||||
BGFX_CHECK_HANDLE("setUniform", s_ctx->m_uniformHandle, _handle);
|
||||
s_ctx->setViewUniform(_id, _handle, _value, _num);
|
||||
}
|
||||
|
||||
void setFrameUniform(UniformHandle _handle, const void* _value, uint16_t _num)
|
||||
{
|
||||
BGFX_CHECK_HANDLE("setUniform", s_ctx->m_uniformHandle, _handle);
|
||||
s_ctx->setViewUniform(UINT16_MAX, _handle, _value, _num);
|
||||
}
|
||||
|
||||
|
||||
33
src/bgfx_p.h
33
src/bgfx_p.h
@@ -3289,6 +3289,23 @@ namespace bgfx
|
||||
{
|
||||
const UniformRef& uniform = getUniformRef(_handle);
|
||||
|
||||
const UniformFreq::Enum freq = UINT16_MAX == _id
|
||||
? UniformFreq::Frame
|
||||
: UniformFreq::View
|
||||
;
|
||||
|
||||
BX_ASSERT(0 < uniform.m_refCount
|
||||
, "Uniform reference count it 0 (handle %3d)!"
|
||||
, _handle.idx
|
||||
);
|
||||
BX_ASSERT(uniform.m_freq == freq
|
||||
, "Setting uniform per view, but uniform is created with different bgfx::UniformFreq::Enum!"
|
||||
);
|
||||
BX_ASSERT(_num == UINT16_MAX || uniform.m_num >= _num
|
||||
, "Truncated uniform update. %d (max: %d)"
|
||||
, _num, uniform.m_num
|
||||
);
|
||||
|
||||
UniformCacheKey key =
|
||||
{
|
||||
.m_offset = 0,
|
||||
@@ -4667,9 +4684,10 @@ namespace bgfx
|
||||
}
|
||||
|
||||
PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name);
|
||||
if (PredefinedUniform::Count == predefined && UniformType::End != UniformType::Enum(type) )
|
||||
if (PredefinedUniform::Count == predefined
|
||||
&& UniformType::End != UniformType::Enum(type) )
|
||||
{
|
||||
uniforms[sr.m_num] = createUniform(name, UniformFreq::Draw, UniformType::Enum(type), num);
|
||||
uniforms[sr.m_num] = createUniform(name, UniformFreq::Count, UniformType::Enum(type), num);
|
||||
sr.m_num++;
|
||||
}
|
||||
}
|
||||
@@ -5354,7 +5372,11 @@ namespace bgfx
|
||||
const uint32_t oldsize = g_uniformTypeSize[uniform.m_type];
|
||||
const uint32_t newsize = g_uniformTypeSize[_type];
|
||||
|
||||
uniform.m_freq = _freq; // Ignore shader created uniforms, and use UniformFreq when user creates uniform.
|
||||
if (UniformFreq::Count != _freq)
|
||||
{
|
||||
// Ignore shader created uniforms, and use UniformFreq when user creates uniform.
|
||||
uniform.m_freq = _freq;
|
||||
}
|
||||
|
||||
if (oldsize < newsize
|
||||
|| uniform.m_num < _num)
|
||||
@@ -5390,7 +5412,10 @@ namespace bgfx
|
||||
UniformRef& uniform = m_uniformRef[handle.idx];
|
||||
uniform.m_name.set(_name);
|
||||
uniform.m_refCount = 1;
|
||||
uniform.m_freq = _freq;
|
||||
uniform.m_freq = UniformFreq::Count == _freq
|
||||
? UniformFreq::Draw
|
||||
: _freq
|
||||
;
|
||||
uniform.m_type = _type;
|
||||
uniform.m_num = _num;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user