1/*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Texture utility class
22 *//*--------------------------------------------------------------------*/
23
24#include "vktImageTexture.hpp"
25
26namespace vkt
27{
28namespace image
29{
30
31Texture::Texture (const ImageType type_, const tcu::IVec3& layerSize_, const int layers)
32	: m_layerSize	(layerSize_)
33	, m_type		(type_)
34	, m_numLayers	(layers)
35{
36	DE_ASSERT(m_numLayers >= 1);
37	DE_ASSERT(m_layerSize.x() >= 1 && m_layerSize.y() >= 1 && m_layerSize.z() >= 1);
38
39	switch (type_)
40	{
41		case IMAGE_TYPE_1D:
42		case IMAGE_TYPE_BUFFER:
43			DE_ASSERT(m_numLayers == 1);
44			DE_ASSERT(m_layerSize.y() == 1 && m_layerSize.z() == 1);
45			break;
46
47		case IMAGE_TYPE_1D_ARRAY:
48			DE_ASSERT(m_layerSize.y() == 1 && m_layerSize.z() == 1);
49			break;
50
51		case IMAGE_TYPE_2D:
52			DE_ASSERT(m_numLayers == 1);
53			DE_ASSERT(m_layerSize.z() == 1);
54			break;
55
56		case IMAGE_TYPE_2D_ARRAY:
57			DE_ASSERT(m_layerSize.z() == 1);
58			break;
59
60		case IMAGE_TYPE_CUBE:
61			DE_ASSERT(m_numLayers == 6);
62			DE_ASSERT(m_layerSize.z() == 1);
63			break;
64
65		case IMAGE_TYPE_CUBE_ARRAY:
66			DE_ASSERT(m_numLayers >= 6 && m_numLayers % 6 == 0);
67			DE_ASSERT(m_layerSize.z() == 1);
68			break;
69
70		case IMAGE_TYPE_3D:
71			DE_ASSERT(m_numLayers == 1);
72			break;
73
74		default:
75			DE_FATAL("Internal error");
76			break;
77	}
78}
79
80tcu::IVec3 Texture::size (void) const
81{
82	switch (m_type)
83	{
84		case IMAGE_TYPE_1D:
85		case IMAGE_TYPE_BUFFER:
86		case IMAGE_TYPE_2D:
87		case IMAGE_TYPE_3D:
88			return m_layerSize;
89
90		case IMAGE_TYPE_1D_ARRAY:
91			return tcu::IVec3(m_layerSize.x(), m_numLayers, 1);
92
93		case IMAGE_TYPE_2D_ARRAY:
94		case IMAGE_TYPE_CUBE:
95		case IMAGE_TYPE_CUBE_ARRAY:
96			return tcu::IVec3(m_layerSize.x(), m_layerSize.y(), m_numLayers);
97
98		default:
99			DE_FATAL("Internal error");
100			return tcu::IVec3();
101	}
102}
103
104int Texture::dimension (void) const
105{
106	switch (m_type)
107	{
108		case IMAGE_TYPE_1D:
109		case IMAGE_TYPE_BUFFER:
110			return 1;
111
112		case IMAGE_TYPE_1D_ARRAY:
113		case IMAGE_TYPE_2D:
114			return 2;
115
116		case IMAGE_TYPE_2D_ARRAY:
117		case IMAGE_TYPE_CUBE:
118		case IMAGE_TYPE_CUBE_ARRAY:
119		case IMAGE_TYPE_3D:
120			return 3;
121
122		default:
123			DE_FATAL("Internal error");
124			return 0;
125	}
126}
127
128int Texture::layerDimension (void) const
129{
130	switch (m_type)
131	{
132		case IMAGE_TYPE_1D:
133		case IMAGE_TYPE_BUFFER:
134		case IMAGE_TYPE_1D_ARRAY:
135			return 1;
136
137		case IMAGE_TYPE_2D:
138		case IMAGE_TYPE_2D_ARRAY:
139		case IMAGE_TYPE_CUBE:
140		case IMAGE_TYPE_CUBE_ARRAY:
141			return 2;
142
143		case IMAGE_TYPE_3D:
144			return 3;
145
146		default:
147			DE_FATAL("Internal error");
148			return 0;
149	}
150}
151
152} // image
153} // vkt
154