@@ -59,6 +59,8 @@ private: | |||||
TrackedState<DepthMask> m_depth_mask; | TrackedState<DepthMask> m_depth_mask; | ||||
TrackedState<CullMode> m_cull_mode; | TrackedState<CullMode> m_cull_mode; | ||||
TrackedState<PolygonMode> m_polygon_mode; | TrackedState<PolygonMode> m_polygon_mode; | ||||
TrackedState<ScissorMode> m_scissor_mode; | |||||
TrackedState<vec4> m_scissor_rect; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -101,6 +103,9 @@ RenderContext::~RenderContext() | |||||
if (m_data->m_polygon_mode.HasChanged()) | if (m_data->m_polygon_mode.HasChanged()) | ||||
Renderer::Get()->SetPolygonMode(m_data->m_polygon_mode.GetValue()); | Renderer::Get()->SetPolygonMode(m_data->m_polygon_mode.GetValue()); | ||||
if (m_data->m_scissor_mode.HasChanged()) | |||||
Renderer::Get()->SetScissorMode(m_data->m_scissor_mode.GetValue()); | |||||
delete m_data; | delete m_data; | ||||
} | } | ||||
@@ -255,5 +260,31 @@ PolygonMode RenderContext::GetPolygonMode() | |||||
return Renderer::Get()->GetPolygonMode(); | return Renderer::Get()->GetPolygonMode(); | ||||
} | } | ||||
void RenderContext::SetScissorMode(ScissorMode mode) | |||||
{ | |||||
if (!m_data->m_scissor_mode.HasChanged()) | |||||
m_data->m_scissor_mode.TrackValue(Renderer::Get()->GetScissorMode()); | |||||
Renderer::Get()->SetScissorMode(mode); | |||||
} | |||||
void RenderContext::SetScissorRect(vec4 rect) | |||||
{ | |||||
if (!m_data->m_scissor_rect.HasChanged()) | |||||
m_data->m_scissor_rect.TrackValue(Renderer::Get()->GetScissorRect()); | |||||
Renderer::Get()->SetScissorRect(rect); | |||||
} | |||||
ScissorMode RenderContext::GetScissorMode() | |||||
{ | |||||
return Renderer::Get()->GetScissorMode(); | |||||
} | |||||
vec4 RenderContext::GetScissorRect() | |||||
{ | |||||
return Renderer::Get()->GetScissorRect(); | |||||
} | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -54,6 +54,8 @@ private: | |||||
DepthMask m_depth_mask; | DepthMask m_depth_mask; | ||||
CullMode m_cull_mode; | CullMode m_cull_mode; | ||||
PolygonMode m_polygon_mode; | PolygonMode m_polygon_mode; | ||||
ScissorMode m_scissor_mode; | |||||
vec4 m_scissor_rect; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -107,6 +109,9 @@ Renderer::Renderer(ivec2 size) | |||||
m_data->m_polygon_mode = PolygonMode::Point; | m_data->m_polygon_mode = PolygonMode::Point; | ||||
SetPolygonMode(PolygonMode::Fill); | SetPolygonMode(PolygonMode::Fill); | ||||
m_data->m_scissor_mode = ScissorMode::Disabled; | |||||
SetPolygonMode(PolygonMode::Fill); | |||||
/* Add some rendering states that we don't export to the user */ | /* Add some rendering states that we don't export to the user */ | ||||
#if defined HAVE_GL_2X && !defined __APPLE__ | #if defined HAVE_GL_2X && !defined __APPLE__ | ||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | ||||
@@ -548,5 +553,42 @@ PolygonMode Renderer::GetPolygonMode() const | |||||
return m_data->m_polygon_mode; | return m_data->m_polygon_mode; | ||||
} | } | ||||
/* | |||||
* Scissor test mode | |||||
*/ | |||||
void Renderer::SetScissorMode(ScissorMode mode) | |||||
{ | |||||
if (m_data->m_scissor_mode == mode) | |||||
return; | |||||
if (mode == ScissorMode::Enabled) | |||||
glEnable(GL_SCISSOR_TEST); | |||||
else | |||||
glDisable(GL_SCISSOR_TEST); | |||||
m_data->m_scissor_mode = mode; | |||||
} | |||||
void Renderer::SetScissorRect(vec4 rect) | |||||
{ | |||||
m_data->m_scissor_rect = rect; | |||||
if (m_data->m_scissor_mode == ScissorMode::Enabled) | |||||
{ | |||||
glScissor((int)rect.x, (int)Video::GetSize().y - rect.w, (int)(rect.z - rect.x), (int)(rect.w - rect.y)); | |||||
//glScissor((int)rect.x, (int)rect.y, (int)(rect.z - rect.x), (int)(rect.w - rect.y)); | |||||
} | |||||
} | |||||
ScissorMode Renderer::GetScissorMode() const | |||||
{ | |||||
return m_data->m_scissor_mode; | |||||
} | |||||
vec4 Renderer::GetScissorRect() const | |||||
{ | |||||
return m_data->m_scissor_rect; | |||||
} | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -114,7 +114,7 @@ InputDeviceInternal* InputDeviceInternal::CreateStandardMouse() | |||||
mouse->AddAxis(g_name_mouse_axis_y.C()); | mouse->AddAxis(g_name_mouse_axis_y.C()); | ||||
mouse->AddAxis(g_name_mouse_axis_xpixel.C()); | mouse->AddAxis(g_name_mouse_axis_xpixel.C()); | ||||
mouse->AddAxis(g_name_mouse_axis_ypixel.C()); | mouse->AddAxis(g_name_mouse_axis_ypixel.C()); | ||||
mouse->AddAxis(g_name_mouse_axis_scroll.C()); | |||||
mouse->AddAxis(g_name_mouse_axis_scroll.C(), .0000001f); | |||||
mouse->AddCursor(g_name_mouse_cursor.C()); | mouse->AddCursor(g_name_mouse_cursor.C()); | ||||
@@ -36,6 +36,8 @@ public: | |||||
void SetDepthMask(DepthMask mask); | void SetDepthMask(DepthMask mask); | ||||
void SetCullMode(CullMode mode); | void SetCullMode(CullMode mode); | ||||
void SetPolygonMode(PolygonMode mode); | void SetPolygonMode(PolygonMode mode); | ||||
void SetScissorMode(ScissorMode mode); | |||||
void SetScissorRect(vec4 rect); | |||||
ibox2 GetViewport(); | ibox2 GetViewport(); | ||||
vec4 GetClearColor(); | vec4 GetClearColor(); | ||||
@@ -50,6 +52,8 @@ public: | |||||
DepthMask GetDepthMask(); | DepthMask GetDepthMask(); | ||||
CullMode GetCullMode(); | CullMode GetCullMode(); | ||||
PolygonMode GetPolygonMode(); | PolygonMode GetPolygonMode(); | ||||
ScissorMode GetScissorMode(); | |||||
vec4 GetScissorRect(); | |||||
private: | private: | ||||
RenderContextData *m_data; | RenderContextData *m_data; | ||||
@@ -123,6 +123,13 @@ enum class AlphaFunc : uint8_t | |||||
Always, | Always, | ||||
}; | }; | ||||
/* A safe enum to indicate the depth mask. */ | |||||
enum class ScissorMode : uint8_t | |||||
{ | |||||
Disabled, | |||||
Enabled, | |||||
}; | |||||
class Renderer | class Renderer | ||||
{ | { | ||||
private: | private: | ||||
@@ -176,6 +183,11 @@ public: | |||||
void SetPolygonMode(PolygonMode mode); | void SetPolygonMode(PolygonMode mode); | ||||
PolygonMode GetPolygonMode() const; | PolygonMode GetPolygonMode() const; | ||||
void SetScissorMode(ScissorMode mode); | |||||
void SetScissorRect(vec4 rect); | |||||
ScissorMode GetScissorMode() const; | |||||
vec4 GetScissorRect() const; | |||||
private: | private: | ||||
RendererData *m_data; | RendererData *m_data; | ||||
}; | }; | ||||
@@ -366,6 +366,7 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
RenderContext rc; | RenderContext rc; | ||||
rc.SetCullMode(CullMode::Disabled); | rc.SetCullMode(CullMode::Disabled); | ||||
rc.SetDepthFunc(DepthFunc::Disabled); | rc.SetDepthFunc(DepthFunc::Disabled); | ||||
rc.SetScissorMode(ScissorMode::Enabled); | |||||
m_shader->Bind(); | m_shader->Bind(); | ||||
for (int n = 0; n < draw_data->CmdListsCount; n++) | for (int n = 0; n < draw_data->CmdListsCount; n++) | ||||
@@ -402,6 +403,11 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) | ||||
{ | { | ||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i]; | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i]; | ||||
TextureImage* image = (TextureImage*)pcmd->TextureId; | |||||
if (image) image->Bind(); | |||||
rc.SetScissorRect(vec4(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w)); | |||||
#ifdef SHOW_IMGUI_DEBUG | #ifdef SHOW_IMGUI_DEBUG | ||||
//----------------------------------------------------------------- | //----------------------------------------------------------------- | ||||
//<Debug render> -------------------------------------------------- | //<Debug render> -------------------------------------------------- | ||||
@@ -448,6 +454,8 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); | m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); | ||||
idx_buffer_offset += pcmd->ElemCount; | idx_buffer_offset += pcmd->ElemCount; | ||||
if (image) image->Unbind(); | |||||
} | } | ||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||