CamRenderer.h
Go to the documentation of this file.00001 #ifndef CAMRENDERER_H_
00002 #define CAMRENDERER_H_
00003
00004 #include "../renderer.h"
00005
00006 class CamRenderer: public Renderer
00007 {
00008 struct state_type
00009 {
00010 state_type () :
00011 m_highlight(0), m_state(0), m_lights(0)
00012 {
00013 }
00014 unsigned int m_highlight;
00015 Shader* m_state;
00016 const LightList* m_lights;
00017 };
00018
00019 std::vector<state_type> m_state_stack;
00020 RenderStateFlags m_globalstate;
00021 Shader* m_state_select0;
00022 Shader* m_state_select1;
00023 const Vector3& m_viewer;
00024
00025 public:
00026 CamRenderer (RenderStateFlags globalstate, Shader* select0, Shader* select1, const Vector3& viewer) :
00027 m_globalstate(globalstate), m_state_select0(select0), m_state_select1(select1), m_viewer(viewer)
00028 {
00029 ASSERT_NOTNULL(select0);
00030 ASSERT_NOTNULL(select1);
00031 m_state_stack.push_back(state_type());
00032 }
00033
00034 void SetState (Shader* state, EStyle style)
00035 {
00036 ASSERT_NOTNULL(state);
00037 if (style == eFullMaterials) {
00038 m_state_stack.back().m_state = state;
00039 }
00040 }
00041 const EStyle getStyle () const
00042 {
00043 return eFullMaterials;
00044 }
00045 void PushState ()
00046 {
00047 m_state_stack.push_back(m_state_stack.back());
00048 }
00049 void PopState ()
00050 {
00051 ASSERT_MESSAGE(!m_state_stack.empty(), "popping empty stack");
00052 m_state_stack.pop_back();
00053 }
00054 void Highlight (EHighlightMode mode, bool bEnable = true)
00055 {
00056 (bEnable) ? m_state_stack.back().m_highlight |= mode : m_state_stack.back().m_highlight &= ~mode;
00057 }
00058 void setLights (const LightList& lights)
00059 {
00060 m_state_stack.back().m_lights = &lights;
00061 }
00062 void addRenderable (const OpenGLRenderable& renderable, const Matrix4& world)
00063 {
00064 if (m_state_stack.back().m_highlight & ePrimitive) {
00065 m_state_select0->addRenderable(renderable, world, m_state_stack.back().m_lights);
00066 }
00067 if (m_state_stack.back().m_highlight & eFace) {
00068 m_state_select1->addRenderable(renderable, world, m_state_stack.back().m_lights);
00069 }
00070
00071 m_state_stack.back().m_state->addRenderable(renderable, world, m_state_stack.back().m_lights);
00072 }
00073
00074 void render (const Matrix4& modelview, const Matrix4& projection)
00075 {
00076 GlobalShaderCache().render(m_globalstate, modelview, projection, m_viewer);
00077 }
00078 };
00079
00080 #endif