driver_opengl_vertex_buffer_hard.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NL_DRIVER_OPENGL_VERTEX_BUFFER_HARD_H
00025 #define NL_DRIVER_OPENGL_VERTEX_BUFFER_HARD_H
00026
00027 #include "nel/misc/types_nl.h"
00028
00029
00030 namespace NL3D
00031 {
00032
00033
00034 class CDriverGL;
00035 class IVertexBufferHardGL;
00036 class CVertexBufferInfo;
00037 class CVertexBufferHardGLMapObjectATI;
00038 class CVertexBufferHardARB;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00054 class IVertexArrayRange
00055 {
00056 public:
00057 IVertexArrayRange(CDriverGL *drv);
00058 virtual ~IVertexArrayRange();
00059
00061 virtual bool allocate(uint32 size, CVertexBuffer::TPreferredMemory vbType)= 0;
00063 virtual void free()= 0;
00065 virtual IVertexBufferHardGL *createVBHardGL(uint size, CVertexBuffer *vb) =0;
00067 virtual uint sizeAllocated() const =0;
00068
00069 virtual void updateLostBuffers() {}
00070
00071 CDriverGL *getDriver() const { return _Driver; }
00072
00073 #ifdef NL_DEBUG
00074 virtual void dumpMappedBuffers() {}
00075 #endif
00076 protected:
00077 CDriverGL *_Driver;
00078 };
00079
00080
00081
00082
00086 class IVertexBufferHardGL
00087 {
00088 public:
00089
00090 IVertexBufferHardGL(CDriverGL *drv, CVertexBuffer *vb);
00091 virtual ~IVertexBufferHardGL();
00092
00093
00094
00095 virtual void *lock() = 0;
00096 virtual void unlock() = 0;
00097 virtual void unlock(uint start, uint end) = 0;
00098 virtual void *getPointer() = 0;
00099
00100 virtual void enable() =0;
00101 virtual void disable() =0;
00102
00103 virtual void setupVBInfos(CVertexBufferInfo &vb) = 0;
00104
00105 enum TVBType { NVidiaVB, ATIVB, ATIMapObjectVB, ARBVB, UnknownVB };
00106
00107 TVBType VBType;
00108
00109 bool GPURenderingAfterFence;
00110
00111
00112 bool isInvalid() { return _Invalid; }
00113
00114 public:
00115
00116 CVertexBuffer *VB;
00117
00118 protected:
00119 CDriverGL *_Driver;
00120 bool _Invalid;
00121 };
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00136 class CVertexArrayRangeNVidia : public IVertexArrayRange
00137 {
00138 public:
00139 CVertexArrayRangeNVidia(CDriverGL *drv);
00140
00141
00143
00145 virtual bool allocate(uint32 size, CVertexBuffer::TPreferredMemory vbType);
00147 virtual void free();
00149 virtual IVertexBufferHardGL *createVBHardGL(uint size, CVertexBuffer *vb);
00151 virtual uint sizeAllocated() const;
00152
00153
00154
00155
00157 void enable();
00159 void disable();
00160
00162 void freeVB(void *ptr);
00163
00164
00165
00166 private:
00167 void *_VertexArrayPtr;
00168 uint32 _VertexArraySize;
00169
00170
00171 NLMISC::CHeapMemory _HeapMemory;
00172
00174 bool allocated() const {return _VertexArrayPtr!=NULL;}
00176 void *allocateVB(uint32 size);
00177
00178 };
00179
00180
00181
00182
00184 class CVertexBufferHardGLNVidia : public IVertexBufferHardGL
00185 {
00186 public:
00187
00188 CVertexBufferHardGLNVidia(CDriverGL *drv, CVertexBuffer *vb);
00189 virtual ~CVertexBufferHardGLNVidia();
00190
00191
00193
00194 virtual void *lock();
00195 virtual void unlock();
00196 virtual void unlock(uint start, uint end);
00197 virtual void *getPointer();
00198 virtual void enable();
00199 virtual void disable();
00200 virtual void lockHintStatic(bool staticLock);
00201 virtual void setupVBInfos(CVertexBufferInfo &vb);
00202
00203
00204
00205
00206 void initGL(CVertexArrayRangeNVidia *var, void *vertexPtr);
00207
00208
00209
00210 bool isFenceSet() const {return _FenceSet;}
00211
00212 void setFence();
00213
00214 void finishFence();
00215
00216 void testFence();
00217
00218 bool getLockHintStatic() const {return _LockHintStatic;}
00219
00220
00221 private:
00222 CVertexArrayRangeNVidia *_VertexArrayRange;
00223 void *_VertexPtr;
00224
00225
00226 GLuint _Fence;
00227
00228 bool _FenceSet;
00229
00230 bool _LockHintStatic;
00231
00232 };
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 #define NL3D_DRV_ATI_FAKE_MEM_START 0x10000
00247
00248
00249
00253 class CVertexArrayRangeATI : public IVertexArrayRange
00254 {
00255 public:
00256 CVertexArrayRangeATI(CDriverGL *drv);
00257
00258
00260
00262 virtual bool allocate(uint32 size, CVertexBuffer::TPreferredMemory vbType);
00264 virtual void free();
00266 virtual IVertexBufferHardGL *createVBHardGL(uint size, CVertexBuffer *vb);
00268 virtual uint sizeAllocated() const;
00269
00270
00271
00272
00276 void enable();
00280 void disable();
00281
00283 void freeVB(void *ptr);
00284
00285
00287 uint getATIVertexObjectId() const {return _VertexObjectId;}
00288
00289
00290 private:
00291 uint _VertexObjectId;
00292 bool _Allocated;
00293 uint32 _VertexArraySize;
00294
00295
00296 NLMISC::CHeapMemory _HeapMemory;
00297
00299 void *allocateVB(uint32 size);
00300
00301 };
00302
00303
00304
00305
00306
00308 class CVertexBufferHardGLATI : public IVertexBufferHardGL
00309 {
00310 public:
00311
00312 CVertexBufferHardGLATI(CDriverGL *drv, CVertexBuffer *vb);
00313 virtual ~CVertexBufferHardGLATI();
00314
00315
00317
00318 virtual void *lock();
00319 virtual void unlock();
00320 virtual void unlock(uint start, uint end);
00321 virtual void *getPointer();
00322 virtual void enable();
00323 virtual void disable();
00324 virtual void lockHintStatic(bool staticLock);
00325 virtual void setupVBInfos(CVertexBufferInfo &vb);
00326
00327
00328
00330 bool createRAMMirror(uint memSize);
00331
00334 void initGL(CVertexArrayRangeATI *var, void *vertexPtr);
00335
00336
00337 public:
00338
00340 uint getATIVertexObjectId() const {return _VertexArrayRange->getATIVertexObjectId();}
00341
00342
00343
00344 private:
00345 CVertexArrayRangeATI *_VertexArrayRange;
00346 void *_VertexPtr;
00347 void *_RAMMirrorVertexPtr;
00348 uint _RAMMirrorVertexSize;
00349
00350 };
00351
00352
00354
00360 class CVertexArrayRangeMapObjectATI : public IVertexArrayRange
00361 {
00362 public:
00363 CVertexArrayRangeMapObjectATI(CDriverGL *drv);
00364
00365
00367
00371 virtual bool allocate(uint32 size, CVertexBuffer::TPreferredMemory vbType);
00373 virtual void free();
00375 virtual IVertexBufferHardGL *createVBHardGL(uint size, CVertexBuffer *vb);
00377 virtual uint sizeAllocated() const { return _SizeAllocated; }
00378
00379
00380
00381
00385 void enable();
00389 void disable();
00390
00391 CVertexBuffer::TPreferredMemory getVBType() const { return _VBType; }
00392
00393
00394 void updateLostBuffers();
00395
00396
00397 #ifdef NL_DEBUG
00398 void dumpMappedBuffers();
00399 #endif
00400
00401
00402 private:
00403 CVertexBuffer::TPreferredMemory _VBType;
00404 uint32 _SizeAllocated;
00405 public:
00406
00407 std::list<CVertexBufferHardGLMapObjectATI *> _LostVBList;
00408 #ifdef NL_DEBUG
00409 std::list<CVertexBufferHardGLMapObjectATI *> _MappedVBList;
00410 #endif
00411 };
00412
00413
00416 class CVertexBufferHardGLMapObjectATI : public IVertexBufferHardGL
00417 {
00418 public:
00419
00420 CVertexBufferHardGLMapObjectATI(CDriverGL *drv, CVertexBuffer *vb);
00421 virtual ~CVertexBufferHardGLMapObjectATI();
00422
00423
00425
00426 virtual void *lock();
00427 virtual void unlock();
00428 virtual void unlock(uint start, uint end);
00429 virtual void *getPointer();
00430 virtual void enable();
00431 virtual void disable();
00432 virtual void lockHintStatic(bool staticLock);
00433 virtual void setupVBInfos(CVertexBufferInfo &vb);
00434
00435
00438 void initGL(CVertexArrayRangeMapObjectATI *var, uint vertexObjectID);
00439
00440
00441 public:
00442
00444 uint getATIVertexObjectId() const { return _VertexObjectId;}
00445
00446
00447
00448 private:
00449 void *_VertexPtr;
00450 CVertexArrayRangeMapObjectATI *_VertexArrayRange;
00451
00452 std::vector<uint8> _DummyVB;
00453
00454 void invalidate();
00455 public:
00456
00457 std::list<CVertexBufferHardGLMapObjectATI *>::iterator _IteratorInLostVBList;
00458 uint _VertexObjectId;
00459
00460 #ifdef NL_DEBUG
00461 bool _Unmapping;
00462 std::list<CVertexBufferHardGLMapObjectATI *>::iterator _IteratorInMappedVBList;
00463 #endif
00464 };
00465
00466
00467
00468
00469
00470
00471 class CVertexArrayRangeARB : public IVertexArrayRange
00472 {
00473 public:
00474 CVertexArrayRangeARB(CDriverGL *drv);
00475
00476
00478
00482 virtual bool allocate(uint32 size, CVertexBuffer::TPreferredMemory vbType);
00484 virtual void free();
00486 virtual IVertexBufferHardGL *createVBHardGL(uint size, CVertexBuffer *vb);
00488 virtual uint sizeAllocated() const { return _SizeAllocated; }
00489
00490
00491
00492
00496 void enable();
00500 void disable();
00501
00502 void updateLostBuffers();
00503
00504 #ifdef NL_DEBUG
00505 virtual void dumpMappedBuffers();
00506 #endif
00507
00508 private:
00509 CVertexBuffer::TPreferredMemory _VBType;
00510 uint32 _SizeAllocated;
00511
00512 public:
00513 std::list<CVertexBufferHardARB *> _LostVBList;
00514 #ifdef NL_DEBUG
00515 std::list<CVertexBufferHardARB *> _MappedVBList;
00516 #endif
00517 };
00518
00519
00522 class CVertexBufferHardARB : public IVertexBufferHardGL
00523 {
00524 public:
00525
00526 CVertexBufferHardARB(CDriverGL *drv, CVertexBuffer *vb);
00527 virtual ~CVertexBufferHardARB();
00528
00529
00531
00532 virtual void *lock();
00533 virtual void unlock();
00534 virtual void unlock(uint startVert, uint endVert);
00535 virtual void *getPointer();
00536 virtual void enable();
00537 virtual void disable();
00538 virtual void lockHintStatic(bool staticLock);
00539 virtual void setupVBInfos(CVertexBufferInfo &vb);
00540
00541
00544 void initGL(uint vertexObjectID, CVertexArrayRangeARB *var, CVertexBuffer::TPreferredMemory memType);
00545
00546
00547 public:
00548
00550 uint getARBVertexObjectId() const { return _VertexObjectId;}
00551
00552
00553 void invalidate();
00554
00555
00556 void checkMappedVBList();
00557
00558
00559 private:
00560 CVertexArrayRangeARB *_VertexArrayRange;
00561 CVertexBuffer::TPreferredMemory _MemType;
00562 void *_VertexPtr;
00563
00564 std::vector<uint8> _DummyVB;
00565
00566 std::list<CVertexBufferHardARB *>::iterator _IteratorInLostVBList;
00567 public:
00568 uint _VertexObjectId;
00569
00570 #ifdef NL_DEBUG
00571 bool _Unmapping;
00572 std::list<CVertexBufferHardARB *>::iterator _IteratorInMappedVBList;
00573 #endif
00574 };
00575
00576
00577 }
00578
00579
00580 #endif // NL_DRIVER_OPENGL_VERTEX_BUFFER_HARD_H
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603