Compare commits

..

2 Commits

Author SHA1 Message Date
Attila Uygun a02d1ba71e OpenGL: fixed-point data values should be normalized 2023-11-01 20:43:06 +01:00
Attila Uygun 849599afd8 Reformat 2023-10-31 21:39:59 +01:00
2 changed files with 16 additions and 18 deletions

View File

@ -146,16 +146,16 @@ void ImguiBackend::Draw() {
if (!draw_data || draw_data->CmdListsCount <= 0)
return;
renderer_->SetViewport(0, 0, draw_data->DisplaySize.x, draw_data->DisplaySize.y);
renderer_->SetViewport(0, 0, draw_data->DisplaySize.x,
draw_data->DisplaySize.y);
base::Matrix4f ortho_projection;
ortho_projection.CreateOrthoProjection(
draw_data->DisplayPos.x,
draw_data->DisplayPos.x + draw_data->DisplaySize.x,
draw_data->DisplayPos.y + draw_data->DisplaySize.y,
draw_data->DisplayPos.y);
base::Matrix4f proj;
proj.CreateOrthoProjection(draw_data->DisplayPos.x,
draw_data->DisplayPos.x + draw_data->DisplaySize.x,
draw_data->DisplayPos.y + draw_data->DisplaySize.y,
draw_data->DisplayPos.y);
shader_->Activate();
shader_->SetUniform("projection", ortho_projection);
shader_->SetUniform("projection", proj);
shader_->UploadUniforms();
for (int n = 0; n < draw_data->CmdListsCount; n++) {

View File

@ -26,9 +26,6 @@ constexpr GLenum kGlDataType[eng::kDataType_Max] = {
GL_UNSIGNED_BYTE, GL_FLOAT, GL_INT,
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] = {
"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;
// Set up the vertex data.
if (it->second.vertex_array_id)
if (it->second.vertex_array_id) {
glBindVertexArray(it->second.vertex_array_id);
else {
} else {
glBindBuffer(GL_ARRAY_BUFFER, it->second.vertex_buffer_id);
for (GLuint attribute_index = 0;
attribute_index < (GLuint)it->second.vertex_layout.size();
++attribute_index) {
GeometryOpenGL::Element& e = it->second.vertex_layout[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,
(const GLvoid*)e.vertex_offset);
}
@ -587,9 +584,8 @@ bool RendererOpenGL::SetupVertexLayout(
if (use_vao) {
// This will be saved into the vertex array object.
glEnableVertexAttribArray(attribute_index);
glVertexAttribPointer(attribute_index, num_elements, type,
kGlNormalize[data_type], vertex_size,
(const GLvoid*)vertex_offset);
glVertexAttribPointer(attribute_index, num_elements, type, GL_TRUE,
vertex_size, (const GLvoid*)vertex_offset);
} else {
// Need to keep this information for when rendering.
GeometryOpenGL::Element element;
@ -633,6 +629,8 @@ GLuint RendererOpenGL::CreateShader(const char* source, GLenum type) {
bool RendererOpenGL::BindAttributeLocation(GLuint id,
const VertexDescription& vd) {
using namespace std::string_literals;
int current = 0;
int tex_coord = 0;
@ -640,7 +638,7 @@ bool RendererOpenGL::BindAttributeLocation(GLuint id,
AttribType attrib_type = std::get<0>(attr);
std::string attrib_name = kAttributeNames[attrib_type];
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());
}
return current > 0;