Add new mesh data formats: int32, uint32, [u]int8, [u]int16, snorm8, and snorm16.

Integer formats for vertex attributes are only supported in glsl3 shaders. They use ivec/uvec types in glsl.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2020-01-11 22:24:38 -04:00
parent 5c009d4bb9
commit 23bc1a7aae
9 changed files with 193 additions and 69 deletions
+33 -3
View File
@@ -627,18 +627,43 @@ GLenum OpenGL::getGLIndexDataType(IndexDataType type)
}
}
GLenum OpenGL::getGLVertexDataType(vertex::DataType type, GLboolean &normalized)
GLenum OpenGL::getGLVertexDataType(vertex::DataType type, GLboolean &normalized, bool &intformat)
{
normalized = GL_FALSE;
intformat = false;
switch (type)
{
case vertex::DATA_SNORM8:
normalized = GL_TRUE;
return GL_BYTE;
case vertex::DATA_UNORM8:
normalized = GL_TRUE;
return GL_UNSIGNED_BYTE;
case vertex::DATA_INT8:
intformat = true;
return GL_BYTE;
case vertex::DATA_UINT8:
intformat = true;
return GL_UNSIGNED_BYTE;
case vertex::DATA_SNORM16:
normalized = GL_TRUE;
return GL_SHORT;
case vertex::DATA_UNORM16:
normalized = GL_TRUE;
return GL_UNSIGNED_SHORT;
case vertex::DATA_INT16:
intformat = true;
return GL_SHORT;
case vertex::DATA_UINT16:
intformat = true;
return GL_UNSIGNED_SHORT;
case vertex::DATA_INT32:
intformat = true;
return GL_INT;
case vertex::DATA_UINT32:
intformat = true;
return GL_UNSIGNED_INT;
case vertex::DATA_FLOAT:
normalized = GL_FALSE;
return GL_FLOAT;
@@ -718,12 +743,17 @@ void OpenGL::setVertexAttributes(const vertex::Attributes &attributes, const ver
glVertexAttribDivisor(i, divisor);
GLboolean normalized = GL_FALSE;
GLenum gltype = getGLVertexDataType(attrib.type, normalized);
bool intformat = false;
GLenum gltype = getGLVertexDataType(attrib.type, normalized, intformat);
const void *offsetpointer = reinterpret_cast<void*>(bufferinfo.offset + attrib.offsetFromVertex);
bindBuffer(BUFFER_VERTEX, (GLuint) bufferinfo.buffer->getHandle());
glVertexAttribPointer(i, attrib.components, gltype, normalized, layout.stride, offsetpointer);
if (intformat)
glVertexAttribIPointer(i, attrib.components, gltype, layout.stride, offsetpointer);
else
glVertexAttribPointer(i, attrib.components, gltype, normalized, layout.stride, offsetpointer);
}
i++;
+1 -1
View File
@@ -404,7 +404,7 @@ public:
static GLenum getGLPrimitiveType(PrimitiveType type);
static GLenum getGLBufferType(BufferType type);
static GLenum getGLIndexDataType(IndexDataType type);
static GLenum getGLVertexDataType(vertex::DataType type, GLboolean &normalized);
static GLenum getGLVertexDataType(vertex::DataType type, GLboolean &normalized, bool &intformat);
static GLenum getGLBufferUsage(vertex::Usage usage);
static GLenum getGLTextureType(TextureType type);
static GLint getGLWrapMode(Texture::WrapMode wmode);