Selaa lähdekoodia

gpu: handle depth test, alpha blending and face culling in Renderer.

legacy
Sam Hocevar sam 11 vuotta sitten
vanhempi
commit
1b213612a5
7 muutettua tiedostoa jossa 141 lisäystä ja 94 poistoa
  1. +29
    -7
      src/gpu/rendercontext.cpp
  2. +93
    -8
      src/gpu/renderer.cpp
  3. +3
    -1
      src/lol/gpu/rendercontext.h
  4. +8
    -2
      src/lol/gpu/renderer.h
  5. +0
    -4
      src/ticker.cpp
  6. +8
    -67
      src/video.cpp
  7. +0
    -5
      src/video.h

+ 29
- 7
src/gpu/rendercontext.cpp Näytä tiedosto

@@ -58,7 +58,7 @@ class RenderContextData
private:
Scene *m_scene;

TrackedState m_blend;
TrackedState m_alpha_blend, m_depth_test, m_face_culling;
};

/*
@@ -73,18 +73,40 @@ RenderContext::RenderContext()

RenderContext::~RenderContext()
{
if (m_data->m_blend.HasChanged())
g_renderer->SetBlendState(m_data->m_blend.GetValue());
if (m_data->m_alpha_blend.HasChanged())
g_renderer->SetAlphaBlend(m_data->m_alpha_blend.GetValue());

if (m_data->m_depth_test.HasChanged())
g_renderer->SetDepthTest(m_data->m_depth_test.GetValue());

if (m_data->m_face_culling.HasChanged())
g_renderer->SetFaceCulling(m_data->m_face_culling.GetValue());

delete m_data;
}

void RenderContext::SetBlendState(bool set)
void RenderContext::SetAlphaBlend(bool set)
{
if (!m_data->m_alpha_blend.HasChanged())
m_data->m_alpha_blend.TrackValue(g_renderer->GetAlphaBlend());

g_renderer->SetAlphaBlend(set);
}

void RenderContext::SetDepthTest(bool set)
{
if (!m_data->m_depth_test.HasChanged())
m_data->m_depth_test.TrackValue(g_renderer->GetDepthTest());

g_renderer->SetDepthTest(set);
}

void RenderContext::SetFaceCulling(bool set)
{
if (!m_data->m_blend.HasChanged())
m_data->m_blend.TrackValue(g_renderer->GetBlendState());
if (!m_data->m_face_culling.HasChanged())
m_data->m_face_culling.TrackValue(g_renderer->GetFaceCulling());

g_renderer->SetBlendState(set);
g_renderer->SetFaceCulling(set);
}

} /* namespace lol */


+ 93
- 8
src/gpu/renderer.cpp Näytä tiedosto

@@ -14,7 +14,22 @@

#include <cstdlib>

#if defined _XBOX
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# if defined USE_D3D9
# include <d3d9.h>
# endif
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

#include "core.h"
#include "lolgl.h"

namespace lol
{
@@ -32,7 +47,7 @@ class RendererData
friend class Renderer;

private:
bool m_blend;
bool m_blend, m_depth_test, m_face_culling;
};

/*
@@ -43,6 +58,13 @@ Renderer::Renderer()
: m_data(new RendererData())
{
m_data->m_blend = false;
SetAlphaBlend(true);

m_data->m_depth_test = false;
SetDepthTest(true);

m_data->m_face_culling = false;
SetFaceCulling(true);
}

Renderer::~Renderer()
@@ -50,25 +72,88 @@ Renderer::~Renderer()
delete m_data;
}

void Renderer::SetBlendState(bool set)
/*
* Alpha blending
*/

void Renderer::SetAlphaBlend(bool set)
{
if (m_data->m_blend == set)
return;

m_data->m_blend = set;

#if defined USE_D3D9 || defined _XBOX
# define STR0(x) #x
# define STR(x) STR0(x)
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Renderer::SetAlphaBlend() not implemented")
#else
if (set)
{
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
#endif
}

bool Renderer::GetAlphaBlend() const
{
return m_data->m_blend;
}

}
/*
* Depth test
*/

void Renderer::SetDepthTest(bool set)
{
if (m_data->m_depth_test == set)
return;

m_data->m_depth_test = set;

#if defined USE_D3D9 || defined _XBOX
# define STR0(x) #x
# define STR(x) STR0(x)
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Renderer::SetDepthTest() not implemented")
#else
if (set)
glEnable(GL_DEPTH_TEST);
else
{
glDisable(GL_DEPTH_TEST);
#endif
}

}
bool Renderer::GetDepthTest() const
{
return m_data->m_depth_test;
}

bool Renderer::GetBlendState() const
/*
* Face culling
*/

void Renderer::SetFaceCulling(bool set)
{
return m_data->m_blend;
if (m_data->m_face_culling == set)
return;

m_data->m_face_culling = set;

#if defined USE_D3D9 || defined _XBOX
# define STR0(x) #x
# define STR(x) STR0(x)
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Renderer::SetFaceCulling() not implemented")
#else
if (set)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
#endif
}

bool Renderer::GetFaceCulling() const
{
return m_data->m_face_culling;
}

} /* namespace lol */


+ 3
- 1
src/lol/gpu/rendercontext.h Näytä tiedosto

