Kaynağa Gözat

gpu: fix numerous OpenGL programming errors.

legacy
Sam Hocevar 5 yıl önce
ebeveyn
işleme
2c45d0918d
13 değiştirilmiş dosya ile 32 ekleme ve 20 silme
  1. +1
    -1
      doc/tutorial/01_triangle.cpp
  2. +1
    -1
      doc/tutorial/02_cube.cpp
  3. +1
    -1
      doc/tutorial/03_noise.cpp
  4. +1
    -1
      doc/tutorial/04_texture.cpp
  5. +1
    -1
      doc/tutorial/07_input.cpp
  6. +2
    -2
      doc/tutorial/08_fbo.cpp
  7. +3
    -3
      doc/tutorial/12_voronoi.cpp
  8. +9
    -2
      src/gpu/framebuffer.cpp
  9. +1
    -1
      src/gpu/shader.cpp
  10. +7
    -4
      src/gpu/vertexbuffer.cpp
  11. +1
    -0
      src/lol/gpu/vertexbuffer.h
  12. +2
    -1
      src/mesh/mesh.cpp
  13. +2
    -2
      src/scene.cpp

+ 1
- 1
doc/tutorial/01_triangle.cpp Dosyayı Görüntüle

@@ -53,8 +53,8 @@ public:
WorldEntity::tick_draw(seconds, scene);

m_shader->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 3);
m_vdecl->Unbind();
}


+ 1
- 1
doc/tutorial/02_cube.cpp Dosyayı Görüntüle

@@ -141,8 +141,8 @@ public:
scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));

m_shader->Bind();
m_vdecl->SetStream(m_vbo, m_coord, m_color);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord, m_color);

m_shader->SetUniform(m_mvp, m_matrix);
m_lines_ibo->Bind();


+ 1
- 1
doc/tutorial/03_noise.cpp Dosyayı Görüntüle

@@ -60,8 +60,8 @@ public:

m_shader->Bind();
m_shader->SetUniform(m_time_uni, m_time);
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
}


+ 1
- 1
doc/tutorial/04_texture.cpp Dosyayı Görüntüle

@@ -90,8 +90,8 @@ public:

m_shader->Bind();
m_shader->SetUniform(m_texture_uni, m_texture->GetTextureUniform(), 0);
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
}


+ 1
- 1
doc/tutorial/07_input.cpp Dosyayı Görüntüle

@@ -165,8 +165,8 @@ public:
scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));

m_shader->Bind();
m_vdecl->SetStream(m_vbo, m_coord, m_color);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord, m_color);

m_shader->SetUniform(m_mvp, m_matrix);
m_lines_ibo->Bind();


+ 2
- 2
doc/tutorial/08_fbo.cpp Dosyayı Görüntüle

@@ -98,8 +98,8 @@ public:
m_shader->SetUniform(m_uni_flag, 0.f);
m_shader->SetUniform(m_uni_point, m_hotspot);
m_shader->SetUniform(m_uni_color, m_color);
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
m_shader->Unbind();
@@ -108,8 +108,8 @@ public:
m_shader->Bind();
m_shader->SetUniform(m_uni_flag, 1.f);
m_shader->SetUniform(m_uni_texture, m_fbo->GetTextureUniform(), 0);
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_coord);
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
m_shader->Unbind();


+ 3
- 3
doc/tutorial/12_voronoi.cpp Dosyayı Görüntüle

@@ -263,8 +263,8 @@ public:
m_fbos[f].m2->SetUniform(m_fbos[f].m3[i++], voronoi_points[j].m1); //"u_source_point"
m_fbos[f].m2->SetUniform(m_fbos[f].m3[i++], vec2(512.f, 512.f)); //"u_screen_res"

m_vdecl->SetStream(m_vbo, m_fbos[f].m4.last());
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_fbos[f].m4.last());
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
m_fbos[f].m2->Unbind();
@@ -329,8 +329,8 @@ public:
shader->SetUniform(m_fbos[m_cur_fbo].m3[i++], vec2(512.f, 512.f)); //"u_screen_res"
}

m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].m4.last());
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].m4.last());
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
m_fbos[m_cur_fbo].m2->Unbind();
@@ -353,8 +353,8 @@ public:
//SCREEN DRAW
m_screen_shader->Bind();
m_screen_shader->SetUniform(m_screen_texture, m_fbos[m_cur_fbo].m1->GetTextureUniform(), 0);
m_vdecl->SetStream(m_vbo, m_screen_coord);
m_vdecl->Bind();
m_vdecl->SetStream(m_vbo, m_screen_coord);
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_vdecl->Unbind();
m_screen_shader->Unbind();


+ 9
- 2
src/gpu/framebuffer.cpp Dosyayı Görüntüle

@@ -151,7 +151,7 @@ uint32_t FramebufferFormat::GetFormatOrder()
case RGBA_8: case RGBA_8_I: case RGBA_8_UI: case RGBA_8_F:
case RGBA_16: case RGBA_16_I: case RGBA_16_UI: case RGBA_16_F:
case RGBA_32: case RGBA_32_I: case RGBA_32_UI: case RGBA_32_F:
# if defined GL_BGRA && !defined __APPLE__
# if defined GL_BGRA && !defined __APPLE__ && !defined __NX__
return (m_invert_rgb)?(GL_BGRA):(GL_RGBA);
# else
return GL_RGBA;
@@ -173,7 +173,10 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format)
{
m_data->m_size = size;
m_data->m_bound = false;
#if defined GL_ES_VERSION_2_0
#if defined GL_VERSION_4_2
GLenum internal_format = fbo_format.GetFormat();
GLenum depth = GL_DEPTH_COMPONENT16; /* for WebGL */
#elif defined GL_ES_VERSION_2_0
/* In OpenGL ES, internal format and format must match. */
GLenum internal_format = fbo_format.GetFormat();
GLenum format = fbo_format.GetFormat();
@@ -205,8 +208,12 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapmode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
#if defined GL_VERSION_4_2
glTexStorage2D(GL_TEXTURE_2D, 1, internal_format, size.x, size.y);
#else
glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size.x, size.y, 0,
format, GL_UNSIGNED_BYTE, nullptr);
#endif

