the Scene code still breaks Direct3D rendering.legacy
@@ -14,29 +14,11 @@ | |||||
#include <cmath> | #include <cmath> | ||||
#ifdef WIN32 | |||||
# define WIN32_LEAN_AND_MEAN | |||||
# include <windows.h> | |||||
# if defined USE_D3D9 | |||||
# include <algorithm> | |||||
using std::min; | |||||
using std::max; | |||||
# include <d3d9.h> | |||||
# include <d3dx9shader.h> | |||||
# endif | |||||
#endif | |||||
#include "core.h" | #include "core.h" | ||||
#include "lolgl.h" | #include "lolgl.h" | ||||
using namespace std; | using namespace std; | ||||
#if defined USE_D3D9 | |||||
extern IDirect3DDevice9 *g_d3ddevice; | |||||
#elif defined _XBOX | |||||
extern D3DDevice *g_d3ddevice; | |||||
#endif | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -221,11 +203,7 @@ void Gradient::TickDraw(float deltams) | |||||
data->m_vdecl->SetStream(data->m_cbo, attr_col); | data->m_vdecl->SetStream(data->m_cbo, attr_col); | ||||
/* Draw arrays */ | /* Draw arrays */ | ||||
#if defined _XBOX || defined USE_D3D9 | |||||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); | |||||
#else | |||||
glDrawArrays(GL_TRIANGLES, 0, 6); | |||||
#endif | |||||
data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 2); | |||||
} | } | ||||
Gradient::~Gradient() | Gradient::~Gradient() | ||||
@@ -110,6 +110,7 @@ Scene::~Scene() | |||||
delete data->bufs[i]; | delete data->bufs[i]; | ||||
free(data->bufs); | free(data->bufs); | ||||
#endif | #endif | ||||
delete data->m_vdecl; | |||||
delete data; | delete data; | ||||
} | } | ||||
@@ -326,10 +327,7 @@ 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_NONE); | |||||
#else | #else | ||||
uni_tex = stdshader->GetUniformLocation("in_Texture"); | uni_tex = stdshader->GetUniformLocation("in_Texture"); | ||||
stdshader->SetUniform(uni_tex, 0); | stdshader->SetUniform(uni_tex, 0); | ||||
@@ -389,24 +387,16 @@ void Scene::Render() // XXX: rename to Blit() | |||||
data->tiles[i].tileset->Bind(); | data->tiles[i].tileset->Bind(); | ||||
/* Bind vertex and texture coordinate buffers */ | /* Bind vertex and texture coordinate buffers */ | ||||
data->m_vdecl->Bind(); | |||||
data->m_vdecl->SetStream(data->bufs[buf], attr_pos); | data->m_vdecl->SetStream(data->bufs[buf], attr_pos); | ||||
data->m_vdecl->SetStream(data->bufs[buf + 1], attr_tex); | data->m_vdecl->SetStream(data->bufs[buf + 1], attr_tex); | ||||
/* Draw arrays */ | /* Draw arrays */ | ||||
#if defined USE_D3D9 || defined _XBOX | |||||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (n - i) * 2); | |||||
#else | |||||
glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); | |||||
# if defined HAVE_GL_2X && !defined __APPLE__ | |||||
//glBindVertexArray(0); | |||||
# endif | |||||
# if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. | |||||
# else | |||||
//glDisableClientState(GL_VERTEX_ARRAY); | |||||
//glDisableClientState(GL_TEXTURE_COORD_ARRAY); | |||||
# endif | |||||
#if 0 | |||||
data->m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, (n - i) * 2); | |||||
#endif | #endif | ||||
data->m_vdecl->Unbind(); | |||||
data->tiles[i].tileset->Unbind(); | |||||
} | } | ||||
free(data->tiles); | free(data->tiles); | ||||
@@ -237,6 +237,16 @@ void TileSet::Bind() | |||||
} | } | ||||
} | } | ||||
void TileSet::Unbind() | |||||
{ | |||||
#if defined USE_D3D9 || defined _XBOX | |||||
g_d3ddevice->SetTexture(0, NULL); | |||||
#else | |||||
glActiveTexture(GL_TEXTURE0); | |||||
glBindTexture(GL_TEXTURE_2D, 0); | |||||
#endif | |||||
} | |||||
void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, | void TileSet::BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, | ||||
float *vertex, float *texture) | float *vertex, float *texture) | ||||
{ | { | ||||
@@ -44,6 +44,7 @@ public: | |||||
ivec2 GetCount() const; | ivec2 GetCount() const; | ||||
ivec2 GetSize(int tileid) const; | ivec2 GetSize(int tileid) const; | ||||
void Bind(); | void Bind(); | ||||
void Unbind(); | |||||
void BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, | void BlitTile(uint32_t id, vec3 pos, int o, vec2 scale, | ||||
float *vertex, float *texture); | float *vertex, float *texture); | ||||
@@ -14,13 +14,14 @@ | |||||
#include <cmath> | #include <cmath> | ||||
#if defined USE_D3D9 | |||||
# include <d3d9.h> | |||||
#elif defined _XBOX | |||||
#if defined _XBOX | |||||
# include <xtl.h> | # include <xtl.h> | ||||
# undef near /* Fuck Microsoft */ | # undef near /* Fuck Microsoft */ | ||||
# undef far /* Fuck Microsoft again */ | # undef far /* Fuck Microsoft again */ | ||||
#elif defined _WIN32 | #elif defined _WIN32 | ||||
# if defined USE_D3D9 | |||||
# include <d3d9.h> | |||||
# endif | |||||
# define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
# include <windows.h> | # include <windows.h> | ||||
# undef near /* Fuck Microsoft */ | # undef near /* Fuck Microsoft */ | ||||
@@ -204,6 +204,7 @@ public: | |||||
glVertexPointer(3, GL_FLOAT, 0, m_vertices); | glVertexPointer(3, GL_FLOAT, 0, m_vertices); | ||||
glDisableClientState(GL_VERTEX_ARRAY); | glDisableClientState(GL_VERTEX_ARRAY); | ||||
#endif | #endif | ||||
m_vdecl->Unbind(); | |||||
} | } | ||||
private: | private: | ||||