summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/null/GfxDeviceNull.cpp
blob: 4981f54806ab9a8ffeadefa71b4b464e2ab4baa2 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include "UnityPrefix.h"
#include "GfxDeviceNull.h"
#include "Runtime/Shaders/GraphicsCaps.h"
#include "Runtime/Graphics/RenderSurface.h"
#include "GfxNullVBO.h"
#include "Runtime/GfxDevice/GfxDeviceWindow.h"
#include "External/shaderlab/Library/program.h"


static DeviceBlendState g_NullBlendState;
static DeviceDepthState g_NullDepthState;
static DeviceStencilState g_NullStencilState;
static DeviceRasterState g_NullRasterState;

static float g_NullWorldMatrix[16];
static float g_NullViewMatrix[16];
static float g_NullProjectionMatrix[16];

static RenderSurfaceBase	_ColorDefaultSurface;
static RenderSurfaceBase	_DepthDefaultSurface;


void GraphicsCaps::InitNull(void)
{
	rendererString = "Null Device";
	vendorString = "Unity Technologies";
	driverVersionString = "1.0";
	fixedVersionString = "NULL 1.0 [1.0]";
	driverLibraryString = "(null)";
	videoMemoryMB = 64.0f;
	rendererID = 0;
	vendorID = 0;

	printf_console( "NullGfxDevice:\n" );
	printf_console( "    Version:  %s\n", fixedVersionString.c_str() );
	printf_console( "    Renderer: %s\n", rendererString.c_str() );
	printf_console( "    Vendor:   %s\n", vendorString.c_str() );

	shaderCaps = kShaderLevel2;

	maxLights = 8;
	hasAnisoFilter = false;
	maxAnisoLevel = 0;
	hasMipLevelBias = false;

	hasMultiSample = false;

	hasBlendSquare = false;
	hasSeparateAlphaBlend = false;

	hasS3TCCompression = false;

	hasAutoMipMapGeneration = false;

	maxTexImageUnits = 2;
	maxTexCoords = 2;


	maxTexUnits = 2;

	maxTextureSize = 1024;
	maxCubeMapSize = 0;
	maxRenderTextureSize = 0;

	for (int i = 0; i < kRTFormatCount; ++i)
	{
		supportsRenderTextureFormat[i] = false;
	}

	has3DTexture = false;
	npotRT = npot = kNPOTNone;

	hasRenderToTexture = false;
	hasRenderToCubemap = false;
	hasRenderTargetStencil = false;
	hasTwoSidedStencil = false;
	hasHighPrecisionTextureCombiners = false;
	hasNativeDepthTexture = false;
	hasStencilInDepthTexture = false;
	hasNativeShadowMap = false;

	needsToSwizzleVertexColors = false;
}


GfxDevice* CreateNullGfxDevice()
{
	::gGraphicsCaps.InitNull();

	return UNITY_NEW_AS_ROOT(GfxDeviceNull(), kMemGfxDevice, "NullGfxDevice","");
}

GfxDeviceNull::GfxDeviceNull(void)
:	dynamicVBO(NULL)
{
	InvalidateState();
	ResetFrameStats();

	m_Renderer = kGfxRendererNull;
	m_UsesOpenGLTextureCoords = false;
	m_UsesHalfTexelOffset = false;
	m_MaxBufferedFrames = -1; // no limiting

	RenderSurfaceBase_InitColor(_ColorDefaultSurface);
	_ColorDefaultSurface.backBuffer = true;
	SetBackBufferColorSurface(&_ColorDefaultSurface);

	RenderSurfaceBase_InitDepth(_DepthDefaultSurface);
	_DepthDefaultSurface.backBuffer = true;
	SetBackBufferDepthSurface(&_DepthDefaultSurface);
}

GfxDeviceNull::~GfxDeviceNull(void)
{
	delete this->dynamicVBO;
}

void GfxDeviceNull::GetMatrix( float outMatrix[16] ) const
{
	for( int i = 0; i < 16; ++i )
		outMatrix[i] = 0.0f;
}


void GfxDeviceNull::GetViewport( int* port ) const
{
	AssertIf(!port);
	port[0] = 0;
	port[1] = 0;
	port[2] = 1;
	port[3] = 1;
}


void GfxDeviceNull::GetScissorRect( int scissor[4] ) const
{
	AssertIf(!scissor);
	scissor[0] = 0;
	scissor[1] = 0;
	scissor[2] = 1;
	scissor[3] = 1;
}

TextureCombinersHandle GfxDeviceNull::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular )
{
	return TextureCombinersHandle(this); // just have to pass non-NULL to the handle
}

void GfxDeviceNull::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners )
{
	textureCombiners.Reset();
}

void GfxDeviceNull::DestroySubProgram( ShaderLab::SubProgram* subprogram )
{
	delete subprogram;
}

VBO* GfxDeviceNull::CreateVBO()
{
	VBO* vbo = new GfxNullVBO();
	OnCreateVBO(vbo);
	return vbo;
}

void GfxDeviceNull::DeleteVBO( VBO* vbo )
{
	AssertIf(!vbo);
	OnDeleteVBO(vbo);
	delete vbo;
}

DynamicVBO&	GfxDeviceNull::GetDynamicVBO()
{
	if (NULL == this->dynamicVBO)
	{
		this->dynamicVBO = new GfxDynamicNullVBO();
	}

	return *this->dynamicVBO;
}



bool GfxDeviceNull::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 )
{
	return true;
}


bool GfxDeviceNull::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY )
{
	return true;
}

DeviceBlendState* GfxDeviceNull::CreateBlendState(const GfxBlendState& state)
{
	return & g_NullBlendState;
}

DeviceDepthState* GfxDeviceNull::CreateDepthState(const GfxDepthState& state)
{
	return & g_NullDepthState;
}

DeviceStencilState* GfxDeviceNull::CreateStencilState(const GfxStencilState& state)
{
	return & g_NullStencilState;
}

DeviceRasterState* GfxDeviceNull::CreateRasterState(const GfxRasterState& state)
{
	return & g_NullRasterState;
}

const float* GfxDeviceNull::GetWorldMatrix() const
{
	return g_NullWorldMatrix;
}

const float* GfxDeviceNull::GetViewMatrix() const
{
	return g_NullViewMatrix;
}

const float* GfxDeviceNull::GetProjectionMatrix() const
{
	return g_NullProjectionMatrix;
}



RenderSurfaceHandle GfxDeviceNull::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags)
{
	return RenderSurfaceHandle(&_ColorDefaultSurface);
}
RenderSurfaceHandle GfxDeviceNull::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags)
{
	return RenderSurfaceHandle(&_DepthDefaultSurface);
}

// -------- editor only functions

#if UNITY_EDITOR

GfxDeviceWindow*	GfxDeviceNull::CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias )
{
	return new GfxDeviceWindow(window,width, height, depthFormat, antiAlias);
}

#endif