Selaa lähdekoodia

gpu: move Video::Clear to Renderer::Clear.

legacy
Sam Hocevar sam 11 vuotta sitten
vanhempi
commit
13fb52cebe
8 muutettua tiedostoa jossa 69 lisäystä ja 62 poistoa
  1. +33
    -0
      src/gpu/renderer.cpp
  2. +23
    -0
      src/lol/gpu/renderer.h
  3. +1
    -1
      src/ticker.cpp
  4. +0
    -30
      src/video.cpp
  5. +2
    -21
      src/video.h
  6. +1
    -1
      test/meshviewer.cpp
  7. +1
    -1
      tutorial/08_fbo.cpp
  8. +8
    -8
      tutorial/12_voronoi.cpp

+ 33
- 0
src/gpu/renderer.cpp Näytä tiedosto

@@ -130,6 +130,39 @@ Renderer::~Renderer()
delete m_data;
}

/*
* Buffer clearing
*/

void Renderer::Clear(ClearMask mask)
{
#if defined USE_D3D9 || defined _XBOX
int m = 0;
if (mask & ClearMask::Color)
m |= D3DCLEAR_TARGET;
if (mask & ClearMask::Depth)
m |= D3DCLEAR_ZBUFFER;
if (mask & ClearMask::Stencil)
m |= D3DCLEAR_STENCIL;

vec3 tmp = 255.999f * GetClearColor().rgb;
D3DCOLOR clear_color = D3DCOLOR_XRGB((int)tmp.r, (int)tmp.g, (int)tmp.b);

if (FAILED(VideoData::d3d_dev->Clear(0, nullptr, m, clear_color,
g_renderer->GetClearDepth(), 0)))
Abort();
#else
GLbitfield m = 0;
if (mask & ClearMask::Color)
m |= GL_COLOR_BUFFER_BIT;
if (mask & ClearMask::Depth)
m |= GL_DEPTH_BUFFER_BIT;
if (mask & ClearMask::Stencil)
m |= GL_STENCIL_BUFFER_BIT;
glClear(m);
#endif
}

/*
* Viewport dimensions
*/


+ 23
- 0
src/lol/gpu/renderer.h Näytä tiedosto

@@ -21,6 +21,26 @@ namespace lol

class RendererData;

/* A list of bitmasks to clear a render buffer. */
struct ClearMask
{
enum Value
{
/* Note: D3D9 doesn't appear to support the accumulation buffer,
* and it is a deprecated OpenGL feature. No reason to support it. */
Color = 1 << 0,
Depth = 1 << 1,
Stencil = 1 << 2,

All = 0xffffffff
}
m_value;

inline ClearMask(Value v) : m_value(v) {}
inline ClearMask(uint64_t i) : m_value((Value)i) {}
inline operator Value() { return m_value; }
};

