@@ -85,6 +85,11 @@ static inline int isnan(float f) | |||||
#endif | #endif | ||||
/* XXX: workaround for X11 headers that try to #define None */ | |||||
#undef None | |||||
#define None None | |||||
/* External declaration for LolFx files. */ | /* External declaration for LolFx files. */ | ||||
#define LOLFX_RESOURCE_DECLARE(name) \ | #define LOLFX_RESOURCE_DECLARE(name) \ | ||||
extern "C" char const *LOLFX_RESOURCE_NAME(name) | extern "C" char const *LOLFX_RESOURCE_NAME(name) | ||||
@@ -61,7 +61,7 @@ private: | |||||
TrackedState<BlendFactor> m_blend_dst; | TrackedState<BlendFactor> m_blend_dst; | ||||
TrackedState<bool> m_alpha_test; | TrackedState<bool> m_alpha_test; | ||||
TrackedState<bool> m_depth_test; | TrackedState<bool> m_depth_test; | ||||
TrackedState<bool> m_face_culling; | |||||
TrackedState<CullMode> m_face_culling; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -151,12 +151,12 @@ void RenderContext::SetDepthTest(bool set) | |||||
g_renderer->SetDepthTest(set); | g_renderer->SetDepthTest(set); | ||||
} | } | ||||
void RenderContext::SetFaceCulling(bool set) | |||||
void RenderContext::SetFaceCulling(CullMode mode) | |||||
{ | { | ||||
if (!m_data->m_face_culling.HasChanged()) | if (!m_data->m_face_culling.HasChanged()) | ||||
m_data->m_face_culling.TrackValue(g_renderer->GetFaceCulling()); | m_data->m_face_culling.TrackValue(g_renderer->GetFaceCulling()); | ||||
g_renderer->SetFaceCulling(set); | |||||
g_renderer->SetFaceCulling(mode); | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -31,6 +31,12 @@ | |||||
#include "core.h" | #include "core.h" | ||||
#include "lolgl.h" | #include "lolgl.h" | ||||
#if defined USE_D3D9 | |||||
extern IDirect3DDevice9 *g_d3ddevice; | |||||
#elif defined _XBOX | |||||
extern D3DDevice *g_d3ddevice; | |||||
#endif | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -50,7 +56,14 @@ private: | |||||
vec4 m_clear_color; | vec4 m_clear_color; | ||||
float m_clear_depth; | float m_clear_depth; | ||||
BlendFactor m_blend_src, m_blend_dst; | BlendFactor m_blend_src, m_blend_dst; | ||||
bool m_alpha_blend, m_alpha_test, m_depth_test, m_face_culling; | |||||
CullMode m_face_culling; | |||||
bool m_alpha_blend, m_alpha_test, m_depth_test; | |||||
#if defined USE_D3D9 | |||||
IDirect3DDevice9 *m_d3d_dev; | |||||
#elif defined _XBOX | |||||
D3DDevice *m_d3d_dev; | |||||
#endif | |||||
}; | }; | ||||
/* | /* | ||||
@@ -61,7 +74,8 @@ Renderer::Renderer() | |||||
: m_data(new RendererData()) | : m_data(new RendererData()) | ||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
/* TODO */ | |||||
/* FIXME: we should be in charge of creating this */ | |||||
m_data->m_d3d_dev = g_d3ddevice; | |||||
#else | #else | ||||
# if defined USE_GLEW && !defined __APPLE__ | # if defined USE_GLEW && !defined __APPLE__ | ||||
/* Initialise GLEW if necessary */ | /* Initialise GLEW if necessary */ | ||||
@@ -94,8 +108,8 @@ Renderer::Renderer() | |||||
m_data->m_depth_test = false; | m_data->m_depth_test = false; | ||||
SetDepthTest(true); | SetDepthTest(true); | ||||
m_data->m_face_culling = false; | |||||
SetFaceCulling(true); | |||||
m_data->m_face_culling = CullMode::None; | |||||
SetFaceCulling(CullMode::CCW); | |||||
/* Add some rendering states that we don't export to the user */ | /* Add some rendering states that we don't export to the user */ | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
@@ -349,26 +363,45 @@ bool Renderer::GetDepthTest() const | |||||
* Face culling | * Face culling | ||||
*/ | */ | ||||
void Renderer::SetFaceCulling(bool set) | |||||
void Renderer::SetFaceCulling(CullMode mode) | |||||
{ | { | ||||
if (m_data->m_face_culling == set) | |||||
if (m_data->m_face_culling == mode) | |||||
return; | return; | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
# define STR0(x) #x | |||||
# define STR(x) STR0(x) | |||||
# pragma message(__FILE__ "(" STR(__LINE__) "): warning: Renderer::SetFaceCulling() not implemented") | |||||
switch (mode) | |||||
{ | |||||
case CullMode::None: | |||||
m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | |||||
break; | |||||
case CullMode::CW: | |||||
m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | |||||
break; | |||||
case CullMode::CCW: | |||||
m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); | |||||
break; | |||||
} | |||||
#else | #else | ||||
if (set) | |||||
glEnable(GL_CULL_FACE); | |||||
else | |||||
switch (mode) | |||||
{ | |||||
case CullMode::None: | |||||
glDisable(GL_CULL_FACE); | glDisable(GL_CULL_FACE); | ||||
break; | |||||
case CullMode::CW: | |||||
glEnable(GL_CULL_FACE); | |||||
glFrontFace(GL_CW); | |||||
break; | |||||
case CullMode::CCW: | |||||
glEnable(GL_CULL_FACE); | |||||
glFrontFace(GL_CCW); | |||||
break; | |||||
} | |||||
#endif | #endif | ||||
m_data->m_face_culling = set; | |||||
m_data->m_face_culling = mode; | |||||
} | } | ||||
bool Renderer::GetFaceCulling() const | |||||
CullMode Renderer::GetFaceCulling() const | |||||
{ | { | ||||
return m_data->m_face_culling; | return m_data->m_face_culling; | ||||
} | } | ||||
@@ -127,8 +127,6 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||||
return; | return; | ||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW))) | |||||
Abort(); | |||||
switch (type) | switch (type) | ||||
{ | { | ||||
case MeshPrimitive::Triangles: | case MeshPrimitive::Triangles: | ||||
@@ -159,8 +157,6 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||||
} | } | ||||
#else | #else | ||||
/* FIXME: this has nothing to do here! */ | /* FIXME: this has nothing to do here! */ | ||||
glFrontFace(GL_CCW); | |||||
switch (type) | switch (type) | ||||
{ | { | ||||
case MeshPrimitive::Triangles: | case MeshPrimitive::Triangles: | ||||
@@ -190,8 +186,6 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | |||||
return; | return; | ||||
#if defined _XBOX || defined USE_D3D9 | #if defined _XBOX || defined USE_D3D9 | ||||
if (FAILED(g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW))) | |||||
Abort(); | |||||
switch (type) | switch (type) | ||||
{ | { | ||||
case MeshPrimitive::Triangles: | case MeshPrimitive::Triangles: | ||||
@@ -225,8 +219,6 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | |||||
} | } | ||||
#else | #else | ||||
/* FIXME: this has nothing to do here! */ | /* FIXME: this has nothing to do here! */ | ||||
glFrontFace(GL_CCW); | |||||
switch (type) | switch (type) | ||||
{ | { | ||||
case MeshPrimitive::Triangles: | case MeshPrimitive::Triangles: | ||||
@@ -33,7 +33,7 @@ public: | |||||
void SetBlendFunc(BlendFactor src, BlendFactor dst); | void SetBlendFunc(BlendFactor src, BlendFactor dst); | ||||
void SetAlphaTest(bool set); | void SetAlphaTest(bool set); | ||||
void SetDepthTest(bool set); | void SetDepthTest(bool set); | ||||
void SetFaceCulling(bool set); | |||||
void SetFaceCulling(CullMode mode); | |||||
private: | private: | ||||
RenderContextData *m_data; | RenderContextData *m_data; | ||||
@@ -48,6 +48,22 @@ struct BlendFactor | |||||
inline operator Value() { return m_value; } | inline operator Value() { return m_value; } | ||||
}; | }; | ||||
/* A safe enum to indicate the face culling mode. */ | |||||
struct CullMode | |||||
{ | |||||
enum Value | |||||
{ | |||||
None, | |||||
CW, | |||||
CCW, | |||||
} | |||||
m_value; | |||||
inline CullMode() : m_value(None) {} | |||||
inline CullMode(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
class Renderer | class Renderer | ||||
{ | { | ||||
private: | private: | ||||
@@ -77,8 +93,8 @@ public: | |||||
void SetDepthTest(bool set); | void SetDepthTest(bool set); | ||||
bool GetDepthTest() const; | bool GetDepthTest() const; | ||||
void SetFaceCulling(bool set); | |||||
bool GetFaceCulling() const; | |||||
void SetFaceCulling(CullMode mode); | |||||
CullMode GetFaceCulling() const; | |||||
private: | private: | ||||
RendererData *m_data; | RendererData *m_data; | ||||
@@ -180,7 +180,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d) | |||||
{ | { | ||||
#if defined USE_D3D9 || defined _XBOX | #if defined USE_D3D9 || defined _XBOX | ||||
#elif defined HAVE_GLES_2X | #elif defined HAVE_GLES_2X | ||||
glEnable(GL_CULL_FACE); | |||||
// glEnable(GL_CULL_FACE); | |||||
#else | #else | ||||
// if (VideoData::render_mode == d && glIsEnabled(GL_CULL_FACE) == GL_TRUE) | // if (VideoData::render_mode == d && glIsEnabled(GL_CULL_FACE) == GL_TRUE) | ||||
// SetFaceCulling(false); | // SetFaceCulling(false); | ||||