@@ -27,7 +27,9 @@ public:
RenderContext();
~RenderContext();

void SetBlendState(bool set);
void SetAlphaBlend(bool set);
void SetDepthTest(bool set);
void SetFaceCulling(bool set);

private:
RenderContextData *m_data;


+ 8
- 2
src/lol/gpu/renderer.h Näytä tiedosto

@@ -27,8 +27,14 @@ public:
Renderer();
~Renderer();

void SetBlendState(bool set);
bool GetBlendState() const;
void SetAlphaBlend(bool set);
bool GetAlphaBlend() const;

void SetDepthTest(bool set);
bool GetDepthTest() const;

void SetFaceCulling(bool set);
bool GetFaceCulling() const;

private:
RendererData *m_data;


+ 0
- 4
src/ticker.cpp Näytä tiedosto

@@ -389,11 +389,7 @@ void TickerData::DrawThreadTick()
Scene::GetDefault()->Reset();
Video::Clear(ClearMask::All);
break;
case Entity::DRAWGROUP_HUD:
Video::SetDepth(false);
break;
default:
Video::SetDepth(true);
break;
}



+ 8
- 67
src/video.cpp Näytä tiedosto

@@ -52,8 +52,6 @@ private:
static mat4 proj_matrix;
static ivec2 saved_viewport;
static DebugRenderMode render_mode;
static bool face_culling;
static bool alpha_blend;
#if defined USE_D3D9 || defined _XBOX
# if defined USE_D3D9
static IDirect3D9 *d3d_ctx;
@@ -70,8 +68,6 @@ private:
mat4 VideoData::proj_matrix;
ivec2 VideoData::saved_viewport(0, 0);
DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;
bool VideoData::face_culling = true;
bool VideoData::alpha_blend = true;

#if defined USE_D3D9 || defined _XBOX
# if defined USE_D3D9
@@ -91,8 +87,6 @@ float VideoData::clear_depth;

void Video::Setup(ivec2 size)
{
g_renderer = new Renderer();

#if defined USE_D3D9 || defined _XBOX
VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION);
if (!VideoData::d3d_ctx)
@@ -158,10 +152,11 @@ void Video::Setup(ivec2 size)
# endif
#endif

g_renderer = new Renderer();

/* Initialise reasonable scene default properties */
SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f));
SetClearDepth(1.f);
SetAlphaBlend(true);
SetDebugRenderMode(DebugRenderMode::Default);
}

@@ -238,60 +233,6 @@ void Video::SetFov(float theta)
}
}

void Video::SetDepth(bool set)
{
#if defined USE_D3D9 || defined _XBOX
# define STR0(x) #x
# define STR(x) STR0(x)
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetDepth() not implemented")
#else
if (set)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);
#endif
}

void Video::SetFaceCulling(bool set)
{
#if defined USE_D3D9 || defined _XBOX
# define STR0(x) #x
# define STR(x) STR0(x)
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetFaceCulling() not implemented")
#else
VideoData::face_culling = set;
if (set)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
#endif
}

bool Video::HasFaceCulling()
{
return VideoData::face_culling;
}

void Video::SetAlphaBlend(bool set)
{
#if defined USE_D3D9 || defined _XBOX
# define STR0(x) #x
# define STR(x) STR0(x)
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Video::SetAlphaBlend() not implemented")
#else
VideoData::alpha_blend = set;
if (set)
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
#endif
}

bool Video::HasAlphaBlend()
{
return VideoData::alpha_blend;
}

void Video::SetClearColor(vec4 color)
{
#if defined USE_D3D9 || defined _XBOX
@@ -328,10 +269,10 @@ void Video::SetDebugRenderMode(DebugRenderMode d)
#elif defined HAVE_GLES_2X
glEnable(GL_CULL_FACE);
#else
if (VideoData::render_mode == d && glIsEnabled(GL_CULL_FACE) == GL_TRUE)
SetFaceCulling(false);
else
SetFaceCulling(true);
// if (VideoData::render_mode == d && glIsEnabled(GL_CULL_FACE) == GL_TRUE)
// SetFaceCulling(false);
// else
// SetFaceCulling(true);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
break;
@@ -342,14 +283,14 @@ void Video::SetDebugRenderMode(DebugRenderMode d)
{
#if defined USE_D3D9 || defined _XBOX
#else
SetFaceCulling(!VideoData::face_culling);
// SetFaceCulling(!VideoData::face_culling);
#endif
}
else
{
#if defined USE_D3D9 || defined _XBOX
#else
SetFaceCulling(false);
// SetFaceCulling(false);
#endif
}
#if defined USE_D3D9 || defined _XBOX


+ 0
- 5
src/video.h Näytä tiedosto

@@ -71,11 +71,6 @@ public:
static void SetCustomSize(ivec2 size);
static void RestoreSize();
static void SetFov(float theta);
static void SetDepth(bool set);
static void SetFaceCulling(bool set);
static bool HasFaceCulling();
static void SetAlphaBlend(bool set);
static bool HasAlphaBlend();
static void SetClearColor(vec4 color);
static void SetClearDepth(float f);
static void SetDebugRenderMode(DebugRenderMode d);


Ladataan…
Peruuta
Tallenna