OLD | NEW |
1 // | 1 // |
2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. | 2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 // | 5 // |
6 | 6 |
7 // VertexDataManager.h: Defines the VertexDataManager, a class that | 7 // VertexDataManager.h: Defines the VertexDataManager, a class that |
8 // runs the Buffer translation process. | 8 // runs the Buffer translation process. |
9 | 9 |
10 #include "libGLESv2/VertexDataManager.h" | 10 #include "libGLESv2/VertexDataManager.h" |
11 | 11 |
12 #include "common/debug.h" | 12 #include "common/debug.h" |
13 | 13 |
14 #include "libGLESv2/Buffer.h" | 14 #include "libGLESv2/Buffer.h" |
15 #include "libGLESv2/Program.h" | 15 #include "libGLESv2/Program.h" |
16 #include "libGLESv2/main.h" | 16 #include "libGLESv2/main.h" |
17 | 17 |
18 #include "libGLESv2/vertexconversion.h" | 18 #include "libGLESv2/vertexconversion.h" |
19 #include "libGLESv2/IndexDataManager.h" | 19 #include "libGLESv2/IndexDataManager.h" |
20 | 20 |
21 namespace | 21 namespace |
22 { | 22 { |
23 enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; | 23 enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; |
24 } | 24 } |
25 | 25 |
26 namespace gl | 26 namespace gl |
27 { | 27 { |
28 | 28 |
29 VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device)
: mContext(context), mDevice(device) | 29 VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device)
: mContext(context), mDevice(device), mMaxLru(0) |
30 { | 30 { |
31 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) | 31 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
32 { | 32 { |
33 mDirtyCurrentValue[i] = true; | 33 mDirtyCurrentValue[i] = true; |
34 mCurrentValueBuffer[i] = NULL; | 34 mCurrentValueBuffer[i] = NULL; |
35 } | 35 } |
| 36 for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 37 { |
| 38 mVertexDeclCache[i].vertexDeclaration = NULL; |
| 39 mVertexDeclCache[i].lruCount = 0; |
| 40 } |
36 | 41 |
37 const D3DCAPS9 &caps = context->getDeviceCaps(); | 42 const D3DCAPS9 &caps = context->getDeviceCaps(); |
38 checkVertexCaps(caps.DeclTypes); | 43 checkVertexCaps(caps.DeclTypes); |
39 | 44 |
40 mStreamingBuffer = new StreamingVertexBuffer(mDevice, INITIAL_STREAM_BUFFER_
SIZE); | 45 mStreamingBuffer = new StreamingVertexBuffer(mDevice, INITIAL_STREAM_BUFFER_
SIZE); |
41 } | 46 } |
42 | 47 |
43 VertexDataManager::~VertexDataManager() | 48 VertexDataManager::~VertexDataManager() |
44 { | 49 { |
45 delete mStreamingBuffer; | 50 delete mStreamingBuffer; |
46 | 51 |
47 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) | 52 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
48 { | 53 { |
49 delete mCurrentValueBuffer[i]; | 54 delete mCurrentValueBuffer[i]; |
50 } | 55 } |
| 56 for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 57 { |
| 58 if (mVertexDeclCache[i].vertexDeclaration) |
| 59 { |
| 60 mVertexDeclCache[i].vertexDeclaration->Release(); |
| 61 } |
| 62 } |
51 } | 63 } |
52 | 64 |
53 UINT VertexDataManager::writeAttributeData(ArrayVertexBuffer *vertexBuffer, GLin
t start, GLsizei count, const VertexAttribute &attribute) | 65 UINT VertexDataManager::writeAttributeData(ArrayVertexBuffer *vertexBuffer, GLin
t start, GLsizei count, const VertexAttribute &attribute) |
54 { | 66 { |
55 Buffer *buffer = attribute.mBoundBuffer.get(); | 67 Buffer *buffer = attribute.mBoundBuffer.get(); |
56 | 68 |
57 int inputStride = attribute.stride(); | 69 int inputStride = attribute.stride(); |
58 int elementSize = attribute.typeSize(); | 70 int elementSize = attribute.typeSize(); |
59 const FormatConverter &converter = formatConverter(attribute); | 71 const FormatConverter &converter = formatConverter(attribute); |
60 UINT streamOffset = 0; | 72 UINT streamOffset = 0; |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 case GL_UNSIGNED_SHORT: return 3; | 514 case GL_UNSIGNED_SHORT: return 3; |
503 case GL_FIXED: return 4; | 515 case GL_FIXED: return 4; |
504 case GL_FLOAT: return 5; | 516 case GL_FLOAT: return 5; |
505 | 517 |
506 default: UNREACHABLE(); return 5; | 518 default: UNREACHABLE(); return 5; |
507 } | 519 } |
508 } | 520 } |
509 | 521 |
510 void VertexDataManager::setupAttributes(const TranslatedAttribute *attributes) | 522 void VertexDataManager::setupAttributes(const TranslatedAttribute *attributes) |
511 { | 523 { |
512 D3DVERTEXELEMENT9 elements[MAX_VERTEX_ATTRIBS]; | 524 D3DVERTEXELEMENT9 elements[MAX_VERTEX_ATTRIBS + 1]; |
513 D3DVERTEXELEMENT9 *element = &elements[0]; | 525 D3DVERTEXELEMENT9 *element = &elements[0]; |
514 | 526 |
515 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) | 527 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
516 { | 528 { |
517 if (attributes[i].active) | 529 if (attributes[i].active) |
518 { | 530 { |
519 mDevice->SetStreamSource(i, attributes[i].vertexBuffer, attributes[i
].offset, attributes[i].stride); | 531 mDevice->SetStreamSource(i, attributes[i].vertexBuffer, attributes[i
].offset, attributes[i].stride); |
520 | 532 |
521 element->Stream = i; | 533 element->Stream = i; |
522 element->Offset = 0; | 534 element->Offset = 0; |
523 element->Type = attributes[i].type; | 535 element->Type = attributes[i].type; |
524 element->Method = D3DDECLMETHOD_DEFAULT; | 536 element->Method = D3DDECLMETHOD_DEFAULT; |
525 element->Usage = D3DDECLUSAGE_TEXCOORD; | 537 element->Usage = D3DDECLUSAGE_TEXCOORD; |
526 element->UsageIndex = attributes[i].semanticIndex; | 538 element->UsageIndex = attributes[i].semanticIndex; |
527 element++; | 539 element++; |
528 } | 540 } |
529 } | 541 } |
530 | 542 |
531 static const D3DVERTEXELEMENT9 end = D3DDECL_END(); | 543 static const D3DVERTEXELEMENT9 end = D3DDECL_END(); |
532 *element = end; | 544 *(element++) = end; |
533 | 545 |
534 IDirect3DVertexDeclaration9 *vertexDeclaration; | 546 for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
535 mDevice->CreateVertexDeclaration(elements, &vertexDeclaration); | 547 { |
536 mDevice->SetVertexDeclaration(vertexDeclaration); | 548 VertexDeclCacheEntry *entry = &mVertexDeclCache[i]; |
537 vertexDeclaration->Release(); | 549 if (memcmp(entry->cachedElements, elements, (element - elements) * sizeo
f(D3DVERTEXELEMENT9)) == 0 && entry->vertexDeclaration) |
| 550 { |
| 551 entry->lruCount = ++mMaxLru; |
| 552 mDevice->SetVertexDeclaration(entry->vertexDeclaration); |
| 553 return; |
| 554 } |
| 555 } |
| 556 |
| 557 VertexDeclCacheEntry *lastCache = mVertexDeclCache; |
| 558 |
| 559 for (int i = 0; i < NUM_VERTEX_DECL_CACHE_ENTRIES; i++) |
| 560 { |
| 561 if (mVertexDeclCache[i].lruCount < lastCache->lruCount) |
| 562 { |
| 563 lastCache = &mVertexDeclCache[i]; |
| 564 } |
| 565 } |
| 566 |
| 567 if (lastCache->vertexDeclaration != NULL) |
| 568 { |
| 569 lastCache->vertexDeclaration->Release(); |
| 570 lastCache->vertexDeclaration = NULL; |
| 571 } |
| 572 |
| 573 memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3
DVERTEXELEMENT9)); |
| 574 mDevice->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration); |
| 575 mDevice->SetVertexDeclaration(lastCache->vertexDeclaration); |
| 576 lastCache->lruCount = ++mMaxLru; |
538 } | 577 } |
539 | 578 |
540 VertexBuffer::VertexBuffer(IDirect3DDevice9 *device, std::size_t size, DWORD usa
geFlags) : mDevice(device), mVertexBuffer(NULL) | 579 VertexBuffer::VertexBuffer(IDirect3DDevice9 *device, std::size_t size, DWORD usa
geFlags) : mDevice(device), mVertexBuffer(NULL) |
541 { | 580 { |
542 if (size > 0) | 581 if (size > 0) |
543 { | 582 { |
544 D3DPOOL pool = getDisplay()->getBufferPool(usageFlags); | 583 D3DPOOL pool = getDisplay()->getBufferPool(usageFlags); |
545 HRESULT result = device->CreateVertexBuffer(size, usageFlags, 0, pool, &
mVertexBuffer, NULL); | 584 HRESULT result = device->CreateVertexBuffer(size, usageFlags, 0, pool, &
mVertexBuffer, NULL); |
546 ········ | 585 ········ |
547 if (FAILED(result)) | 586 if (FAILED(result)) |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 } | 799 } |
761 | 800 |
762 return -1; | 801 return -1; |
763 } | 802 } |
764 | 803 |
765 const VertexDataManager::FormatConverter &VertexDataManager::formatConverter(con
st VertexAttribute &attribute) const | 804 const VertexDataManager::FormatConverter &VertexDataManager::formatConverter(con
st VertexAttribute &attribute) const |
766 { | 805 { |
767 return mAttributeTypes[typeIndex(attribute.mType)][attribute.mNormalized][at
tribute.mSize - 1]; | 806 return mAttributeTypes[typeIndex(attribute.mType)][attribute.mNormalized][at
tribute.mSize - 1]; |
768 } | 807 } |
769 } | 808 } |
OLD | NEW |