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)
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 proj;
proj.CreateOrthoProjection(draw_data->DisplayPos.x,
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);
shader_->Activate();
shader_->SetUniform("projection", proj);
shader_->SetUniform("projection", ortho_projection);
shader_->UploadUniforms();
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_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"};
@ -159,16 +162,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_TRUE,
glVertexAttribPointer(attribute_index, e.num_elements, e.type, GL_FALSE,
it->second.vertex_size,
(const GLvoid*)e.vertex_offset);
}
@ -584,8 +587,9 @@ bool RendererOpenGL::SetupVertexLayout(
if (use_vao) {
// This will be saved into the vertex array object.
glEnableVertexAttribArray(attribute_index);
glVertexAttribPointer(attribute_index, num_elements, type, GL_TRUE,
vertex_size, (const GLvoid*)vertex_offset);
glVertexAttribPointer(attribute_index, num_elements, type,
kGlNormalize[data_type], vertex_size,
(const GLvoid*)vertex_offset);
} else {
// Need to keep this information for when rendering.
GeometryOpenGL::Element element;
@ -629,8 +633,6 @@ 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;
@ -638,7 +640,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 += "_"s + std::to_string(tex_coord++);
attrib_name += std::to_string(tex_coord++);
glBindAttribLocation(id, current++, attrib_name.c_str());
}
return current > 0;