summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/null/GfxNullVBO.cpp
blob: b624160cd6e2838fd9fb622361b38d0857e28607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "UnityPrefix.h"
#include "Runtime/Shaders/VBO.h"
#include "GfxNullVBO.h"
#include "Runtime/GfxDevice/GfxDevice.h"



void GfxNullVBO::UpdateVertexData( const VertexBufferData& buffer )
{
	BufferAccessibleVertexData(buffer);
		}

void GfxNullVBO::UpdateIndexData (const IndexBufferData& buffer)
{
}

void GfxNullVBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount )
{
}
#if GFX_ENABLE_DRAW_CALL_BATCHING
	void GfxNullVBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount,
								   GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount )
	{
	}
#endif


bool GfxDynamicNullVBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB )
{
	AssertIf(this->m_LendedChunk);
	AssertIf((maxVertices >= 65536) || (maxIndices >= (65536 * 3)));
	bool indexed = IsIndexed(renderMode);
	DebugAssertIf(indexed && (outIB == NULL));
	DebugAssertIf(!indexed && ((maxIndices != 0) || (outIB != NULL)));
	
	this->m_LendedChunk = true;
	this->m_LastChunkShaderChannelMask = shaderChannelMask;
	this->m_LastRenderMode = renderMode;

	if (maxVertices == 0)
	{
		maxVertices = 8;
	}
	
	this->m_LastChunkStride = 0;

	for (int i = 0; i < kShaderChannelCount; ++i)
	{
		if (shaderChannelMask & (1 << i))
		{
			this->m_LastChunkStride += GfxNullVBO::GetDefaultChannelByteSize(i);
		}
	}

	//

	DebugAssertIf(NULL == outVB);

	UInt32 vbCapacity = (maxVertices * this->m_LastChunkStride);

	if (vbCapacity > this->vertexBufferSize)
	{
		delete[] this->vertexBuffer;
		this->vertexBuffer = new UInt8[vbCapacity];
		this->vertexBufferSize = vbCapacity;
	}

	*outVB = this->vertexBuffer;

	//
	
	if (maxIndices && indexed)
	{
		UInt32 ibCapacity = maxIndices * kVBOIndexSize;

		if (ibCapacity > this->indexBufferSize)
		{
			delete[] this->indexBuffer;
			this->indexBuffer = new UInt8[ibCapacity];
			this->indexBufferSize = ibCapacity;
		}

		*outIB = this->indexBuffer;
	}

	//

	return true;
}

void GfxDynamicNullVBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices )
{
	AssertIf(!m_LendedChunk);
	this->m_LendedChunk = false;
	
	this->m_LastChunkVertices = actualVertices;
	this->m_LastChunkIndices = actualIndices;
	
	if (!actualVertices || (IsIndexed(m_LastRenderMode) && !actualIndices))
	{
		this->m_LastChunkShaderChannelMask = 0;
	}
}

void GfxDynamicNullVBO::DrawChunk (const ChannelAssigns& channels)
{
}