mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-25 16:06:31 +00:00
Emulate bad vertex attribute casts on GL in mesh viewer
* On GL you can specify a vertex attribute that's stored as int but gets converted to float with glVertexAttribFormat instead of glVertexAttribIFormat. However if the shader accepts an int this is invalid and the value is undefined - we emulate this as the float bits being read as int directly, but that's not guaranteed behaviour. * Normally we don't emulate this kind of mis-cast behaviour and just display the type of data passed to the shader, but in this case GL lets you specify three types (stored as int, cast to float, read as int) so our normal behaviour of just showing the input can be more misleading than normal.
This commit is contained in:
@@ -455,6 +455,7 @@ struct BufferElementProperties
|
||||
int buffer = 0;
|
||||
ShaderBuiltin systemValue = ShaderBuiltin::Undefined;
|
||||
bool perinstance = false;
|
||||
bool floatCastWrong = false;
|
||||
int instancerate = 1;
|
||||
};
|
||||
|
||||
@@ -733,7 +734,14 @@ static QString interpretVariant(const QVariant &v, const ShaderConstant &el,
|
||||
}
|
||||
else if(vt == QMetaType::UInt || vt == QMetaType::UShort || vt == QMetaType::UChar)
|
||||
{
|
||||
uint u = v.toUInt();
|
||||
uint32_t u = v.toUInt();
|
||||
|
||||
if(prop.floatCastWrong)
|
||||
{
|
||||
float f = (float)u;
|
||||
memcpy(&u, &f, sizeof(f));
|
||||
}
|
||||
|
||||
if(el.type.descriptor.displayAsHex && prop.format.type == ResourceFormatType::Regular)
|
||||
ret = Formatter::HexFormat(u, prop.format.compByteWidth);
|
||||
else
|
||||
@@ -741,7 +749,14 @@ static QString interpretVariant(const QVariant &v, const ShaderConstant &el,
|
||||
}
|
||||
else if(vt == QMetaType::Int || vt == QMetaType::Short || vt == QMetaType::SChar)
|
||||
{
|
||||
int i = v.toInt();
|
||||
int32_t i = v.toInt();
|
||||
|
||||
if(prop.floatCastWrong)
|
||||
{
|
||||
float f = (float)i;
|
||||
memcpy(&i, &f, sizeof(f));
|
||||
}
|
||||
|
||||
if(i >= 0)
|
||||
ret = lit(" ") + Formatter::Format(i);
|
||||
else
|
||||
@@ -1533,6 +1548,7 @@ static void ConfigureMeshColumns(ICaptureContext &ctx, PopulateBufferData *bufda
|
||||
p.buffer = a.vertexBuffer;
|
||||
p.perinstance = a.perInstance;
|
||||
p.instancerate = a.instanceRate;
|
||||
p.floatCastWrong = a.floatCastWrong;
|
||||
p.format = a.format;
|
||||
|
||||
bufdata->vsinConfig.genericsEnabled[bufdata->vsinConfig.columns.count()] = false;
|
||||
|
||||
Reference in New Issue
Block a user