Ver código fonte

gpu: implement polygon rendering mode in GL and D3D.

legacy
Sam Hocevar sam 11 anos atrás
pai
commit
9158677eae
6 arquivos alterados com 101 adições e 171 exclusões
  1. +19
    -7
      src/gpu/rendercontext.cpp
  2. +57
    -8
      src/gpu/renderer.cpp
  3. +0
    -151
      src/gpu/renderer_private.h
  4. +2
    -1
      src/lol/gpu/rendercontext.h
  5. +21
    -2
      src/lol/gpu/renderer.h
  6. +2
    -2
      src/video.cpp

+ 19
- 7
src/gpu/rendercontext.cpp Ver arquivo

@@ -59,7 +59,8 @@ private:
TrackedState<float> m_alpha_value;
TrackedState<BlendFunc> m_blend_src, m_blend_dst;
TrackedState<DepthFunc> m_depth_func;
TrackedState<CullMode> m_face_culling;
TrackedState<CullMode> m_cull_mode;
TrackedState<PolygonMode> m_polygon_mode;
};

/*
@@ -93,8 +94,11 @@ RenderContext::~RenderContext()
if (m_data->m_depth_func.HasChanged())
g_renderer->SetDepthFunc(m_data->m_depth_func.GetValue());

if (m_data->m_face_culling.HasChanged())
g_renderer->SetFaceCulling(m_data->m_face_culling.GetValue());
if (m_data->m_cull_mode.HasChanged())
g_renderer->SetCullMode(m_data->m_cull_mode.GetValue());

if (m_data->m_polygon_mode.HasChanged())
g_renderer->SetPolygonMode(m_data->m_polygon_mode.GetValue());

delete m_data;
}
@@ -151,12 +155,20 @@ void RenderContext::SetDepthFunc(DepthFunc func)
g_renderer->SetDepthFunc(func);
}

void RenderContext::SetFaceCulling(CullMode mode)
void RenderContext::SetCullMode(CullMode mode)
{
if (!m_data->m_cull_mode.HasChanged())
m_data->m_cull_mode.TrackValue(g_renderer->GetCullMode());

g_renderer->SetCullMode(mode);
}

void RenderContext::SetPolygonMode(PolygonMode mode)
{
if (!m_data->m_face_culling.HasChanged())
m_data->m_face_culling.TrackValue(g_renderer->GetFaceCulling());
if (!m_data->m_polygon_mode.HasChanged())
m_data->m_polygon_mode.TrackValue(g_renderer->GetPolygonMode());

g_renderer->SetFaceCulling(mode);
g_renderer->SetPolygonMode(mode);
}

} /* namespace lol */


+ 57
- 8
src/gpu/renderer.cpp Ver arquivo

@@ -63,7 +63,8 @@ private:
float m_alpha_value;
BlendFunc m_blend_src, m_blend_dst;
DepthFunc m_depth_func;
CullMode m_face_culling;
CullMode m_cull_mode;
PolygonMode m_polygon_mode;

private:
#if defined USE_D3D9
@@ -155,8 +156,11 @@ Renderer::Renderer(ivec2 size)
m_data->m_depth_func = DepthFunc::Disabled;
SetDepthFunc(DepthFunc::LessOrEqual);

m_data->m_face_culling = CullMode::Disabled;
SetFaceCulling(CullMode::CounterClockwise);
m_data->m_cull_mode = CullMode::Disabled;
SetCullMode(CullMode::CounterClockwise);

m_data->m_polygon_mode = PolygonMode::Point;
SetPolygonMode(PolygonMode::Fill);

/* Add some rendering states that we don't export to the user */
#if defined USE_D3D9 || defined _XBOX
@@ -600,9 +604,9 @@ DepthFunc Renderer::GetDepthFunc() const
* Face culling
*/

void Renderer::SetFaceCulling(CullMode mode)
void Renderer::SetCullMode(CullMode mode)
{
if (m_data->m_face_culling == mode)
if (m_data->m_cull_mode == mode)
return;

#if defined USE_D3D9 || defined _XBOX
@@ -637,12 +641,57 @@ void Renderer::SetFaceCulling(CullMode mode)
}
#endif

m_data->m_face_culling = mode;
m_data->m_cull_mode = mode;
}

CullMode Renderer::GetCullMode() const
{
return m_data->m_cull_mode;
}

/*
* Polygon rendering mode
*/

void Renderer::SetPolygonMode(PolygonMode mode)
{
if (m_data->m_polygon_mode == mode)
return;

#if defined USE_D3D9 || defined _XBOX
switch (mode)
{
case PolygonMode::Point:
m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);
break;
case PolygonMode::Line:
m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
break;
case PolygonMode::Fill:
m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DCULL_SOLID);
break;
}
#else
switch (mode)
{
case PolygonMode::Point:
glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
break;
case PolygonMode::Line:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
break;
case PolygonMode::Fill:
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
break;
}
#endif

