cannot used DirectX 10 because my video card only supports DX9, and there is no compatibility layer. DX11 has feature levels for older hardware so it would work with a DX9 card, but it's not available for WinXP.legacy
@@ -12,7 +12,7 @@ | |||
# include "config.h" | |||
#endif | |||
#if !defined _XBOX /* This file is meaningless on Xbox */ | |||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||
#if defined WIN32 && !_XBOX | |||
# define _USE_MATH_DEFINES /* for M_PI */ | |||
@@ -12,7 +12,7 @@ | |||
# include "config.h" | |||
#endif | |||
#if !defined _XBOX /* This file is meaningless on Xbox */ | |||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||
#if defined WIN32 | |||
# define _USE_MATH_DEFINES /* for M_PI */ | |||
@@ -19,6 +19,10 @@ | |||
#ifdef WIN32 | |||
# define WIN32_LEAN_AND_MEAN | |||
# include <windows.h> | |||
# if defined USE_D3D9 | |||
# include <d3d9.h> | |||
# include <d3dx9shader.h> | |||
# endif | |||
#endif | |||
#include "core.h" | |||
@@ -26,6 +30,12 @@ | |||
using namespace std; | |||
#if defined USE_D3D9 | |||
extern IDirect3DDevice9 *g_d3ddevice; | |||
#elif defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#endif | |||
namespace lol | |||
{ | |||
@@ -38,7 +48,11 @@ class ShaderData | |||
friend class Shader; | |||
private: | |||
#if defined _XBOX | |||
#if defined USE_D3D9 | |||
IDirect3DVertexShader9 *vert_shader; | |||
IDirect3DPixelShader9 *frag_shader; | |||
ID3DXConstantTable *vert_table, *frag_table; | |||
#elif defined _XBOX | |||
D3DVertexShader *vert_shader; | |||
D3DPixelShader *frag_shader; | |||
ID3DXConstantTable *vert_table, *frag_table; | |||
@@ -92,8 +106,7 @@ void Shader::Destroy(Shader *shader) | |||
Shader::Shader(char const *vert, char const *frag) | |||
: data(new ShaderData()) | |||
{ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#if defined USE_D3D9 || defined _XBOX | |||
ID3DXBuffer *shader_code, *error_msg; | |||
HRESULT hr; | |||
#elif !defined __CELLOS_LV2__ | |||
@@ -109,7 +122,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
/* Compile vertex shader */ | |||
data->vert_crc = Hash::Crc32(vert); | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
hr = D3DXCompileShader(vert, (UINT)strlen(vert), NULL, NULL, "main", | |||
"vs_2_0", 0, &shader_code, &error_msg, | |||
&data->vert_table); | |||
@@ -148,7 +161,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
/* Compile fragment shader */ | |||
data->frag_crc = Hash::Crc32(frag); | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
hr = D3DXCompileShader(frag, (UINT)strlen(frag), NULL, NULL, "main", | |||
"ps_2_0", 0, &shader_code, &error_msg, | |||
&data->frag_table); | |||
@@ -185,7 +198,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
} | |||
#endif | |||
#if !defined _XBOX && !defined __CELLOS_LV2__ | |||
#if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__ | |||
/* Create program */ | |||
data->prog_id = glCreateProgram(); | |||
glAttachShader(data->prog_id, data->vert_id); | |||
@@ -198,7 +211,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
int Shader::GetAttribLocation(char const *attr) const | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
/* FIXME: do we have attribs? */ | |||
return 0; | |||
#elif !defined __CELLOS_LV2__ | |||
@@ -211,9 +224,9 @@ int Shader::GetAttribLocation(char const *attr) const | |||
int Shader::GetUniformLocation(char const *uni) const | |||
{ | |||
#if defined _XBOX | |||
D3DXHANDLE hr1 = data->frag_table->GetConstantByName(NULL, uni); | |||
D3DXHANDLE hr2 = data->vert_table->GetConstantByName(NULL, uni); | |||
#if defined USE_D3D9 || defined _XBOX | |||
UINT hr1 = (uintptr_t)data->frag_table->GetConstantByName(NULL, uni); | |||
UINT hr2 = (uintptr_t)data->vert_table->GetConstantByName(NULL, uni); | |||
return (int)(((uint32_t)hr1 << 16) | (uint32_t)hr2); | |||
#elif !defined __CELLOS_LV2__ | |||
return glGetUniformLocation(data->prog_id, uni); | |||
@@ -229,7 +242,7 @@ int Shader::GetUniformLocation(char const *uni) const | |||
void Shader::SetUniform(int uni, float f) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
SetUniform(uni, vec4(f, 0, 0, 0)); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform1f(uni, f); | |||
@@ -240,7 +253,7 @@ void Shader::SetUniform(int uni, float f) | |||
void Shader::SetUniform(int uni, vec2 const &v) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
SetUniform(uni, vec4(v, 0, 0)); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform2f(uni, v.x, v.y); | |||
@@ -251,7 +264,7 @@ void Shader::SetUniform(int uni, vec2 const &v) | |||
void Shader::SetUniform(int uni, vec3 const &v) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
SetUniform(uni, vec4(v, 0)); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform3f(uni, v.x, v.y, v.z); | |||
@@ -263,10 +276,9 @@ void Shader::SetUniform(int uni, vec3 const &v) | |||
void Shader::SetUniform(int uni, vec4 const &v) | |||
{ | |||
/* FIXME: use the array versions of these functions */ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
D3DXHANDLE hr1 = (uint32_t)uni >> 16; | |||
D3DXHANDLE hr2 = (uint32_t)(uint16_t)uni; | |||
#if defined USE_D3D9 || defined _XBOX | |||
UINT hr1 = (uint32_t)uni >> 16; | |||
UINT hr2 = (uint32_t)(uint16_t)uni; | |||
g_d3ddevice->SetPixelShaderConstantF(hr1, &v[0], 1); | |||
g_d3ddevice->SetVertexShaderConstantF(hr2, &v[0], 1); | |||
#elif !defined __CELLOS_LV2__ | |||
@@ -278,10 +290,9 @@ void Shader::SetUniform(int uni, vec4 const &v) | |||
void Shader::SetUniform(int uni, mat4 const &m) | |||
{ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
D3DXHANDLE hr1 = (uint32_t)uni >> 16; | |||
D3DXHANDLE hr2 = (uint32_t)(uint16_t)uni; | |||
#if defined USE_D3D9 || defined _XBOX | |||
UINT hr1 = (uint32_t)uni >> 16; | |||
UINT hr2 = (uint32_t)(uint16_t)uni; | |||
g_d3ddevice->SetPixelShaderConstantF(hr1, &m[0][0], 4); | |||
g_d3ddevice->SetVertexShaderConstantF(hr2, &m[0][0], 4); | |||
#elif !defined __CELLOS_LV2__ | |||
@@ -293,10 +304,10 @@ void Shader::SetUniform(int uni, mat4 const &m) | |||
void Shader::Bind() const | |||
{ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
g_d3ddevice->SetVertexShader(data->vert_shader); | |||
g_d3ddevice->SetPixelShader(data->frag_shader); | |||
#if defined USE_D3D9 || defined _XBOX | |||
HRESULT hr; | |||
hr = g_d3ddevice->SetVertexShader(data->vert_shader); | |||
hr = g_d3ddevice->SetPixelShader(data->frag_shader); | |||
#elif !defined __CELLOS_LV2__ | |||
glUseProgram(data->prog_id); | |||
#else | |||
@@ -309,8 +320,7 @@ void Shader::Bind() const | |||
Shader::~Shader() | |||
{ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#if defined USE_D3D9 || defined _XBOX | |||
data->vert_shader->Release(); | |||
data->vert_table->Release(); | |||
data->frag_shader->Release(); | |||
@@ -333,7 +343,7 @@ int ShaderData::GetVersion() | |||
{ | |||
static int version = 0; | |||
#if !defined _XBOX && !defined __CELLOS_LV2__ | |||
#if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__ | |||
if (!version) | |||
{ | |||
char buf[4096]; | |||
@@ -32,7 +32,7 @@ class GradientData | |||
private: | |||
Shader *shader; | |||
#if !defined _XBOX /* This file is meaningless on Xbox */ | |||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||
GLuint bufs[2]; | |||
#if defined HAVE_GL_2X && !defined __APPLE__ | |||
@@ -65,7 +65,7 @@ void Gradient::TickDraw(float deltams) | |||
{ | |||
Entity::TickDraw(deltams); | |||
#if !defined _XBOX /* This file is meaningless on Xbox */ | |||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||
if (!data->shader) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
@@ -14,6 +14,10 @@ | |||
#if defined USE_SDL | |||
# include <SDL.h> | |||
# if defined USE_D3D9 | |||
# include <d3d9.h> | |||
# include <SDL_syswm.h> | |||
# endif | |||
#endif | |||
#include "core.h" | |||
@@ -21,6 +25,10 @@ | |||
#include "platform/sdl/sdlapp.h" | |||
#include "platform/sdl/sdlinput.h" | |||
#if defined USE_D3D9 | |||
HWND g_hwnd = NULL; | |||
#endif | |||
namespace lol | |||
{ | |||
@@ -51,12 +59,20 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | |||
exit(EXIT_FAILURE); | |||
} | |||
# if defined USE_D3D9 | |||
SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 16, 0); | |||
SDL_SysWMinfo wminfo; | |||
SDL_VERSION(&wminfo.version); | |||
SDL_GetWMInfo(&wminfo); | |||
g_hwnd = wminfo.window; | |||
# else | |||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | |||
SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); | |||
# endif | |||
if (!video) | |||
{ | |||
Log::Error("cannot create OpenGL screen: %s\n", SDL_GetError()); | |||
Log::Error("cannot create rendering window: %s\n", SDL_GetError()); | |||
SDL_Quit(); | |||
exit(EXIT_FAILURE); | |||
} | |||
@@ -84,10 +100,19 @@ void SdlApp::Run() | |||
{ | |||
while (!Ticker::Finished()) | |||
{ | |||
#if defined USE_SDL && defined USE_D3D9 | |||
extern IDirect3DDevice9 *g_d3ddevice; | |||
g_d3ddevice->BeginScene(); | |||
#endif | |||
/* Tick the renderer, show the frame and clamp to desired framerate. */ | |||
Ticker::TickDraw(); | |||
#if defined USE_SDL | |||
# if defined USE_D3D9 | |||
g_d3ddevice->EndScene(); | |||
g_d3ddevice->Present(NULL, NULL, NULL, NULL); | |||
# else | |||
SDL_GL_SwapBuffers(); | |||
# endif | |||
#endif | |||
} | |||
} | |||
@@ -60,7 +60,7 @@ private: | |||
int ntiles; | |||
float angle; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene not implemented") | |||
@@ -90,7 +90,7 @@ Scene::Scene(float angle) | |||
data->ntiles = 0; | |||
data->angle = angle; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Scene() not implemented") | |||
@@ -108,7 +108,7 @@ Scene::Scene(float angle) | |||
Scene::~Scene() | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::~Scene() not implemented") | |||
@@ -144,7 +144,7 @@ void Scene::Reset() | |||
void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) | |||
{ | |||
#if !defined _XBOX /* No WPOS on Xbox */ | |||
#if !defined USE_D3D9 && !defined _XBOX | |||
if ((data->ntiles % 1024) == 0) | |||
data->tiles = (Tile *)realloc(data->tiles, | |||
(data->ntiles + 1024) * sizeof(Tile)); | |||
@@ -161,7 +161,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) | |||
void Scene::Render() // XXX: rename to Blit() | |||
{ | |||
#if !defined _XBOX /* No WPOS on Xbox */ | |||
#if !defined USE_D3D9 && !defined _XBOX /* No WPOS on Xbox, what about Win32? */ | |||
if (!stdshader) | |||
{ | |||
#if !defined _XBOX && !defined __CELLOS_LV2__ | |||
@@ -343,7 +343,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
uni_mat = stdshader->GetUniformLocation("model_matrix"); | |||
stdshader->SetUniform(uni_mat, data->model_matrix); | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
@@ -358,7 +358,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
//cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0); | |||
#endif | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
@@ -380,7 +380,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
@@ -422,7 +422,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
#if defined HAVE_GL_2X && !defined __APPLE__ | |||
glBindVertexArray(data->vao); | |||
#endif | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
@@ -473,7 +473,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
data->tiles = 0; | |||
data->ntiles = 0; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
@@ -489,7 +489,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
#endif | |||
glDisable(GL_BLEND); | |||
#endif | |||
#endif /* _XBOX */ | |||
#endif /* _XBOX || USE_D3D9 */ | |||
} | |||
} /* namespace lol */ | |||
@@ -46,7 +46,7 @@ private: | |||
float tx, ty; | |||
Image *img; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet not implemented") | |||
@@ -69,7 +69,7 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count) | |||
sprintf(data->name, "<tileset> %s", path); | |||
data->tiles = NULL; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") | |||
@@ -118,7 +118,7 @@ void TileSet::TickDraw(float deltams) | |||
{ | |||
if (data->img) | |||
delete data->img; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") | |||
@@ -131,7 +131,7 @@ void TileSet::TickDraw(float deltams) | |||
} | |||
else if (data->img) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") | |||
@@ -203,7 +203,7 @@ ivec2 TileSet::GetSize(int tileid) const | |||
void TileSet::Bind() | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::Bind() not implemented") | |||
@@ -228,7 +228,7 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, | |||
int dy = o ? 0 : data->size.y * scale.y; | |||
int dz = o ? data->size.y * scale.y : 0; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") | |||
@@ -14,7 +14,9 @@ | |||
#include <cmath> | |||
#if _XBOX | |||
#if defined USE_D3D9 | |||
# include <d3d9.h> | |||
#elif defined _XBOX | |||
# include <xtl.h> | |||
# undef near /* Fuck Microsoft */ | |||
# undef far /* Fuck Microsoft again */ | |||
@@ -30,8 +32,13 @@ | |||
using namespace std; | |||
#if defined _XBOX | |||
/* 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; | |||
#endif | |||
@@ -45,7 +52,11 @@ class VideoData | |||
private: | |||
static mat4 proj_matrix, view_matrix; | |||
static ivec2 saved_viewport; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 | |||
static IDirect3D9 *d3d_ctx; | |||
static IDirect3DDevice9 *d3d_dev; | |||
static D3DCOLOR clear_color; | |||
#elif defined _XBOX | |||
static Direct3D *d3d_ctx; | |||
static D3DDevice *d3d_dev; | |||
static D3DCOLOR clear_color; | |||
@@ -56,7 +67,11 @@ mat4 VideoData::proj_matrix; | |||
mat4 VideoData::view_matrix; | |||
ivec2 VideoData::saved_viewport(0, 0); | |||
#if defined _XBOX | |||
#if defined USE_D3D9 | |||
IDirect3D9 *VideoData::d3d_ctx; | |||
IDirect3DDevice9 *VideoData::d3d_dev; | |||
D3DCOLOR VideoData::clear_color; | |||
#elif defined _XBOX | |||
Direct3D *VideoData::d3d_ctx; | |||
D3DDevice *VideoData::d3d_dev; | |||
D3DCOLOR VideoData::clear_color; | |||
@@ -68,7 +83,7 @@ D3DCOLOR VideoData::clear_color; | |||
void Video::Setup(ivec2 size) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION); | |||
if (!VideoData::d3d_ctx) | |||
{ | |||
@@ -76,15 +91,22 @@ 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 | |||
XVIDEO_MODE VideoMode; | |||
XGetVideoMode( &VideoMode ); | |||
if (size.x > VideoMode.dwDisplayWidth) | |||
size.x = VideoMode.dwDisplayWidth; | |||
if (size.y > VideoMode.dwDisplayHeight) | |||
size.y = VideoMode.dwDisplayHeight; | |||
# endif | |||
VideoData::saved_viewport = size; | |||
VideoData::clear_color = D3DCOLOR_XRGB(26, 51, 77); | |||
@@ -98,9 +120,10 @@ void Video::Setup(ivec2 size) | |||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; | |||
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; | |||
if (FAILED(VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL, | |||
D3DCREATE_HARDWARE_VERTEXPROCESSING, | |||
&d3dpp, &VideoData::d3d_dev))) | |||
HRESULT hr = VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, window, | |||
D3DCREATE_HARDWARE_VERTEXPROCESSING, | |||
&d3dpp, &VideoData::d3d_dev); | |||
if (FAILED(hr)) | |||
{ | |||
Log::Error("cannot create D3D device\n"); | |||
exit(EXIT_FAILURE); | |||
@@ -177,7 +200,7 @@ void Video::SetFov(float theta) | |||
void Video::SetDepth(bool set) | |||
{ | |||
#if defined _XBOX | |||
#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") | |||
@@ -191,7 +214,7 @@ void Video::SetDepth(bool set) | |||
void Video::SetClearColor(vec4 color) | |||
{ | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
VideoData::clear_color = D3DCOLOR_XRGB((int)(color.r * 255.999f), | |||
(int)(color.g * 255.999f), | |||
(int)(color.b * 255.999f)); | |||
@@ -203,7 +226,7 @@ void Video::SetClearColor(vec4 color) | |||
void Video::Clear() | |||
{ | |||
ivec2 size = GetSize(); | |||
#if defined _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | |||
| D3DCLEAR_STENCIL, | |||
VideoData::clear_color, 1.0f, 0); | |||
@@ -222,7 +245,7 @@ void Video::Destroy() | |||
void Video::Capture(uint32_t *buffer) | |||
{ | |||
#if _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
/* TODO */ | |||
#else | |||
GLint v[4]; | |||
@@ -258,7 +281,7 @@ void Video::Capture(uint32_t *buffer) | |||
ivec2 Video::GetSize() | |||
{ | |||
#if _XBOX | |||
#if defined USE_D3D9 || defined _XBOX | |||
return VideoData::saved_viewport; | |||
#elif 1 | |||
/* GetSize() is called too often on the game thread; we cannot rely on | |||
@@ -19,6 +19,12 @@ | |||
using namespace std; | |||
using namespace lol; | |||
#if defined _WIN32 && defined USE_D3D9 | |||
# define FAR | |||
# define NEAR | |||
# include <d3d9.h> | |||
#endif | |||
#if USE_SDL && defined __APPLE__ | |||
# include <SDL_main.h> | |||
#endif | |||
@@ -32,6 +38,12 @@ using namespace lol; | |||
# include <direct.h> | |||
#endif | |||
#if defined USE_D3D9 | |||
extern IDirect3DDevice9 *g_d3ddevice; | |||
#elif defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#endif | |||
class Triangle : public WorldEntity | |||
{ | |||
public: | |||
@@ -50,7 +62,7 @@ public: | |||
if (!m_ready) | |||
{ | |||
m_shader = Shader::Create( | |||
#if !defined __CELLOS_LV2__ && !defined _XBOX | |||
#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 | |||
"#version 120\n" | |||
"attribute vec2 in_Position;" | |||
"void main(void) {" | |||
@@ -72,21 +84,20 @@ public: | |||
"}" | |||
#endif | |||
); | |||
#if !defined _XBOX | |||
#if !defined _XBOX && !defined USE_D3D9 | |||
m_attrib = m_shader->GetAttribLocation("in_Position"); | |||
#endif | |||
m_ready = true; | |||
#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX | |||
#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 | |||
/* Method 1: store vertex buffer on the GPU memory */ | |||
glGenBuffers(1, &m_vbo); | |||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||
glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices, | |||
GL_STATIC_DRAW); | |||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX | |||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 | |||
/* Method 2: upload vertex information at each frame */ | |||
#elif defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#elif defined _XBOX || defined USE_D3D9 | |||
D3DVERTEXELEMENT9 const elements[2] = | |||
{ | |||
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, | |||
@@ -108,8 +119,7 @@ public: | |||
} | |||
m_shader->Bind(); | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#if defined _XBOX || defined USE_D3D9 | |||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | |||
g_d3ddevice->SetVertexDeclaration(m_vdecl); | |||
g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices)); | |||
@@ -126,13 +136,13 @@ public: | |||
glVertexPointer(3, GL_FLOAT, 0, m_vertices); | |||
#endif | |||
#if defined _XBOX | |||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); | |||
#if defined _XBOX || defined USE_D3D9 | |||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 3); | |||
#else | |||
glDrawArrays(GL_TRIANGLES, 0, 3); | |||
#endif | |||
#if defined _XBOX | |||
#if defined _XBOX || defined USE_D3D9 | |||
/* FIXME: do we need to unset anything here? */ | |||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
glDisableVertexAttribArray(m_attrib); | |||
@@ -148,7 +158,10 @@ public: | |||
private: | |||
vec2 m_vertices[3]; | |||
Shader *m_shader; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 | |||
IDirect3DVertexDeclaration9 *m_vdecl; | |||
IDirect3DVertexBuffer9 *m_vbo; | |||
#elif defined _XBOX | |||
D3DVertexDeclaration *m_vdecl; | |||
D3DVertexBuffer *m_vbo; | |||
#else | |||
@@ -19,6 +19,12 @@ | |||
using namespace std; | |||
using namespace lol; | |||
#if defined _WIN32 && defined USE_D3D9 | |||
# define FAR | |||
# define NEAR | |||
# include <d3d9.h> | |||
#endif | |||
#if USE_SDL && defined __APPLE__ | |||
# include <SDL_main.h> | |||
#endif | |||
@@ -28,6 +34,12 @@ using namespace lol; | |||
# include <direct.h> | |||
#endif | |||
#if defined USE_D3D9 | |||
extern IDirect3DDevice9 *g_d3ddevice; | |||
#elif defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#endif | |||
class Cube : public WorldEntity | |||
{ | |||
public: | |||
@@ -92,7 +104,7 @@ public: | |||
if (!m_ready) | |||
{ | |||
m_shader = Shader::Create( | |||
#if !defined __CELLOS_LV2__ && !defined _XBOX | |||
#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 | |||
"#version 120\n" | |||
"attribute vec3 in_Vertex;" | |||
"attribute vec3 in_Color;" | |||
@@ -126,14 +138,14 @@ public: | |||
"}" | |||
#endif | |||
); | |||
#if !defined _XBOX | |||
#if !defined _XBOX && !defined USE_D3D9 | |||
m_coord = m_shader->GetAttribLocation("in_Vertex"); | |||
m_color = m_shader->GetAttribLocation("in_Color"); | |||
#endif | |||
m_mvp = m_shader->GetUniformLocation("in_Matrix"); | |||
m_ready = true; | |||
#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX | |||
#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined _XBOX && !defined USE_D3D9 | |||
/* Method 1: store vertex buffer on the GPU memory */ | |||
glGenBuffers(1, &m_vbo); | |||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||
@@ -147,8 +159,7 @@ public: | |||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | |||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_indices), m_indices, | |||
GL_STATIC_DRAW); | |||
#elif defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#elif defined _XBOX || defined USE_D3D9 | |||
D3DVERTEXELEMENT9 const elements[] = | |||
{ | |||
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, | |||
@@ -191,8 +202,7 @@ public: | |||
m_shader->Bind(); | |||
m_shader->SetUniform(m_mvp, m_matrix); | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
#if defined _XBOX || defined USE_D3D9 | |||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | |||
g_d3ddevice->SetVertexDeclaration(m_vdecl); | |||
g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*m_vertices)); | |||
@@ -232,7 +242,11 @@ private: | |||
vec3 m_colors[8]; | |||
i16vec3 m_indices[12]; | |||
Shader *m_shader; | |||
#if defined _XBOX | |||
#if defined USE_D3D9 | |||
IDirect3DVertexDeclaration9 *m_vdecl; | |||
IDirect3DVertexBuffer9 *m_vbo, *m_cbo; | |||
IDirect3DIndexBuffer9 *m_ibo; | |||
#elif defined _XBOX | |||
D3DVertexDeclaration *m_vdecl; | |||
D3DVertexBuffer *m_vbo, *m_cbo; | |||
D3DIndexBuffer *m_ibo; | |||
@@ -10,7 +10,7 @@ | |||
<MultiProcessorCompilation>true</MultiProcessorCompilation> | |||
<FloatingPointModel>Fast</FloatingPointModel> | |||
<AdditionalIncludeDirectories>$(SolutionDir)\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<AdditionalIncludeDirectories Condition="'$(Platform)'=='Win32'">$(GlIncludes);$(SdlIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<AdditionalIncludeDirectories Condition="'$(Platform)'=='Win32'">$(GlIncludes);$(SdlIncludes);$(D3d9Includes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions Condition="'$(Platform)'=='Win32'">WIN32;$(Win32Defines);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions Condition="'$(Platform)'=='Xbox 360'">_XBOX;$(XboxDefines);%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<BufferSecurityCheck Condition="'$(Platform)'=='Xbox 360'">false</BufferSecurityCheck> | |||
@@ -32,8 +32,8 @@ | |||
<Link> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<!-- FIXME: not for the static library! --> | |||
<AdditionalDependencies Condition="'$(Platform)'=='Win32'">kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(SdlDeps);$(GdiDeps);$(GlDeps);%(AdditionalDependencies)</AdditionalDependencies> | |||
<AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32'">$(SdlLibs);$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
<AdditionalDependencies Condition="'$(Platform)'=='Win32'">kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(SdlDeps);$(GdiDeps);$(GlDeps);$(D3d9Deps);%(AdditionalDependencies)</AdditionalDependencies> | |||
<AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32'">$(SdlLibs);$(GlLibs);$(D3d9Libs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Xbox 360'">xapilibd.lib;d3d9d.lib;d3dx9d.lib;xgraphicsd.lib;xboxkrnl.lib;xnetd.lib;xaudiod2.lib;xactd3.lib;x3daudiod.lib;xmcored.lib;xbdm.lib;vcompd.lib;%(AdditionalDependencies)</AdditionalDependencies> | |||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Xbox 360'">xapilib.lib;d3d9.lib;d3dx9.lib;xgraphics.lib;xboxkrnl.lib;xnet.lib;xaudio2.lib;xact3.lib;x3daudio.lib;xmcore.lib;vcomp.lib;%(AdditionalDependencies)</AdditionalDependencies> | |||
</Link> | |||
@@ -3,45 +3,64 @@ | |||
<ImportGroup Label="PropertySheets" /> | |||
<PropertyGroup Label="UserMacros"> | |||
<ContribDir>$(SolutionDir)\..\contrib</ContribDir> | |||
<GlewDir>$(ContribDir)\glew-1.7.0</GlewDir> | |||
<GtkDir>$(ContribDir)\gtk-2.22.1</GtkDir> | |||
<GtkGlDir>$(ContribDir)\gtkglarea-2.0.1</GtkGlDir> | |||
<!-- SDL --> | |||
<SdlDir>$(ContribDir)\sdl-1.2.14</SdlDir> | |||
<SdlImageDir>$(ContribDir)\sdl-image-1.2.10</SdlImageDir> | |||
<SdlMixerDir>$(ContribDir)\sdl-mixer-1.2.11</SdlMixerDir> | |||
<GlIncludes>$(GlewDir)\include\GL</GlIncludes> | |||
<GtkIncludes>$(GtkDir)\lib\glib-2.0\include;$(GtkDir)\lib\gtk-2.0\include;$(GtkDir)\include\glib-2.0;$(GtkDir)\include\gtk-2.0;$(GtkDir)\include\cairo;$(GtkDir)\include\pango-1.0;$(GtkDir)\include\gdk-pixbuf-2.0;$(GtkDir)\include\atk-1.0;$(GtkGlDir)\include</GtkIncludes> | |||
<SdlIncludes>$(SdlDir)\include;$(SdlImageDir)\include;$(SdlMixerDir)\include</SdlIncludes> | |||
<GlLibs>$(GlewDir)\lib\i686-w64-mingw32</GlLibs> | |||
<GtkLibs>$(GtkDir)\lib;$(GtkDir)\bin;$(GtkGlDir)\lib</GtkLibs> | |||
<SdlLibs>$(SdlDir)\lib\i686-w64-mingw32;$(SdlImageDir)\lib\i686-w64-mingw32;$(SdlMixerDir)\lib\i686-w64-mingw32</SdlLibs> | |||
<SdlDeps>SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib</SdlDeps> | |||
<!-- GTK+ & GtkGl --> | |||
<GtkDir>$(ContribDir)\gtk-2.22.1</GtkDir> | |||
<GtkGlDir>$(ContribDir)\gtkglarea-2.0.1</GtkGlDir> | |||
<GtkIncludes>$(GtkDir)\lib\glib-2.0\include;$(GtkDir)\lib\gtk-2.0\include;$(GtkDir)\include\glib-2.0;$(GtkDir)\include\gtk-2.0;$(GtkDir)\include\cairo;$(GtkDir)\include\pango-1.0;$(GtkDir)\include\gdk-pixbuf-2.0;$(GtkDir)\include\atk-1.0;$(GtkGlDir)\include</GtkIncludes> | |||
<GtkLibs>$(GtkDir)\lib;$(GtkDir)\bin;$(GtkGlDir)\lib</GtkLibs> | |||
<GtkDeps>gobject-2.0.lib;gthread-2.0.lib;glib-2.0.lib;gdk-win32-2.0.lib;gtk-win32-2.0.lib;gtkgl-2.0.lib</GtkDeps> | |||
<!-- GDI+ --> | |||
<GdiDeps>Gdiplus.lib</GdiDeps> | |||
<!-- OpenGL & GLEW --> | |||
<GlewDir>$(ContribDir)\glew-1.7.0</GlewDir> | |||
<GlIncludes>$(GlewDir)\include\GL</GlIncludes> | |||
<GlLibs>$(GlewDir)\lib\i686-w64-mingw32</GlLibs> | |||
<GlDeps>opengl32.lib;glew32.lib</GlDeps> | |||
<GtkDeps>gobject-2.0.lib;gthread-2.0.lib;glib-2.0.lib;gdk-win32-2.0.lib;gtk-win32-2.0.lib;gtkgl-2.0.lib</GtkDeps> | |||
<SdlDeps>SDL.lib;SDLmain.lib;SDL_image.lib;SDL_mixer.lib</SdlDeps> | |||
<Win32Defines>USE_GLEW;GLEW_STATIC;HAVE_SDL_H;USE_SDL;USE_GDIPLUS</Win32Defines> | |||
<!-- Direct3D 9 --> | |||
<D3d9Includes>$(DXSDK_DIR)\Include</D3d9Includes> | |||
<D3d9Libs Condition="'$(Platform)'=='Win32'">$(DXSDK_DIR)\Lib\x86</D3d9Libs> | |||
<D3d9Libs Condition="'$(Platform)'=='Win64'">$(DXSDK_DIR)\Lib\x64</D3d9Libs> | |||
<D3d9Deps Condition="'$(Configuration)'=='Release'">d3d9.lib;d3dx9.lib</D3d9Deps> | |||
<D3d9Deps Condition="'$(Configuration)'=='Debug'">d3d9.lib;d3dx9d.lib</D3d9Deps> | |||
<Win32Defines>HAVE_SDL_H;USE_SDL;USE_GDIPLUS;USE_D3D9</Win32Defines> | |||
<XboxDefines></XboxDefines> | |||
</PropertyGroup> | |||
<PropertyGroup /> | |||
<ItemDefinitionGroup /> | |||
<ItemGroup> | |||
<BuildMacro Include="ContribDir"><Value>$(ContribDir)</Value></BuildMacro> | |||
<BuildMacro Include="GlewDir"><Value>$(GlewDir)</Value></BuildMacro> | |||
<BuildMacro Include="GtkDir"><Value>$(GtkDir)</Value></BuildMacro> | |||
<BuildMacro Include="GtkGlDir"><Value>$(GtkGlDir)</Value></BuildMacro> | |||
<BuildMacro Include="SdlDir"><Value>$(SdlDir)</Value></BuildMacro> | |||
<BuildMacro Include="SdlImageDir"><Value>$(SdlImageDir)</Value></BuildMacro> | |||
<BuildMacro Include="SdlMixerDir"><Value>$(SdlMixerDir)</Value></BuildMacro> | |||
<BuildMacro Include="GlIncludes"><Value>$(GlIncludes)</Value></BuildMacro> | |||
<BuildMacro Include="GtkIncludes"><Value>$(GtkIncludes)</Value></BuildMacro> | |||
<BuildMacro Include="SdlIncludes"><Value>$(SdlIncludes)</Value></BuildMacro> | |||
<BuildMacro Include="GlLibs"><Value>$(GlLibs)</Value></BuildMacro> | |||
<BuildMacro Include="GtkLibs"><Value>$(GtkLibs)</Value></BuildMacro> | |||
<BuildMacro Include="SdlLibs"><Value>$(SdlLibs)</Value></BuildMacro> | |||
<BuildMacro Include="SdlDeps"><Value>$(SdlDeps)</Value></BuildMacro> | |||
<BuildMacro Include="GtkDir"><Value>$(GtkDir)</Value></BuildMacro> | |||
<BuildMacro Include="GtkGlDir"><Value>$(GtkGlDir)</Value></BuildMacro> | |||
<BuildMacro Include="GtkIncludes"><Value>$(GtkIncludes)</Value></BuildMacro> | |||
<BuildMacro Include="GtkLibs"><Value>$(GtkLibs)</Value></BuildMacro> | |||
<BuildMacro Include="GtkDeps"><Value>$(GtkDeps)</Value></BuildMacro> | |||
<BuildMacro Include="GdiDeps"><Value>$(GdiDeps)</Value></BuildMacro> | |||
<BuildMacro Include="GlewDir"><Value>$(GlewDir)</Value></BuildMacro> | |||
<BuildMacro Include="GlIncludes"><Value>$(GlIncludes)</Value></BuildMacro> | |||
<BuildMacro Include="GlLibs"><Value>$(GlLibs)</Value></BuildMacro> | |||
<BuildMacro Include="GlDeps"><Value>$(GlDeps)</Value></BuildMacro> | |||
<BuildMacro Include="GtkDeps"><Value>$(GtkDeps)</Value></BuildMacro> | |||
<BuildMacro Include="SdlDeps"><Value>$(SdlDeps)</Value></BuildMacro> | |||
<BuildMacro Include="D3d9Includes"><Value>$(D3d9Includes)</Value></BuildMacro> | |||
<BuildMacro Include="D3d9Libs"><Value>$(D3d9Libs)</Value></BuildMacro> | |||
<BuildMacro Include="D3d9Deps"><Value>$(D3d9Deps)</Value></BuildMacro> | |||
<BuildMacro Include="Win32Defines"><Value>$(Win32Defines)</Value></BuildMacro> | |||
<BuildMacro Include="XboxDefines"><Value>$(XboxDefines)</Value></BuildMacro> | |||
</ItemGroup> | |||