ivideo/rndbuf.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ivideo/rndbuf.h
Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2002 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_IVIDEO_RNDBUF_H__
    00021 #define __CS_IVIDEO_RNDBUF_H__
    00022
    00027 #include "csutil/scf.h"
    00028 #include "csutil/strset.h"
    00029 #include "csutil/refcount.h"
    00030
    00035 class csVector3;
    00036 class csVector2;
    00037 class csColor;
    00038 class csReversibleTransform;
    00039 struct iTextureHandle;
    00040 struct iMaterialWrapper;
    00041 class csRenderBufferHolder;
    00042
    00048 enum csRenderBufferType
    00049 {
    00051   CS_BUF_DYNAMIC,
    00053   CS_BUF_STATIC,
    00055   CS_BUF_STREAM
    00056 };
    00057
    00059 /* Note: csgfx/renderbuffer.h stores this in _very_ few bits, take care when
    00060    changing this! */
    00061 enum csRenderBufferComponentType
    00062 {
    00064   CS_BUFCOMP_BYTE = 0,
    00066   CS_BUFCOMP_UNSIGNED_BYTE,
    00068   CS_BUFCOMP_SHORT,
    00070   CS_BUFCOMP_UNSIGNED_SHORT,
    00072   CS_BUFCOMP_INT,
    00074   CS_BUFCOMP_UNSIGNED_INT,
    00076   CS_BUFCOMP_FLOAT,
    00078   CS_BUFCOMP_DOUBLE,
    00080   CS_BUFCOMP_HALF,
    00081
    00082   CS_BUFCOMP_BASE_TYPECOUNT,
    00083
    00085   CS_BUFCOMP_NORMALIZED = 0x10,
    00086
    00088   CS_BUFCOMP_BYTE_NORM = CS_BUFCOMP_BYTE | CS_BUFCOMP_NORMALIZED,
    00090   CS_BUFCOMP_UNSIGNED_BYTE_NORM =
    00091       CS_BUFCOMP_UNSIGNED_BYTE | CS_BUFCOMP_NORMALIZED,
    00093   CS_BUFCOMP_SHORT_NORM =
    00094       CS_BUFCOMP_SHORT | CS_BUFCOMP_NORMALIZED,
    00096   CS_BUFCOMP_UNSIGNED_SHORT_NORM =
    00097       CS_BUFCOMP_UNSIGNED_SHORT | CS_BUFCOMP_NORMALIZED,
    00099   CS_BUFCOMP_INT_NORM = CS_BUFCOMP_INT | CS_BUFCOMP_NORMALIZED,
    00101   CS_BUFCOMP_UNSIGNED_INT_NORM =
    00102       CS_BUFCOMP_UNSIGNED_INT | CS_BUFCOMP_NORMALIZED
    00103 };
    00104
    00108 enum csRenderBufferLockType
    00109 {
    00111   CS_BUF_LOCK_READ = 1,
    00113   CS_BUF_LOCK_NORMAL
    00114 };
    00115
    00116 #include "csutil/deprecated_warn_off.h"
    00117
    00118 namespace CS
    00119 {
    00120   namespace Deprecated
    00121   {
    00122     struct CS_DEPRECATED_TYPE_MSG("You shouldn't use CS_BUF_LOCK_NOLOCK in "
    00123       "the first place")
    00124       CS_BUF_LOCK_NOLOCK
    00125     {
    00126       static const uint value = 0;
    00127     };
    00128   }
    00129 }
    00130
    00131 #include "csutil/deprecated_warn_on.h"
    00132
    00133 #define CS_BUF_LOCK_NOLOCK      CS::Deprecated::CS_BUF_LOCK_NOLOCK::value
    00134
    00138 static const size_t csRenderBufferComponentSizes[CS_BUFCOMP_BASE_TYPECOUNT] =
    00139 {
    00140   sizeof (char), sizeof (unsigned char),
    00141   sizeof (short), sizeof (unsigned short),
    00142   sizeof (int), sizeof (unsigned int),
    00143   sizeof (float),
    00144   sizeof (double),
    00145   sizeof (uint16)
    00146 };
    00147
    00148 struct iRenderBuffer;
    00149
    00154 struct iRenderBufferCallback : public virtual iBase
    00155 {
    00156   SCF_INTERFACE (iRenderBufferCallback, 1,0,0);
    00160   virtual void RenderBufferDestroyed (iRenderBuffer* buffer) = 0;
    00161 };
    00162
    00173 struct iRenderBuffer : public virtual iBase
    00174 {
    00175   SCF_INTERFACE (iRenderBuffer, 2, 1, 1);
    00176
    00184   virtual void* Lock(csRenderBufferLockType lockType) = 0;
    00185
    00190   virtual void Release() = 0;
    00191
    00198   virtual void CopyInto (const void *data, size_t elementCount,
    00199     size_t elemOffset = 0) = 0;
    00200
    00202   virtual int GetComponentCount () const = 0;
    00203
    00205   virtual csRenderBufferComponentType GetComponentType () const = 0;
    00206
    00208   virtual csRenderBufferType GetBufferType() const = 0;
    00209
    00211   virtual size_t GetSize() const = 0;
    00212
    00214   virtual size_t GetStride() const = 0;
    00215
    00217   virtual size_t GetElementDistance() const = 0;
    00218
    00220   virtual size_t GetOffset() const = 0;
    00221
    00223   virtual uint GetVersion () = 0;
    00224
    00231   virtual iRenderBuffer* GetMasterBuffer () const = 0;
    00232
    00234   virtual bool IsIndexBuffer() const = 0;
    00236   virtual size_t GetRangeStart() const = 0;
    00238   virtual size_t GetRangeEnd() const = 0;
    00239
    00241   virtual size_t GetElementCount() const = 0;
    00242
    00244   virtual void SetCallback (iRenderBufferCallback* cb) = 0;
    00245
    00256   virtual void SetData (const void *data) = 0;
    00257 };
    00258
    00266 enum csRenderBufferName
    00267 {
    00268   CS_BUFFER_NONE = -1,
    00270   CS_BUFFER_INDEX,
    00272   CS_BUFFER_POSITION,
    00274   CS_BUFFER_NORMAL,
    00276   CS_BUFFER_COLOR,
    00278   CS_BUFFER_COLOR_UNLIT,
    00280   CS_BUFFER_TEXCOORD0,
    00282   CS_BUFFER_TEXCOORD1,
    00284   CS_BUFFER_TEXCOORD2,
    00286   CS_BUFFER_TEXCOORD3,
    00288   CS_BUFFER_TEXCOORD_LIGHTMAP,
    00290   CS_BUFFER_GENERIC0,
    00292   CS_BUFFER_GENERIC1,
    00294   CS_BUFFER_GENERIC2,
    00296   CS_BUFFER_GENERIC3,
    00298   CS_BUFFER_TANGENT,
    00300   CS_BUFFER_BINORMAL,
    00301
    00306   CS_BUFFER_COUNT
    00307 };
    00308
    00309 #define CS_BUFFER_MAKE_MASKABLE(x) (1<<(x))
    00310
    00312 enum csRenderBufferNameMask
    00313 {
    00315   CS_BUFFER_INDEX_MASK = 1 << CS_BUFFER_INDEX,
    00317   CS_BUFFER_POSITION_MASK = 1 << CS_BUFFER_POSITION,
    00319   CS_BUFFER_NORMAL_MASK = 1 << CS_BUFFER_NORMAL,
    00321   CS_BUFFER_COLOR_MASK = 1 << CS_BUFFER_COLOR,
    00323   CS_BUFFER_COLOR_LIGHTING_MASK = 1 << CS_BUFFER_COLOR_UNLIT,
    00325   CS_BUFFER_TEXCOORD0_MASK = 1 << CS_BUFFER_TEXCOORD0,
    00327   CS_BUFFER_TEXCOORD1_MASK = 1 << CS_BUFFER_TEXCOORD1,
    00329   CS_BUFFER_TEXCOORD2_MASK = 1 << CS_BUFFER_TEXCOORD2,
    00331   CS_BUFFER_TEXCOORD3_MASK = 1 << CS_BUFFER_TEXCOORD3,
    00333   CS_BUFFER_TEXCOORD_LIGHTMAP_MASK = 1 << CS_BUFFER_TEXCOORD_LIGHTMAP,
    00335   CS_BUFFER_GENERIC0_MASK = 1 << CS_BUFFER_GENERIC0,
    00337   CS_BUFFER_GENERIC1_MASK = 1 << CS_BUFFER_GENERIC1,
    00339   CS_BUFFER_GENERIC2_MASK = 1 << CS_BUFFER_GENERIC2,
    00341   CS_BUFFER_GENERIC3_MASK = 1 << CS_BUFFER_GENERIC3,
    00343   CS_BUFFER_TANGENT_MASK = 1 << CS_BUFFER_TANGENT,
    00345   CS_BUFFER_BINORMAL_MASK = 1 << CS_BUFFER_BINORMAL,
    00347   CS_BUFFER_ALL_MASK = ~0
    00348 };
    00349
    00350
    00356 struct iRenderBufferAccessor : public virtual iBase
    00357 {
    00358   SCF_INTERFACE (iRenderBufferAccessor,0,0,1);
    00360   virtual void PreGetBuffer (csRenderBufferHolder* holder,
    00361     csRenderBufferName buffer) = 0;
    00362 };
    00363
    00368 class csRenderBufferHolder : public csRefCount
    00369 {
    00370 public:
    00372   csRenderBufferHolder ()
    00373     : accessorMask (0)
    00374   {
    00375   }
    00376
    00377   csRenderBufferHolder (const csRenderBufferHolder& other)
    00378     : csRefCount (), accessorMask (other.accessorMask),
    00379     accessor (other.accessor)
    00380   {
    00381     for (size_t i = 0; i < CS_BUFFER_COUNT; ++i)
    00382     {
    00383       buffers[i] = other.buffers[i];
    00384     }
    00385   }
    00386
    00387   csRenderBufferHolder& operator= (const csRenderBufferHolder& other)
    00388   {
    00389     accessorMask = other.accessorMask;
    00390     accessor = other.accessor;
    00391
    00392     for (size_t i = 0; i < CS_BUFFER_COUNT; ++i)
    00393     {
    00394       buffers[i] = other.buffers[i];
    00395     }
    00396
    00397     return *this;
    00398   }
    00399
    00405   iRenderBuffer* GetRenderBuffer (csRenderBufferName bufferName)
    00406   {
    00407     if (bufferName < CS_BUFFER_INDEX) return 0;
    00408     if (accessor &&
    00409         accessorMask & CS_BUFFER_MAKE_MASKABLE(bufferName))
    00410       accessor->PreGetBuffer (this, bufferName);
    00411
    00412     return buffers[bufferName];
    00413   }
    00414
    00419   iRenderBuffer* GetRenderBufferNoAccessor (csRenderBufferName bufferName)
    00420   {
    00421     if (bufferName < CS_BUFFER_INDEX) return 0;
    00422
    00423     return buffers[bufferName];
    00424   }
    00425
    00429   void SetRenderBuffer (csRenderBufferName bufferName, iRenderBuffer* buffer)
    00430   {
    00431     CS_ASSERT(bufferName >= 0 && bufferName < CS_BUFFER_COUNT);
    00432     buffers[bufferName] = buffer;
    00433   }
    00434
    00438   void SetAccessor (iRenderBufferAccessor* a, uint32 mask)
    00439   {
    00440     accessorMask = mask;
    00441     accessor = a;
    00442   }
    00444   uint GetAccessorMask() const { return accessorMask; }
    00446   iRenderBufferAccessor* GetAccessor() const { return accessor; }
    00447 protected:
    00448   uint32 accessorMask;
    00449   csRef<iRenderBufferAccessor> accessor;
    00450   csRef<iRenderBuffer> buffers[CS_BUFFER_COUNT];
    00451 };
    00452
    00455 #endif // __CS_IVIDEO_RNDBUF_H__