class, so that the calling code does not need to know what the backend is.legacy
@@ -118,15 +118,39 @@ void VertexDeclaration::Bind() | |||||
#endif | #endif | ||||
} | } | ||||
void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||||
{ | |||||
#if defined _XBOX || defined USE_D3D9 | |||||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | |||||
switch (type) | |||||
{ | |||||
case MeshPrimitive::Triangles: | |||||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, skip, count); | |||||
break; | |||||
} | |||||
#else | |||||
switch (type) | |||||
{ | |||||
case MeshPrimitive::Triangles: | |||||
glDrawArrays(GL_TRIANGLES, skip * 3, count * 3); | |||||
break; | |||||
} | |||||
#endif | |||||
} | |||||
void VertexDeclaration::Unbind() | void VertexDeclaration::Unbind() | ||||
{ | { | ||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
/* FIXME: Nothing to do? */ | /* FIXME: Nothing to do? */ | ||||
#else | #else | ||||
/* FIXME: we need to record what happens */ | |||||
/* FIXME: we need to unbind what we bound */ | |||||
//glDisableVertexAttribArray(m_attrib); | //glDisableVertexAttribArray(m_attrib); | ||||
/* FIXME: only useful for VAOs */ | /* FIXME: only useful for VAOs */ | ||||
//glBindBuffer(GL_ARRAY_BUFFER, 0); | //glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
/* Or: */ | |||||
//glDisableVertexAttribArray(m_attrib); | |||||
/* Or even: */ | |||||
//glDisableClientState(GL_VERTEX_ARRAY); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -185,15 +209,12 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, | |||||
/* We need to parse the whole vertex declaration to retrieve | /* We need to parse the whole vertex declaration to retrieve | ||||
* the information. It sucks. */ | * the information. It sucks. */ | ||||
int attr_index = 0, usage_index = 0, stream = -1; | |||||
int attr_index = 0, usage_index = 0; | |||||
/* First, find the stream index */ | /* First, find the stream index */ | ||||
for (; attr_index < m_count; attr_index++) | for (; attr_index < m_count; attr_index++) | ||||
if (m_streams[attr_index].usage == usage) | if (m_streams[attr_index].usage == usage) | ||||
if (usage_index++ == index) | if (usage_index++ == index) | ||||
{ | |||||
stream = m_streams[attr_index].index; | |||||
break; | break; | ||||
} | |||||
/* Now compute the stride and offset up to this stream index */ | /* Now compute the stride and offset up to this stream index */ | ||||
int stride = 0, offset = 0; | int stride = 0, offset = 0; | ||||
@@ -61,6 +61,18 @@ struct VertexUsage | |||||
inline operator Value() { return m_value; } | inline operator Value() { return m_value; } | ||||
}; | }; | ||||
struct MeshPrimitive | |||||
{ | |||||
enum Value | |||||
{ | |||||
Triangles, | |||||
} | |||||
m_value; | |||||
inline MeshPrimitive(Value v) { m_value = v; } | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
class VertexStreamBase | class VertexStreamBase | ||||
{ | { | ||||
friend class VertexDeclaration; | friend class VertexDeclaration; | ||||
@@ -164,6 +176,7 @@ public: | |||||
~VertexDeclaration(); | ~VertexDeclaration(); | ||||
void Bind(); | void Bind(); | ||||
void DrawElements(MeshPrimitive type, int skip, int count); | |||||
void Unbind(); | void Unbind(); | ||||
void SetStream(VertexBuffer *vb, ShaderAttrib attr1, | void SetStream(VertexBuffer *vb, ShaderAttrib attr1, | ||||
ShaderAttrib attr2 = ShaderAttrib(), | ShaderAttrib attr2 = ShaderAttrib(), | ||||
@@ -13,18 +13,11 @@ | |||||
#endif | #endif | ||||
#include "core.h" | #include "core.h" | ||||
#include "lolgl.h" | |||||
#include "loldebug.h" | #include "loldebug.h" | ||||
using namespace std; | using namespace std; | ||||
using namespace lol; | using namespace lol; | ||||
#if defined _WIN32 && defined USE_D3D9 | |||||
# define FAR | |||||
# define NEAR | |||||
# include <d3d9.h> | |||||
#endif | |||||
#if USE_SDL && defined __APPLE__ | #if USE_SDL && defined __APPLE__ | ||||
# include <SDL_main.h> | # include <SDL_main.h> | ||||
#endif | #endif | ||||
@@ -38,12 +31,6 @@ using namespace lol; | |||||
# include <direct.h> | # include <direct.h> | ||||
#endif | #endif | ||||
#if defined USE_D3D9 | |||||
extern IDirect3DDevice9 *g_d3ddevice; | |||||
#elif defined _XBOX | |||||
extern D3DDevice *g_d3ddevice; | |||||
#endif | |||||
class Triangle : public WorldEntity | class Triangle : public WorldEntity | ||||
{ | { | ||||
public: | public: | ||||
@@ -61,21 +48,6 @@ public: | |||||
if (!m_ready) | if (!m_ready) | ||||
{ | { | ||||
m_shader = Shader::Create( | m_shader = Shader::Create( | ||||
#if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 | #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 | ||||
"#version 120\n" | "#version 120\n" | ||||
@@ -116,36 +88,16 @@ public: | |||||
m_shader->Bind(); | m_shader->Bind(); | ||||
m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
m_vdecl->SetStream(m_vbo, m_coord); | m_vdecl->SetStream(m_vbo, m_coord); | ||||
#if defined _XBOX || defined USE_D3D9 | |||||
g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | |||||
#endif | |||||
#if defined _XBOX || defined USE_D3D9 | |||||
g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); | |||||
#else | |||||
glDrawArrays(GL_TRIANGLES, 0, 3); | |||||
#endif | |||||
m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 1); | |||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
#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); | |||||
//glBindBuffer(GL_ARRAY_BUFFER, 0); | |||||
#elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||||
/* Never used for now */ | |||||
glDisableVertexAttribArray(m_attrib); | |||||
#else | |||||
glDisableClientState(GL_VERTEX_ARRAY); | |||||
#endif | |||||
} | } | ||||
private: | private: | ||||
vec2 m_vertices[3]; | vec2 m_vertices[3]; | ||||
Shader *m_shader; | Shader *m_shader; | ||||
ShaderAttrib m_coord; | |||||
VertexDeclaration *m_vdecl; | VertexDeclaration *m_vdecl; | ||||
VertexBuffer *m_vbo; | VertexBuffer *m_vbo; | ||||
ShaderAttrib m_coord; | |||||
bool m_ready; | bool m_ready; | ||||
}; | }; | ||||