Compare commits

..

No commits in common. "a02d1ba71ec5b8586f84863b5dfa03e34c2fcdba" and "874fec434afa2d18c2d3454eef9a723d2d154196" have entirely different histories.

2 changed files with 18 additions and 16 deletions

View File

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

View File

@ -26,6 +26,9 @@ 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"};
@ -159,16 +162,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_TRUE, glVertexAttribPointer(attribute_index, e.num_elements, e.type, GL_FALSE,
it->second.vertex_size, it->second.vertex_size,
(const GLvoid*)e.vertex_offset); (const GLvoid*)e.vertex_offset);
} }
@ -584,8 +587,9 @@ 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, GL_TRUE, glVertexAttribPointer(attribute_index, num_elements, type,
vertex_size, (const GLvoid*)vertex_offset); kGlNormalize[data_type], vertex_size,
(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;
@ -629,8 +633,6 @@ 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;
@ -638,7 +640,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 += "_"s + std::to_string(tex_coord++); attrib_name += 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;