Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

SpriteGraphicsBuffer.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 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 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * スプライトグラフィックスバッファヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef SPRITE_GRAPHICS_BUFFER_H_
00026 #define SPRITE_GRAPHICS_BUFFER_H_
00027 
00028 #include <Graphics/System/GraphicsDeviceObjectHolder.h>
00029 
00030 namespace Lamp{
00031 
00032 //------------------------------------------------------------------------------
00033 /**
00034  * スプライトグラフィックスバッファ
00035  */
00036 class SpriteGraphicsBuffer : public GraphicsDeviceObjectHolder{
00037 friend class SpriteRenderer;
00038 public:
00039     //--------------------------------------------------------------------------
00040     // 描画
00041     //--------------------------------------------------------------------------
00042     /**
00043      * リクエスト
00044      * @param minPosition 最小位置
00045      * @param maxPosition 最大位置
00046      * @param minUV 最小UV
00047      * @param maxUV 最大UV
00048      */
00049     virtual void request(
00050         const Point2f& minPosition, const Point2f& maxPosition,
00051         const TexCoord2& minUV, const TexCoord2& maxUV);
00052 
00053     /**
00054      * レンダリング
00055      */
00056     virtual void render();
00057 
00058     //--------------------------------------------------------------------------
00059     // デバイスオブジェクト
00060     //--------------------------------------------------------------------------
00061     /**
00062      * デバイスオブジェクトの初期化
00063      * @return 成功したらtrueを返す
00064      */
00065     virtual bool initializeGraphicsDeviceObjects(){ return true; }
00066 
00067     /**
00068      * デバイスオブジェクトの削除
00069      */
00070     virtual void deleteGraphicsDeviceObjects(){}
00071 
00072     /**
00073      * デバイスオブジェクトのリストア
00074      * @return 成功したらtrueを返す
00075      */
00076     virtual bool restoreGraphicsDeviceObjects(){ return true; }
00077 
00078     /**
00079      * デバイスオブジェクトの無効化
00080      */
00081     virtual void invalidateGraphicsDeviceObjects(){
00082         SafeRelease(vertexDeclaration_);
00083         SafeRelease(vertexBuffer_);
00084         SafeRelease(indexBuffer_);
00085     }
00086 
00087 protected:
00088     //--------------------------------------------------------------------------
00089     // 生成、破棄
00090     //--------------------------------------------------------------------------
00091     /**
00092      * コンストラクタ
00093      */
00094     SpriteGraphicsBuffer();
00095 
00096     /**
00097      * デストラクタ
00098      */
00099     virtual ~SpriteGraphicsBuffer();
00100 
00101     //--------------------------------------------------------------------------
00102     // 描画
00103     //--------------------------------------------------------------------------
00104     /**
00105      * セットアップ
00106      */
00107     virtual void setup();
00108 
00109     /**
00110      * インデックスバッファの構築
00111      */
00112     virtual void buildIndexBuffer();
00113 
00114 private:
00115     //--------------------------------------------------------------------------
00116     // コピーコンストラクタの隠蔽
00117     SpriteGraphicsBuffer(const SpriteGraphicsBuffer& copy);
00118 
00119     // 代入コピーの隠蔽
00120     void operator =(const SpriteGraphicsBuffer& copy);
00121 
00122     //--------------------------------------------------------------------------
00123     // 定数
00124     //--------------------------------------------------------------------------
00125     // 頂点サイズ
00126     static const int vertexSize_ = (sizeof(Vector3) + sizeof(TexCoord2));
00127     // インデックスサイズ
00128     static const int indexSize_ = sizeof(u_short);
00129     // 最大スプライト数
00130     static const int maxSpriteCount_ = 256;
00131     // スプライトあたりの頂点数
00132     static const int vertexPerSprite_ = 4;
00133     // 頂点バッファサイズ
00134     static const int vertexBufferSize_ = maxSpriteCount_ * vertexPerSprite_;
00135     // スプライト当たりのインデックス数
00136     static const int indexPerSprite_ = 6;
00137     // インデックスバッファサイズ
00138     static const int indexBufferSize_ = maxSpriteCount_ * indexPerSprite_;
00139 
00140     //--------------------------------------------------------------------------
00141 #pragma pack(1)
00142     /// スプライトデータ
00143     class SpriteData{
00144     public:
00145         Vector3 position0;
00146         TexCoord2 uv0;
00147         Vector3 position1;
00148         TexCoord2 uv1;
00149         Vector3 position2;
00150         TexCoord2 uv2;
00151         Vector3 position3;
00152         TexCoord2 uv3;
00153     };
00154 #pragma pack()
00155 
00156     //--------------------------------------------------------------------------
00157     // メンバ
00158     //--------------------------------------------------------------------------
00159     // インデックスバッファ
00160     Direct3DIndexBuffer* indexBuffer_;
00161     // 頂点バッファ
00162     Direct3DVertexBuffer* vertexBuffer_;
00163     // 頂点記述
00164     Direct3DVertexDeclaration* vertexDeclaration_;
00165     // データバッファ
00166     SpriteData dataBuffer_[maxSpriteCount_];
00167     // 先頭インデックス
00168     int topIndex_;
00169     // 末尾インデックス
00170     int bottomIndex_;
00171 
00172 };
00173 
00174 //------------------------------------------------------------------------------
00175 } // End of namespace Lamp
00176 #endif // End of SPRITE_GRAPHICS_BUFFER_H_
00177 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:36 2005 for Lamp by doxygen 1.3.2