Basic Image AlgorithmS Library 2.8.0

glfBatch.hh

00001 /*
00002  This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004  Copyright (C) 2003-2009    (see file CONTACT for details)
00005  Multimediale Systeme der Informationsverarbeitung
00006  Institut fuer Informatik
00007  Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010  BIAS is free software; you can redistribute it and/or modify
00011  it under the terms of the GNU Lesser General Public License as published by
00012  the Free Software Foundation; either version 2.1 of the License, or
00013  (at your option) any later version.
00014 
00015  BIAS is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU Lesser General Public License for more details.
00019 
00020  You should have received a copy of the GNU Lesser General Public License
00021  along with BIAS; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 
00025 #ifndef __glfBatch_hh__
00026 #define __glfBatch_hh__
00027 
00028 #include "glfRenderTarget.hh"
00029 #include "glfViewport.hh"
00030 #include "glfTexture.hh"
00031 #include "glfDepthBufferMode.hh"
00032 #include "glfStencilBufferMode.hh"
00033 #include "glfBlendMode.hh"
00034 #include "glfShaderProgram.hh"
00035 #include "glfVertexBuffer.hh"
00036 #include "glfElementBuffer.hh"
00037 #include "glfMatrix.hh"
00038 
00039 namespace BIAS {
00040 
00041   /**
00042    * \brief A batch represents a single Draw call including all parameters (render states).
00043    * \attention The pointers to all objects passed to the 'Set...' functions must still
00044    * be valid when the batch is rendered. The objects are not copied!
00045    * \ingroup g_openglframework 
00046    * \author jkollmann
00047    */
00048   class BIASOpenGLFramework_EXPORT glfBatch {
00049   public:
00050     glfBatch();
00051     ~glfBatch();
00052 
00053     /**
00054      * Sets the render target. Must be non-NULL. Default render target is 'glfScreen'.
00055      */
00056     void SetRenderTarget(const glfRenderTarget* renderTarget);
00057 
00058     /**
00059      * Sets the viewport. Must be non-NULL. There is no default viewport, so
00060      * you _must_ set one.
00061      */
00062     void SetViewport(const glfViewport* viewport);
00063 
00064     /**
00065      * Sets the texture of a texture unit. NULL is allowed. Defaults are NULL.
00066      * If a texture of a texture unit is NULL, it should not be used.
00067      */
00068     void SetTexture(const glfTexture* texture, int textureUnit);
00069     
00070     unsigned int GetMaxUsedTextureIndex();
00071     
00072     /**
00073      * Releases texture including the matrix associated with
00074      * the argument index.
00075      */
00076     void ReleaseTextures(unsigned int fromIndex);
00077 
00078     /**
00079      * Sets the depth buffer mode. 
00080      * Defaults to GL Default.
00081      * \Attention If passed NULL, the currently set GL state is used!  
00082      */
00083     void SetDepthBufferMode(const glfDepthBufferMode* depthBufferMode);
00084 
00085     /**
00086      * Sets the stencil buffer mode. 
00087      * Defaults to GL Default.
00088      * \Attention If passed NULL, the currently set GL state is used!
00089      */
00090     void SetStencilBufferMode(const glfStencilBufferMode* stencilBufferMode);
00091 
00092 
00093     /**
00094     * Sets the blend mode. 
00095     * Defaults to GL Default.
00096     * \Attention If passed NULL, the currently set GL state is used!
00097     */
00098     void SetBlendMode(const glfBlendMode* blendMode);
00099 
00100     /**
00101      * Sets the shader program. NULL is allowed. If the shader program is NULL,
00102      * the fixed-function pipeline is used.
00103      */
00104     void SetShaderProgram(const glfShaderProgram* shaderProgram);
00105 
00106     /**
00107      * Sets the vertex buffer. Must be non-NULL.
00108      */
00109     void SetVertexBuffer(const glfVertexBuffer* vertexBuffer);
00110 
00111     /**
00112      * Sets the element buffer. NULL is allowed. If no element buffer is used,
00113      * you call Batch::SetPrimitiveType and vertices will be rendered
00114      * straight from the vertex buffer.
00115      */
00116     void SetElementBuffer(const glfElementBuffer* elementBuffer);
00117 
00118     /**
00119      * Sets the primitive type to rendering.
00120      * This is used only if no element buffer is provided.
00121      * Valid primitive types are be GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP,
00122      * GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES,
00123      * GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON.
00124      */
00125     void SetPrimitiveType(GLenum primitiveType);
00126 
00127     /**
00128      * Sets the range of vertices to be rendered if no element buffer is
00129      * set, or the range of vertex indices if an element buffer is set.
00130      * By default, all geometry will be rendered.
00131      */
00132     void SetRange(int first, int count);
00133 
00134     /**
00135      * Sets the modelview matrix. Must be non-NULL. Default is the identity matrix.
00136      */
00137     void SetModelViewMatrix(const glfMatrix* matrix);
00138 
00139     /**
00140      * Sets the projection matrix. Must be non-NULL. Default is the identity matrix.
00141      */
00142     void SetProjectionMatrix(const glfMatrix* matrix);
00143 
00144     /**
00145      * Sets a texture matrix. NULL is allowed. If a texture matrix is NULL,
00146      * it will not be set and is undefined. Make sure to not use a texture
00147      * matrix that is not set.
00148      */
00149     void SetTextureMatrix(const glfMatrix* matrix, int index);
00150 
00151     unsigned int GetMaxUsedTextureMatrixIndex() const;
00152     
00153     /**
00154      * Releases texture matrices including the matrix associated with
00155      * the argument index.
00156      */
00157     void ReleaseTextureMatrices(unsigned int fromIndex);
00158 
00159     /**
00160      * Draws the batch.
00161      */
00162     void Draw();
00163 
00164     /**
00165      * Sets all render states possibly modified by Batch to the OpenGL defaults.
00166      * Should be called before using an external library that uses OpenGL.
00167      * \note: The viewport cannot be set to default, because the default is
00168      * unknown to Batch.
00169      */
00170     static void SetDefaultRenderStates();
00171 
00172     static int GetMaxSupportedTextureUnits();
00173     static int GetMaxSupportedTextureMatrices();
00174 
00175     void Init();
00176 
00177   private:
00178     void BindRenderStates();
00179 
00180     GLint MAX_TEXTURE_UNITS_;
00181     GLint MAX_TEXTURE_COORDS_;
00182     bool initialized_;
00183     int maxUsedTextureIndex_;
00184     int maxUsedTextureMatrixIndex_;
00185 
00186     const glfViewport* viewport_;
00187     std::vector<const glfTexture*> textures_;
00188     const glfDepthBufferMode* depthBufferMode_;
00189     const glfStencilBufferMode* stencilBufferMode_;
00190     const glfBlendMode* blendMode_;
00191     const glfShaderProgram* shaderProgram_;
00192     const glfRenderTarget* renderTarget_;
00193     const glfVertexBuffer* vertexBuffer_;
00194     const glfElementBuffer* elementBuffer_;
00195     GLenum primitiveType_;
00196     int first_, count_;
00197     const glfMatrix* modelViewMatrix_;
00198     const glfMatrix* projectionMatrix_;
00199     std::vector<const glfMatrix*> textureMatrix_;
00200   };
00201   
00202 } // namespace BIAS
00203 
00204 #endif // __glfBatch_hh__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends