Commit 40d96904 authored by Laszlo Agocs's avatar Laszlo Agocs

Make unorm vertex attrs normalized with all backends

parent 7d71abd1
......@@ -17,6 +17,6 @@ out gl_PerVertex { vec4 gl_Position; };
void main()
{
v_texcoord = texcoord;
v_color = color / vec4(255.0);
v_color = color;
gl_Position = ubuf.mvp * vec4(position.xy, 0.0, 1.0);
}
......@@ -975,6 +975,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
const int stride = psD->m_vertexInputLayout.bindings[a.binding].stride;
int size = 1;
GLenum type = GL_FLOAT;
bool normalize = false;
switch (a.format) {
case QRhiVertexInputLayout::Attribute::Float4:
type = GL_FLOAT;
......@@ -994,21 +995,24 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
break;
case QRhiVertexInputLayout::Attribute::UNormByte4:
type = GL_UNSIGNED_BYTE;
normalize = true;
size = 4;
break;
case QRhiVertexInputLayout::Attribute::UNormByte2:
type = GL_UNSIGNED_BYTE;
normalize = true;
size = 2;
break;
case QRhiVertexInputLayout::Attribute::UNormByte:
type = GL_UNSIGNED_BYTE;
normalize = true;
size = 1;
break;
default:
break;
}
quint32 ofs = a.offset + cmd.args.bindVertexBuffer.offset;
f->glVertexAttribPointer(a.location, size, type, GL_FALSE, stride,
f->glVertexAttribPointer(a.location, size, type, normalize, stride,
reinterpret_cast<const GLvoid *>(quintptr(ofs)));
f->glEnableVertexAttribArray(a.location);
}
......
......@@ -1836,12 +1836,12 @@ static inline MTLVertexFormat toMetalAttributeFormat(QRhiVertexInputLayout::Attr
case QRhiVertexInputLayout::Attribute::Float:
return MTLVertexFormatFloat;
case QRhiVertexInputLayout::Attribute::UNormByte4:
return MTLVertexFormatUChar4;
return MTLVertexFormatUChar4Normalized;
case QRhiVertexInputLayout::Attribute::UNormByte2:
return MTLVertexFormatUChar2;
return MTLVertexFormatUChar2Normalized;
case QRhiVertexInputLayout::Attribute::UNormByte:
if (@available(macOS 10.13, iOS 11.0, *))
return MTLVertexFormatUChar;
return MTLVertexFormatUCharNormalized;
else
Q_UNREACHABLE();
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment