@@ -428,6 +428,22 @@ void Shader::Bind() const | |||
#endif | |||
} | |||
void Shader::Unbind() const | |||
{ | |||
#if defined USE_D3D9 || defined _XBOX | |||
HRESULT hr; | |||
hr = g_d3ddevice->SetVertexShader(NULL); | |||
hr = g_d3ddevice->SetPixelShader(NULL); | |||
#elif !defined __CELLOS_LV2__ | |||
/* FIXME: untested */ | |||
glUseProgram(0); | |||
#else | |||
/* FIXME: untested */ | |||
cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_VERTEX)); | |||
cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT)); | |||
#endif | |||
} | |||
Shader::~Shader() | |||
{ | |||
#if defined USE_D3D9 || defined _XBOX | |||
@@ -69,6 +69,7 @@ public: | |||
void SetUniform(ShaderUniform const &uni, mat4 const &m); | |||
void Bind() const; | |||
void Unbind() const; | |||
protected: | |||
Shader(char const *vert, char const *frag); | |||
@@ -145,7 +145,16 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||
void VertexDeclaration::Unbind() | |||
{ | |||
#if defined _XBOX || defined USE_D3D9 | |||
/* FIXME: Nothing to do? */ | |||
int stream = -1; | |||
for (int i = 0; i < m_count; i++) | |||
if (m_streams[i].index != stream) | |||
{ | |||
stream = m_streams[i].index; | |||
if (FAILED(g_d3ddevice->SetStreamSource(stream, 0, 0, 0))) | |||
Abort(); | |||
} | |||
if (FAILED(g_d3ddevice->SetVertexDeclaration(NULL))) | |||
Abort(); | |||
#else | |||
/* FIXME: we need to unbind what we bound */ | |||
//glDisableVertexAttribArray(m_attrib); | |||
@@ -297,7 +306,11 @@ void VertexDeclaration::Initialize() | |||
D3DDECLUSAGE_TANGENT, | |||
D3DDECLUSAGE_BINORMAL, | |||
D3DDECLUSAGE_TESSFACTOR, | |||
#if defined _XBOX | |||
D3DDECLUSAGE_TEXCOORD, /* FIXME: nonexistent */ | |||
#else | |||
D3DDECLUSAGE_POSITIONT, | |||
#endif | |||
D3DDECLUSAGE_COLOR, | |||
D3DDECLUSAGE_FOG, | |||
D3DDECLUSAGE_DEPTH, | |||
@@ -102,16 +102,20 @@ void SdlApp::Run() | |||
while (!Ticker::Finished()) | |||
{ | |||
#if defined USE_SDL && defined USE_D3D9 | |||
if (FAILED(g_d3ddevice->BeginScene())) | |||
HRESULT hr; | |||
hr = g_d3ddevice->BeginScene(); | |||
if (FAILED(hr)) | |||
Abort(); | |||
#endif | |||
/* Tick the renderer, show the frame and clamp to desired framerate. */ | |||
Ticker::TickDraw(); | |||
#if defined USE_SDL | |||
# if defined USE_D3D9 | |||
if (FAILED(g_d3ddevice->EndScene())) | |||
hr = g_d3ddevice->EndScene(); | |||
if (FAILED(hr)) | |||
Abort(); | |||
if (FAILED(g_d3ddevice->Present(NULL, NULL, NULL, NULL))) | |||
hr = g_d3ddevice->Present(NULL, NULL, NULL, NULL); | |||
if (FAILED(hr)) | |||
Abort(); | |||
# else | |||
SDL_GL_SwapBuffers(); | |||
@@ -385,6 +385,8 @@ void Scene::Render() // XXX: rename to Blit() | |||
data->tiles = 0; | |||
data->ntiles = 0; | |||
stdshader->Unbind(); | |||
#if defined USE_D3D9 || defined _XBOX | |||
/* TODO */ | |||
#else | |||
@@ -142,7 +142,7 @@ void TileSet::TickDraw(float deltams) | |||
#if defined USE_D3D9 | |||
format = D3DFMT_R8G8B8; | |||
#elif defined _XBOX | |||
format = D3DFMT_LIN_R8G8B8; /* FIXME */ | |||
format = D3DFMT_LIN_A8R8G8B8; /* FIXME */ | |||
#else | |||
format = GL_RGB; | |||
#endif | |||
@@ -153,6 +153,7 @@ void TileSet::TickDraw(float deltams) | |||
#if defined USE_D3D9 | |||
format = D3DFMT_A8R8G8B8; | |||
#elif defined _XBOX | |||
/* By default the X360 will swizzle the texture. Ask for linear. */ | |||
format = D3DFMT_LIN_A8R8G8B8; | |||
#else | |||
format = GL_RGBA; | |||
@@ -177,19 +178,28 @@ void TileSet::TickDraw(float deltams) | |||
#if defined USE_D3D9 || defined _XBOX | |||
D3DLOCKED_RECT rect; | |||
HRESULT hr; | |||
# if defined USE_D3D9 | |||
g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_DYNAMIC, format, | |||
D3DPOOL_SYSTEMMEM, &data->m_tex, NULL); | |||
data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE); | |||
hr = g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_DYNAMIC, format, | |||
D3DPOOL_DEFAULT, &data->m_tex, NULL); | |||
# elif defined _XBOX | |||
/* By default the X360 will swizzle the texture. Ask for linear. */ | |||
g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_WRITEONLY, format, | |||
D3DPOOL_DEFAULT, &data->m_tex, NULL); | |||
data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE); | |||
hr = g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_WRITEONLY, format, | |||
D3DPOOL_DEFAULT, &data->m_tex, NULL); | |||
# endif | |||
if (FAILED(hr)) | |||
Abort(); | |||
# if defined USE_D3D9 | |||
hr = data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD); | |||
# else | |||
hr = data->m_tex->LockRect(0, &rect, NULL, 0); | |||
# endif | |||
if (FAILED(hr)) | |||
Abort(); | |||
for (int j = 0; j < h; j++) | |||
memcpy((uint8_t *)rect.pBits + j * rect.Pitch, pixels + w * j * 4, w * 4); | |||
data->m_tex->UnlockRect(0); | |||
hr = data->m_tex->UnlockRect(0); | |||
if (FAILED(hr)) | |||
Abort(); | |||
#else | |||
glGenTextures(1, &data->m_tex); | |||
glEnable(GL_TEXTURE_2D); | |||
@@ -229,7 +239,9 @@ void TileSet::Bind() | |||
if (!data->img && data->m_tex) | |||
{ | |||
#if defined USE_D3D9 || defined _XBOX | |||
g_d3ddevice->SetTexture(0, data->m_tex); | |||
HRESULT hr = g_d3ddevice->SetTexture(0, data->m_tex); | |||
if (FAILED(hr)) | |||
Abort(); | |||
#else | |||
glActiveTexture(GL_TEXTURE0); | |||
glBindTexture(GL_TEXTURE_2D, data->m_tex); | |||
@@ -239,12 +251,17 @@ void TileSet::Bind() | |||
void TileSet::Unbind() | |||
{ | |||
if (!data->img && data->m_tex) | |||
{ | |||
#if defined USE_D3D9 || defined _XBOX | |||
g_d3ddevice->SetTexture(0, NULL); | |||
HRESULT hr = g_d3ddevice->SetTexture(0, NULL); | |||
if (FAILED(hr)) | |||
Abort(); | |||
#else | |||
glActiveTexture(GL_TEXTURE0); | |||
glBindTexture(GL_TEXTURE_2D, 0); | |||
glActiveTexture(GL_TEXTURE0); | |||
glBindTexture(GL_TEXTURE_2D, 0); | |||
#endif | |||
} | |||
} | |||
void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, | |||
@@ -178,7 +178,7 @@ public: | |||
Abort(); | |||
if (FAILED(g_d3ddevice->SetIndices(m_ibo))) | |||
Abort(); | |||
if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, sizeof(m_indices) / sizeof(*m_indices)))) | |||
if (FAILED(g_d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, sizeof(m_indices) / sizeof(*m_indices)))) | |||
Abort(); | |||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | |||