Blender V2.61 - r43446

RAS_OpenGLRasterizer.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef __RAS_OPENGLRASTERIZER
00033 #define __RAS_OPENGLRASTERIZER
00034 
00035 #if defined(WIN32) && !defined(FREE_WINDOWS)
00036 #pragma warning (disable:4786)
00037 #endif
00038 
00039 #include "MT_CmMatrix4x4.h"
00040 #include <vector>
00041 using namespace std;
00042 
00043 #include "RAS_IRasterizer.h"
00044 #include "RAS_MaterialBucket.h"
00045 #include "RAS_ICanvas.h"
00046 
00047 #define RAS_MAX_TEXCO   8   // match in BL_Material
00048 #define RAS_MAX_ATTRIB  16  // match in BL_BlenderShader
00049 
00050 struct  OglDebugShape
00051 {
00052     enum SHAPE_TYPE{
00053         LINE, CIRCLE
00054     };
00055     SHAPE_TYPE  m_type;
00056     MT_Vector3  m_pos;
00057     MT_Vector3  m_param;
00058     MT_Vector3  m_param2;
00059     MT_Vector3  m_color;
00060 };
00061 
00065 class RAS_OpenGLRasterizer : public RAS_IRasterizer
00066 {
00067 
00068     RAS_ICanvas*    m_2DCanvas;
00069     
00070     // fogging vars
00071     bool            m_fogenabled;
00072     float           m_fogstart;
00073     float           m_fogdist;
00074     float           m_fogr;
00075     float           m_fogg;
00076     float           m_fogb;
00077     
00078     float           m_redback;
00079     float           m_greenback;
00080     float           m_blueback;
00081     float           m_alphaback;
00082     
00083     float           m_ambr;
00084     float           m_ambg;
00085     float           m_ambb;
00086 
00087     double          m_time;
00088     MT_Matrix4x4    m_viewmatrix;
00089     MT_Matrix4x4    m_viewinvmatrix;
00090     MT_Point3       m_campos;
00091     bool            m_camortho;
00092 
00093     StereoMode      m_stereomode;
00094     StereoEye       m_curreye;
00095     float           m_eyeseparation;
00096     float           m_focallength;
00097     bool            m_setfocallength;
00098     int             m_noOfScanlines;
00099 
00100     short           m_prevafvalue;
00101 
00102     //motion blur
00103     int m_motionblur;
00104     float   m_motionblurvalue;
00105 
00106 protected:
00107     int             m_drawingmode;
00108     TexCoGen        m_texco[RAS_MAX_TEXCO];
00109     TexCoGen        m_attrib[RAS_MAX_ATTRIB];
00110     int             m_texco_num;
00111     int             m_attrib_num;
00112     //int               m_last_alphablend;
00113     bool            m_last_frontface;
00114 
00116     RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
00117 
00118 public:
00119     double GetTime();
00120     RAS_OpenGLRasterizer(RAS_ICanvas* canv);
00121     virtual ~RAS_OpenGLRasterizer();
00122 
00123     /*enum DrawType
00124     {
00125             KX_BOUNDINGBOX = 1,
00126             KX_WIREFRAME,
00127             KX_SOLID,
00128             KX_SHADED,
00129             KX_TEXTURED
00130     };
00131 
00132     enum DepthMask
00133     {
00134             KX_DEPTHMASK_ENABLED =1,
00135             KX_DEPTHMASK_DISABLED,
00136     };*/
00137     virtual void    SetDepthMask(DepthMask depthmask);
00138 
00139     virtual bool    SetMaterial(const RAS_IPolyMaterial& mat);
00140     virtual bool    Init();
00141     virtual void    Exit();
00142     virtual bool    BeginFrame(int drawingmode, double time);
00143     virtual void    ClearColorBuffer();
00144     virtual void    ClearDepthBuffer();
00145     virtual void    ClearCachingInfo(void);
00146     virtual void    EndFrame();
00147     virtual void    SetRenderArea();
00148 
00149     virtual void    SetStereoMode(const StereoMode stereomode);
00150     virtual RAS_IRasterizer::StereoMode GetStereoMode();
00151     virtual bool    Stereo();
00152     virtual bool    InterlacedStereo();
00153     virtual void    SetEye(const StereoEye eye);
00154     virtual StereoEye   GetEye();
00155     virtual void    SetEyeSeparation(const float eyeseparation);
00156     virtual float   GetEyeSeparation();
00157     virtual void    SetFocalLength(const float focallength);
00158     virtual float   GetFocalLength();
00159 
00160     virtual void    SwapBuffers();
00161 
00162     virtual void    IndexPrimitives(class RAS_MeshSlot& ms);
00163     virtual void    IndexPrimitivesMulti(class RAS_MeshSlot& ms);
00164     virtual void    IndexPrimitives_3DText(
00165                         class RAS_MeshSlot& ms,
00166                         class RAS_IPolyMaterial* polymat,
00167                         class RAS_IRenderTools* rendertools);
00168 
00169     void            IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi);
00170 
00171     virtual void    SetProjectionMatrix(MT_CmMatrix4x4 & mat);
00172     virtual void    SetProjectionMatrix(const MT_Matrix4x4 & mat);
00173     virtual void    SetViewMatrix(
00174                         const MT_Matrix4x4 & mat,
00175                         const MT_Matrix3x3 & ori,
00176                         const MT_Point3 & pos,
00177                         bool perspective
00178                     );
00179 
00180     virtual const   MT_Point3& GetCameraPosition();
00181     virtual bool    GetCameraOrtho();
00182     
00183     virtual void    SetFog(
00184                         float start,
00185                         float dist,
00186                         float r,
00187                         float g,
00188                         float b
00189                     );
00190 
00191     virtual void    SetFogColor(
00192                         float r,
00193                         float g,
00194                         float b
00195                     );
00196 
00197     virtual void    SetFogStart(float fogstart);
00198     virtual void    SetFogEnd(float fogend);
00199 
00200     void            DisableFog();
00201     virtual void    DisplayFog();
00202     virtual bool    IsFogEnabled();
00203 
00204     virtual void    SetBackColor(
00205                         float red,
00206                         float green,
00207                         float blue,
00208                         float alpha
00209                     );
00210     
00211     virtual void    SetDrawingMode(int drawingmode);
00212     virtual int     GetDrawingMode();
00213 
00214     virtual void    SetCullFace(bool enable);
00215     virtual void    SetLines(bool enable);
00216 
00217     virtual MT_Matrix4x4 GetFrustumMatrix(
00218                             float left,
00219                             float right,
00220                             float bottom,
00221                             float top,
00222                             float frustnear,
00223                             float frustfar,
00224                             float focallength,
00225                             bool perspective
00226                         );
00227 
00228     virtual MT_Matrix4x4 GetOrthoMatrix(
00229                             float left,
00230                             float right,
00231                             float bottom,
00232                             float top,
00233                             float frustnear,
00234                             float frustfar
00235                         );
00236 
00237     virtual void    SetSpecularity(
00238                         float specX,
00239                         float specY,
00240                         float specZ,
00241                         float specval
00242                     );
00243 
00244     virtual void    SetShinyness(float shiny);
00245     virtual void    SetDiffuse(
00246                         float difX,
00247                         float difY,
00248                         float difZ,
00249                         float diffuse
00250                     );
00251     virtual void    SetEmissive(float eX,
00252                                 float eY,
00253                                 float eZ,
00254                                 float e
00255                                );
00256 
00257     virtual void    SetAmbientColor(float red, float green, float blue);
00258     virtual void    SetAmbient(float factor);
00259 
00260     virtual void    SetPolygonOffset(float mult, float add);
00261 
00262     virtual void    FlushDebugShapes();
00263 
00264     virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
00265     {
00266         OglDebugShape line;
00267         line.m_type = OglDebugShape::LINE;
00268         line.m_pos= from;
00269         line.m_param = to;
00270         line.m_color = color;
00271         m_debugShapes.push_back(line);
00272     }
00273 
00274     virtual void DrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
00275                                     const MT_Vector3& normal, int nsector)
00276     {
00277         OglDebugShape line;
00278         line.m_type = OglDebugShape::CIRCLE;
00279         line.m_pos= center;
00280         line.m_param = normal;
00281         line.m_color = color;   
00282         line.m_param2.x() = radius;
00283         line.m_param2.y() = (float) nsector;
00284         m_debugShapes.push_back(line);
00285     }
00286 
00287     std::vector <OglDebugShape> m_debugShapes;
00288 
00289     virtual void SetTexCoordNum(int num);
00290     virtual void SetAttribNum(int num);
00291     virtual void SetTexCoord(TexCoGen coords, int unit);
00292     virtual void SetAttrib(TexCoGen coords, int unit);
00293 
00294     void TexCoord(const RAS_TexVert &tv);
00295 
00296     const MT_Matrix4x4& GetViewMatrix() const;
00297     const MT_Matrix4x4& GetViewInvMatrix() const;
00298     
00299     virtual void    EnableMotionBlur(float motionblurvalue);
00300     virtual void    DisableMotionBlur();
00301     virtual float   GetMotionBlurValue(){return m_motionblurvalue;};
00302     virtual int     GetMotionBlurState(){return m_motionblur;};
00303     virtual void    SetMotionBlurState(int newstate)
00304     {
00305         if(newstate<0) 
00306             m_motionblur = 0;
00307         else if(newstate>2)
00308             m_motionblur = 2;
00309         else 
00310             m_motionblur = newstate;
00311     };
00312 
00313     virtual void    SetAlphaBlend(int alphablend);
00314     virtual void    SetFrontFace(bool ccw);
00315     
00316     virtual void    SetAnisotropicFiltering(short level);
00317     virtual short   GetAnisotropicFiltering();
00318     
00319     
00320 #ifdef WITH_CXX_GUARDEDALLOC
00321 public:
00322     void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_OpenGLRasterizer"); }
00323     void operator delete( void *mem ) { MEM_freeN(mem); }
00324 #endif
00325 };
00326 
00327 #endif //__RAS_OPENGLRASTERIZER
00328 
00329