Browse Source

gpu: move more platform-specific code from Video to Render.

legacy
Sam Hocevar sam 11 years ago
parent
commit
7c8fc6df12
6 changed files with 41 additions and 88 deletions
  1. +24
    -0
      src/gpu/renderer.cpp
  2. +0
    -1
      src/gradient.cpp
  3. +0
    -7
      src/tileset.cpp
  4. +17
    -78
      src/video.cpp
  5. +0
    -1
      src/video.h
  6. +0
    -1
      test/xolotl/xolotl.cpp

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

@@ -59,6 +59,21 @@ private:
Renderer::Renderer()
: m_data(new RendererData())
{
#if defined USE_D3D9 || defined _XBOX
/* TODO */
#else
# if defined USE_GLEW && !defined __APPLE__
/* Initialise GLEW if necessary */
GLenum glerr = glewInit();
if (glerr != GLEW_OK)
{
Log::Error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr));
exit(EXIT_FAILURE);
}
# endif
#endif

/* Initialise rendering states */
m_data->m_clear_color = vec4(-1.f);
SetClearColor(vec4(0.1f, 0.2f, 0.3f, 1.0f));

@@ -73,6 +88,15 @@ Renderer::Renderer()

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

/* Add some rendering states that we don't export to the user */
#if defined USE_D3D9 || defined _XBOX
/* TODO */
#else
# if defined HAVE_GL_2X && !defined __APPLE__
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
# endif
#endif
}

Renderer::~Renderer()


+ 0
- 1
src/gradient.cpp View File

@@ -13,7 +13,6 @@
#endif

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

using namespace std;



+ 0
- 7
src/tileset.cpp View File

@@ -27,16 +27,9 @@
#endif

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

using namespace std;

#if defined USE_D3D9
extern IDirect3DDevice9 *g_d3ddevice;
#elif defined _XBOX
extern D3DDevice *g_d3ddevice;
#endif

namespace lol
{



+ 17
- 78
src/video.cpp View File

@@ -34,11 +34,10 @@ using namespace std;
/* FIXME: g_d3ddevice should never be exported */
#if defined USE_D3D9
IDirect3DDevice9 *g_d3ddevice;
# if defined USE_SDL
extern HWND g_hwnd;
# endif
#elif defined _XBOX
D3DDevice *g_d3ddevice;
HWND g_hwnd = 0;
#endif

namespace lol
@@ -49,7 +48,6 @@ class VideoData
friend class Video;

private:
static mat4 proj_matrix;
static ivec2 saved_viewport;
static DebugRenderMode render_mode;
#if defined USE_D3D9 || defined _XBOX
@@ -63,7 +61,6 @@ private:
#endif
};

mat4 VideoData::proj_matrix;
ivec2 VideoData::saved_viewport(0, 0);
DebugRenderMode VideoData::render_mode = DebugRenderMode::Default;

@@ -91,34 +88,31 @@ void Video::Setup(ivec2 size)
exit(EXIT_FAILURE);
}

HWND window = 0;
D3DPRESENT_PARAMETERS d3dpp;
memset(&d3dpp, 0, sizeof(d3dpp));

# if defined USE_SDL
window = g_hwnd;
d3dpp.hDeviceWindow = g_hwnd;
d3dpp.Windowed = TRUE;
# elif defined _XBOX
/* Choose best viewport size */
# if defined _XBOX
XVIDEO_MODE VideoMode;
XGetVideoMode( &VideoMode );
if (size.x > VideoMode.dwDisplayWidth)
size.x = VideoMode.dwDisplayWidth;
if (size.y > VideoMode.dwDisplayHeight)
size.y = VideoMode.dwDisplayHeight;
XGetVideoMode(&VideoMode);
size = lol::min(size, ivec2(VideoMode.dwDisplayWidth,
VideoMode.dwDisplayHeight);
# endif
VideoData::saved_viewport = size;

D3DPRESENT_PARAMETERS d3dpp;
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.BackBufferWidth = size.x;
d3dpp.BackBufferHeight = size.y;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.hDeviceWindow = g_hwnd;
# if defined USE_SDL
d3dpp.Windowed = TRUE;
# endif
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, window,
HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, g_hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &VideoData::d3d_dev);
if (FAILED(hr))
@@ -128,28 +122,16 @@ void Video::Setup(ivec2 size)
}

g_d3ddevice = VideoData::d3d_dev;
#else
# if defined USE_GLEW && !defined __APPLE__
/* Initialise GLEW if necessary */
GLenum glerr = glewInit();
if (glerr != GLEW_OK)
{
Log::Error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr));
exit(EXIT_FAILURE);
}
# endif

g_renderer = new Renderer();
#else
/* Initialise OpenGL */
g_renderer = new Renderer();

glViewport(0, 0, size.x, size.y);
VideoData::saved_viewport = size;

# if defined HAVE_GL_2X && !defined __APPLE__
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
# endif
#endif

g_renderer = new Renderer();

/* Initialise reasonable scene default properties */
SetDebugRenderMode(DebugRenderMode::Default);
}
@@ -186,47 +168,6 @@ void Video::RestoreSize()
#endif
}

void Video::SetFov(float theta)
{
vec2 size = GetSize();
float near = -size.x - size.y;
float far = size.x + size.y;

#if defined __ANDROID__
size = vec2(640.0f, 480.0f);
#endif

/* Set the projection matrix */
if (theta < 1e-4f)
{
/* The easy way: purely orthogonal projection. */
VideoData::proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far);
}
else
{
/* Compute a view that approximates the glOrtho view when theta
* approaches zero. This view ensures that the z=0 plane fills
* the screen. */
float t1 = tanf(theta / 2);
float t2 = t1 * size.y / size.y;
float dist = size.x / (2.0f * t1);

near += dist;
far += dist;

if (near <= 0.0f)
{
far -= (near - 1.0f);
near = 1.0f;
}

mat4 proj = mat4::frustum(-near * t1, near * t1,
-near * t2, near * t2, near, far);
mat4 trans = mat4::translate(-0.5f * size.x, -0.5f * size.y, -dist);
VideoData::proj_matrix = proj * trans;
}
}

void Video::SetDebugRenderMode(DebugRenderMode d)
{
switch(d)
@@ -315,8 +256,6 @@ void Video::Clear(ClearMask m)
mask |= GL_STENCIL_BUFFER_BIT;
glClear(mask);
#endif

SetFov(0.0f);
}

void Video::Destroy()


+ 0
- 1
src/video.h View File

@@ -70,7 +70,6 @@ public:

static void SetCustomSize(ivec2 size);
static void RestoreSize();
static void SetFov(float theta);
static void SetDebugRenderMode(DebugRenderMode d);
static DebugRenderMode GetDebugRenderMode();
static void Clear(ClearMask m);


+ 0
- 1
test/xolotl/xolotl.cpp View File

@@ -14,7 +14,6 @@
#endif

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

using namespace lol;


Loading…
Cancel
Save