BVB Source Codes

CRYENGINE Show ParticleRenderImpl.h Source code

Return Download CRYENGINE: download ParticleRenderImpl.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  Created:     04/05/2015 by Filipe amim
  5. //  Description:
  6. // -------------------------------------------------------------------------
  7. //
  8. ////////////////////////////////////////////////////////////////////////////
  9.  
  10. namespace pfx2
  11. {
  12.  
  13. ILINE void CopyToVideoMemory(void* pDst, void* pSrc, uint32 size)
  14. {
  15.         //      assert(((uintptr_t)pDst & 127) == ((uintptr_t)pSrc & 127));
  16.         memcpy(pDst, pSrc, size);
  17. }
  18.  
  19. template<class T, uint bufferSize, uint chunckSize>
  20. ILINE CWriteCombinedBuffer<T, bufferSize, chunckSize>::CWriteCombinedBuffer(FixedDynArray<T>& destMem)
  21.         : m_pDestMem(&destMem)
  22.         , m_pDestMemBegin((byte*)destMem.begin())
  23.         , m_flushedBytes(0)
  24.         , m_writtenDestBytes(0)
  25. {
  26.         uint alignOffset = alias_cast<uint>(m_pDestMemBegin - (byte*)m_srcBuffer) & (CRY_PFX2_PARTICLES_ALIGNMENT - 1);
  27.         m_pSrcMemBegin = m_srcBuffer + alignOffset;
  28.         int capacity = (sizeof(m_srcBuffer) - alignOffset) / sizeof(T);
  29.         capacity = min(capacity, destMem.capacity());
  30.         m_srcArray.set(ArrayT((T*)m_pSrcMemBegin, capacity));
  31. }
  32.  
  33. template<class T, uint bufferSize, uint chunckSize>
  34. ILINE CWriteCombinedBuffer<T, bufferSize, chunckSize>::~CWriteCombinedBuffer()
  35. {
  36.         // Write remaining data.
  37.         FlushData(UnflushedBytes());
  38.  
  39.         // Set final count of elems written to dest buffer.
  40.         //      CRY_PFX2_ASSERT(m_writtenDestBytes % sizeof(T) == 0);
  41.         m_pDestMem->resize(m_writtenDestBytes / sizeof(T), eNoInit);
  42. }
  43.  
  44. template<class T, uint bufferSize, uint chunckSize>
  45. ILINE FixedDynArray<T>& CWriteCombinedBuffer<T, bufferSize, chunckSize >::Array()
  46. {
  47.         return m_srcArray;
  48. }
  49.  
  50. template<class T, uint bufferSize, uint chunckSize>
  51. ILINE T* CWriteCombinedBuffer<T, bufferSize, chunckSize >::CheckAvailable(int elems)
  52. {
  53.         // Transfer data chunks no longer needed
  54.         uint unflushedBytes = UnflushedBytes();
  55.         if (unflushedBytes >= chunckSize)
  56.                 FlushData(unflushedBytes & ~(chunckSize - 1));
  57.  
  58.         // If buffer is too full for new elements, clear out flushed data.
  59.         if (m_srcArray.available() < elems)
  60.         {
  61.                 WrapBuffer();
  62.                 if (m_srcArray.available() < elems)
  63.                         return 0;
  64.         }
  65.         return m_srcArray.end();
  66. }
  67.  
  68. template<class T, uint bufferSize, uint chunckSize>
  69. ILINE uint CWriteCombinedBuffer<T, bufferSize, chunckSize >::UnflushedBytes() const
  70. {
  71.         return check_cast<uint>((byte*)m_srcArray.end() - m_pSrcMemBegin - m_flushedBytes);
  72. }
  73.  
  74. template<class T, uint bufferSize, uint chunckSize>
  75. ILINE void CWriteCombinedBuffer<T, bufferSize, chunckSize >::FlushData(uint flushBytes)
  76. {
  77.         if (flushBytes)
  78.         {
  79.                 //              CRY_PFX2_ASSERT(m_writtenDestBytes + flushBytes <= m_pDestMem->capacity() * sizeof(T));
  80.                 CopyToVideoMemory(
  81.                   m_pDestMemBegin + m_writtenDestBytes,
  82.                   m_pSrcMemBegin + m_flushedBytes,
  83.                   flushBytes);
  84.                 m_writtenDestBytes += flushBytes;
  85.                 m_flushedBytes += flushBytes;
  86.         }
  87. }
  88.  
  89. template<class T, uint bufferSize, uint chunckSize>
  90. ILINE void CWriteCombinedBuffer<T, bufferSize, chunckSize >::WrapBuffer()
  91. {
  92.         // Copy unflushed bytes to the buffer beginning
  93.         uint unflushedBytes = UnflushedBytes();
  94.         memcpy(m_pSrcMemBegin, m_pSrcMemBegin + m_flushedBytes, unflushedBytes);
  95.         uint availableBytes = check_cast<uint>(m_srcBuffer + sizeof(m_srcBuffer) - m_pSrcMemBegin - unflushedBytes);
  96.         availableBytes = min(availableBytes, m_pDestMem->capacity() * (uint)sizeof(T) - m_writtenDestBytes - unflushedBytes);
  97.         m_srcArray.set(ArrayT((T*)(m_pSrcMemBegin + unflushedBytes), int(availableBytes / sizeof(T))));
  98.         m_flushedBytes = 0;
  99. }
  100.  
  101. }
  102.  
downloadParticleRenderImpl.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top