| @@ -53,8 +53,8 @@ public: | |||||
| WorldEntity::tick_draw(seconds, scene); | WorldEntity::tick_draw(seconds, scene); | ||||
| m_shader->Bind(); | m_shader->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 3); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 3); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| } | } | ||||
| @@ -141,8 +141,8 @@ public: | |||||
| scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | ||||
| m_shader->Bind(); | m_shader->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord, m_color); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord, m_color); | |||||
| m_shader->SetUniform(m_mvp, m_matrix); | m_shader->SetUniform(m_mvp, m_matrix); | ||||
| m_lines_ibo->Bind(); | m_lines_ibo->Bind(); | ||||
| @@ -60,8 +60,8 @@ public: | |||||
| m_shader->Bind(); | m_shader->Bind(); | ||||
| m_shader->SetUniform(m_time_uni, m_time); | m_shader->SetUniform(m_time_uni, m_time); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| } | } | ||||
| @@ -90,8 +90,8 @@ public: | |||||
| m_shader->Bind(); | m_shader->Bind(); | ||||
| m_shader->SetUniform(m_texture_uni, m_texture->GetTextureUniform(), 0); | m_shader->SetUniform(m_texture_uni, m_texture->GetTextureUniform(), 0); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| } | } | ||||
| @@ -165,8 +165,8 @@ public: | |||||
| scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | ||||
| m_shader->Bind(); | m_shader->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord, m_color); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord, m_color); | |||||
| m_shader->SetUniform(m_mvp, m_matrix); | m_shader->SetUniform(m_mvp, m_matrix); | ||||
| m_lines_ibo->Bind(); | m_lines_ibo->Bind(); | ||||
| @@ -98,8 +98,8 @@ public: | |||||
| m_shader->SetUniform(m_uni_flag, 0.f); | m_shader->SetUniform(m_uni_flag, 0.f); | ||||
| m_shader->SetUniform(m_uni_point, m_hotspot); | m_shader->SetUniform(m_uni_point, m_hotspot); | ||||
| m_shader->SetUniform(m_uni_color, m_color); | m_shader->SetUniform(m_uni_color, m_color); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| m_shader->Unbind(); | m_shader->Unbind(); | ||||
| @@ -108,8 +108,8 @@ public: | |||||
| m_shader->Bind(); | m_shader->Bind(); | ||||
| m_shader->SetUniform(m_uni_flag, 1.f); | m_shader->SetUniform(m_uni_flag, 1.f); | ||||
| m_shader->SetUniform(m_uni_texture, m_fbo->GetTextureUniform(), 0); | m_shader->SetUniform(m_uni_texture, m_fbo->GetTextureUniform(), 0); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_coord); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| m_shader->Unbind(); | m_shader->Unbind(); | ||||
| @@ -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++], 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_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->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_fbos[f].m4.last()); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| m_fbos[f].m2->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" | 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->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_fbos[m_cur_fbo].m4.last()); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| m_fbos[m_cur_fbo].m2->Unbind(); | m_fbos[m_cur_fbo].m2->Unbind(); | ||||
| @@ -353,8 +353,8 @@ public: | |||||
| //SCREEN DRAW | //SCREEN DRAW | ||||
| m_screen_shader->Bind(); | m_screen_shader->Bind(); | ||||
| m_screen_shader->SetUniform(m_screen_texture, m_fbos[m_cur_fbo].m1->GetTextureUniform(), 0); | 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->Bind(); | ||||
| m_vdecl->SetStream(m_vbo, m_screen_coord); | |||||
| m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| m_screen_shader->Unbind(); | m_screen_shader->Unbind(); | ||||
| @@ -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_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_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: | 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); | return (m_invert_rgb)?(GL_BGRA):(GL_RGBA); | ||||
| # else | # else | ||||
| return GL_RGBA; | return GL_RGBA; | ||||
| @@ -173,7 +173,10 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format) | |||||
| { | { | ||||
| m_data->m_size = size; | m_data->m_size = size; | ||||
| m_data->m_bound = false; | 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. */ | /* In OpenGL ES, internal format and format must match. */ | ||||
| GLenum internal_format = fbo_format.GetFormat(); | GLenum internal_format = fbo_format.GetFormat(); | ||||
| GLenum 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_WRAP_T, wrapmode); | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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, | glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size.x, size.y, 0, | ||||
| format, GL_UNSIGNED_BYTE, nullptr); | format, GL_UNSIGNED_BYTE, nullptr); | ||||
| #endif | |||||
| #if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0 | #if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0 | ||||
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | ||||
| @@ -342,7 +342,7 @@ Shader::Shader(std::string const &name, | |||||
| uint64_t flags = (uint64_t)(uint16_t)usage.ToScalar() << 16; | uint64_t flags = (uint64_t)(uint16_t)usage.ToScalar() << 16; | ||||
| flags |= (uint64_t)(uint16_t)index; | flags |= (uint64_t)(uint16_t)index; | ||||
| // TODO: this is here just in case. Remove this once everything has been correctly tested | // 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)) | if (has_key(data->attrib_locations, flags)) | ||||
| { | { | ||||
| msg::error("error while parsing attribute semantics in %s\n", | msg::error("error while parsing attribute semantics in %s\n", | ||||
| @@ -69,15 +69,19 @@ VertexDeclaration::VertexDeclaration(VertexStreamBase const &s1, | |||||
| if (&s10 != &VertexStreamBase::Empty) AddStream(s10); | if (&s10 != &VertexStreamBase::Empty) AddStream(s10); | ||||
| if (&s11 != &VertexStreamBase::Empty) AddStream(s11); | if (&s11 != &VertexStreamBase::Empty) AddStream(s11); | ||||
| if (&s12 != &VertexStreamBase::Empty) AddStream(s12); | if (&s12 != &VertexStreamBase::Empty) AddStream(s12); | ||||
| glGenVertexArrays(1, &m_vao); | |||||
| } | } | ||||
| VertexDeclaration::~VertexDeclaration() | VertexDeclaration::~VertexDeclaration() | ||||
| { | { | ||||
| glDeleteVertexArrays(1, &m_vao); | |||||
| } | } | ||||
| void VertexDeclaration::Bind() | void VertexDeclaration::Bind() | ||||
| { | { | ||||
| /* FIXME: Nothing to do? */ | /* FIXME: Nothing to do? */ | ||||
| glBindVertexArray(m_vao); | |||||
| } | } | ||||
| void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | ||||
| @@ -148,6 +152,7 @@ void VertexDeclaration::Unbind() | |||||
| } | } | ||||
| } | } | ||||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
| glBindVertexArray(0); | |||||
| } | } | ||||
| void VertexDeclaration::SetStream(std::shared_ptr<VertexBuffer> vb, | void VertexDeclaration::SetStream(std::shared_ptr<VertexBuffer> vb, | ||||
| @@ -176,15 +181,13 @@ void VertexDeclaration::SetStream(std::shared_ptr<VertexBuffer> vb, ShaderAttrib | |||||
| return; | return; | ||||
| glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | ||||
| for (int n = 0; n < 12 && attribs[n].m_flags != (uint64_t)0 - 1; n++) | for (int n = 0; n < 12 && attribs[n].m_flags != (uint64_t)0 - 1; n++) | ||||
| { | { | ||||
| VertexUsage usage = VertexUsage((attribs[n].m_flags >> 16) & 0xffff); | VertexUsage usage = VertexUsage((attribs[n].m_flags >> 16) & 0xffff); | ||||
| uint32_t index = attribs[n].m_flags & 0xffff; | uint32_t index = attribs[n].m_flags & 0xffff; | ||||
| uint32_t reg = attribs[n].m_flags >> 32; | uint32_t reg = attribs[n].m_flags >> 32; | ||||
| if (reg != 0xffffffffu) | |||||
| glEnableVertexAttribArray((GLint)reg); | |||||
| /* We need to parse the whole vertex declaration to retrieve | /* We need to parse the whole vertex declaration to retrieve | ||||
| * the information. It sucks. */ | * 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))) | if (type_index < 0 || type_index >= (int)(sizeof(tlut) / sizeof(*tlut))) | ||||
| type_index = 0; | type_index = 0; | ||||
| if (reg != 0xffffffffu) | if (reg != 0xffffffffu) | ||||
| { | { | ||||
| glEnableVertexAttribArray((GLint)reg); | |||||
| if (tlut[type_index].type == GL_FLOAT | if (tlut[type_index].type == GL_FLOAT | ||||
| || tlut[type_index].type == GL_DOUBLE | || tlut[type_index].type == GL_DOUBLE | ||||
| || tlut[type_index].type == GL_BYTE | || tlut[type_index].type == GL_BYTE | ||||
| @@ -245,6 +245,7 @@ private: | |||||
| int reg; | int reg; | ||||
| } m_streams[12 + 1]; | } m_streams[12 + 1]; | ||||
| unsigned int m_vao; | |||||
| int m_count; | int m_count; | ||||
| }; | }; | ||||
| @@ -109,6 +109,8 @@ void SubMesh::Render() | |||||
| { | { | ||||
| size_t vertex_count = 0; | size_t vertex_count = 0; | ||||
| m_vdecl->Bind(); | |||||
| for (int i = 0; i < m_vbos.count(); ++i) | for (int i = 0; i < m_vbos.count(); ++i) | ||||
| { | { | ||||
| ShaderAttrib attribs[12]; | ShaderAttrib attribs[12]; | ||||
| @@ -143,7 +145,6 @@ void SubMesh::Render() | |||||
| } | } | ||||
| m_ibo->Bind(); | m_ibo->Bind(); | ||||
| m_vdecl->Bind(); | |||||
| m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, (int)(m_ibo->GetSize() / sizeof(uint16_t))); | m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, (int)(m_ibo->GetSize() / sizeof(uint16_t))); | ||||
| m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
| m_ibo->Unbind(); | m_ibo->Unbind(); | ||||
| @@ -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][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][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_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->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->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_pp.m_vdecl->Unbind(); | m_pp.m_vdecl->Unbind(); | ||||
| m_pp.m_shader[1]->Unbind(); | m_pp.m_shader[1]->Unbind(); | ||||
| @@ -538,8 +538,8 @@ void Scene::post_render(float) | |||||
| /* Blit final image to screen */ | /* 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_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->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->DrawElements(MeshPrimitive::Triangles, 0, 6); | ||||
| m_pp.m_vdecl->Unbind(); | m_pp.m_vdecl->Unbind(); | ||||
| m_pp.m_shader[0]->Unbind(); | m_pp.m_shader[0]->Unbind(); | ||||