#if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,


+ 1
- 1
src/gpu/shader.cpp Dosyayı Görüntüle

@@ -342,7 +342,7 @@ Shader::Shader(std::string const &name,
uint64_t flags = (uint64_t)(uint16_t)usage.ToScalar() << 16;
flags |= (uint64_t)(uint16_t)index;
// TODO: this is here just in case. Remove this once everything has been correctly tested
#if _DEBUG
#if LOL_BUILD_DEBUG
if (has_key(data->attrib_locations, flags))
{
msg::error("error while parsing attribute semantics in %s\n",


+ 7
- 4
src/gpu/vertexbuffer.cpp Dosyayı Görüntüle

@@ -69,15 +69,19 @@ VertexDeclaration::VertexDeclaration(VertexStreamBase const &s1,
if (&s10 != &VertexStreamBase::Empty) AddStream(s10);
if (&s11 != &VertexStreamBase::Empty) AddStream(s11);
if (&s12 != &VertexStreamBase::Empty) AddStream(s12);

glGenVertexArrays(1, &m_vao);
}

VertexDeclaration::~VertexDeclaration()
{
glDeleteVertexArrays(1, &m_vao);
}

void VertexDeclaration::Bind()
{
/* FIXME: Nothing to do? */
glBindVertexArray(m_vao);
}

void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count)
@@ -148,6 +152,7 @@ void VertexDeclaration::Unbind()
}
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}

void VertexDeclaration::SetStream(std::shared_ptr<VertexBuffer> vb,
@@ -176,15 +181,13 @@ void VertexDeclaration::SetStream(std::shared_ptr<VertexBuffer> vb, ShaderAttrib
return;

glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo);

for (int n = 0; n < 12 && attribs[n].m_flags != (uint64_t)0 - 1; n++)
{
VertexUsage usage = VertexUsage((attribs[n].m_flags >> 16) & 0xffff);
uint32_t index = attribs[n].m_flags & 0xffff;
uint32_t reg = attribs[n].m_flags >> 32;

if (reg != 0xffffffffu)
glEnableVertexAttribArray((GLint)reg);

/* We need to parse the whole vertex declaration to retrieve
* the information. It sucks. */

@@ -245,9 +248,9 @@ void VertexDeclaration::SetStream(std::shared_ptr<VertexBuffer> vb, ShaderAttrib
if (type_index < 0 || type_index >= (int)(sizeof(tlut) / sizeof(*tlut)))
type_index = 0;


if (reg != 0xffffffffu)
{
glEnableVertexAttribArray((GLint)reg);
if (tlut[type_index].type == GL_FLOAT
|| tlut[type_index].type == GL_DOUBLE
|| tlut[type_index].type == GL_BYTE


+ 1
- 0
src/lol/gpu/vertexbuffer.h Dosyayı Görüntüle

@@ -245,6 +245,7 @@ private:
int reg;
} m_streams[12 + 1];

unsigned int m_vao;
int m_count;
};



+ 2
- 1
src/mesh/mesh.cpp Dosyayı Görüntüle

@@ -109,6 +109,8 @@ void SubMesh::Render()
{
size_t vertex_count = 0;

m_vdecl->Bind();

for (int i = 0; i < m_vbos.count(); ++i)
{
ShaderAttrib attribs[12];
@@ -143,7 +145,6 @@ void SubMesh::Render()
}

m_ibo->Bind();
m_vdecl->Bind();
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, (int)(m_ibo->GetSize() / sizeof(uint16_t)));
m_vdecl->Unbind();
m_ibo->Unbind();


+ 2
- 2
src/scene.cpp Dosyayı Görüntüle

@@ -517,8 +517,8 @@ void Scene::post_render(float)
m_pp.m_shader[1]->SetUniform(m_pp.m_buffer_uni[1][0], m_renderbuffer[0]->GetTextureUniform(), 0);
m_pp.m_shader[1]->SetUniform(m_pp.m_buffer_uni[1][1], m_renderbuffer[1]->GetTextureUniform(), 1);
m_pp.m_shader[1]->SetUniform(m_pp.m_buffer_uni[1][2], m_renderbuffer[2]->GetTextureUniform(), 2);
m_pp.m_vdecl->SetStream(m_pp.m_vbo, m_pp.m_coord[1]);
m_pp.m_vdecl->Bind();
m_pp.m_vdecl->SetStream(m_pp.m_vbo, m_pp.m_coord[1]);
m_pp.m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_pp.m_vdecl->Unbind();
m_pp.m_shader[1]->Unbind();
@@ -538,8 +538,8 @@ void Scene::post_render(float)

/* Blit final image to screen */
m_pp.m_shader[0]->SetUniform(m_pp.m_buffer_uni[0][0], m_renderbuffer[3]->GetTextureUniform(), 3);
m_pp.m_vdecl->SetStream(m_pp.m_vbo, m_pp.m_coord[0]);
m_pp.m_vdecl->Bind();
m_pp.m_vdecl->SetStream(m_pp.m_vbo, m_pp.m_coord[0]);
m_pp.m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6);
m_pp.m_vdecl->Unbind();
m_pp.m_shader[0]->Unbind();


Yükleniyor…
İptal
Kaydet