@@ -59,11 +59,19 @@ private: | |||
int ntiles; | |||
float angle; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
#if defined HAVE_GL_2X && !defined __APPLE__ | |||
GLuint vao; | |||
#endif | |||
GLuint *bufs; | |||
int nbufs; | |||
#endif | |||
static Scene *scene; | |||
}; | |||
@@ -81,8 +89,16 @@ Scene::Scene(float angle) | |||
data->ntiles = 0; | |||
data->angle = angle; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Scene() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
data->bufs = 0; | |||
data->nbufs = 0; | |||
#endif | |||
#if defined HAVE_GL_2X && !defined __APPLE__ | |||
glGenVertexArrays(1, &data->vao); | |||
@@ -91,6 +107,13 @@ Scene::Scene(float angle) | |||
Scene::~Scene() | |||
{ | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::~Scene() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
/* FIXME: this must be done while the GL context is still active. | |||
* Change the code architecture to make sure of that. */ | |||
/* XXX: The test is necessary because of a crash with PSGL. */ | |||
@@ -100,6 +123,7 @@ Scene::~Scene() | |||
glDeleteVertexArrays(1, &data->vao); | |||
#endif | |||
free(data->bufs); | |||
#endif | |||
delete data; | |||
} | |||
@@ -135,7 +159,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
{ | |||
if (!stdshader) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if !defined _XBOX && !defined __CELLOS_LV2__ | |||
stdshader = Shader::Create( | |||
#if !defined HAVE_GLES_2X | |||
"#version 130\n" | |||
@@ -299,7 +323,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
data->model_matrix *= mat4::translate(-320.0f, -240.0f, 0.0f); | |||
// XXX: end of debug stuff | |||
GLuint uni_mat, uni_tex, attr_pos, attr_tex; | |||
int uni_mat, uni_tex, attr_pos, attr_tex; | |||
#if !defined __CELLOS_LV2__ | |||
attr_pos = stdshader->GetAttribLocation("in_Position"); | |||
attr_tex = stdshader->GetAttribLocation("in_TexCoord"); | |||
@@ -314,7 +338,13 @@ void Scene::Render() // XXX: rename to Blit() | |||
uni_mat = stdshader->GetUniformLocation("model_matrix"); | |||
stdshader->SetUniform(uni_mat, data->model_matrix); | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#elif !defined __CELLOS_LV2__ | |||
uni_tex = stdshader->GetUniformLocation("in_Texture"); | |||
glUniform1i(uni_tex, 0); | |||
#else | |||
@@ -323,6 +353,13 @@ void Scene::Render() // XXX: rename to Blit() | |||
//cgGLSetParameter1i((CGparameter)(intptr_t)uni_tex, 0); | |||
#endif | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
#if !defined HAVE_GLES_2X | |||
glEnable(GL_TEXTURE_2D); | |||
#endif | |||
@@ -334,16 +371,25 @@ void Scene::Render() // XXX: rename to Blit() | |||
#endif | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
#endif | |||
for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2) | |||
{ | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
/* Generate new vertex / texture coord buffers if necessary */ | |||
if (buf + 2 > data->nbufs) | |||
{ | |||
data->bufs = (GLuint *)realloc(data->bufs, (buf + 2) * sizeof(GLuint)); | |||
data->bufs = (uint32_t *)realloc(data->bufs, (buf + 2) * sizeof(uint32_t)); | |||
glGenBuffers(buf + 2 - data->nbufs, data->bufs + data->nbufs); | |||
data->nbufs = buf + 2; | |||
} | |||
#endif | |||
/* Count how many quads will be needed */ | |||
for (n = i + 1; n < data->ntiles; n++) | |||
@@ -370,6 +416,13 @@ void Scene::Render() // XXX: rename to Blit() | |||
#if defined HAVE_GL_2X && !defined __APPLE__ | |||
glBindVertexArray(data->vao); | |||
#endif | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
#if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. | |||
glEnableVertexAttribArray(attr_pos); | |||
glEnableVertexAttribArray(attr_tex); | |||
@@ -403,6 +456,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
#else | |||
glDisableClientState(GL_VERTEX_ARRAY); | |||
glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||
#endif | |||
#endif | |||
free(vertex); | |||
@@ -413,6 +467,13 @@ void Scene::Render() // XXX: rename to Blit() | |||
data->tiles = 0; | |||
data->ntiles = 0; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene::Render() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
#if !defined HAVE_GLES_2X | |||
glDisable(GL_TEXTURE_2D); | |||
#endif | |||
@@ -421,6 +482,7 @@ void Scene::Render() // XXX: rename to Blit() | |||
glDisable(GL_ALPHA_TEST); | |||
#endif | |||
glDisable(GL_BLEND); | |||
#endif | |||
} | |||
} /* namespace lol */ | |||
@@ -39,7 +39,9 @@ class ShaderData | |||
private: | |||
#if defined _XBOX | |||
D3DVertexShader *vert_shader; | |||
D3DPixelShader *frag_shader; | |||
ID3DXConstantTable *vert_table, *frag_table; | |||
#elif !defined __CELLOS_LV2__ | |||
GLuint prog_id, vert_id, frag_id; | |||
#else | |||
@@ -90,7 +92,11 @@ void Shader::Destroy(Shader *shader) | |||
Shader::Shader(char const *vert, char const *frag) | |||
: data(new ShaderData()) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
ID3DXBuffer *shader_code, *error_msg; | |||
HRESULT hr; | |||
#elif !defined __CELLOS_LV2__ | |||
char buf[4096], errbuf[4096]; | |||
char const *shader = buf; | |||
GLint status; | |||
@@ -103,7 +109,20 @@ Shader::Shader(char const *vert, char const *frag) | |||
/* Compile vertex shader */ | |||
data->vert_crc = Hash::Crc32(vert); | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
hr = D3DXCompileShader(vert, (UINT)strlen(vert), NULL, NULL, "main", | |||
"vs_2_0", 0, &shader_code, &error_msg, | |||
&data->vert_table); | |||
if (FAILED(hr)) | |||
{ | |||
Log::Error("failed to compile vertex shader: %s", | |||
error_msg ? error_msg->GetBufferPointer() : "error"); | |||
Log::Error("shader source:\n%s\n", vert); | |||
} | |||
g_d3ddevice->CreateVertexShader((DWORD *)shader_code->GetBufferPointer(), | |||
&data->vert_shader); | |||
shader_code->Release(); | |||
#elif !defined __CELLOS_LV2__ | |||
ShaderData::Patch(buf, vert, NULL); | |||
data->vert_id = glCreateShader(GL_VERTEX_SHADER); | |||
glShaderSource(data->vert_id, 1, &shader, NULL); | |||
@@ -129,7 +148,20 @@ Shader::Shader(char const *vert, char const *frag) | |||
/* Compile fragment shader */ | |||
data->frag_crc = Hash::Crc32(frag); | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
hr = D3DXCompileShader(frag, (UINT)strlen(frag), NULL, NULL, "main", | |||
"vs_2_0", 0, &shader_code, &error_msg, | |||
&data->frag_table); | |||
if (FAILED(hr)) | |||
{ | |||
Log::Error("failed to compile fragment shader: %s", | |||
error_msg ? error_msg->GetBufferPointer() : "error"); | |||
Log::Error("shader source:\n%s\n", frag); | |||
} | |||
g_d3ddevice->CreatePixelShader((DWORD *)shader_code->GetBufferPointer(), | |||
&data->frag_shader); | |||
shader_code->Release(); | |||
#elif !defined __CELLOS_LV2__ | |||
ShaderData::Patch(buf, NULL, frag); | |||
data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | |||
glShaderSource(data->frag_id, 1, &shader, NULL); | |||
@@ -153,7 +185,7 @@ Shader::Shader(char const *vert, char const *frag) | |||
} | |||
#endif | |||
#if !defined __CELLOS_LV2__ | |||
#if !defined _XBOX && !defined __CELLOS_LV2__ | |||
/* Create program */ | |||
data->prog_id = glCreateProgram(); | |||
glAttachShader(data->prog_id, data->vert_id); | |||
@@ -166,7 +198,15 @@ Shader::Shader(char const *vert, char const *frag) | |||
int Shader::GetAttribLocation(char const *attr) const | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
D3DXHANDLE hr = data->frag_table->GetConstantByName(NULL, attr); | |||
if (FAILED(hr)) | |||
return -1; | |||
UINT count; | |||
D3DXCONSTANT_DESC desc; | |||
data->frag_table->GetConstantDesc(hr, &desc, &count); | |||
return desc.RegisterIndex; | |||
#elif !defined __CELLOS_LV2__ | |||
return glGetAttribLocation(data->prog_id, attr); | |||
#else | |||
/* FIXME: need to differentiate between vertex and fragment program */ | |||
@@ -176,7 +216,15 @@ int Shader::GetAttribLocation(char const *attr) const | |||
int Shader::GetUniformLocation(char const *uni) const | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
D3DXHANDLE hr = data->frag_table->GetConstantByName(NULL, uni); | |||
if (FAILED(hr)) | |||
return -1; | |||
UINT count; | |||
D3DXCONSTANT_DESC desc; | |||
data->frag_table->GetConstantDesc(hr, &desc, &count); | |||
return desc.RegisterIndex; | |||
#elif !defined __CELLOS_LV2__ | |||
return glGetUniformLocation(data->prog_id, uni); | |||
#else | |||
/* FIXME: need to differentiate between vertex and fragment program, | |||
@@ -190,7 +238,11 @@ int Shader::GetUniformLocation(char const *uni) const | |||
void Shader::SetUniform(int uni, float f) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
vec4 tmp(f, 0.0f, 0.0f, 0.0f); | |||
g_d3ddevice->SetPixelShaderConstantF(uni, &tmp[0], 1); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform1f(uni, f); | |||
#else | |||
cgGLSetParameter1f((CGparameter)(intptr_t)uni, f); | |||
@@ -199,7 +251,11 @@ void Shader::SetUniform(int uni, float f) | |||
void Shader::SetUniform(int uni, vec2 const &v) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
vec4 tmp(v, 0.0f, 0.0f); | |||
g_d3ddevice->SetPixelShaderConstantF(uni, &tmp[0], 1); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform2f(uni, v.x, v.y); | |||
#else | |||
cgGLSetParameter2f((CGparameter)(intptr_t)uni, v.x, v.y); | |||
@@ -208,7 +264,11 @@ void Shader::SetUniform(int uni, vec2 const &v) | |||
void Shader::SetUniform(int uni, vec3 const &v) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
vec4 tmp(v, 0.0f); | |||
g_d3ddevice->SetPixelShaderConstantF(uni, &tmp[0], 1); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform3f(uni, v.x, v.y, v.z); | |||
#else | |||
cgGLSetParameter3f((CGparameter)(intptr_t)uni, v.x, v.y, v.z); | |||
@@ -218,7 +278,10 @@ 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 __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
g_d3ddevice->SetPixelShaderConstantF(uni, &v[0], 1); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniform4f(uni, v.x, v.y, v.z, v.w); | |||
#else | |||
cgGLSetParameter4f((CGparameter)(intptr_t)uni, v.x, v.y, v.z, v.w); | |||
@@ -227,7 +290,10 @@ void Shader::SetUniform(int uni, vec4 const &v) | |||
void Shader::SetUniform(int uni, mat4 const &m) | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
g_d3ddevice->SetPixelShaderConstantF(uni, &m[0][0], 4); | |||
#elif !defined __CELLOS_LV2__ | |||
glUniformMatrix4fv(uni, 1, GL_FALSE, &m[0][0]); | |||
#else | |||
cgGLSetMatrixParameterfc((CGparameter)(intptr_t)uni, &m[0][0]); | |||
@@ -236,7 +302,11 @@ void Shader::SetUniform(int uni, mat4 const &m) | |||
void Shader::Bind() const | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
g_d3ddevice->SetVertexShader(data->vert_shader); | |||
g_d3ddevice->SetPixelShader(data->frag_shader); | |||
#elif !defined __CELLOS_LV2__ | |||
glUseProgram(data->prog_id); | |||
#else | |||
cgGLEnableProfile(cgGLGetLatestProfile(CG_GL_VERTEX)); | |||
@@ -248,7 +318,13 @@ void Shader::Bind() const | |||
Shader::~Shader() | |||
{ | |||
#if !defined __CELLOS_LV2__ | |||
#if defined _XBOX | |||
extern D3DDevice *g_d3ddevice; | |||
data->vert_shader->Release(); | |||
data->vert_table->Release(); | |||
data->frag_shader->Release(); | |||
data->frag_table->Release(); | |||
#elif !defined __CELLOS_LV2__ | |||
glDetachShader(data->prog_id, data->vert_id); | |||
glDetachShader(data->prog_id, data->frag_id); | |||
glDeleteShader(data->vert_id); | |||
@@ -266,7 +342,7 @@ int ShaderData::GetVersion() | |||
{ | |||
static int version = 0; | |||
#if !defined __CELLOS_LV2__ | |||
#if !defined _XBOX && !defined __CELLOS_LV2__ | |||
if (!version) | |||
{ | |||
char buf[4096]; | |||
@@ -45,7 +45,15 @@ private: | |||
float dilate, tx, ty; | |||
Image *img; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
GLuint texture; | |||
#endif | |||
}; | |||
/* | |||
@@ -60,7 +68,15 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count, float dilate) | |||
sprintf(data->name, "<tileset> %s", path); | |||
data->tiles = NULL; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
data->texture = 0; | |||
#endif | |||
data->img = new Image(path); | |||
data->isize = data->img->GetSize(); | |||
@@ -102,11 +118,26 @@ void TileSet::TickDraw(float deltams) | |||
{ | |||
if (data->img) | |||
delete data->img; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
else | |||
glDeleteTextures(1, &data->texture); | |||
#endif | |||
} | |||
else if (data->img) | |||
{ | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
GLuint format; | |||
int planes; | |||
@@ -149,6 +180,7 @@ void TileSet::TickDraw(float deltams) | |||
if (pixels != data->img->GetData()) | |||
free(pixels); | |||
#endif | |||
delete data->img; | |||
data->img = NULL; | |||
} | |||
@@ -171,11 +203,19 @@ ivec2 TileSet::GetSize(int tileid) const | |||
void TileSet::Bind() | |||
{ | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::Bind() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
if (!data->img && data->texture) | |||
{ | |||
glActiveTexture(GL_TEXTURE0); | |||
glBindTexture(GL_TEXTURE_2D, data->texture); | |||
} | |||
#endif | |||
} | |||
void TileSet::BlitTile(uint32_t id, vec3 pos, int o, | |||
@@ -189,6 +229,13 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, | |||
int dy = o ? 0 : data->size.y; | |||
int dz = o ? data->size.y : 0; | |||
#if defined _XBOX | |||
# define STR0(x) #x | |||
# define STR(x) STR0(x) | |||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") | |||
# undef STR | |||
# undef STR0 | |||
#else | |||
if (!data->img && data->texture) | |||
{ | |||
float tmp[10]; | |||
@@ -234,6 +281,7 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, | |||
memset(vertex, 0, 3 * sizeof(float)); | |||
memset(texture, 0, 2 * sizeof(float)); | |||
} | |||
#endif | |||
} | |||
} /* namespace lol */ | |||
@@ -166,10 +166,16 @@ void Video::SetFov(float theta) | |||
void Video::SetDepth(bool set) | |||
{ | |||
#if 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::Clear() | |||
@@ -29,6 +29,7 @@ using namespace lol; | |||
#if defined _WIN32 | |||
# undef main /* FIXME: still needed? */ | |||
# include <direct.h> | |||
#endif | |||
class Triangle : public WorldEntity | |||
@@ -25,6 +25,7 @@ using namespace lol; | |||
#if defined _WIN32 | |||
# undef main /* FIXME: still needed? */ | |||
# include <direct.h> | |||
#endif | |||
class Cube : public WorldEntity | |||