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