State.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #include "Renderer.h"
00018 #include "TexturePainter.h"
00019 #include "State.h"
00020 
00021 using namespace Fluxus;
00022 
00023 State::State() :
00024 Colour(1,1,1),
00025 Shinyness(1.0f),
00026 Opacity(1.0f),
00027 Parent(1),
00028 Hints(HINT_SOLID),
00029 LineWidth(1),
00030 PointWidth(1),
00031 SourceBlend(GL_SRC_ALPHA),
00032 DestinationBlend(GL_ONE_MINUS_SRC_ALPHA),
00033 WireColour(1,1,1),
00034 WireOpacity(1.0f),
00035 ColourMode(MODE_RGB),
00036 Shader(NULL),
00037 Cull(true)
00038 {
00039     for (int c=0; c<MAX_TEXTURES; c++)
00040     {
00041         Textures[c]=0;
00042     }
00043 }
00044 
00045 State::State(const State &other) 
00046 {
00047     *this=other;
00048 }
00049 
00050 const State &State::operator=(const State &other)
00051 {
00052     Colour=other.Colour;
00053     Specular=other.Specular;
00054     Emissive=other.Emissive;
00055     Ambient=other.Ambient;
00056     Shinyness=other.Shinyness;
00057     Opacity=other.Opacity;
00058     Parent=other.Parent;
00059     Hints=other.Hints;
00060     LineWidth=other.LineWidth;
00061     PointWidth=other.PointWidth;
00062     SourceBlend=other.SourceBlend;
00063     DestinationBlend=other.DestinationBlend;
00064     WireColour=other.WireColour;
00065     WireOpacity=other.WireOpacity;
00066     ColourMode=other.ColourMode;
00067     Transform=other.Transform;
00068     Shader=other.Shader;
00069     Cull=other.Cull;
00070     
00071     if (Shader!=NULL) 
00072     {
00073         Shader->IncRef();
00074     }
00075     for (int n=0; n<=MAX_TEXTURES; n++)
00076     {
00077         Textures[n]=other.Textures[n];
00078         TextureStates[n]=other.TextureStates[n];
00079     }
00080     
00081     return *this;
00082 }
00083 
00084 State::~State()
00085 {
00086     if (Shader!=NULL && Shader->DecRef()) delete Shader;
00087 }
00088 
00089 void State::Apply()
00090 {
00091     glMultMatrixf(Transform.arr());
00092     if (Opacity != 1.0f) Colour.a=Ambient.a=Emissive.a=Specular.a=Opacity;
00093     if (WireOpacity != 1.0f) WireColour.a=WireOpacity;
00094     glColor4f(Colour.r,Colour.g,Colour.b,Colour.a);
00095     glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,Ambient.arr());
00096     glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Emissive.arr());
00097     glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,Colour.arr());
00098     glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,Specular.arr());
00099     glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,&Shinyness);
00100     glLineWidth(LineWidth);
00101     glPointSize(PointWidth);
00102     glBlendFunc(SourceBlend,DestinationBlend);
00103     
00104     if (Cull) glEnable(GL_CULL_FACE);
00105     else glDisable(GL_CULL_FACE);
00106         
00107     if (Hints&HINT_CULL_CCW) glFrontFace(GL_CW);
00108     else glFrontFace(GL_CCW);
00109     
00110     TexturePainter::Get()->SetCurrent(Textures,TextureStates);
00111 
00112     if (Shader!=NULL) 
00113     {
00114         Shader->Apply();
00115     }
00116     else GLSLShader::Unapply();
00117 }
00118 
00119 void State::Spew()
00120 {
00121     Trace::Stream<<"Colour: "<<Colour<<endl
00122         <<"Specular: "<<Specular<<endl
00123         <<"Ambient: "<<Ambient<<endl
00124         <<"Emissive: "<<Emissive<<endl
00125         <<"Shinyness: "<<Shinyness<<endl
00126         <<"Opacity: "<<Opacity<<endl
00127         <<"WireOpacity: "<<WireOpacity<<endl
00128         <<"Texture: "<<Textures[0]<<endl
00129         <<"Parent: "<<Parent<<endl
00130         <<"Hints: "<<Hints<<endl
00131         <<"LineWidth: "<<LineWidth<<endl
00132         <<"Transform: "<<Transform<<endl;
00133 }
00134 

Generated on Wed Sep 17 21:16:30 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1