PixelLightAPI  .
IndexBuffer.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: IndexBuffer.h                                  *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLRENDERER_INDEXBUFFER_H__
00024 #define __PLRENDERER_INDEXBUFFER_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLRenderer/Renderer/Buffer.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLRenderer {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Abstract renderer index buffer (IBO) resource
00046 */
00047 class IndexBuffer : public Buffer {
00048 
00049 
00050     //[-------------------------------------------------------]
00051     //[ Public definitions                                    ]
00052     //[-------------------------------------------------------]
00053     public:
00054         /**
00055         *  @brief
00056         *    Vertex index types
00057         */
00058         enum EType {
00059             UInt   = 0, /**< Unsigned int (may not be supported by each API) */
00060             UShort = 1, /**< Unsigned short (default) */
00061             UByte  = 2  /**< Unsigned byte (may not be supported by each API) */
00062         };
00063 
00064         /** Maximum vertex index which can be used if UShort is used as index buffer type */
00065         static const PLCore::uint32 MaxVertexIndexUShort = 65535;
00066 
00067         /** Maximum vertex index which can be used if UByte is used as index buffer type */
00068         static const PLCore::uint32 MaxVertexIndexUByte = 255;
00069 
00070 
00071     //[-------------------------------------------------------]
00072     //[ Public functions                                      ]
00073     //[-------------------------------------------------------]
00074     public:
00075         /**
00076         *  @brief
00077         *    Destructor
00078         */
00079         PLRENDERER_API virtual ~IndexBuffer();
00080 
00081         /**
00082         *  @brief
00083         *    Returns the type of the buffer elements
00084         *
00085         *  @return
00086         *    The type of the buffer elements
00087         */
00088         inline EType GetElementType() const;
00089 
00090         /**
00091         *  @brief
00092         *    Sets the type of the buffer elements
00093         *
00094         *  @param[in] nType
00095         *    The type of the buffer elements
00096         *
00097         *  @return
00098         *    'true' if all went fine, else 'false' (maybe the buffer is already allocated)
00099         *
00100         *  @note
00101         *    - It's only possible to change the element type if the buffer isn't allocated
00102         *    - Try to avoid UInt whenever possible for more performance and better compatibility to for example mobile graphics API's
00103         */
00104         inline bool SetElementType(EType nType = UShort);
00105 
00106         /**
00107         *  @brief
00108         *    Sets the type of the buffer elements automatically by using a given maximum vertex index
00109         *
00110         *  @param[in] nMaximumIndex
00111         *    Maximum vertex index
00112         *
00113         *  @return
00114         *    'true' if all went fine, else 'false' (maybe the buffer is already allocated)
00115         *
00116         *  @remarks
00117         *    If the given maximum vertex index is <= 'MaxVertexIndexUByte' the type
00118         *    'EByte' is chosen. If the given maximum vertex index is <= 'MaxVertexIndexUShort'
00119         *    the type 'EShort' is chosen, else 'UInt'. Please don't oversight the '='.
00120         *    If you have n vertices, the last one has the index n-1 because we start
00121         *    counting at zero.
00122         *
00123         *  @see
00124         *    - SetElementType()
00125         */
00126         inline bool SetElementTypeByMaximumIndex(PLCore::uint32 nMaximumIndex);
00127 
00128         /**
00129         *  @brief
00130         *    Copy operator
00131         *
00132         *  @param[in] cSource
00133         *    Source to copy from
00134         *
00135         *  @return
00136         *    Reference to this object
00137         */
00138         PLRENDERER_API IndexBuffer &operator =(const IndexBuffer &cSource);
00139 
00140         /**
00141         *  @brief
00142         *    Returns the data of the index buffer
00143         *
00144         *  @param[in] nIndex
00145         *    Index index
00146         *
00147         *  @return
00148         *    Index data
00149         *
00150         *  @note
00151         *    - This function will give you the correct data of the requested
00152         *      index, therefore you should always use this function to be not forced
00153         *      to worry about the internal index data type. (see EType)
00154         *
00155         *  @see
00156         *    - Buffer::GetData()
00157         */
00158         PLRENDERER_API PLCore::uint32 GetData(PLCore::uint32 nIndex);
00159 
00160         /**
00161         *  @brief
00162         *    Sets the data of the index buffer
00163         *
00164         *  @param[in] nIndex
00165         *    Index index
00166         *  @param[in] nData
00167         *    Data to set
00168         *
00169         *  @return
00170         *    'true' if all went fine, else 'false'
00171         *
00172         *  @see
00173         *    - GetData()
00174         */
00175         PLRENDERER_API bool SetData(PLCore::uint32 nIndex, PLCore::uint32 nData);
00176 
00177 
00178     //[-------------------------------------------------------]
00179     //[ Protected functions                                   ]
00180     //[-------------------------------------------------------]
00181     protected:
00182         /**
00183         *  @brief
00184         *    Constructor
00185         *
00186         *  @param[in] cRenderer
00187         *    Owner renderer
00188         */
00189         PLRENDERER_API IndexBuffer(Renderer &cRenderer);
00190 
00191 
00192     //[-------------------------------------------------------]
00193     //[ Protected data                                        ]
00194     //[-------------------------------------------------------]
00195     protected:
00196         EType m_nElementType;   /**< Element type */
00197 
00198 
00199     //[-------------------------------------------------------]
00200     //[ Private functions                                     ]
00201     //[-------------------------------------------------------]
00202     private:
00203         /**
00204         *  @brief
00205         *    Copy constructor
00206         *
00207         *  @param[in] cSource
00208         *    Source to copy from
00209         */
00210         IndexBuffer(const IndexBuffer &cSource);
00211 
00212 
00213     //[-------------------------------------------------------]
00214     //[ Public virtual Buffer functions                       ]
00215     //[-------------------------------------------------------]
00216     public:
00217         PLRENDERER_API virtual void *GetData() override;
00218 
00219 
00220 };
00221 
00222 
00223 //[-------------------------------------------------------]
00224 //[ Namespace                                             ]
00225 //[-------------------------------------------------------]
00226 } // PLRenderer
00227 
00228 
00229 //[-------------------------------------------------------]
00230 //[ Implementation                                        ]
00231 //[-------------------------------------------------------]
00232 #include "PLRenderer/Renderer/IndexBuffer.inl"
00233 
00234 
00235 #endif // __PLRENDERER_INDEXBUFFER_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported