@@ -12,7 +12,7 @@ | |||||
# include "config.h" | # include "config.h" | ||||
#endif | #endif | ||||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||||
#if 0 | |||||
#if defined WIN32 && !_XBOX | #if defined WIN32 && !_XBOX | ||||
# define _USE_MATH_DEFINES /* for M_PI */ | # define _USE_MATH_DEFINES /* for M_PI */ | ||||
@@ -1119,4 +1119,4 @@ void DebugQuad::ResetState() | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
#endif /* !defined _XBOX */ | |||||
#endif /* 0 */ |
@@ -235,13 +235,14 @@ ShaderAttrib Shader::GetAttribLocation(char const *attr, | |||||
VertexUsage usage, int index) const | VertexUsage usage, int index) const | ||||
{ | { | ||||
ShaderAttrib ret; | ShaderAttrib ret; | ||||
ret.m_flags = (uint64_t)(uint16_t)usage << 16; | |||||
ret.m_flags |= (uint64_t)(uint16_t)index; | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
ret.m_flags = (uint32_t)index << 16; | |||||
ret.m_flags |= (uint32_t)usage; | |||||
#elif !defined __CELLOS_LV2__ | #elif !defined __CELLOS_LV2__ | ||||
ret.m_flags = glGetAttribLocation(data->prog_id, attr); | |||||
ret.m_flags |= (uint64_t) | |||||
(uint32_t)glGetAttribLocation(data->prog_id, attr) << 32; | |||||
#else | #else | ||||
/* FIXME: can we do this at all? */ | |||||
/* FIXME: can we do this at all on the PS3? */ | |||||
#endif | #endif | ||||
return ret; | return ret; | ||||
} | } | ||||
@@ -26,7 +26,7 @@ struct ShaderUniform | |||||
friend class Shader; | friend class Shader; | ||||
public: | public: | ||||
ShaderUniform() : flags(0) {} | |||||
inline ShaderUniform() : flags(0) {} | |||||
private: | private: | ||||
uintptr_t frag, vert; | uintptr_t frag, vert; | ||||
@@ -40,10 +40,10 @@ struct ShaderAttrib | |||||
friend class VertexDeclaration; | friend class VertexDeclaration; | ||||
public: | public: | ||||
ShaderAttrib(int flags = 0xffffffff) : m_flags(flags) {} | |||||
inline ShaderAttrib() : m_flags((uint64_t)0 - 1) {} | |||||
private: | private: | ||||
uint32_t m_flags; | |||||
uint64_t m_flags; | |||||
}; | }; | ||||
class ShaderData; | class ShaderData; | ||||
@@ -114,7 +114,19 @@ void VertexDeclaration::Bind() | |||||
g_d3ddevice->SetVertexDeclaration(vdecl); | g_d3ddevice->SetVertexDeclaration(vdecl); | ||||
#else | #else | ||||
/* FIXME: Nothing to do? */ | |||||
#endif | |||||
} | |||||
void VertexDeclaration::Unbind() | |||||
{ | |||||
#if defined _XBOX || defined USE_D3D9 | |||||
/* FIXME: Nothing to do? */ | |||||
#else | |||||
/* FIXME: we need to record what happens */ | |||||
//glDisableVertexAttribArray(m_attrib); | |||||
/* FIXME: only useful for VAOs */ | |||||
//glBindBuffer(GL_ARRAY_BUFFER, 0); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -135,33 +147,97 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, | |||||
/* Only the first item is required to know which stream this | /* Only the first item is required to know which stream this | ||||
* is about; the rest of the information is stored in the | * is about; the rest of the information is stored in the | ||||
* vertex declaration already. */ | * vertex declaration already. */ | ||||
uint32_t usage = attr1.m_flags >> 16; | |||||
uint32_t usage = (attr1.m_flags >> 16) & 0xffff; | |||||
uint32_t index = attr1.m_flags & 0xffff; | uint32_t index = attr1.m_flags & 0xffff; | ||||
int usage_index = 0, stream = -1, stride = 0; | |||||
/* Find the stream number */ | |||||
int usage_index = 0, stream = -1; | |||||
for (int i = 0; i < m_count; i++) | for (int i = 0; i < m_count; i++) | ||||
{ | |||||
if (m_streams[i].usage == usage) | if (m_streams[i].usage == usage) | ||||
if (usage_index++ == index) | if (usage_index++ == index) | ||||
{ | |||||
stream = m_streams[i].index; | stream = m_streams[i].index; | ||||
break; | |||||
} | |||||
/* Compute this stream's stride */ | |||||
int stride = 0; | |||||
for (int i = 0; i < m_count; i++) | |||||
if (stream == m_streams[i].index) | if (stream == m_streams[i].index) | ||||
stride += m_streams[i].size; | stride += m_streams[i].size; | ||||
} | |||||
/* Now we know the stream index and the element stride */ | /* Now we know the stream index and the element stride */ | ||||
/* FIXME: precompute most of the crap above! */ | /* FIXME: precompute most of the crap above! */ | ||||
if (stream >= 0) | if (stream >= 0) | ||||
g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride); | g_d3ddevice->SetStreamSource(stream, vb->m_data->m_vbo, 0, stride); | ||||
#else | #else | ||||
glBindBuffer(GL_ARRAY_BUFFER, vb); | |||||
glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | |||||
ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6, | ShaderAttrib l[12] = { attr1, attr2, attr3, attr4, attr5, attr6, | ||||
attr7, attr8, attr9, attr10, attr11, attr12 }; | attr7, attr8, attr9, attr10, attr11, attr12 }; | ||||
for (int i = 0; i < 12 && l[i].m_flags != 0xffffffff; i++) | |||||
for (int n = 0; n < 12 && l[n].m_flags != (uint64_t)0 - 1; n++) | |||||
{ | { | ||||
uint32_t usage = l[i].m_flags >> 16; | |||||
uint32_t index = l[i].m_flags & 0xffff; | |||||
glEnableVertexAttribArray((GLint)attr.flags); | |||||
/* FIXME: Hardcoded!! Where to get that from? */ | |||||
glVertexAttribPointer((GLint)attr.flags, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||||
uint32_t reg = l[n].m_flags >> 32; | |||||
uint32_t usage = (l[n].m_flags >> 16) & 0xffff; | |||||
uint32_t index = l[n].m_flags & 0xffff; | |||||
glEnableVertexAttribArray((GLint)reg); | |||||
/* We need to parse the whole vertex declaration to retrieve | |||||
* the information. It sucks. */ | |||||
int attr_index = 0, usage_index = 0, stream = -1; | |||||
/* First, find the stream index */ | |||||
for (; attr_index < m_count; attr_index++) | |||||
if (m_streams[attr_index].usage == usage) | |||||
if (usage_index++ == index) | |||||
{ | |||||
stream = m_streams[attr_index].index; | |||||
break; | |||||
} | |||||
/* Now compute the stride and offset up to this stream index */ | |||||
int stride = 0, offset = 0; | |||||
for (int i = 0; i < m_count; i++) | |||||
if (m_streams[i].index == m_streams[attr_index].index) | |||||
{ | |||||
stride += m_streams[i].size; | |||||
if (i < attr_index) | |||||
offset += m_streams[i].size; | |||||
} | |||||
/* Finally, we need to retrieve the type of the data */ | |||||
static struct { GLint size; GLenum type; } const tlut[] = | |||||
{ | |||||
{ 0, 0 }, | |||||
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, /* half */ | |||||
{ 1, GL_FLOAT }, { 2, GL_FLOAT }, { 3, GL_FLOAT }, | |||||
{ 4, GL_FLOAT }, /* float */ | |||||
{ 1, GL_DOUBLE }, { 2, GL_DOUBLE }, { 3, GL_DOUBLE }, | |||||
{ 4, GL_DOUBLE }, /* double */ | |||||
{ 1, GL_BYTE }, { 2, GL_BYTE }, { 3, GL_BYTE }, | |||||
{ 4, GL_BYTE }, /* int8_t */ | |||||
{ 1, GL_UNSIGNED_BYTE }, { 2, GL_UNSIGNED_BYTE }, | |||||
{ 3, GL_UNSIGNED_BYTE }, { 4, GL_UNSIGNED_BYTE }, /* uint8_t */ | |||||
{ 1, GL_SHORT }, { 2, GL_SHORT }, { 3, GL_SHORT }, | |||||
{ 4, GL_SHORT }, /* int16_t */ | |||||
{ 1, GL_UNSIGNED_SHORT }, { 2, GL_UNSIGNED_SHORT }, { 3, | |||||
GL_UNSIGNED_SHORT }, { 4, GL_UNSIGNED_SHORT }, /* uint16_t */ | |||||
{ 1, GL_INT }, { 2, GL_INT }, { 3, GL_INT }, | |||||
{ 4, GL_INT }, /* int32_t */ | |||||
{ 1, GL_UNSIGNED_INT }, { 2, GL_UNSIGNED_INT }, | |||||
{ 3, GL_UNSIGNED_INT }, { 4, GL_UNSIGNED_INT }, /* uint32_t */ | |||||
}; | |||||
int type_index = m_streams[attr_index].stream_type; | |||||
if (type_index < 0 || type_index >= sizeof(tlut) / sizeof(*tlut)) | |||||
type_index = 0; | |||||
Log::Error("Size %d Type %d Stride %d offset %d\n", tlut[type_index].size, | |||||
tlut[type_index].type,stride,offset); | |||||
glVertexAttribPointer((GLint)reg, tlut[type_index].size, | |||||
tlut[type_index].type, GL_FALSE, | |||||
stride, (GLvoid const *)(uintptr_t)offset); | |||||
} | |||||
#endif | #endif | ||||
} | } | ||||
@@ -306,7 +382,7 @@ void VertexBuffer::Unlock() | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
m_data->m_vbo->Unlock(); | m_data->m_vbo->Unlock(); | ||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); | |||||
glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | ||||
GL_STATIC_DRAW); | GL_STATIC_DRAW); | ||||
#endif | #endif | ||||
@@ -164,6 +164,7 @@ public: | |||||
~VertexDeclaration(); | ~VertexDeclaration(); | ||||
void Bind(); | void Bind(); | ||||
void Unbind(); | |||||
void SetStream(VertexBuffer *vb, ShaderAttrib attr1, | void SetStream(VertexBuffer *vb, ShaderAttrib attr1, | ||||
ShaderAttrib attr2 = ShaderAttrib(), | ShaderAttrib attr2 = ShaderAttrib(), | ||||
ShaderAttrib attr3 = ShaderAttrib(), | ShaderAttrib attr3 = ShaderAttrib(), | ||||
@@ -32,13 +32,8 @@ class GradientData | |||||
private: | private: | ||||
Shader *shader; | Shader *shader; | ||||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||||
GLuint bufs[2]; | |||||
#if defined HAVE_GL_2X && !defined __APPLE__ | |||||
GLuint vaos[1]; | |||||
#endif | |||||
#endif | |||||
VertexDeclaration *m_vdecl; | |||||
VertexBuffer *m_vbo, *m_cbo; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -65,10 +60,23 @@ void Gradient::TickDraw(float deltams) | |||||
{ | { | ||||
Entity::TickDraw(deltams); | Entity::TickDraw(deltams); | ||||
#if !defined USE_D3D9 && !defined _XBOX /* This file is meaningless on Xbox */ | |||||
float const vertex[] = { 0.0f, 0.0f, 0.0f, | |||||
640.0f, 0.0f, 0.0f, | |||||
0.0f, 480.0f, 0.0f, | |||||
0.0f, 480.0f, 0.0f, | |||||
640.0f, 480.0f, 0.0f, | |||||
640.0f, 0.0f, 0.0f, }; | |||||
float const color[] = { 0.73f, 0.85f, 0.85f, 1.0f, | |||||
0.73f, 0.85f, 0.85f, 1.0f, | |||||
0.0f, 0.0f, 1.0f, 1.0f, | |||||
0.0f, 0.0f, 1.0f, 1.0f, | |||||
0.0f, 0.0f, 1.0f, 1.0f, | |||||
0.73f, 0.85f, 0.85f, 1.0f, }; | |||||
if (!data->shader) | if (!data->shader) | ||||
{ | { | ||||
#if !defined __CELLOS_LV2__ | |||||
#if !defined __CELLOS_LV2__ && !defined USE_D3D9 && !defined _XBOX | |||||
data->shader = Shader::Create( | data->shader = Shader::Create( | ||||
"#version 130\n" | "#version 130\n" | ||||
"\n" | "\n" | ||||
@@ -156,22 +164,19 @@ void Gradient::TickDraw(float deltams) | |||||
" out_FragColor = col;" | " out_FragColor = col;" | ||||
"}"); | "}"); | ||||
#endif | #endif | ||||
#if !defined __CELLOS_LV2__ | |||||
glGenBuffers(2, data->bufs); | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
glGenVertexArrays(1, data->vaos); | |||||
# endif | |||||
#endif | |||||
data->m_vbo = new VertexBuffer(sizeof(vertex)); | |||||
data->m_cbo = new VertexBuffer(sizeof(color)); | |||||
data->m_vdecl = new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position), | |||||
VertexStream<vec4>(VertexUsage::Color)); | |||||
} | } | ||||
mat4 model_matrix = mat4(1.0f); | mat4 model_matrix = mat4(1.0f); | ||||
ShaderUniform uni_mat; | ShaderUniform uni_mat; | ||||
GLuint attr_pos, attr_col; | |||||
#if !defined __CELLOS_LV2__ | |||||
attr_pos = data->shader->GetAttribLocation("in_Vertex"); | |||||
attr_col = data->shader->GetAttribLocation("in_Color"); | |||||
#endif | |||||
ShaderAttrib attr_pos, attr_col; | |||||
attr_pos = data->shader->GetAttribLocation("in_Vertex", VertexUsage::Position, 0); | |||||
attr_col = data->shader->GetAttribLocation("in_Color", VertexUsage::Color, 0); | |||||
data->shader->Bind(); | data->shader->Bind(); | ||||
@@ -182,61 +187,23 @@ void Gradient::TickDraw(float deltams) | |||||
uni_mat = data->shader->GetUniformLocation("model_matrix"); | uni_mat = data->shader->GetUniformLocation("model_matrix"); | ||||
data->shader->SetUniform(uni_mat, model_matrix); | data->shader->SetUniform(uni_mat, model_matrix); | ||||
float const vertex[] = { 0.0f, 0.0f, 0.0f, | |||||
640.0f, 0.0f, 0.0f, | |||||
0.0f, 480.0f, 0.0f, | |||||
0.0f, 480.0f, 0.0f, | |||||
640.0f, 480.0f, 0.0f, | |||||
640.0f, 0.0f, 0.0f, }; | |||||
float const color[] = { 0.73f, 0.85f, 0.85f, 1.0f, | |||||
0.73f, 0.85f, 0.85f, 1.0f, | |||||
0.0f, 0.0f, 1.0f, 1.0f, | |||||
0.0f, 0.0f, 1.0f, 1.0f, | |||||
0.0f, 0.0f, 1.0f, 1.0f, | |||||
0.73f, 0.85f, 0.85f, 1.0f, }; | |||||
data->shader->Bind(); | data->shader->Bind(); | ||||
data->m_vdecl->Bind(); | |||||
/* Bind vertex, color and texture coordinate buffers */ | |||||
#if !defined __CELLOS_LV2__ | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
glBindVertexArray(data->vaos[0]); | |||||
# endif | |||||
glEnableVertexAttribArray(attr_pos); | |||||
glEnableVertexAttribArray(attr_col); | |||||
glBindBuffer(GL_ARRAY_BUFFER, data->bufs[0]); | |||||
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), | |||||
vertex, GL_DYNAMIC_DRAW); | |||||
glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||||
glBindBuffer(GL_ARRAY_BUFFER, data->bufs[1]); | |||||
glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat), | |||||
color, GL_DYNAMIC_DRAW); | |||||
glVertexAttribPointer(attr_col, 4, GL_FLOAT, GL_FALSE, 0, 0); | |||||
#else | |||||
glEnableClientState(GL_VERTEX_ARRAY); | |||||
glEnableClientState(GL_COLOR_ARRAY); | |||||
void *tmp = data->m_vbo->Lock(0, 0); | |||||
memcpy(tmp, vertex, sizeof(vertex)); | |||||
data->m_vbo->Unlock(); | |||||
glVertexPointer(3, GL_FLOAT, 0, vertex); | |||||
glColorPointer(4, GL_FLOAT, 0, color); | |||||
#endif | |||||
tmp = data->m_cbo->Lock(0, 0); | |||||
memcpy(tmp, color, sizeof(color)); | |||||
data->m_cbo->Unlock(); | |||||
/* Bind vertex and color buffers */ | |||||
data->m_vdecl->SetStream(data->m_vbo, attr_pos); | |||||
data->m_vdecl->SetStream(data->m_cbo, attr_col); | |||||
/* Draw arrays */ | /* Draw arrays */ | ||||
glDrawArrays(GL_TRIANGLES, 0, 6); | glDrawArrays(GL_TRIANGLES, 0, 6); | ||||
#if !defined __CELLOS_LV2__ | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
glBindVertexArray(0); | |||||
# endif | |||||
glDisableVertexAttribArray(attr_pos); | |||||
glDisableVertexAttribArray(attr_col); | |||||
#else | |||||
glDisableClientState(GL_VERTEX_ARRAY); | |||||
glDisableClientState(GL_COLOR_ARRAY); | |||||
#endif | |||||
#endif | |||||
} | } | ||||
Gradient::~Gradient() | Gradient::~Gradient() | ||||
@@ -71,18 +71,8 @@ private: | |||||
int ntiles; | int ntiles; | ||||
float angle; | float angle; | ||||
#if defined USE_D3D9 | |||||
IDirect3DVertexDeclaration9 *m_vdecl; | |||||
IDirect3DVertexBuffer9 **bufs; | |||||
#elif defined _XBOX | |||||
D3DVertexDeclaration *m_vdecl; | |||||
D3DVertexBuffer **bufs; | |||||
#else | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
GLuint vao; | |||||
# endif | |||||
GLuint *bufs; | |||||
#endif | |||||
VertexDeclaration *m_vdecl; | |||||
VertexBuffer **bufs; | |||||
int nbufs; | int nbufs; | ||||
static Scene *scene; | static Scene *scene; | ||||
@@ -104,19 +94,8 @@ Scene::Scene(float angle) | |||||
data->bufs = 0; | data->bufs = 0; | ||||
data->nbufs = 0; | data->nbufs = 0; | ||||
#if defined _XBOX || defined USE_D3D9 | |||||
D3DVERTEXELEMENT9 const elements[] = | |||||
{ | |||||
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, | |||||
{ 1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, | |||||
D3DDECL_END() | |||||
}; | |||||
g_d3ddevice->CreateVertexDeclaration(elements, &data->m_vdecl); | |||||
#else | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
glGenVertexArrays(1, &data->vao); | |||||
# endif | |||||
#endif | |||||
data->m_vdecl = new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position), | |||||
VertexStream<vec2>(VertexUsage::TexCoord)); | |||||
} | } | ||||
Scene::~Scene() | Scene::~Scene() | ||||
@@ -127,11 +106,8 @@ Scene::~Scene() | |||||
/* FIXME: this must be done while the GL context is still active. | /* FIXME: this must be done while the GL context is still active. | ||||
* Change the code architecture to make sure of that. */ | * Change the code architecture to make sure of that. */ | ||||
/* XXX: The test is necessary because of a crash with PSGL. */ | /* XXX: The test is necessary because of a crash with PSGL. */ | ||||
if (data->nbufs > 0) | |||||
glDeleteBuffers(data->nbufs, data->bufs); | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
glDeleteVertexArrays(1, &data->vao); | |||||
# endif | |||||
for (int i = 0; i < data->nbufs; i++) | |||||
delete data->bufs[i]; | |||||
free(data->bufs); | free(data->bufs); | ||||
#endif | #endif | ||||
delete data; | delete data; | ||||
@@ -337,13 +313,9 @@ void Scene::Render() // XXX: rename to Blit() | |||||
// XXX: end of debug stuff | // XXX: end of debug stuff | ||||
ShaderUniform uni_mat, uni_tex; | ShaderUniform uni_mat, uni_tex; | ||||
#if defined USE_D3D9 || defined _XBOX | |||||
/* Nothing? */ | |||||
#elif !defined __CELLOS_LV2__ | |||||
int attr_pos, attr_tex; | |||||
attr_pos = stdshader->GetAttribLocation("in_Position"); | |||||
attr_tex = stdshader->GetAttribLocation("in_TexCoord"); | |||||
#endif | |||||
ShaderAttrib attr_pos, attr_tex; | |||||
attr_pos = stdshader->GetAttribLocation("in_Position", VertexUsage::Position, 0); | |||||
attr_tex = stdshader->GetAttribLocation("in_TexCoord", VertexUsage::TexCoord, 0); | |||||
stdshader->Bind(); | stdshader->Bind(); | ||||
@@ -354,10 +326,10 @@ void Scene::Render() // XXX: rename to Blit() | |||||
uni_mat = stdshader->GetUniformLocation("model_matrix"); | uni_mat = stdshader->GetUniformLocation("model_matrix"); | ||||
stdshader->SetUniform(uni_mat, data->model_matrix); | stdshader->SetUniform(uni_mat, data->model_matrix); | ||||
data->m_vdecl->Bind(); | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
//g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | //g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | ||||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | ||||
g_d3ddevice->SetVertexDeclaration(data->m_vdecl); | |||||
#else | #else | ||||
uni_tex = stdshader->GetUniformLocation("in_Texture"); | uni_tex = stdshader->GetUniformLocation("in_Texture"); | ||||
stdshader->SetUniform(uni_tex, 0); | stdshader->SetUniform(uni_tex, 0); | ||||
@@ -380,23 +352,14 @@ void Scene::Render() // XXX: rename to Blit() | |||||
/* Generate new vertex / texture coord buffers if necessary */ | /* Generate new vertex / texture coord buffers if necessary */ | ||||
if (buf + 2 > data->nbufs) | if (buf + 2 > data->nbufs) | ||||
{ | { | ||||
#if defined USE_D3D9 | |||||
data->bufs = (IDirect3DVertexBuffer9 **)realloc(data->bufs, (buf + 2) * sizeof(IDirect3DVertexBuffer9 *)); | |||||
#elif defined _XBOX | |||||
data->bufs = (D3DVertexBuffer **)realloc(data->bufs, (buf + 2) * sizeof(D3DVertexBuffer *)); | |||||
#else | |||||
data->bufs = (uint32_t *)realloc(data->bufs, (buf + 2) * sizeof(uint32_t)); | |||||
glGenBuffers(buf + 2 - data->nbufs, data->bufs + data->nbufs); | |||||
#endif | |||||
data->bufs = (VertexBuffer **)realloc(data->bufs, (buf + 2) * sizeof(VertexBuffer *)); | |||||
data->nbufs = buf + 2; | data->nbufs = buf + 2; | ||||
} | } | ||||
#if defined USE_D3D9 || defined _XBOX | |||||
else | else | ||||
{ | { | ||||
data->bufs[buf]->Release(); | |||||
data->bufs[buf + 1]->Release(); | |||||
delete data->bufs[buf]; | |||||
delete data->bufs[buf + 1]; | |||||
} | } | ||||
#endif | |||||
/* Count how many quads will be needed */ | /* Count how many quads will be needed */ | ||||
for (n = i + 1; n < data->ntiles; n++) | for (n = i + 1; n < data->ntiles; n++) | ||||
@@ -404,20 +367,10 @@ void Scene::Render() // XXX: rename to Blit() | |||||
break; | break; | ||||
/* Create a vertex array object */ | /* Create a vertex array object */ | ||||
float *vertex, *texture; | |||||
#if defined USE_D3D9 || defined _XBOX | |||||
if (FAILED(g_d3ddevice->CreateVertexBuffer(6 * 3 * (n - i) * sizeof(float), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &data->bufs[buf], NULL))) | |||||
exit(0); | |||||
if (FAILED(data->bufs[buf]->Lock(0, 0, (void **)&vertex, 0))) | |||||
exit(0); | |||||
if (FAILED(g_d3ddevice->CreateVertexBuffer(6 * 2 * (n - i) * sizeof(float), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &data->bufs[buf + 1], NULL))) | |||||
exit(0); | |||||
if (FAILED(data->bufs[buf + 1]->Lock(0, 0, (void **)&texture, 0))) | |||||
exit(0); | |||||
#else | |||||
vertex = (float *)malloc(6 * 3 * (n - i) * sizeof(float)); | |||||
texture = (float *)malloc(6 * 2 * (n - i) * sizeof(float)); | |||||
#endif | |||||
data->bufs[buf] = new VertexBuffer(6 * 3 * (n - i) * sizeof(float)); | |||||
float *vertex = (float *)data->bufs[buf]->Lock(0, 0); | |||||
data->bufs[buf + 1] = new VertexBuffer(6 * 2 * (n - i) * sizeof(float)); | |||||
float *texture = (float *)data->bufs[buf + 1]->Lock(0, 0); | |||||
for (int j = i; j < n; j++) | for (int j = i; j < n; j++) | ||||
{ | { | ||||
@@ -427,62 +380,29 @@ void Scene::Render() // XXX: rename to Blit() | |||||
vertex + 18 * (j - i), texture + 12 * (j - i)); | vertex + 18 * (j - i), texture + 12 * (j - i)); | ||||
} | } | ||||
#if defined USE_D3D9 || defined _XBOX | |||||
data->bufs[buf]->Unlock(); | |||||
data->bufs[buf + 1]->Unlock(); | |||||
#endif | |||||
stdshader->Bind(); | stdshader->Bind(); | ||||
/* Bind texture */ | /* Bind texture */ | ||||
data->tiles[i].tileset->Bind(); | data->tiles[i].tileset->Bind(); | ||||
/* Bind vertex, color and texture coordinate buffers */ | |||||
/* Bind vertex and texture coordinate buffers */ | |||||
data->m_vdecl->SetStream(data->bufs[buf], attr_pos); | |||||
data->m_vdecl->SetStream(data->bufs[buf + 1], attr_tex); | |||||
/* Draw arrays */ | |||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
g_d3ddevice->SetStreamSource(0, data->bufs[data->nbufs - 2], 0, 6 * 3 * (n - i) * sizeof(float)); | |||||
g_d3ddevice->SetStreamSource(1, data->bufs[data->nbufs - 1], 0, 6 * 2 * (n - i) * sizeof(float)); | |||||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (n - i) * 6); | g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (n - i) * 6); | ||||
#else | #else | ||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
glBindVertexArray(data->vao); | |||||
# endif | |||||
# if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. | |||||
glEnableVertexAttribArray(attr_pos); | |||||
glEnableVertexAttribArray(attr_tex); | |||||
glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf]); | |||||
glBufferData(GL_ARRAY_BUFFER, 18 * (n - i) * sizeof(GLfloat), | |||||
vertex, GL_STATIC_DRAW); | |||||
glVertexAttribPointer(attr_pos, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||||
glBindBuffer(GL_ARRAY_BUFFER, data->bufs[buf + 1]); | |||||
glBufferData(GL_ARRAY_BUFFER, 12 * (n - i) * sizeof(GLfloat), | |||||
texture, GL_STATIC_DRAW); | |||||
glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); | |||||
# else | |||||
glEnableClientState(GL_VERTEX_ARRAY); | |||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY); | |||||
glVertexPointer(3, GL_FLOAT, 0, vertex); | |||||
glTexCoordPointer(2, GL_FLOAT, 0, texture); | |||||
# endif | |||||
/* Draw arrays */ | |||||
glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); | glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); | ||||
# if defined HAVE_GL_2X && !defined __APPLE__ | # if defined HAVE_GL_2X && !defined __APPLE__ | ||||
glBindVertexArray(0); | glBindVertexArray(0); | ||||
# endif | # endif | ||||
# if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. | # if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. | ||||
glDisableVertexAttribArray(attr_pos); | |||||
glDisableVertexAttribArray(attr_tex); | |||||
# else | # else | ||||
glDisableClientState(GL_VERTEX_ARRAY); | glDisableClientState(GL_VERTEX_ARRAY); | ||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY); | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||||
# endif | # endif | ||||
free(vertex); | |||||
free(texture); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -33,7 +33,7 @@ int main(int argc, char **argv) | |||||
/* Register some debug stuff */ | /* Register some debug stuff */ | ||||
new DebugFps(5, 5); | new DebugFps(5, 5); | ||||
new DebugQuad(); | |||||
//new DebugQuad(); | |||||
app.Run(); | app.Run(); | ||||
@@ -126,11 +126,12 @@ public: | |||||
glDrawArrays(GL_TRIANGLES, 0, 3); | glDrawArrays(GL_TRIANGLES, 0, 3); | ||||
#endif | #endif | ||||
m_vdecl->Unbind(); | |||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
/* FIXME: do we need to unset anything here? */ | /* FIXME: do we need to unset anything here? */ | ||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | ||||
glDisableVertexAttribArray(m_attrib); | |||||
glBindBuffer(GL_ARRAY_BUFFER, 0); | |||||
//glDisableVertexAttribArray(m_attrib); | |||||
//glBindBuffer(GL_ARRAY_BUFFER, 0); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | ||||
/* Never used for now */ | /* Never used for now */ | ||||
glDisableVertexAttribArray(m_attrib); | glDisableVertexAttribArray(m_attrib); | ||||
@@ -191,14 +191,6 @@ public: | |||||
g_d3ddevice->SetIndices(m_ibo); | g_d3ddevice->SetIndices(m_ibo); | ||||
g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices)); | g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices)); | ||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | ||||
glEnableVertexAttribArray(m_coord); | |||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||||
glVertexAttribPointer(m_coord, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||||
glEnableVertexAttribArray(m_color); | |||||
glBindBuffer(GL_ARRAY_BUFFER, m_cbo); | |||||
glVertexAttribPointer(m_color, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | ||||
int size; | int size; | ||||
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); | glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); | ||||
@@ -206,8 +198,6 @@ public: | |||||
glDrawElements(GL_TRIANGLES, size / sizeof(uint16_t), GL_UNSIGNED_SHORT, 0); | glDrawElements(GL_TRIANGLES, size / sizeof(uint16_t), GL_UNSIGNED_SHORT, 0); | ||||
glDisableVertexAttribArray(m_coord); | |||||
glDisableVertexAttribArray(m_color); | |||||
glBindBuffer(GL_ARRAY_BUFFER, 0); | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
#else | #else | ||||
glEnableClientState(GL_VERTEX_ARRAY); | glEnableClientState(GL_VERTEX_ARRAY); | ||||
@@ -427,6 +427,7 @@ public: | |||||
virtual void TickDraw(float deltams) | virtual void TickDraw(float deltams) | ||||
{ | { | ||||
Log::Error("Tick Fractal\n"); | |||||
WorldEntity::TickDraw(deltams); | WorldEntity::TickDraw(deltams); | ||||
static float const vertices[] = | static float const vertices[] = | ||||
@@ -666,50 +667,28 @@ public: | |||||
"}" | "}" | ||||
#endif | #endif | ||||
); | ); | ||||
#if !defined _XBOX && !defined USE_D3D9 | |||||
m_vertexattrib = m_shader->GetAttribLocation("a_Vertex"); | |||||
m_texattrib = m_shader->GetAttribLocation("a_TexCoord"); | |||||
#endif | |||||
m_vertexattrib = m_shader->GetAttribLocation("a_Vertex", VertexUsage::Position, 0); | |||||
m_texattrib = m_shader->GetAttribLocation("a_TexCoord", VertexUsage::TexCoord, 0); | |||||
m_texeluni = m_shader->GetUniformLocation("u_TexelSize"); | m_texeluni = m_shader->GetUniformLocation("u_TexelSize"); | ||||
m_screenuni = m_shader->GetUniformLocation("u_ScreenSize"); | m_screenuni = m_shader->GetUniformLocation("u_ScreenSize"); | ||||
m_zoomuni = m_shader->GetUniformLocation("u_ZoomSettings"); | m_zoomuni = m_shader->GetUniformLocation("u_ZoomSettings"); | ||||
m_ready = true; | |||||
m_vdecl = | m_vdecl = | ||||
new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position), | new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position), | ||||
VertexStream<vec2>(VertexUsage::TexCoord)); | VertexStream<vec2>(VertexUsage::TexCoord)); | ||||
#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !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(vertices), vertices, | |||||
GL_STATIC_DRAW); | |||||
glGenBuffers(1, &m_tbo); | |||||
glBindBuffer(GL_ARRAY_BUFFER, m_tbo); | |||||
glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, | |||||
GL_STATIC_DRAW); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined _XBOX && !defined USE_D3D9 | |||||
/* Method 2: upload vertex information at each frame */ | |||||
#elif defined _XBOX || defined USE_D3D9 | |||||
if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL))) | |||||
exit(0); | |||||
vec2 *tmp1; | |||||
if (FAILED(m_vbo->Lock(0, 0, (void **)&tmp1, 0))) | |||||
exit(0); | |||||
memcpy(tmp1, vertices, sizeof(vertices)); | |||||
m_vbo = new VertexBuffer(sizeof(vertices)); | |||||
m_tbo = new VertexBuffer(sizeof(texcoords)); | |||||
void *tmp = m_vbo->Lock(0, 0); | |||||
memcpy(tmp, vertices, sizeof(vertices)); | |||||
m_vbo->Unlock(); | m_vbo->Unlock(); | ||||
if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(texcoords), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_tbo, NULL))) | |||||
exit(0); | |||||
vec2 *tmp2; | |||||
if (FAILED(m_tbo->Lock(0, 0, (void **)&tmp2, 0))) | |||||
exit(0); | |||||
memcpy(tmp2, texcoords, sizeof(texcoords)); | |||||
tmp = m_tbo->Lock(0, 0); | |||||
memcpy(tmp, texcoords, sizeof(texcoords)); | |||||
m_tbo->Unlock(); | m_tbo->Unlock(); | ||||
#else | |||||
#endif | |||||
/* FIXME: this object never cleans up */ | /* FIXME: this object never cleans up */ | ||||
m_ready = true; | |||||
} | } | ||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
@@ -762,29 +741,18 @@ public: | |||||
m_shader->SetUniform(m_screenuni, m_screen_settings); | m_shader->SetUniform(m_screenuni, m_screen_settings); | ||||
m_shader->SetUniform(m_zoomuni, m_zoom_settings); | m_shader->SetUniform(m_zoomuni, m_zoom_settings); | ||||
m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
m_vdecl->SetStream(m_vbo, m_vertexattrib); | |||||
m_vdecl->SetStream(m_tbo, m_texattrib); | |||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
g_d3ddevice->SetTexture(0, m_tex); | g_d3ddevice->SetTexture(0, m_tex); | ||||
//g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | //g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | ||||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | ||||
g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*vertices)); | |||||
g_d3ddevice->SetStreamSource(1, m_tbo, 0, sizeof(*texcoords)); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | |||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||||
glEnableVertexAttribArray(m_vertexattrib); | |||||
glVertexAttribPointer(m_vertexattrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | |||||
glBindBuffer(GL_ARRAY_BUFFER, m_tbo); | |||||
glEnableVertexAttribArray(m_texattrib); | |||||
glVertexAttribPointer(m_texattrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
/* Never used for now */ | |||||
//glEnableVertexAttribArray(m_vertexattrib); | |||||
//glVertexAttribPointer(m_vertexattrib, 2, GL_FLOAT, GL_FALSE, 0, vertices); | |||||
#else | #else | ||||
glEnableClientState(GL_VERTEX_ARRAY); | |||||
glVertexPointer(2, GL_FLOAT, 0, vertices); | |||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY); | |||||
glTexCoordPointer(2, GL_FLOAT, 0, texcoords); | |||||
//glEnableClientState(GL_VERTEX_ARRAY); | |||||
//glVertexPointer(2, GL_FLOAT, 0, vertices); | |||||
//glEnableClientState(GL_TEXTURE_COORD_ARRAY); | |||||
//glTexCoordPointer(2, GL_FLOAT, 0, texcoords); | |||||
#endif | #endif | ||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
@@ -796,18 +764,20 @@ public: | |||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
m_vdecl->Unbind(); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
glDisableVertexAttribArray(m_vertexattrib); | |||||
glDisableVertexAttribArray(m_texattrib); | |||||
glBindBuffer(GL_ARRAY_BUFFER, 0); | |||||
//glDisableVertexAttribArray(m_vertexattrib); | |||||
//glDisableVertexAttribArray(m_texattrib); | |||||
//glBindBuffer(GL_ARRAY_BUFFER, 0); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ | ||||
/* Never used for now */ | /* Never used for now */ | ||||
//glDisableVertexAttribArray(m_vertexattrib); | //glDisableVertexAttribArray(m_vertexattrib); | ||||
//glDisableVertexAttribArray(m_texattrib); | //glDisableVertexAttribArray(m_texattrib); | ||||
#else | #else | ||||
glDisableClientState(GL_VERTEX_ARRAY); | |||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||||
//glDisableClientState(GL_VERTEX_ARRAY); | |||||
//glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||||
#endif | #endif | ||||
Log::Error("~Tick Fractal\n"); | |||||
} | } | ||||
private: | private: | ||||
@@ -820,23 +790,20 @@ private: | |||||
double m_window2world; | double m_window2world; | ||||
f64vec2 m_texel2world; | f64vec2 m_texel2world; | ||||
u8vec4 *m_pixels, *m_tmppixels, *m_palette; | u8vec4 *m_pixels, *m_tmppixels, *m_palette; | ||||
Shader *m_shader; | Shader *m_shader; | ||||
ShaderAttrib m_vertexattrib, m_texattrib; | |||||
ShaderUniform m_texeluni, m_screenuni, m_zoomuni; | |||||
VertexDeclaration *m_vdecl; | VertexDeclaration *m_vdecl; | ||||
VertexBuffer *m_vbo, *m_tbo; | |||||
#if defined USE_D3D9 | #if defined USE_D3D9 | ||||
IDirect3DTexture9 *m_tex; | IDirect3DTexture9 *m_tex; | ||||
IDirect3DVertexBuffer9 *m_vbo, *m_tbo; | |||||
#elif defined _XBOX | #elif defined _XBOX | ||||
D3DTexture *m_tex; | D3DTexture *m_tex; | ||||
D3DVertexBuffer *m_vbo, *m_tbo; | |||||
#else | #else | ||||
GLuint m_texid; | GLuint m_texid; | ||||
# if !defined __CELLOS_LV2__ && !defined __ANDROID__ | |||||
GLuint m_vbo, m_tbo; | |||||
GLuint m_tco; | |||||
# endif | |||||
#endif | #endif | ||||
int m_vertexattrib, m_texattrib; | |||||
ShaderUniform m_texeluni, m_screenuni, m_zoomuni; | |||||
int m_frame, m_slices, m_dirty[4]; | int m_frame, m_slices, m_dirty[4]; | ||||
bool m_ready, m_drag; | bool m_ready, m_drag; | ||||