mirror of https://github.com/auygun/kaliber.git
OpenGL: fixed-point data values should be normalized
This commit is contained in:
parent
849599afd8
commit
a02d1ba71e
|
@ -26,9 +26,6 @@ constexpr GLenum kGlDataType[eng::kDataType_Max] = {
|
||||||
GL_UNSIGNED_BYTE, GL_FLOAT, GL_INT,
|
GL_UNSIGNED_BYTE, GL_FLOAT, GL_INT,
|
||||||
GL_SHORT, GL_UNSIGNED_INT, GL_UNSIGNED_SHORT};
|
GL_SHORT, GL_UNSIGNED_INT, GL_UNSIGNED_SHORT};
|
||||||
|
|
||||||
constexpr GLboolean kGlNormalize[eng::kDataType_Max] = {
|
|
||||||
GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE};
|
|
||||||
|
|
||||||
const std::string kAttributeNames[eng::kAttribType_Max] = {
|
const std::string kAttributeNames[eng::kAttribType_Max] = {
|
||||||
"in_color", "in_normal", "in_position", "in_tex_coord"};
|
"in_color", "in_normal", "in_position", "in_tex_coord"};
|
||||||
|
|
||||||
|
@ -162,16 +159,16 @@ void RendererOpenGL::Draw(uint64_t resource_id,
|
||||||
num_indices = it->second.num_indices;
|
num_indices = it->second.num_indices;
|
||||||
|
|
||||||
// Set up the vertex data.
|
// Set up the vertex data.
|
||||||
if (it->second.vertex_array_id)
|
if (it->second.vertex_array_id) {
|
||||||
glBindVertexArray(it->second.vertex_array_id);
|
glBindVertexArray(it->second.vertex_array_id);
|
||||||
else {
|
} else {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, it->second.vertex_buffer_id);
|
glBindBuffer(GL_ARRAY_BUFFER, it->second.vertex_buffer_id);
|
||||||
for (GLuint attribute_index = 0;
|
for (GLuint attribute_index = 0;
|
||||||
attribute_index < (GLuint)it->second.vertex_layout.size();
|
attribute_index < (GLuint)it->second.vertex_layout.size();
|
||||||
++attribute_index) {
|
++attribute_index) {
|
||||||
GeometryOpenGL::Element& e = it->second.vertex_layout[attribute_index];
|
GeometryOpenGL::Element& e = it->second.vertex_layout[attribute_index];
|
||||||
glEnableVertexAttribArray(attribute_index);
|
glEnableVertexAttribArray(attribute_index);
|
||||||
glVertexAttribPointer(attribute_index, e.num_elements, e.type, GL_FALSE,
|
glVertexAttribPointer(attribute_index, e.num_elements, e.type, GL_TRUE,
|
||||||
it->second.vertex_size,
|
it->second.vertex_size,
|
||||||
(const GLvoid*)e.vertex_offset);
|
(const GLvoid*)e.vertex_offset);
|
||||||
}
|
}
|
||||||
|
@ -587,9 +584,8 @@ bool RendererOpenGL::SetupVertexLayout(
|
||||||
if (use_vao) {
|
if (use_vao) {
|
||||||
// This will be saved into the vertex array object.
|
// This will be saved into the vertex array object.
|
||||||
glEnableVertexAttribArray(attribute_index);
|
glEnableVertexAttribArray(attribute_index);
|
||||||
glVertexAttribPointer(attribute_index, num_elements, type,
|
glVertexAttribPointer(attribute_index, num_elements, type, GL_TRUE,
|
||||||
kGlNormalize[data_type], vertex_size,
|
vertex_size, (const GLvoid*)vertex_offset);
|
||||||
(const GLvoid*)vertex_offset);
|
|
||||||
} else {
|
} else {
|
||||||
// Need to keep this information for when rendering.
|
// Need to keep this information for when rendering.
|
||||||
GeometryOpenGL::Element element;
|
GeometryOpenGL::Element element;
|
||||||
|
@ -633,6 +629,8 @@ GLuint RendererOpenGL::CreateShader(const char* source, GLenum type) {
|
||||||
|
|
||||||
bool RendererOpenGL::BindAttributeLocation(GLuint id,
|
bool RendererOpenGL::BindAttributeLocation(GLuint id,
|
||||||
const VertexDescription& vd) {
|
const VertexDescription& vd) {
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
int current = 0;
|
int current = 0;
|
||||||
int tex_coord = 0;
|
int tex_coord = 0;
|
||||||
|
|
||||||
|
@ -640,7 +638,7 @@ bool RendererOpenGL::BindAttributeLocation(GLuint id,
|
||||||
AttribType attrib_type = std::get<0>(attr);
|
AttribType attrib_type = std::get<0>(attr);
|
||||||
std::string attrib_name = kAttributeNames[attrib_type];
|
std::string attrib_name = kAttributeNames[attrib_type];
|
||||||
if (attrib_type == kAttribType_TexCoord)
|
if (attrib_type == kAttribType_TexCoord)
|
||||||
attrib_name += std::to_string(tex_coord++);
|
attrib_name += "_"s + std::to_string(tex_coord++);
|
||||||
glBindAttribLocation(id, current++, attrib_name.c_str());
|
glBindAttribLocation(id, current++, attrib_name.c_str());
|
||||||
}
|
}
|
||||||
return current > 0;
|
return current > 0;
|
||||||
|
|
Loading…
Reference in New Issue