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

PrimitiveDrawRequest.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 PRIMITIVE_DRAW_REQUEST_H_
00026 #define PRIMITIVE_DRAW_REQUEST_H_
00027 
00028 #include <Graphics/System/GraphicsDeviceObjectHolder.h>
00029 
00030 namespace Lamp{
00031 
00032 //------------------------------------------------------------------------------
00033 /**
00034  * プリミティブ描画リクエスト
00035  */
00036 class PrimitiveDrawRequest{
00037 friend class PrimitiveRenderer;
00038 public:
00039     //--------------------------------------------------------------------------
00040     // 生成、破棄
00041     //--------------------------------------------------------------------------
00042     /**
00043      * コンストラクタ
00044      */
00045     PrimitiveDrawRequest();
00046 
00047     /**
00048      * コピーコンストラクタ
00049      * @param copy コピー元
00050      */
00051     PrimitiveDrawRequest(const PrimitiveDrawRequest& copy);
00052 
00053     /**
00054      * 代入コピー
00055      * @param copy コピー元
00056      */
00057     PrimitiveDrawRequest& operator =(const PrimitiveDrawRequest& copy);
00058 
00059     /**
00060      * デストラクタ
00061      */
00062     virtual ~PrimitiveDrawRequest();
00063 
00064     //--------------------------------------------------------------------------
00065     // 頂点数
00066     //--------------------------------------------------------------------------
00067     /**
00068      * 頂点数の設定
00069      * @param vertexCount 頂点数
00070      */
00071     virtual void setVertexCount(int vertexCount);
00072 
00073     /**
00074      * 頂点数の取得
00075      * @return 頂点数
00076      */
00077     virtual int getVertexCount() const{ return data_->vertexCount_; }
00078 
00079     /**
00080      * 頂点サイズの取得
00081      * @return 頂点サイズ
00082      */
00083     virtual int getVertexSize() const{
00084         if(hasColor()){ return sizeof(Vector3) + sizeof(Color4c); }
00085         else{ return sizeof(Vector3); }
00086     }
00087 
00088     //--------------------------------------------------------------------------
00089     // 位置
00090     //--------------------------------------------------------------------------
00091     /**
00092      * 位置の設定
00093      * @param index インデックス
00094      * @param position 位置
00095      */
00096     virtual void setPosition(int index, const Vector3& position){
00097         Assert((index >= 0) && (index < data_->vertexCount_));
00098         data_->positions_[index] = position;
00099         data_->vertexBufferChanged_ = true;
00100     }
00101 
00102     /**
00103      * 位置の取得
00104      * @param index インデックス
00105      * @return 位置
00106      */
00107     virtual const Vector3& getPosition(int index) const{
00108         Assert((index >= 0) && (index < data_->vertexCount_));
00109         return data_->positions_[index];
00110     }
00111 
00112     /**
00113      * 位置配列の取得
00114      * @return 位置配列
00115      */
00116     virtual const Vector3* getPositionArray() const{ return data_->positions_; }
00117 
00118     //--------------------------------------------------------------------------
00119     // カラー
00120     //--------------------------------------------------------------------------
00121     /**
00122      * カラーを有効にするかどうか
00123      * @param colorFlag trueならカラーが有効になる
00124      */
00125     virtual void enableColor(bool colorFlag);
00126 
00127     /**
00128      * カラーを持つか
00129      * @return カラーを持つならtrue
00130      */
00131     virtual bool hasColor() const{ return (data_->colors_ != NULL); }
00132 
00133     /**
00134      * カラーの設定
00135      * @param index インデックス
00136      * @param color カラー
00137      */
00138     virtual void setColor(int index, const Color4c& color){
00139         Assert(hasColor());
00140         Assert((index >= 0) && (index < data_->vertexCount_));
00141         data_->colors_[index] = color;
00142         data_->vertexBufferChanged_ = true;
00143     }
00144 
00145     /**
00146      * カラーの取得
00147      * @param index インデックス
00148      * @return カラー
00149      */
00150     virtual const Color4c& getColor(int index) const{
00151         Assert(hasColor());
00152         Assert((index >= 0) && (index < data_->vertexCount_));
00153         return data_->colors_[index];
00154     }
00155 
00156     /**
00157      * カラー配列の取得
00158      * @return カラー配列
00159      */
00160     virtual const Color4c* getColorArray() const{ return data_->colors_; }
00161 
00162     //--------------------------------------------------------------------------
00163     // インデックス
00164     //--------------------------------------------------------------------------
00165     /**
00166      * 頂点インデックスを持つかどうか
00167      * @return 頂点インデックスを持つならtrue
00168      */
00169     virtual bool hasVertexIndices() const{
00170         return (data_->vertexIndexCount_ != 0);
00171     }
00172 
00173     /**
00174      * 頂点インデックス数の設定
00175      * @param vertexIndexCount 頂点インデックス数
00176      */
00177     virtual void setVertexIndexCount(int vertexIndexCount);
00178 
00179     /**
00180      * 頂点インデックス数の取得
00181      * @return 頂点インデックス数
00182      */
00183     virtual int getVertexIndexCount() const{ return data_->vertexIndexCount_; }
00184 
00185     /**
00186      * 頂点インデックスの設定
00187      * @param index インデックス
00188      * @param vertexIndex 頂点インデックス
00189      */
00190     virtual void setVertexIndex(int index, u_short vertexIndex){
00191         Assert(hasVertexIndices());
00192         Assert((index >= 0) && (index < getVertexIndexCount()));
00193         data_->vertexIndices_[index] = vertexIndex;
00194         data_->indexBufferChanged_ = true;
00195     }
00196 
00197     /**
00198      * 頂点インデックスの取得
00199      * @param index インデックス
00200      * @return 頂点インデックス
00201      */
00202     virtual u_short getVertexIndex(int index) const{
00203         Assert(hasVertexIndices());
00204         Assert((index >= 0) && (index < getVertexIndexCount()));
00205         return data_->vertexIndices_[index];
00206     }
00207 
00208     /**
00209      * 頂点インデックス配列の取得
00210      * @return 頂点インデックス配列
00211      */
00212     virtual const u_short* getVertexIndexArray(){
00213         return data_->vertexIndices_;
00214     }
00215 
00216 private:
00217     //--------------------------------------------------------------------------
00218     /**
00219      * リファレンスの削除
00220      * @return リファレンスカウント
00221      */
00222     virtual int removeReference();
00223 
00224     //--------------------------------------------------------------------------
00225     /**
00226      * 頂点バッファの取得
00227      * @return 頂点バッファ
00228      */
00229     Direct3DVertexBuffer* getVertexBuffer();
00230 
00231     /**
00232      * インデックスバッファの取得
00233      * @return インデックスバッファ
00234      */
00235     Direct3DIndexBuffer* getIndexBuffer();
00236 
00237     //--------------------------------------------------------------------------
00238     /**
00239      * データ
00240      */
00241     class Data : public GraphicsDeviceObjectHolder{
00242     friend class PrimitiveDrawRequest;
00243     private:
00244         //----------------------------------------------------------------------
00245         /**
00246          * コンストラクタ
00247          */
00248         Data();
00249 
00250         /**
00251          * デストラクタ
00252          */
00253         virtual ~Data();
00254 
00255         //----------------------------------------------------------------------
00256         // リファレンスの追加
00257         virtual int addReference(){
00258             referenceCount_++;
00259             return referenceCount_;
00260         }
00261 
00262         // リファレンスの削除
00263         virtual int removeReference(){
00264             referenceCount_--;
00265             return referenceCount_;
00266         }
00267 
00268         //----------------------------------------------------------------------
00269         /**
00270          * デバイスオブジェクトの初期化
00271          * @return 成功したらtrueを返す
00272          */
00273         virtual bool initializeGraphicsDeviceObjects(){ return true; }
00274 
00275         /**
00276          * デバイスオブジェクトの削除
00277          */
00278         virtual void deleteGraphicsDeviceObjects(){}
00279 
00280         /**
00281          * デバイスオブジェクトのリストア
00282          * @return 成功したらtrueを返す
00283          */
00284         virtual bool restoreGraphicsDeviceObjects(){ return true; }
00285 
00286         /**
00287          * デバイスオブジェクトの無効化
00288          */
00289         virtual void invalidateGraphicsDeviceObjects(){
00290             SafeRelease(indexBuffer_);
00291             SafeRelease(vertexBuffer_);
00292         }
00293 
00294         //----------------------------------------------------------------------
00295         // 頂点数
00296         int vertexCount_;
00297         // 位置
00298         Vector3* positions_;
00299         // カラー
00300         Color4c* colors_;
00301         // 頂点インデックス数
00302         int vertexIndexCount_;
00303         // 頂点インデックス
00304         u_short* vertexIndices_;
00305         // 頂点バッファ
00306         Direct3DVertexBuffer* vertexBuffer_;
00307         // インデックスバッファ
00308         Direct3DIndexBuffer* indexBuffer_;
00309         // リファレンスカウント
00310         int referenceCount_;
00311         // 頂点バッファに変更があった
00312         bool vertexBufferChanged_;
00313         // インデックスバッファに変更があった
00314         bool indexBufferChanged_;
00315 
00316     };
00317 
00318     //--------------------------------------------------------------------------
00319     // メンバ変数
00320     //--------------------------------------------------------------------------
00321     /// データ
00322     Data* data_;
00323 
00324 };
00325 
00326 //------------------------------------------------------------------------------
00327 } // End of namespace Lamp
00328 #endif // End of PRIMITIVE_DRAW_REQUEST_H_
00329 //------------------------------------------------------------------------------

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