# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/DrawArrays.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #ifndef DrawArrays_INCLUDE_DEFINE
    00033 #define DrawArrays_INCLUDE_DEFINE
    00034
    00035 #include <vlGraphics/DrawCall.hpp>
    00036 #include <vlGraphics/TriangleIterator.hpp>
    00037
    00038 namespace vl
    00039 {
    00040   //------------------------------------------------------------------------------
    00041   // DrawArrays
    00042   //------------------------------------------------------------------------------
    00049   class DrawArrays: public DrawCall
    00050   {
    00051   public:
    00052     DrawArrays(): mStart(0), mCount(0)
    00053     {
    00054       VL_DEBUG_SET_OBJECT_NAME()
    00055       mType      = PT_TRIANGLES;
    00056       mInstances = 1;
    00057     }
    00058     DrawArrays(EPrimitiveType primitive, int start, int count, int instances=1)
    00059       : mStart(start), mCount(count)
    00060     {
    00061       VL_DEBUG_SET_OBJECT_NAME()
    00062       mInstances = instances;
    00063       mType = primitive;
    00064     }
    00065     virtual const char* className() { return "vl::DrawArrays"; }
    00066
    00067     DrawArrays& operator=(const DrawArrays& other)
    00068     {
    00069       DrawCall::operator=(other);
    00070       mStart     = other.mStart;
    00071       mCount     = other.mCount;
    00072       mInstances = other.mInstances;
    00073       return *this;
    00074     }
    00075
    00076     virtual ref<DrawCall> clone() const
    00077     {
    00078       return new DrawArrays( primitiveType(), (int)start(), (int)count(), (int)instances() );
    00079     }
    00080
    00081     virtual void deleteVBOs() {}
    00082     virtual void updateVBOs(bool,bool) {}
    00083     virtual unsigned int handle() const { return 0; }
    00084
    00085     virtual void render(bool) const
    00086     {
    00087       // apply patch parameters if any and if using PT_PATCHES
    00088       applyPatchParameters();
    00089
    00090       if ( instances() > 1 && (GLEW_ARB_draw_instanced||GLEW_EXT_draw_instanced) )
    00091         VL_glDrawArraysInstanced( primitiveType(), (int)start(), (int)count(), (int)instances() );
    00092       else
    00093         glDrawArrays( primitiveType(), (int)start(), (int)count() );
    00094
    00095       #ifndef NDEBUG
    00096         unsigned int glerr = glGetError();
    00097         if (glerr != GL_NO_ERROR)
    00098         {
    00099           String msg( (char*)gluErrorString(glerr) );
    00100           Log::error( Say("glGetError() [%s:%n]: %s\n") << __FILE__ << __LINE__ << msg );
    00101           Log::print(
    00102             "OpenGL Geometry Instancing (GL_ARB_draw_instanced) does not support display lists."
    00103             "If you are using geometry instancing in conjunction with display lists you will have to disable one of them.\n"
    00104           );
    00105           VL_TRAP()
    00106         }
    00107       #endif
    00108     }
    00109
    00111     void setStart(int start) { mStart = start; }
    00112
    00114     int start() const { return mStart; }
    00115
    00117     void setCount(int count) { mCount = count; }
    00118
    00120     int count() const { return mCount; }
    00121
    00123     void setInstances(int instances) { mInstances = instances; }
    00124
    00126     int instances() const { return mInstances; }
    00127
    00128     TriangleIterator triangleIterator() const
    00129     {
    00130       ref<TriangleIteratorDirect> tid = new TriangleIteratorDirect( primitiveType() );
    00131       tid->initialize(mStart, mStart+mCount);
    00132       return TriangleIterator(tid.get());
    00133     }
    00134
    00135     IndexIterator indexIterator() const
    00136     {
    00137       ref<IndexIteratorDrawArrays> iida = new IndexIteratorDrawArrays;
    00138       iida->initialize( mStart, mCount );
    00139       IndexIterator iit;
    00140       iit.initialize( iida.get() );
    00141       return iit;
    00142     }
    00143
    00144     protected:
    00145       int mStart;
    00146       int mCount;
    00147       int mInstances;
    00148   };
    00149
    00150 }
    00151
    00152 #endif
    00153

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:23.
Permission is granted to use this page to write and publish articles regarding Visualization Library.