Home | History | Annotate | Download | only in d3d
      1 //
      2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 // BufferD3D.cpp Defines common functionality between the Buffer9 and Buffer11 classes.
      8 
      9 #include "libGLESv2/renderer/d3d/BufferD3D.h"
     10 #include "libGLESv2/renderer/d3d/VertexBuffer.h"
     11 #include "libGLESv2/renderer/d3d/IndexBuffer.h"
     12 #include "libGLESv2/renderer/Renderer.h"
     13 #include "libGLESv2/main.h"
     14 
     15 namespace rx
     16 {
     17 
     18 unsigned int BufferD3D::mNextSerial = 1;
     19 
     20 BufferD3D::BufferD3D()
     21     : BufferImpl(),
     22       mStaticVertexBuffer(NULL),
     23       mStaticIndexBuffer(NULL)
     24 {
     25     updateSerial();
     26 }
     27 
     28 BufferD3D::~BufferD3D()
     29 {
     30     SafeDelete(mStaticVertexBuffer);
     31     SafeDelete(mStaticIndexBuffer);
     32 }
     33 
     34 BufferD3D *BufferD3D::makeBufferD3D(BufferImpl *buffer)
     35 {
     36     ASSERT(HAS_DYNAMIC_TYPE(BufferD3D*, buffer));
     37     return static_cast<BufferD3D*>(buffer);
     38 }
     39 
     40 void BufferD3D::updateSerial()
     41 {
     42     mSerial = mNextSerial++;
     43 }
     44 
     45 void BufferD3D::initializeStaticData()
     46 {
     47     if (!mStaticVertexBuffer)
     48     {
     49         mStaticVertexBuffer = new rx::StaticVertexBufferInterface(getRenderer());
     50     }
     51     if (!mStaticIndexBuffer)
     52     {
     53         mStaticIndexBuffer = new rx::StaticIndexBufferInterface(getRenderer());
     54     }
     55 }
     56 
     57 void BufferD3D::invalidateStaticData()
     58 {
     59     if ((mStaticVertexBuffer && mStaticVertexBuffer->getBufferSize() != 0) || (mStaticIndexBuffer && mStaticIndexBuffer->getBufferSize() != 0))
     60     {
     61         SafeDelete(mStaticVertexBuffer);
     62         SafeDelete(mStaticIndexBuffer);
     63     }
     64 
     65     mUnmodifiedDataUse = 0;
     66 }
     67 
     68 // Creates static buffers if sufficient used data has been left unmodified
     69 void BufferD3D::promoteStaticUsage(int dataSize)
     70 {
     71     if (!mStaticVertexBuffer && !mStaticIndexBuffer)
     72     {
     73         mUnmodifiedDataUse += dataSize;
     74 
     75         if (mUnmodifiedDataUse > 3 * getSize())
     76         {
     77             initializeStaticData();
     78         }
     79     }
     80 }
     81 
     82 }