@@ -694,7 +694,7 @@ void BtPhysTest::tick_draw(float seconds, Scene &scene) | |||
#endif //CAT_MODE | |||
} | |||
//Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f)); | |||
//Video::set_clear_color(vec4(0.0f, 0.0f, 0.12f, 1.0f)); | |||
} | |||
@@ -132,7 +132,7 @@ public: | |||
{ | |||
WorldEntity::tick_draw(seconds, scene); | |||
scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
scene.get_renderer()->clear_color(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
m_shader->Bind(); | |||
m_vdecl->Bind(); | |||
@@ -121,7 +121,7 @@ public: | |||
{ | |||
Scene& scene = Scene::GetScene(); | |||
scene.PushCamera(m_camera); | |||
scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
scene.get_renderer()->clear_color(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
/* Upload vertex data to GPU */ | |||
for (int i = 0; i < m_gears.count(); i++) | |||
@@ -63,7 +63,7 @@ public: | |||
{ | |||
Scene& scene = Scene::GetScene(); | |||
scene.PushCamera(m_camera); | |||
scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
scene.get_renderer()->clear_color(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
return true; | |||
} | |||
@@ -156,7 +156,7 @@ public: | |||
{ | |||
WorldEntity::tick_draw(seconds, scene); | |||
scene.get_renderer()->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
scene.get_renderer()->clear_color(vec4(0.0f, 0.0f, 0.0f, 1.0f)); | |||
m_shader->Bind(); | |||
m_vdecl->Bind(); | |||
@@ -66,16 +66,17 @@ public: | |||
m_vbo = std::make_shared<VertexBuffer>(vertices.bytes()); | |||
m_vbo->set_data(vertices.data(), vertices.bytes()); | |||
m_fbo = std::make_shared<Framebuffer>(Video::GetSize()); | |||
m_fbo->Bind(); | |||
// Create the back buffer and clear it | |||
m_backbuffer = std::make_shared<Framebuffer>(Video::GetSize()); | |||
m_backbuffer->Bind(); | |||
{ | |||
Scene& scene = Scene::GetScene(); | |||
render_context rc(scene.get_renderer()); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
m_fbo->Unbind(); | |||
m_backbuffer->Unbind(); | |||
return true; | |||
} | |||
@@ -90,9 +91,8 @@ public: | |||
/* FIXME: this no longer works because we don’t restore the | |||
* actually bound framebuffer. */ | |||
m_fbo->Bind(); | |||
m_backbuffer->Bind(); | |||
m_shader->Bind(); | |||
m_shader->SetUniform(m_uni_flag, 0.f); | |||
m_shader->SetUniform(m_uni_point, m_hotspot); | |||
m_shader->SetUniform(m_uni_color, m_color); | |||
@@ -101,11 +101,11 @@ public: | |||
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||
m_vdecl->Unbind(); | |||
m_shader->Unbind(); | |||
m_fbo->Unbind(); | |||
m_backbuffer->Unbind(); | |||
m_shader->Bind(); | |||
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_backbuffer->GetTextureUniform(), 0); | |||
m_vdecl->Bind(); | |||
m_vdecl->SetStream(m_vbo, m_coord); | |||
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||
@@ -118,7 +118,7 @@ public: | |||
m_shader.reset(); | |||
m_vdecl.reset(); | |||
m_vbo.reset(); | |||
m_fbo.reset(); | |||
m_backbuffer.reset(); | |||
return true; | |||
} | |||
@@ -128,7 +128,7 @@ private: | |||
ShaderUniform m_uni_flag, m_uni_point, m_uni_color, m_uni_texture; | |||
std::shared_ptr<VertexDeclaration> m_vdecl; | |||
std::shared_ptr<VertexBuffer> m_vbo; | |||
std::shared_ptr<Framebuffer> m_fbo; | |||
std::shared_ptr<Framebuffer> m_backbuffer; | |||
double m_time = 0.0f; | |||
vec3 m_hotspot, m_color; | |||
}; | |||
@@ -127,7 +127,7 @@ public: | |||
render_context rc(scene.get_renderer()); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
m_fbos.last().m1->Unbind(); | |||
} | |||
@@ -138,7 +138,7 @@ public: | |||
render_context rc(scene.get_renderer()); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
temp_buffer->Unbind(); | |||
@@ -201,7 +201,7 @@ public: | |||
render_context rc(scene.get_renderer()); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
temp_buffer->Unbind(); | |||
@@ -231,7 +231,7 @@ public: | |||
render_context rc(scene.get_renderer()); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
m_fbos[f].m1->Unbind(); | |||
@@ -253,7 +253,7 @@ public: | |||
dst_buf->Bind(); | |||
/* FIXME: we should just disable depth test in the shader */ | |||
scene.get_renderer()->Clear(ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Depth); | |||
m_fbos[f].m2->Bind(); | |||
int i = 0; | |||
@@ -272,7 +272,7 @@ public: | |||
} | |||
} | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
//FRAME BUFFER DRAW | |||
m_timer -= seconds; | |||
@@ -284,7 +284,7 @@ public: | |||
render_context rc(scene.get_renderer()); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
scene.get_renderer()->Clear(ClearMask::Color | ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
m_fbos[m_cur_fbo].m1->Unbind(); | |||
@@ -314,7 +314,7 @@ public: | |||
dst_buf->Bind(); | |||
/* FIXME: we should just disable depth test in the shader */ | |||
scene.get_renderer()->Clear(ClearMask::Depth); | |||
scene.get_renderer()->clear(ClearMask::Depth); | |||
shader->Bind(); | |||
int i = 0; | |||
@@ -229,14 +229,14 @@ void Debug::DrawBox(vec2 a, vec2 b, mat2 transform, DCD data) | |||
} | |||
void Debug::DrawBox(vec2 a, float s, mat2 transform, DCD data) | |||
{ | |||
vec2 b = s * vec2(1.f, Scene::GetScene(0).get_renderer()->GetXYRatio()); | |||
vec2 b = s * vec2(1.f, Scene::GetScene(0).get_renderer()->xy_ratio()); | |||
Debug::DrawBox(a - b, a + b, transform, data); | |||
} | |||
//-- CIRCLE ------------------------------------------------------------------- | |||
void Debug::DrawCircle(vec2 a, float s) { Debug::DrawCircle(a, s * vec2(1.f, Scene::GetScene(0).get_renderer()->GetXYRatio()), DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec2 a, float s) { Debug::DrawCircle(a, s * vec2(1.f, Scene::GetScene(0).get_renderer()->xy_ratio()), DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec3 a, vec3 n) { Debug::DrawCircle(a, n, DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec2 a, vec2 s) { Debug::DrawCircle(a, s * vec2(1.f, Scene::GetScene(0).get_renderer()->GetXYRatio()), DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec2 a, vec2 s) { Debug::DrawCircle(a, s * vec2(1.f, Scene::GetScene(0).get_renderer()->xy_ratio()), DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec3 a, vec3 x, vec3 y) { Debug::DrawCircle(a, x, y, DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec2 a, vec2 x, vec2 y) { Debug::DrawCircle(a, x, y, DC::GetGlobalData()); } | |||
void Debug::DrawCircle(vec3 a, vec3 n, DCD data) | |||
@@ -306,8 +306,8 @@ void Framebuffer::Bind() | |||
* instead, maybe by getting rid of Framebuffer::Bind() and | |||
* creating RenderContext::SetFramebuffer() instead. */ | |||
auto renderer = Scene::GetScene(0).get_renderer(); | |||
m_data->m_saved_viewport = renderer->GetViewport(); | |||
renderer->SetViewport(ibox2(ivec2::zero, m_data->m_size)); | |||
m_data->m_saved_viewport = renderer->viewport(); | |||
renderer->viewport(ibox2(ivec2::zero, m_data->m_size)); | |||
m_data->m_bound = true; | |||
} | |||
@@ -322,7 +322,7 @@ void Framebuffer::Unbind() | |||
#endif | |||
auto renderer = Scene::GetScene(0).get_renderer(); | |||
renderer->SetViewport(m_data->m_saved_viewport); | |||
renderer->viewport(m_data->m_saved_viewport); | |||
m_data->m_bound = false; | |||
} | |||
@@ -78,13 +78,13 @@ render_context::render_context(std::shared_ptr<Renderer> renderer) | |||
render_context::~render_context() | |||
{ | |||
if (m_data->m_viewport.is_dirty()) | |||
m_renderer->SetViewport(m_data->m_viewport.get()); | |||
m_renderer->viewport(m_data->m_viewport.get()); | |||
if (m_data->m_clear_color.is_dirty()) | |||
m_renderer->SetClearColor(m_data->m_clear_color.get()); | |||
m_renderer->clear_color(m_data->m_clear_color.get()); | |||
if (m_data->m_clear_depth.is_dirty()) | |||
m_renderer->SetClearDepth(m_data->m_clear_depth.get()); | |||
m_renderer->clear_depth(m_data->m_clear_depth.get()); | |||
if (m_data->m_alpha_func.is_dirty()) | |||
m_renderer->SetAlphaFunc(m_data->m_alpha_func.get(), | |||
@@ -113,40 +113,40 @@ render_context::~render_context() | |||
void render_context::viewport(ibox2 viewport) | |||
{ | |||
if (!m_data->m_viewport.is_dirty()) | |||
m_data->m_viewport.set(m_renderer->GetViewport()); | |||
m_data->m_viewport.set(m_renderer->viewport()); | |||
m_renderer->SetViewport(viewport); | |||
m_renderer->viewport(viewport); | |||
} | |||
ibox2 render_context::viewport() | |||
{ | |||
return m_renderer->GetViewport(); | |||
return m_renderer->viewport(); | |||
} | |||
void render_context::clear_color(vec4 color) | |||
{ | |||
if (!m_data->m_clear_color.is_dirty()) | |||
m_data->m_clear_color.set(m_renderer->GetClearColor()); | |||
m_data->m_clear_color.set(m_renderer->clear_color()); | |||
m_renderer->SetClearColor(color); | |||
m_renderer->clear_color(color); | |||
} | |||
vec4 render_context::clear_color() | |||
{ | |||
return m_renderer->GetClearColor(); | |||
return m_renderer->clear_color(); | |||
} | |||
void render_context::clear_depth(float depth) | |||
{ | |||
if (!m_data->m_clear_depth.is_dirty()) | |||
m_data->m_clear_depth.set(m_renderer->GetClearDepth()); | |||
m_data->m_clear_depth.set(m_renderer->clear_depth()); | |||
m_renderer->SetClearDepth(depth); | |||
m_renderer->clear_depth(depth); | |||
} | |||
float render_context::clear_depth() | |||
{ | |||
return m_renderer->GetClearDepth(); | |||
return m_renderer->clear_depth(); | |||
} | |||
void render_context::alpha_func(AlphaFunc func, float alpha) | |||
@@ -76,13 +76,13 @@ Renderer::Renderer(ivec2 size) | |||
/* Initialise rendering states */ | |||
m_data->m_viewport = ibox2(0, 0, 0, 0); | |||
SetViewport(ibox2(ivec2::zero, size)); | |||
viewport(ibox2(ivec2::zero, size)); | |||
m_data->m_clear_color = vec4(-1.f); | |||
SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f)); | |||
clear_color(vec4(0.1f, 0.2f, 0.3f, 1.0f)); | |||
m_data->m_clear_depth = -1.f; | |||
SetClearDepth(1.f); | |||
clear_depth(1.f); | |||
m_data->m_alpha_func = AlphaFunc::Never; | |||
m_data->m_alpha_value = -1.0f; | |||
@@ -125,7 +125,7 @@ Renderer::~Renderer() | |||
* Buffer clearing | |||
*/ | |||
void Renderer::Clear(ClearMask mask) | |||
void Renderer::clear(ClearMask mask) | |||
{ | |||
GLbitfield m = 0; | |||
if (mask & ClearMask::Color) | |||
@@ -141,30 +141,30 @@ void Renderer::Clear(ClearMask mask) | |||
* Viewport dimensions | |||
*/ | |||
void Renderer::SetViewport(ibox2 viewport) | |||
void Renderer::viewport(ibox2 bounds) | |||
{ | |||
if (m_data->m_viewport == viewport) | |||
if (m_data->m_viewport == bounds) | |||
return; | |||
glViewport(viewport.aa.x, viewport.aa.y, viewport.bb.x, viewport.bb.y); | |||
glViewport(bounds.aa.x, bounds.aa.y, bounds.bb.x, bounds.bb.y); | |||
m_data->m_viewport = viewport; | |||
m_data->m_viewport = bounds; | |||
} | |||
ibox2 Renderer::GetViewport() const | |||
ibox2 Renderer::viewport() const | |||
{ | |||
return m_data->m_viewport; | |||
} | |||
float Renderer::GetXYRatio() const | |||
float Renderer::xy_ratio() const | |||
{ | |||
ivec2 s = GetViewport().extent(); | |||
ivec2 s = viewport().extent(); | |||
return (float)s.x / s.y; | |||
} | |||
float Renderer::GetYXRatio() const | |||
float Renderer::yx_ratio() const | |||
{ | |||
ivec2 s = GetViewport().extent(); | |||
ivec2 s = viewport().extent(); | |||
return (float)s.y / s.x; | |||
} | |||
@@ -172,7 +172,7 @@ float Renderer::GetYXRatio() const | |||
* Clear color | |||
*/ | |||
void Renderer::SetClearColor(vec4 color) | |||
void Renderer::clear_color(vec4 color) | |||
{ | |||
if (m_data->m_clear_color == color) | |||
return; | |||
@@ -182,7 +182,7 @@ void Renderer::SetClearColor(vec4 color) | |||
m_data->m_clear_color = color; | |||
} | |||
vec4 Renderer::GetClearColor() const | |||
vec4 Renderer::clear_color() const | |||
{ | |||
return m_data->m_clear_color; | |||
} | |||
@@ -191,7 +191,7 @@ vec4 Renderer::GetClearColor() const | |||
* Clear depth | |||
*/ | |||
void Renderer::SetClearDepth(float depth) | |||
void Renderer::clear_depth(float depth) | |||
{ | |||
if (m_data->m_clear_depth == depth) | |||
return; | |||
@@ -205,7 +205,7 @@ void Renderer::SetClearDepth(float depth) | |||
m_data->m_clear_depth = depth; | |||
} | |||
float Renderer::GetClearDepth() const | |||
float Renderer::clear_depth() const | |||
{ | |||
return m_data->m_clear_depth; | |||
} | |||
@@ -139,18 +139,18 @@ public: | |||
Renderer(ivec2 size); | |||
~Renderer(); | |||
void Clear(ClearMask mask); | |||
void clear(ClearMask mask); | |||
void SetViewport(ibox2 viewport); | |||
ibox2 GetViewport() const; | |||
float GetXYRatio() const; | |||
float GetYXRatio() const; | |||
void viewport(ibox2 bounds); | |||
ibox2 viewport() const; | |||
float xy_ratio() const; | |||
float yx_ratio() const; | |||
void SetClearColor(vec4 color); | |||
vec4 GetClearColor() const; | |||
void clear_color(vec4 color); | |||
vec4 clear_color() const; | |||
void SetClearDepth(float depth); | |||
float GetClearDepth() const; | |||
void clear_depth(float depth); | |||
float clear_depth() const; | |||
void SetAlphaFunc(AlphaFunc func, float alpha); | |||
AlphaFunc GetAlphaFunc() const; | |||
@@ -458,7 +458,7 @@ void Scene::pre_render(float) | |||
{ | |||
m_size = m_wanted_size; | |||
m_renderer->SetViewport(ibox2(ivec2::zero, m_size)); | |||
m_renderer->viewport(ibox2(ivec2::zero, m_size)); | |||
for (int i = 0; i < 4; ++i) | |||
m_renderbuffer[i] = std::make_shared<Framebuffer>(m_size); | |||
@@ -480,7 +480,7 @@ void Scene::pre_render(float) | |||
rc.clear_depth(1.f); | |||
} | |||
m_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||
m_renderer->clear(ClearMask::Color | ClearMask::Depth); | |||
} | |||
} | |||
@@ -513,7 +513,7 @@ void Scene::post_render(float) | |||
render_context rc(m_renderer); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
m_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||
m_renderer->clear(ClearMask::Color | ClearMask::Depth); | |||
/* Execute post process */ | |||
m_pp.pp_shader->Bind(); | |||
@@ -537,7 +537,7 @@ void Scene::post_render(float) | |||
render_context rc(m_renderer); | |||
rc.clear_color(vec4(0.f, 0.f, 0.f, 1.f)); | |||
rc.clear_depth(1.f); | |||
m_renderer->Clear(ClearMask::Color | ClearMask::Depth); | |||
m_renderer->clear(ClearMask::Color | ClearMask::Depth); | |||
/* Blit final image to screen */ | |||
m_pp.blit_shader->SetUniform(m_pp.m_buffer_uni[0][0], m_renderbuffer[3]->GetTextureUniform(), 3); | |||
@@ -127,7 +127,7 @@ void Video::Resize(ivec2 size) | |||
ivec2 Video::GetSize() | |||
{ | |||
return Scene::GetScene(0).get_renderer()->GetViewport().extent(); | |||
return Scene::GetScene(0).get_renderer()->viewport().extent(); | |||
} | |||
} /* namespace lol */ | |||