00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00050
00051 PrimitiveDrawRequest(const PrimitiveDrawRequest& copy);
00052
00053
00054
00055
00056
00057 PrimitiveDrawRequest& operator =(const PrimitiveDrawRequest& copy);
00058
00059
00060
00061
00062 virtual ~PrimitiveDrawRequest();
00063
00064
00065
00066
00067
00068
00069
00070
00071 virtual void setVertexCount(int vertexCount);
00072
00073
00074
00075
00076
00077 virtual int getVertexCount() const{ return data_->vertexCount_; }
00078
00079
00080
00081
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
00094
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
00105
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
00115
00116 virtual const Vector3* getPositionArray() const{ return data_->positions_; }
00117
00118
00119
00120
00121
00122
00123
00124
00125 virtual void enableColor(bool colorFlag);
00126
00127
00128
00129
00130
00131 virtual bool hasColor() const{ return (data_->colors_ != NULL); }
00132
00133
00134
00135
00136
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
00148
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
00159
00160 virtual const Color4c* getColorArray() const{ return data_->colors_; }
00161
00162
00163
00164
00165
00166
00167
00168
00169 virtual bool hasVertexIndices() const{
00170 return (data_->vertexIndexCount_ != 0);
00171 }
00172
00173
00174
00175
00176
00177 virtual void setVertexIndexCount(int vertexIndexCount);
00178
00179
00180
00181
00182
00183 virtual int getVertexIndexCount() const{ return data_->vertexIndexCount_; }
00184
00185
00186
00187
00188
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
00200
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
00211
00212 virtual const u_short* getVertexIndexArray(){
00213 return data_->vertexIndices_;
00214 }
00215
00216 private:
00217
00218
00219
00220
00221
00222 virtual int removeReference();
00223
00224
00225
00226
00227
00228
00229 Direct3DVertexBuffer* getVertexBuffer();
00230
00231
00232
00233
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
00272
00273 virtual bool initializeGraphicsDeviceObjects(){ return true; }
00274
00275
00276
00277
00278 virtual void deleteGraphicsDeviceObjects(){}
00279
00280
00281
00282
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 }
00328 #endif // End of PRIMITIVE_DRAW_REQUEST_H_
00329