Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlGraphics/DrawPixels.hpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
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 DrawPixels_INCLUDE_ONCE
00033 #define DrawPixels_INCLUDE_ONCE
00034 
00035 #include <vlGraphics/Renderable.hpp>
00036 #include <vlGraphics/ImagePBO.hpp>
00037 #include <vlCore/Collection.hpp>
00038 
00039 namespace vl
00040 {
00041   //-----------------------------------------------------------------------------
00042   // DrawPixels
00043   //-----------------------------------------------------------------------------
00059   //-----------------------------------------------------------------------------
00060   class VLGRAPHICS_EXPORT DrawPixels: public Renderable
00061   {
00062     VL_INSTRUMENT_CLASS(vl::DrawPixels, Renderable)
00063 
00064   public:
00065   //-----------------------------------------------------------------------------
00066   // Pixels
00067   //-----------------------------------------------------------------------------
00071     class VLGRAPHICS_EXPORT Pixels: public Object
00072     {
00073       VL_INSTRUMENT_CLASS(vl::DrawPixels::Pixels, Object)
00074 
00075       friend class DrawPixels;
00076 
00077     public:
00078       Pixels();
00084       Pixels(ImagePBO* img, int scrx, int scry, int startx=0, int starty=0, int width=-1, int height=-1, int alignment = AlignBottom | AlignLeft);
00085 
00086       Pixels(const Pixels& other);
00087 
00088       Pixels& operator=(const Pixels& other);
00089 
00090       ~Pixels();
00091 
00092       const ivec2& position() const { return mPosition; }
00093 
00094       const ivec2& start() const { return mStart; }
00095 
00096       const ivec2& size() const { return mSize; }
00097 
00098       void setPosition( const ivec2& position) { mPosition = position; }
00099 
00100       void setStart( const ivec2& start) { mStart = start; }
00101 
00102       void setSize( const ivec2& size) { mSize = size; }
00103 
00104       ImagePBO* image() { return mImage.get(); }
00105 
00106       const ImagePBO* image() const { return mImage.get(); }
00107 
00108       int align() const { return mAlign; }
00109 
00110       void setAlign(int align) { mAlign = align; }
00111 
00117       bool generatePixelBufferObject(EBufferObjectUsage usage, bool discard_local_storage);
00118 
00119       void deletePixelBufferObject();
00120 
00121       bool hasPixelBufferObject() const;
00122 
00123     protected:
00124       ref<ImagePBO> mImage;
00125       ivec2 mPosition;
00126       ivec2 mStart;
00127       ivec2 mSize;
00128       int mAlign;
00129     };
00130   public:
00131 
00132     DrawPixels();
00133 
00134     void computeBounds_Implementation() { setBoundingBox(AABB()); setBoundingSphere(Sphere()); }
00135 
00140     void render_Implementation(const Actor* actor, const Shader* shader, const Camera* camera, OpenGLContext* gl_context) const;
00141 
00142     const Collection<Pixels>* draws() const { return &mDraws; }
00143     
00144     Collection<Pixels>* draws() { return &mDraws; }
00145 
00147     void deletePixelBufferObjects();
00148 
00150     void releaseImages();
00151 
00153     bool generatePixelBufferObjects(EBufferObjectUsage usage, bool discard_local_storage);
00154 
00155     void setUsePixelBufferObject(bool use_pbo);
00156 
00157     bool usePixelBufferObject() const { return mUsePixelBufferObject; }
00158 
00159     // Renderable interface implementation.
00160 
00161     virtual void updateDirtyBufferObject(EBufferObjectUpdateMode) {}
00162 
00163     virtual void deleteBufferObject() {}
00164 
00165   protected:
00166     Collection<Pixels> mDraws;
00167     bool mUsePixelBufferObject;
00168   };
00169   //-----------------------------------------------------------------------------
00170 }
00171 
00172 #endif

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:36.
Permission is granted to use this page to write and publish articles regarding Visualization Library.