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/leakguard.h"
00029 #include "csutil/scf_implementation.h"
00030 #include "ivideo/rndbuf.h"
00031 
00040 struct csInterleavedSubBufferOptions
00041 {
00043   csRenderBufferComponentType componentType;
00045   uint componentCount;
00046 };
00047 
00048 #ifdef CS_DEBUG
00049 class csCallStack;
00050 #endif
00051 
00055 class CS_CRYSTALSPACE_EXPORT csRenderBuffer :
00056   public scfImplementation1<csRenderBuffer, iRenderBuffer>
00057 {
00058 protected:
00062   csRenderBuffer (size_t size, csRenderBufferType type, 
00063     csRenderBufferComponentType componentType, uint componentCount, 
00064     size_t rangeStart, size_t rangeEnd, bool copy);
00065 public:
00066   CS_LEAKGUARD_DECLARE (csRenderBuffer);
00067 
00071   virtual ~csRenderBuffer ();
00072 
00075   virtual void* Lock (csRenderBufferLockType lockType);
00076 
00077   virtual void Release();
00078 
00079   virtual void CopyInto (const void *data, size_t elementCount,
00080     size_t elemOffset = 0);
00081 
00082   virtual int GetComponentCount () const
00083   {
00084     return props.compCount;
00085   }
00086 
00087   virtual csRenderBufferComponentType GetComponentType () const 
00088   {
00089     return props.comptype;
00090   }
00091 
00092   virtual csRenderBufferType GetBufferType() const
00093   {
00094     return props.bufferType;
00095   }
00096 
00097   virtual size_t GetSize() const
00098   {
00099     return bufferSize;
00100   }
00101 
00102   virtual size_t GetStride() const 
00103   {
00104     return props.stride;
00105   }
00106 
00107   virtual size_t GetElementDistance() const
00108   {
00109     return props.stride ? props.stride :
00110       props.compCount * csRenderBufferComponentSizes[props.comptype];
00111   }
00112 
00113   virtual size_t GetOffset() const
00114   { return props.offset; }
00115 
00117   virtual uint GetVersion ()
00118   {
00119     return version;
00120   }
00121 
00122   virtual bool IsMasterBuffer ()
00123   {
00124     return !masterBuffer.IsValid();
00125   }
00126 
00127   virtual iRenderBuffer* GetMasterBuffer () const
00128   {
00129     return masterBuffer;
00130   }
00131 
00132   virtual bool IsIndexBuffer() const
00133   { return props.isIndex; }
00134 
00135   virtual size_t GetRangeStart() const
00136   { return rangeStart; }
00137   virtual size_t GetRangeEnd() const
00138   { return rangeEnd; }
00139 
00140   virtual size_t GetElementCount() const;
00160   static csRef<csRenderBuffer> CreateRenderBuffer (size_t elementCount, 
00161     csRenderBufferType type, csRenderBufferComponentType componentType, 
00162     uint componentCount, bool copy = true);
00180   static csRef<csRenderBuffer> CreateIndexRenderBuffer (size_t elementCount, 
00181     csRenderBufferType type, csRenderBufferComponentType componentType,
00182     size_t rangeStart, size_t rangeEnd, bool copy = true);
00207   static csRef<csRenderBuffer> CreateInterleavedRenderBuffers (
00208     size_t elementCount, 
00209     csRenderBufferType type, uint count, 
00210     const csInterleavedSubBufferOptions* elements, 
00211     csRef<iRenderBuffer>* buffers);
00220   static const char* GetDescrFromBufferName (csRenderBufferName bufferName);
00225   static csRenderBufferName GetBufferNameFromDescr (const char* name);
00236   void SetRenderBufferProperties (size_t elementCount, 
00237     csRenderBufferType type, csRenderBufferComponentType componentType, 
00238     uint componentCount, bool copy = true);
00239   void SetIndexBufferProperties (size_t elementCount, 
00240     csRenderBufferType type, csRenderBufferComponentType componentType,
00241     size_t rangeStart, size_t rangeEnd, bool copy = true);
00243 protected:
00245   size_t bufferSize;
00246 
00251   struct Props
00252   {
00254     csRenderBufferType bufferType : 2;
00256     csRenderBufferComponentType comptype : 4; 
00257   
00259     uint compCount : 8;
00261     size_t stride : 8;
00263     size_t offset : 8;
00264 
00266     bool doCopy : 1; 
00268     bool doDelete : 1;
00270     bool isLocked : 1;
00272     bool isIndex : 1;
00273 
00275     uint lastLock : 2;
00276 
00277     Props (csRenderBufferType type, csRenderBufferComponentType componentType,
00278       uint componentCount, bool copy) : bufferType (type), 
00279       comptype (componentType), compCount (componentCount), stride(0), 
00280       offset (0), doCopy (copy), doDelete (false), isLocked (false), 
00281       isIndex (false), lastLock (CS_BUF_LOCK_NOLOCK)
00282     {
00283       CS_ASSERT(componentCount <= 255); // Just to be sure...
00284     }
00285   } props;
00286 
00288   size_t rangeStart; 
00290   size_t rangeEnd; 
00291   
00293   unsigned int version; 
00294 
00296   unsigned char *buffer; 
00297   
00298   csRef<iRenderBuffer> masterBuffer;
00299 #ifdef CS_DEBUG
00300   csCallStack* lockStack;
00301 #endif
00302 };
00303 
00306 #endif // __CS_CSGFX_RENDERBUFFER_H__

Generated for Crystal Space 1.0.2 by doxygen 1.4.7