CrystalSpace

Public API Reference

csgfx/renderbuffer.h
Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2003-2005 by Marten Svanfeldt
00003                              Anders Stenberg
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public
00016   License along with this library; if not, write to the Free
00017   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSGFX_RENDERBUFFER_H__
00021 #define __CS_CSGFX_RENDERBUFFER_H__
00022 
00027 #include "csextern.h"
00028 #include "csutil/csstring.h"
00029 #include "csutil/leakguard.h"
00030 #include "csutil/scf_implementation.h"
00031 #include "csutil/weakref.h"
00032 #include "imap/renderbufferpersistence.h"
00033 #include "ivideo/rndbuf.h"
00034 
00043 struct csInterleavedSubBufferOptions
00044 {
00046   csRenderBufferComponentType componentType;
00048   uint componentCount;
00049 };
00050 
00051 #ifdef CS_DEBUG
00052 class csCallStack;
00053 #endif
00054 
00058 class CS_CRYSTALSPACE_EXPORT csRenderBuffer :
00059   public scfImplementation1<csRenderBuffer, iRenderBuffer>
00060 {
00061 protected:
00065   csRenderBuffer (size_t size, csRenderBufferType type, 
00066     csRenderBufferComponentType componentType, uint componentCount, 
00067     size_t rangeStart, size_t rangeEnd, bool copy = true);
00068 public:
00069   CS_LEAKGUARD_DECLARE (csRenderBuffer);
00070 
00074   virtual ~csRenderBuffer ();
00075 
00078   virtual void* Lock (csRenderBufferLockType lockType);
00079 
00080   virtual void Release ();
00081 
00082   virtual void CopyInto (const void* data, size_t elementCount,
00083     size_t elemOffset = 0);
00084 
00085   virtual int GetComponentCount () const
00086   {
00087     return props.compCount;
00088   }
00089 
00090   virtual csRenderBufferComponentType GetComponentType () const 
00091   {
00092     return props.comptype;
00093   }
00094 
00095   virtual csRenderBufferType GetBufferType () const
00096   {
00097     return props.bufferType;
00098   }
00099 
00100   virtual size_t GetSize () const
00101   {
00102     return bufferSize;
00103   }
00104 
00105   virtual size_t GetStride () const 
00106   {
00107     return props.stride;
00108   }
00109 
00110   virtual size_t GetElementDistance () const
00111   {
00112     return props.stride ? props.stride :
00113       props.compCount * csRenderBufferComponentSizes[props.comptype & ~CS_BUFCOMP_NORMALIZED];
00114   }
00115 
00116   virtual size_t GetOffset () const
00117   { return props.offset; }
00118 
00119   virtual uint GetVersion ()
00120   {
00121     return version;
00122   }
00123 
00124   bool IsMasterBuffer ()
00125   {
00126     return !masterBuffer.IsValid ();
00127   }
00128 
00129   virtual iRenderBuffer* GetMasterBuffer () const
00130   {
00131     return masterBuffer;
00132   }
00133 
00134   virtual bool IsIndexBuffer () const
00135   { return props.isIndex; }
00136 
00137   virtual size_t GetRangeStart () const
00138   { return rangeStart; }
00139   virtual size_t GetRangeEnd () const
00140   { return rangeEnd; }
00141 
00142   virtual size_t GetElementCount () const;
00143 
00144   virtual void SetCallback (iRenderBufferCallback *cb)
00145   {
00146     callback = cb;
00147   }
00148   virtual void SetData (const void *data);
00168   static csRef<csRenderBuffer> CreateRenderBuffer (size_t elementCount, 
00169     csRenderBufferType type, csRenderBufferComponentType componentType, 
00170     uint componentCount);
00171     
00172   CS_DEPRECATED_METHOD_MSG("Using the 'copy' flag is deprecated; "
00173     "use SetData() instead if data copying is not desired") 
00174   static csRef<csRenderBuffer> CreateRenderBuffer (size_t elementCount, 
00175     csRenderBufferType type, csRenderBufferComponentType componentType, 
00176     uint componentCount, bool copy);
00177     
00195   static csRef<csRenderBuffer> CreateIndexRenderBuffer (size_t elementCount, 
00196     csRenderBufferType type, csRenderBufferComponentType componentType,
00197     size_t rangeStart, size_t rangeEnd);
00198 
00199   CS_DEPRECATED_METHOD_MSG("Using the 'copy' flag is deprecated; "
00200     "use SetData() instead of data copying is not desired") 
00201   static csRef<csRenderBuffer> CreateIndexRenderBuffer (size_t elementCount, 
00202     csRenderBufferType type, csRenderBufferComponentType componentType,
00203     size_t rangeStart, size_t rangeEnd, bool copy);
00204     
00229   static csRef<csRenderBuffer> CreateInterleavedRenderBuffers (
00230     size_t elementCount, 
00231     csRenderBufferType type, uint count, 
00232     const csInterleavedSubBufferOptions* elements, 
00233     csRef<iRenderBuffer>* buffers);
00242   static const char* GetDescrFromBufferName (csRenderBufferName bufferName);
00247   static csRenderBufferName GetBufferNameFromDescr (const char* name);
00258   void SetRenderBufferProperties (size_t elementCount, 
00259     csRenderBufferType type, csRenderBufferComponentType componentType, 
00260     uint componentCount, bool copy = true);
00261   void SetIndexBufferProperties (size_t elementCount, 
00262     csRenderBufferType type, csRenderBufferComponentType componentType,
00263     size_t rangeStart, size_t rangeEnd, bool copy = true);
00265 protected:
00267   size_t bufferSize;
00268 
00273   struct Props
00274   {
00276     csRenderBufferType bufferType : 2;
00278     csRenderBufferComponentType comptype : 5;
00279     
00280     // padding
00281     uint unused0 : 1;
00282   
00284     uint compCount : 8;
00286     size_t stride : 8;
00288     size_t offset : 8;
00289 
00291     bool doCopy : 1; 
00293     bool doDelete : 1;
00295     bool isLocked : 1;
00297     bool isIndex : 1;
00298 
00299     // padding
00300     uint unused1 : 2;
00301     
00303     uint lastLock : 2;
00304 
00305     Props (csRenderBufferType type, csRenderBufferComponentType componentType,
00306       uint componentCount, bool copy) : bufferType (type), 
00307       comptype (componentType), compCount (componentCount), stride(0), 
00308       offset (0), doCopy (copy), doDelete (false), isLocked (false), 
00309       isIndex (false), lastLock (0)
00310     {
00311       CS_ASSERT (componentCount <= 255); // Just to be sure...
00312     }
00313   } props;
00314 
00316   size_t rangeStart; 
00318   size_t rangeEnd; 
00319   
00321   unsigned int version; 
00322 
00324   unsigned char* buffer; 
00325   
00326   csRef<iRenderBuffer> masterBuffer;
00327 
00328   csWeakRef<iRenderBufferCallback> callback;
00329 
00330 #ifdef CS_DEBUG
00331   csCallStack* lockStack;
00332 #endif
00333 };
00334 
00337 namespace CS
00338 {
00343 
00344   class RenderBufferPersistent : 
00345     public scfImplementation2<RenderBufferPersistent,
00346       iRenderBuffer, iRenderBufferPersistence>
00347   {
00348     csRef<iRenderBuffer> wrappedBuffer;
00349     csString filename;
00350   public:
00351     RenderBufferPersistent (iRenderBuffer* wrappedBuffer) : 
00352       scfImplementationType (this), wrappedBuffer (wrappedBuffer) {}
00353 
00354     void SetFileName (const char* filename) { this->filename = filename; }
00355     const char* GetFileName () { return filename; }
00356 
00359     void* Lock (csRenderBufferLockType lockType)
00360     { return wrappedBuffer->Lock (lockType); }
00361     void Release () { wrappedBuffer->Release (); }
00362     void CopyInto (const void* data, size_t elementCount,
00363       size_t elemOffset = 0) 
00364     { wrappedBuffer->CopyInto (data, elementCount, elemOffset); }
00365     int GetComponentCount () const
00366     { return wrappedBuffer->GetComponentCount (); }
00367     csRenderBufferComponentType GetComponentType () const 
00368     { return wrappedBuffer->GetComponentType (); }
00369     csRenderBufferType GetBufferType () const
00370     { return wrappedBuffer->GetBufferType (); }
00371     size_t GetSize () const
00372     { return wrappedBuffer->GetSize (); }
00373     size_t GetStride () const 
00374     { return wrappedBuffer->GetStride (); }
00375     size_t GetElementDistance () const
00376     { return wrappedBuffer->GetElementDistance (); }
00377     size_t GetOffset () const
00378     { return wrappedBuffer->GetOffset (); }
00379     uint GetVersion ()
00380     { return wrappedBuffer->GetVersion (); }
00381     iRenderBuffer* GetMasterBuffer () const
00382     { return wrappedBuffer->GetMasterBuffer (); }
00383     bool IsIndexBuffer () const
00384     { return wrappedBuffer->IsIndexBuffer (); }
00385     size_t GetRangeStart () const
00386     { return wrappedBuffer->GetRangeStart (); }
00387     size_t GetRangeEnd() const
00388     { return wrappedBuffer->GetRangeEnd (); }
00389     size_t GetElementCount () const
00390     { return wrappedBuffer->GetElementCount (); }
00391     void SetCallback (iRenderBufferCallback *cb)
00392     { wrappedBuffer->SetCallback (cb); }
00393     void SetData (const void *data)
00394     { wrappedBuffer->SetData (data); }
00396   };
00397 
00399 } // namespace CS
00400 
00401 #endif // __CS_CSGFX_RENDERBUFFER_H__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1