Browse Source

gpu: create a Renderer and a RenderContext class to handle render states

such as alpha blending, depth test, etc.
legacy
Sam Hocevar sam 11 years ago
parent
commit
716c2b5592
10 changed files with 274 additions and 3 deletions
  1. +3
    -1
      src/Makefile.am
  2. +91
    -0
      src/gpu/rendercontext.cpp
  3. +75
    -0
      src/gpu/renderer.cpp
  4. +2
    -0
      src/lol/gpu/all.h
  5. +39
    -0
      src/lol/gpu/rendercontext.h
  6. +42
    -0
      src/lol/gpu/renderer.h
  7. +4
    -0
      src/lolcore.vcxproj
  8. +12
    -0
      src/lolcore.vcxproj.filters
  9. +4
    -1
      src/video.cpp
  10. +2
    -1
      src/video.h

+ 3
- 1
src/Makefile.am View File

@@ -50,6 +50,7 @@ liblolcore_headers = \
lol/gpu/all.h \
lol/gpu/shader.h lol/gpu/indexbuffer.h lol/gpu/vertexbuffer.h \
lol/gpu/framebuffer.h lol/gpu/texture.h lol/gpu/lolfx.h \
lol/gpu/renderer.h lol/gpu/rendercontext.h \
\
lol/debug/all.h \
lol/debug/lines.h \
@@ -77,7 +78,8 @@ liblolcore_sources = \
math/geometry.cpp \
\
gpu/shader.cpp gpu/indexbuffer.cpp gpu/vertexbuffer.cpp \
gpu/framebuffer.cpp gpu/texture.cpp \
gpu/framebuffer.cpp gpu/texture.cpp gpu/renderer.cpp \
gpu/rendercontext.cpp \
\
input/input.cpp input/input.h \
input/keyboard.cpp input/keyboard.h \


+ 91
- 0
src/gpu/rendercontext.cpp View File

@@ -0,0 +1,91 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdlib>

#include "core.h"

namespace lol
{

class TrackedState
{
public:
inline TrackedState()
: m_state(Unchanged)
{}

inline void TrackValue(bool set)
{
m_state = set ? MustSet : MustUnset;
}

inline bool HasChanged()
{
return m_state != Unchanged;
}

inline bool GetValue()
{
return m_state == MustSet;
}

private:
enum
{
Unchanged,
MustSet,
MustUnset,
}
m_state;
};

class RenderContextData
{
friend class RenderContext;

private:
Scene *m_scene;

TrackedState m_blend;
};

/*
* Public RenderContext class
*/

RenderContext::RenderContext()
: m_data(new RenderContextData())
{
m_data->m_scene = Scene::GetDefault();
}

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

delete m_data;
}

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

g_renderer->SetBlendState(set);
}

} /* namespace lol */


+ 75
- 0
src/gpu/renderer.cpp View File

@@ -0,0 +1,75 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdlib>

#include "core.h"

namespace lol
{

/*
* The global g_renderer object, initialised by Video::Init
*/
Renderer *g_renderer;

/*
* Private RendererData class
*/
class RendererData
{
friend class Renderer;

private:
bool m_blend;
};

/*
* Public Renderer class
*/

Renderer::Renderer()
: m_data(new RendererData())
{
m_data->m_blend = false;
}

Renderer::~Renderer()
{
delete m_data;
}

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

m_data->m_blend = set;
if (set)
{

}
else
{

}
}

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

} /* namespace lol */


+ 2
- 0
src/lol/gpu/all.h View File

@@ -17,6 +17,8 @@
#include <lol/gpu/texture.h>
#include <lol/gpu/framebuffer.h>
#include <lol/gpu/lolfx.h>
#include <lol/gpu/renderer.h>
#include <lol/gpu/rendercontext.h>

#endif // __LOL_GPU_ALL_H__


+ 39
- 0
src/lol/gpu/rendercontext.h View File

