Render: Add support for int/double shader attributes
This commit is contained in:
@@ -4,14 +4,14 @@ layout(location = 0) out vec4 color;
|
|||||||
|
|
||||||
in vec3 v_normal;
|
in vec3 v_normal;
|
||||||
in vec2 v_textureCoordinates;
|
in vec2 v_textureCoordinates;
|
||||||
in flat float v_textureIndex;
|
in flat uint v_textureIndex;
|
||||||
|
|
||||||
uniform sampler2D u_textures[32];
|
uniform sampler2D u_textures[32];
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 textureColor = vec4(1.0f);
|
vec4 textureColor = vec4(1.0f);
|
||||||
switch(int(v_textureIndex)) {
|
switch(v_textureIndex) {
|
||||||
case 0: break; // Texture unit 0 is reserved for no texture
|
case 0: break; // Texture unit 0 is reserved for no texture
|
||||||
case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
||||||
case 2: textureColor *= texture(u_textures[2], v_textureCoordinates); break;
|
case 2: textureColor *= texture(u_textures[2], v_textureCoordinates); break;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
layout(location = 0) in vec3 a_position;
|
layout(location = 0) in vec3 a_position;
|
||||||
layout(location = 1) in vec3 a_normal;
|
layout(location = 1) in vec3 a_normal;
|
||||||
layout(location = 2) in vec2 a_textureCoordinates;
|
layout(location = 2) in vec2 a_textureCoordinates;
|
||||||
layout(location = 3) in float a_textureIndex;
|
layout(location = 3) in uint a_textureIndex;
|
||||||
|
|
||||||
out vec3 v_normal;
|
out vec3 v_normal;
|
||||||
out vec2 v_textureCoordinates;
|
out vec2 v_textureCoordinates;
|
||||||
out flat float v_textureIndex;
|
out flat uint v_textureIndex;
|
||||||
|
|
||||||
uniform mat4 u_projectionView;
|
uniform mat4 u_projectionView;
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ layout(location = 0) out vec4 color;
|
|||||||
|
|
||||||
in vec4 v_color;
|
in vec4 v_color;
|
||||||
in vec3 v_textureCoordinates;
|
in vec3 v_textureCoordinates;
|
||||||
in flat float v_textureIndex;
|
in flat uint v_textureIndex;
|
||||||
|
|
||||||
uniform samplerCube u_textures[32];
|
uniform samplerCube u_textures[32];
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 textureColor = v_color;
|
vec4 textureColor = v_color;
|
||||||
switch(int(v_textureIndex)) {
|
switch(v_textureIndex) {
|
||||||
case 0: break; // Texture unit 0 is reserved for no texture
|
case 0: break; // Texture unit 0 is reserved for no texture
|
||||||
case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
||||||
case 2: textureColor *= texture(u_textures[2], v_textureCoordinates); break;
|
case 2: textureColor *= texture(u_textures[2], v_textureCoordinates); break;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
layout(location = 0) in vec3 a_position;
|
layout(location = 0) in vec3 a_position;
|
||||||
layout(location = 1) in vec4 a_color;
|
layout(location = 1) in vec4 a_color;
|
||||||
layout(location = 2) in float a_textureIndex;
|
layout(location = 2) in uint a_textureIndex;
|
||||||
|
|
||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec3 v_textureCoordinates;
|
out vec3 v_textureCoordinates;
|
||||||
out flat float v_textureIndex;
|
out flat uint v_textureIndex;
|
||||||
|
|
||||||
uniform mat4 u_projectionView;
|
uniform mat4 u_projectionView;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ layout(location = 0) out vec4 color;
|
|||||||
|
|
||||||
in vec4 v_color;
|
in vec4 v_color;
|
||||||
in vec2 v_textureCoordinates;
|
in vec2 v_textureCoordinates;
|
||||||
in flat float v_textureIndex;
|
in flat uint v_textureIndex;
|
||||||
in float v_width;
|
in float v_width;
|
||||||
in float v_edge;
|
in float v_edge;
|
||||||
in float v_borderWidth;
|
in float v_borderWidth;
|
||||||
@@ -25,7 +25,7 @@ float alpha(float textureAlpha)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 textureColor = v_color;
|
vec4 textureColor = v_color;
|
||||||
switch(int(v_textureIndex)) {
|
switch(v_textureIndex) {
|
||||||
case 0: break; // Texture unit 0 is reserved for no texture
|
case 0: break; // Texture unit 0 is reserved for no texture
|
||||||
// case 1: textureColor.a = 1; break;
|
// case 1: textureColor.a = 1; break;
|
||||||
case 1: textureColor.a = alpha(texture(u_textures[1], v_textureCoordinates).a); break;
|
case 1: textureColor.a = alpha(texture(u_textures[1], v_textureCoordinates).a); break;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
layout(location = 0) in vec3 a_position;
|
layout(location = 0) in vec3 a_position;
|
||||||
layout(location = 1) in vec4 a_color;
|
layout(location = 1) in vec4 a_color;
|
||||||
layout(location = 2) in vec2 a_textureCoordinates;
|
layout(location = 2) in vec2 a_textureCoordinates;
|
||||||
layout(location = 3) in float a_textureIndex;
|
layout(location = 3) in uint a_textureIndex;
|
||||||
layout(location = 4) in float a_width;
|
layout(location = 4) in float a_width;
|
||||||
layout(location = 5) in float a_edge;
|
layout(location = 5) in float a_edge;
|
||||||
layout(location = 6) in float a_borderWidth;
|
layout(location = 6) in float a_borderWidth;
|
||||||
@@ -13,7 +13,7 @@ layout(location = 9) in float a_offset;
|
|||||||
|
|
||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec2 v_textureCoordinates;
|
out vec2 v_textureCoordinates;
|
||||||
out flat float v_textureIndex;
|
out flat uint v_textureIndex;
|
||||||
out float v_width;
|
out float v_width;
|
||||||
out float v_edge;
|
out float v_edge;
|
||||||
out float v_borderWidth;
|
out float v_borderWidth;
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ layout(location = 0) out vec4 color;
|
|||||||
|
|
||||||
in vec4 v_color;
|
in vec4 v_color;
|
||||||
in vec2 v_textureCoordinates;
|
in vec2 v_textureCoordinates;
|
||||||
in flat float v_textureIndex;
|
in flat uint v_textureIndex;
|
||||||
|
|
||||||
uniform sampler2D u_textures[32];
|
uniform sampler2D u_textures[32];
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 textureColor = v_color;
|
vec4 textureColor = v_color;
|
||||||
switch(int(v_textureIndex)) {
|
switch(v_textureIndex) {
|
||||||
case 0: break; // Texture unit 0 is reserved for no texture
|
case 0: break; // Texture unit 0 is reserved for no texture
|
||||||
case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
case 1: textureColor *= texture(u_textures[1], v_textureCoordinates); break;
|
||||||
case 2: textureColor *= texture(u_textures[2], v_textureCoordinates); break;
|
case 2: textureColor *= texture(u_textures[2], v_textureCoordinates); break;
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
layout(location = 0) in vec3 a_position;
|
layout(location = 0) in vec3 a_position;
|
||||||
layout(location = 1) in vec4 a_color;
|
layout(location = 1) in vec4 a_color;
|
||||||
layout(location = 2) in vec2 a_textureCoordinates;
|
layout(location = 2) in vec2 a_textureCoordinates;
|
||||||
layout(location = 3) in float a_textureIndex;
|
layout(location = 3) in uint a_textureIndex;
|
||||||
|
|
||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec2 v_textureCoordinates;
|
out vec2 v_textureCoordinates;
|
||||||
out flat float v_textureIndex;
|
out flat uint v_textureIndex;
|
||||||
|
|
||||||
uniform mat4 u_projectionView;
|
uniform mat4 u_projectionView;
|
||||||
|
|
||||||
|
|||||||
@@ -306,6 +306,36 @@ void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer)
|
|||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
for (const auto& element : layout) {
|
for (const auto& element : layout) {
|
||||||
glEnableVertexAttribArray(index);
|
glEnableVertexAttribArray(index);
|
||||||
|
switch (element.getType()) {
|
||||||
|
case BufferElementType::None:
|
||||||
|
break;
|
||||||
|
case BufferElementType::Int:
|
||||||
|
case BufferElementType::Int2:
|
||||||
|
case BufferElementType::Int3:
|
||||||
|
case BufferElementType::Int4:
|
||||||
|
case BufferElementType::Uint:
|
||||||
|
case BufferElementType::Uint2:
|
||||||
|
case BufferElementType::Uint3:
|
||||||
|
case BufferElementType::Uint4: {
|
||||||
|
glVertexAttribIPointer(
|
||||||
|
index,
|
||||||
|
element.getTypeCount(),
|
||||||
|
element.getTypeGL(),
|
||||||
|
layout.getStride(),
|
||||||
|
reinterpret_cast<const void*>(element.getOffset()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BufferElementType::Bool:
|
||||||
|
case BufferElementType::Bool2:
|
||||||
|
case BufferElementType::Bool3:
|
||||||
|
case BufferElementType::Bool4:
|
||||||
|
case BufferElementType::Float:
|
||||||
|
case BufferElementType::Vec2:
|
||||||
|
case BufferElementType::Vec3:
|
||||||
|
case BufferElementType::Vec4:
|
||||||
|
case BufferElementType::Mat2:
|
||||||
|
case BufferElementType::Mat3:
|
||||||
|
case BufferElementType::Mat4: {
|
||||||
glVertexAttribPointer(
|
glVertexAttribPointer(
|
||||||
index,
|
index,
|
||||||
element.getTypeCount(),
|
element.getTypeCount(),
|
||||||
@@ -313,6 +343,26 @@ void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer)
|
|||||||
element.getNormalized() ? GL_TRUE : GL_FALSE,
|
element.getNormalized() ? GL_TRUE : GL_FALSE,
|
||||||
layout.getStride(),
|
layout.getStride(),
|
||||||
reinterpret_cast<const void*>(element.getOffset()));
|
reinterpret_cast<const void*>(element.getOffset()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BufferElementType::VecDouble:
|
||||||
|
case BufferElementType::VecDouble2:
|
||||||
|
case BufferElementType::VecDouble3:
|
||||||
|
case BufferElementType::VecDouble4:
|
||||||
|
case BufferElementType::MatDouble2:
|
||||||
|
case BufferElementType::MatDouble3:
|
||||||
|
case BufferElementType::MatDouble4: {
|
||||||
|
glVertexAttribLPointer(
|
||||||
|
index,
|
||||||
|
element.getTypeCount(),
|
||||||
|
element.getTypeGL(),
|
||||||
|
layout.getStride(),
|
||||||
|
reinterpret_cast<const void*>(element.getOffset()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
};
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ Renderer2D::Renderer2D(s)
|
|||||||
{ BufferElementType::Vec3, "a_position" },
|
{ BufferElementType::Vec3, "a_position" },
|
||||||
{ BufferElementType::Vec4, "a_color" },
|
{ BufferElementType::Vec4, "a_color" },
|
||||||
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
||||||
{ BufferElementType::Float, "a_textureIndex" },
|
{ BufferElementType::Uint, "a_textureIndex" },
|
||||||
});
|
});
|
||||||
m_vertexArray->addVertexBuffer(vertexBuffer);
|
m_vertexArray->addVertexBuffer(vertexBuffer);
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color,
|
|||||||
m_vertexBufferPtr->position = transform.transform * m_vertexPositions[i];
|
m_vertexBufferPtr->position = transform.transform * m_vertexPositions[i];
|
||||||
m_vertexBufferPtr->color = color[i];
|
m_vertexBufferPtr->color = color[i];
|
||||||
m_vertexBufferPtr->textureCoordinates = textureCoordinates[i];
|
m_vertexBufferPtr->textureCoordinates = textureCoordinates[i];
|
||||||
m_vertexBufferPtr->textureIndex = static_cast<float>(textureUnitIndex);
|
m_vertexBufferPtr->textureIndex = textureUnitIndex;
|
||||||
m_vertexBufferPtr++;
|
m_vertexBufferPtr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ RendererCubemap::RendererCubemap(s)
|
|||||||
vertexBuffer->setLayout({
|
vertexBuffer->setLayout({
|
||||||
{ BufferElementType::Vec3, "a_position" },
|
{ BufferElementType::Vec3, "a_position" },
|
||||||
{ BufferElementType::Vec4, "a_color" },
|
{ BufferElementType::Vec4, "a_color" },
|
||||||
{ BufferElementType::Float, "a_textureIndex" },
|
{ BufferElementType::Uint, "a_textureIndex" },
|
||||||
});
|
});
|
||||||
m_vertexArray->addVertexBuffer(vertexBuffer);
|
m_vertexArray->addVertexBuffer(vertexBuffer);
|
||||||
|
|
||||||
@@ -386,7 +386,7 @@ void RendererCubemap::drawCubemap(const TransformComponent& transform, glm::mat4
|
|||||||
for (uint32_t i = 0; i < vertexPerQuad * quadPerCube; i++) {
|
for (uint32_t i = 0; i < vertexPerQuad * quadPerCube; i++) {
|
||||||
m_vertexBufferPtr->position = transform.transform * m_vertexPositions[i];
|
m_vertexBufferPtr->position = transform.transform * m_vertexPositions[i];
|
||||||
m_vertexBufferPtr->color = color[i % 4];
|
m_vertexBufferPtr->color = color[i % 4];
|
||||||
m_vertexBufferPtr->textureIndex = static_cast<float>(textureUnitIndex);
|
m_vertexBufferPtr->textureIndex = textureUnitIndex;
|
||||||
m_vertexBufferPtr++;
|
m_vertexBufferPtr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,7 +423,7 @@ RendererFont::RendererFont(s)
|
|||||||
{ BufferElementType::Vec3, "a_position" },
|
{ BufferElementType::Vec3, "a_position" },
|
||||||
{ BufferElementType::Vec4, "a_color" },
|
{ BufferElementType::Vec4, "a_color" },
|
||||||
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
||||||
{ BufferElementType::Float, "a_textureIndex" },
|
{ BufferElementType::Uint, "a_textureIndex" },
|
||||||
{ BufferElementType::Float, "a_width" },
|
{ BufferElementType::Float, "a_width" },
|
||||||
{ BufferElementType::Float, "a_edge" },
|
{ BufferElementType::Float, "a_edge" },
|
||||||
{ BufferElementType::Float, "a_borderWidth" },
|
{ BufferElementType::Float, "a_borderWidth" },
|
||||||
@@ -450,7 +450,7 @@ void RendererFont::drawSymbol(std::array<SymbolVertex, vertexPerQuad>& symbolQua
|
|||||||
m_vertexBufferPtr->quad.position = symbolQuad[i].quad.position;
|
m_vertexBufferPtr->quad.position = symbolQuad[i].quad.position;
|
||||||
m_vertexBufferPtr->quad.color = symbolQuad[i].quad.color;
|
m_vertexBufferPtr->quad.color = symbolQuad[i].quad.color;
|
||||||
m_vertexBufferPtr->quad.textureCoordinates = symbolQuad[i].quad.textureCoordinates;
|
m_vertexBufferPtr->quad.textureCoordinates = symbolQuad[i].quad.textureCoordinates;
|
||||||
m_vertexBufferPtr->quad.textureIndex = static_cast<float>(textureUnitIndex);
|
m_vertexBufferPtr->quad.textureIndex = textureUnitIndex;
|
||||||
|
|
||||||
m_vertexBufferPtr->width = symbolQuad[i].width;
|
m_vertexBufferPtr->width = symbolQuad[i].width;
|
||||||
m_vertexBufferPtr->edge = symbolQuad[i].edge;
|
m_vertexBufferPtr->edge = symbolQuad[i].edge;
|
||||||
@@ -495,7 +495,7 @@ Renderer3D::Renderer3D(s)
|
|||||||
{ BufferElementType::Vec3, "a_position" },
|
{ BufferElementType::Vec3, "a_position" },
|
||||||
{ BufferElementType::Vec3, "a_normal" },
|
{ BufferElementType::Vec3, "a_normal" },
|
||||||
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
{ BufferElementType::Vec2, "a_textureCoordinates" },
|
||||||
{ BufferElementType::Float, "a_textureIndex" },
|
{ BufferElementType::Uint, "a_textureIndex" },
|
||||||
});
|
});
|
||||||
m_vertexArray->addVertexBuffer(vertexBuffer);
|
m_vertexArray->addVertexBuffer(vertexBuffer);
|
||||||
|
|
||||||
@@ -521,7 +521,7 @@ void Renderer3D::drawModel(std::span<const Vertex> vertices, std::span<const uin
|
|||||||
m_vertexBufferPtr->position = transform.transform * glm::vec4(vertex.position, 1.0f);
|
m_vertexBufferPtr->position = transform.transform * glm::vec4(vertex.position, 1.0f);
|
||||||
m_vertexBufferPtr->normal = vertex.normal;
|
m_vertexBufferPtr->normal = vertex.normal;
|
||||||
m_vertexBufferPtr->textureCoordinates = vertex.textureCoordinates;
|
m_vertexBufferPtr->textureCoordinates = vertex.textureCoordinates;
|
||||||
m_vertexBufferPtr->textureIndex = static_cast<float>(textureUnitIndex);
|
m_vertexBufferPtr->textureIndex = textureUnitIndex;
|
||||||
m_vertexBufferPtr++;
|
m_vertexBufferPtr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ struct QuadVertex {
|
|||||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||||
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
||||||
float textureIndex = 0;
|
uint32_t textureIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CubemapVertex {
|
struct CubemapVertex {
|
||||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||||
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
glm::vec4 color { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
float textureIndex = 0;
|
uint32_t textureIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SymbolVertex {
|
struct SymbolVertex {
|
||||||
@@ -54,7 +54,7 @@ struct Vertex {
|
|||||||
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
glm::vec3 position { 0.0f, 0.0f, 0.0f };
|
||||||
glm::vec3 normal { 1.0f, 1.0f, 1.0f };
|
glm::vec3 normal { 1.0f, 1.0f, 1.0f };
|
||||||
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
glm::vec2 textureCoordinates { 0.0f, 0.0f };
|
||||||
float textureIndex = 0;
|
uint32_t textureIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user