/* A safe enum to indicate the blending factors. */
struct BlendFunc
{
@@ -118,6 +138,9 @@ private:
Renderer(ivec2 size);
~Renderer();

public:
void Clear(ClearMask mask);

public:
void SetViewport(ibox2 viewport);
ibox2 GetViewport() const;


+ 1
- 1
src/ticker.cpp Näytä tiedosto

@@ -387,7 +387,7 @@ void TickerData::DrawThreadTick()
{
case Entity::DRAWGROUP_BEGIN:
Scene::GetDefault()->Reset();
Video::Clear(ClearMask::All);
g_renderer->Clear(ClearMask::All);
break;
default:
break;


+ 0
- 30
src/video.cpp Näytä tiedosto

@@ -185,36 +185,6 @@ DebugRenderMode Video::GetDebugRenderMode()
return VideoData::render_mode;
}

void Video::Clear(ClearMask m)
{
#if defined USE_D3D9 || defined _XBOX
int mask = 0;
if (m & ClearMask::Color)
mask |= D3DCLEAR_TARGET;
if (m & ClearMask::Depth)
mask |= D3DCLEAR_ZBUFFER;
if (m & ClearMask::Stencil)
mask |= D3DCLEAR_STENCIL;

vec4 tmp = 255.999f * g_renderer->GetClearColor();
D3DCOLOR clear_color = D3DCOLOR_XRGB((int)tmp.r, (int)tmp.g, (int)tmp.b);

if (FAILED(VideoData::d3d_dev->Clear(0, nullptr, mask,
clear_color,
g_renderer->GetClearDepth(), 0)))
Abort();
#else
GLbitfield mask = 0;
if (m & ClearMask::Color)
mask |= GL_COLOR_BUFFER_BIT;
if (m & ClearMask::Depth)
mask |= GL_DEPTH_BUFFER_BIT;
if (m & ClearMask::Stencil)
mask |= GL_STENCIL_BUFFER_BIT;
glClear(mask);
#endif
}

void Video::Destroy()
{
delete g_renderer;


+ 2
- 21
src/video.h Näytä tiedosto

@@ -22,25 +22,6 @@
namespace lol
{

struct ClearMask
{
enum Value
{
/* Note: D3D9 doesn't appear to support the accumulation buffer,
* and it is a deprecated OpenGL feature. No reason to support it. */
Color = 1 << 0,
Depth = 1 << 1,
Stencil = 1 << 2,

All = 0xffffffff
}
m_value;

inline ClearMask(Value v) : m_value(v) {}
inline ClearMask(uint64_t i) : m_value((Value)i) {}
inline operator Value() { return m_value; }
};

struct DebugRenderMode
{
enum Value
@@ -68,11 +49,11 @@ public:
static void Setup(ivec2 size);
static void Destroy();

static ivec2 GetSize();

static void SetDebugRenderMode(DebugRenderMode d);
static DebugRenderMode GetDebugRenderMode();
static void Clear(ClearMask m);
static void Capture(uint32_t *buffer);
static ivec2 GetSize();
};

} /* namespace lol */


+ 1
- 1
test/meshviewer.cpp Näytä tiedosto

@@ -472,7 +472,7 @@ public:
#else
m_meshes[i].m1.Render(m_mat);
#endif
Video::Clear(ClearMask::Depth);
g_renderer->Clear(ClearMask::Depth);
}
}
Scene::GetDefault()->GetCamera()->SetProjection(default_proj);


+ 1
- 1
tutorial/08_fbo.cpp Näytä tiedosto

@@ -78,7 +78,7 @@ public:
RenderContext rc;
rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
rc.SetClearDepth(1.f);
Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
}

m_fbo->Unbind();


+ 8
- 8
tutorial/12_voronoi.cpp Näytä tiedosto

@@ -126,7 +126,7 @@ public:
RenderContext rc;
rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
rc.SetClearDepth(1.f);
Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
}
m_fbos.Last().m1->Unbind();
}
@@ -137,7 +137,7 @@ public:
RenderContext rc;
rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
rc.SetClearDepth(1.f);
Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
}
temp_buffer->Unbind();

@@ -198,7 +198,7 @@ public:
RenderContext rc;
rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
rc.SetClearDepth(1.f);
Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
}
temp_buffer->Unbind();

@@ -228,7 +228,7 @@ public:
RenderContext rc;
rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
rc.SetClearDepth(1.f);
Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
}
m_fbos[f].m1->Unbind();

@@ -251,7 +251,7 @@ public:

dst_buf->Bind();
/* FIXME: we should just disable depth test in the shader */
Video::Clear(ClearMask::Depth);
g_renderer->Clear(ClearMask::Depth);
m_fbos[f].m2->Bind();

int i = 0;
@@ -270,7 +270,7 @@ public:
}
}

Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);

//FRAME BUFFER DRAW
m_timer -= seconds;
@@ -282,7 +282,7 @@ public:
RenderContext rc;
rc.SetClearColor(vec4(0.f, 0.f, 0.f, 1.f));
rc.SetClearDepth(1.f);
Video::Clear(ClearMask::Color | ClearMask::Depth);
g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
}
m_fbos[m_cur_fbo].m1->Unbind();

@@ -313,7 +313,7 @@ public:

dst_buf->Bind();
/* FIXME: we should just disable depth test in the shader */
Video::Clear(ClearMask::Depth);
g_renderer->Clear(ClearMask::Depth);
shader->Bind();

//08_FBO ??


Ladataan…
Peruuta
Tallenna