@@ -0,0 +1,39 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

//
// The RenderContext class
// -----------------------
//

#if !defined __LOL_RENDERCONTEXT_H__
#define __LOL_RENDERCONTEXT_H__

namespace lol
{

class RenderContextData;

class RenderContext
{
public:
RenderContext();
~RenderContext();

void SetBlendState(bool set);

private:
RenderContextData *m_data;
};

} /* namespace lol */

#endif // __LOL_RENDERCONTEXT_H__


+ 42
- 0
src/lol/gpu/renderer.h View File

@@ -0,0 +1,42 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

//
// The Renderer class
// ------------------
//

#if !defined __LOL_RENDERER_H__
#define __LOL_RENDERER_H__

namespace lol
{

class RendererData;

class Renderer
{
public:
Renderer();
~Renderer();

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

private:
RendererData *m_data;
};

extern Renderer *g_renderer;

} /* namespace lol */

#endif // __LOL_RENDERER_H__


+ 4
- 0
src/lolcore.vcxproj View File

@@ -115,6 +115,8 @@
<ClCompile Include="gpu\indexbuffer.cpp" />
<ClCompile Include="gpu\lolfx-compiler.cpp" />
<ClCompile Include="gpu\lolfx.cpp" />
<ClCompile Include="gpu\rendercontext.cpp" />
<ClCompile Include="gpu\renderer.cpp" />
<ClCompile Include="gpu\shader.cpp" />
<ClCompile Include="gpu\texture.cpp" />
<ClCompile Include="gpu\vertexbuffer.cpp" />
@@ -209,6 +211,8 @@
<ClInclude Include="lol\gpu\framebuffer.h" />
<ClInclude Include="lol\gpu\indexbuffer.h" />
<ClInclude Include="lol\gpu\lolfx.h" />
<ClInclude Include="lol\gpu\rendercontext.h" />
<ClInclude Include="lol\gpu\renderer.h" />
<ClInclude Include="lol\gpu\shader.h" />
<ClInclude Include="lol\gpu\texture.h" />
<ClInclude Include="lol\gpu\vertexbuffer.h" />


+ 12
- 0
src/lolcore.vcxproj.filters View File

@@ -111,6 +111,12 @@
<ClCompile Include="mesh\mesh.cpp">
<Filter>mesh</Filter>
</ClCompile>
<ClCompile Include="gpu\rendercontext.cpp">
<Filter>gpu</Filter>
</ClCompile>
<ClCompile Include="gpu\renderer.cpp">
<Filter>gpu</Filter>
</ClCompile>
<ClCompile Include="gpu\shader.cpp">
<Filter>gpu</Filter>
</ClCompile>
@@ -560,6 +566,12 @@
<ClInclude Include="lol\base\log.h">
<Filter>lol\base</Filter>
</ClInclude>
<ClInclude Include="lol\gpu\rendercontext.h">
<Filter>lol\gpu</Filter>
</ClInclude>
<ClInclude Include="lol\gpu\renderer.h">
<Filter>lol\gpu</Filter>
</ClInclude>
<ClInclude Include="lol\gpu\shader.h">
<Filter>lol\gpu</Filter>
</ClInclude>


+ 4
- 1
src/video.cpp View File

@@ -91,6 +91,8 @@ 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)
@@ -402,7 +404,8 @@ void Video::Clear(ClearMask m)

void Video::Destroy()
{
;
delete g_renderer;
g_renderer = nullptr;
}

void Video::Capture(uint32_t *buffer)


+ 2
- 1
src/video.h View File

@@ -66,9 +66,10 @@ class Video
{
public:
static void Setup(ivec2 size);
static void Destroy();

static void SetCustomSize(ivec2 size);
static void RestoreSize();
static void Destroy();
static void SetFov(float theta);
static void SetDepth(bool set);
static void SetFaceCulling(bool set);


Loading…
Cancel
Save