m_data->m_polygon_mode = mode;
}

CullMode Renderer::GetFaceCulling() const
PolygonMode Renderer::GetPolygonMode() const
{
return m_data->m_face_culling;
return m_data->m_polygon_mode;
}

} /* namespace lol */


+ 0
- 151
src/gpu/renderer_private.h Ver arquivo

@@ -1,151 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

//
// The Renderer class
// ------------------
//

#if !defined __LOL_RENDERER_H__
#define __LOL_RENDERER_H__

namespace lol
{

class RendererData;

/* A safe enum to indicate the blending factors. */
struct BlendFunc
{
enum Value
{
Disabled,
Zero,
One,
SrcColor,
OneMinusSrcColor,
DstColor,
OneMinusDstColor,
SrcAlpha,
OneMinusSrcAlpha,
DstAlpha,
OneMinusDstAlpha,
ConstantColor,
OneMinusConstantColor,
ConstantAlpha,
OneMinusConstantAlpha,
}
m_value;

inline BlendFunc() : m_value(Zero) {}
inline BlendFunc(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

/* A safe enum to indicate the face culling mode. */
struct CullMode
{
enum Value
{
Disabled,
Clockwise,
CounterClockwise,
}
m_value;

inline CullMode() : m_value(Disabled) {}
inline CullMode(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

/* A safe enum to indicate the depth test mode. */
struct DepthFunc
{
enum Value
{
Disabled,
Never,
Less,
Equal,
LessOrEqual,
Greater,
NotEqual,
GreaterOrEqual,
Always,
}
m_value;

inline DepthFunc() : m_value(Disabled) {}
inline DepthFunc(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

/* A safe enum to indicate the alpha test mode. */
struct AlphaFunc
{
enum Value
{
Disabled,
Never,
Less,
Equal,
LessOrEqual,
Greater,
NotEqual,
GreaterOrEqual,
Always,
}
m_value;

inline AlphaFunc() : m_value(Disabled) {}
inline AlphaFunc(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

class Renderer
{
private:
/* Only the Video class can create a renderer for now. */
friend class Video;

Renderer();
~Renderer();

public:
void SetClearColor(vec4 color);
vec4 GetClearColor() const;

void SetClearDepth(float depth);
float GetClearDepth() const;

void SetAlphaFunc(AlphaFunc func, float alpha);
AlphaFunc GetAlphaFunc() const;
float GetAlphaValue() const;

void SetBlendFunc(BlendFunc src, BlendFunc dst);
BlendFunc GetBlendFuncSrc() const;
BlendFunc GetBlendFuncDst() const;

void SetDepthFunc(DepthFunc func);
DepthFunc GetDepthFunc() const;

void SetFaceCulling(CullMode mode);
CullMode GetFaceCulling() const;

private:
RendererData *m_data;
};

extern Renderer *g_renderer;

} /* namespace lol */

#endif // __LOL_RENDERER_H__


+ 2
- 1
src/lol/gpu/rendercontext.h Ver arquivo

@@ -33,7 +33,8 @@ public:
void SetAlphaFunc(AlphaFunc func, float alpha);
void SetBlendFunc(BlendFunc src, BlendFunc dst);
void SetDepthFunc(DepthFunc func);
void SetFaceCulling(CullMode mode);
void SetCullMode(CullMode mode);
void SetPolygonMode(PolygonMode mode);

private:
RenderContextData *m_data;


+ 21
- 2
src/lol/gpu/renderer.h Ver arquivo

@@ -85,6 +85,22 @@ struct CullMode
inline operator Value() { return m_value; }
};

/* A safe enum to indicate the polygon mode. */
struct PolygonMode
{
enum Value
{
Fill,
Line,
Point,
}
m_value;

inline PolygonMode() : m_value(Fill) {}
inline PolygonMode(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

/* A safe enum to indicate the depth test mode. */
struct DepthFunc
{
@@ -164,8 +180,11 @@ public:
void SetDepthFunc(DepthFunc func);
DepthFunc GetDepthFunc() const;

void SetFaceCulling(CullMode mode);
CullMode GetFaceCulling() const;
void SetCullMode(CullMode mode);
CullMode GetCullMode() const;

void SetPolygonMode(PolygonMode mode);
PolygonMode GetPolygonMode() const;

private:
RendererData *m_data;


+ 2
- 2
src/video.cpp Ver arquivo

@@ -75,7 +75,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d)
// SetFaceCulling(false);
// else
// SetFaceCulling(true);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
break;
}
@@ -98,7 +98,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d)
#if defined USE_D3D9 || defined _XBOX
#elif defined HAVE_GLES_2X
#else
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
#endif
break;
}


Carregando…
Cancelar
Salvar