MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / ktxTexture_construct

Function ktxTexture_construct

lib/texture.c:83–178  ·  view source on GitHub ↗

* @memberof ktxTexture @private * @~English * @brief Construct (initialize) a ktxTexture base class instance. * * @param[in] This pointer to a ktxTexture-sized block of memory to * initialize. * @param[in] createInfo pointer to a ktxTextureCreateInfo struct with * information describing the texture. * @param[in] formatSize pointer to a ktxFormatSize gi

Source from the content-addressed store, hash-verified

81 * @exception KTX_OUT_OF_MEMORY Not enough memory for the texture.
82 */
83KTX_error_code
84ktxTexture_construct(ktxTexture* This,
85 const ktxTextureCreateInfo* const createInfo,
86 ktxFormatSize* formatSize)
87{
88 DECLARE_PROTECTED(ktxTexture);
89
90 memset(This, 0, sizeof(*This));
91 This->_protected = (struct ktxTexture_protected*)malloc(sizeof(*prtctd));
92 if (!This->_protected)
93 return KTX_OUT_OF_MEMORY;
94 prtctd = This->_protected;
95 memset(prtctd, 0, sizeof(*prtctd));
96 memcpy(&prtctd->_formatSize, formatSize, sizeof(prtctd->_formatSize));
97
98 This->isCompressed = (formatSize->flags & KTX_FORMAT_SIZE_COMPRESSED_BIT);
99
100 This->orientation.x = KTX_ORIENT_X_RIGHT;
101 This->orientation.y = KTX_ORIENT_Y_DOWN;
102 This->orientation.z = KTX_ORIENT_Z_OUT;
103
104 /* Check texture dimensions. KTX files can store 8 types of textures:
105 * 1D, 2D, 3D, cube, and array variants of these.
106 */
107 if (createInfo->numDimensions < 1 || createInfo->numDimensions > 3)
108 return KTX_INVALID_VALUE;
109
110 if (createInfo->baseWidth == 0 || createInfo->baseHeight == 0
111 || createInfo->baseDepth == 0)
112 return KTX_INVALID_VALUE;
113
114 switch (createInfo->numDimensions) {
115 case 1:
116 if (createInfo->baseHeight > 1 || createInfo->baseDepth > 1)
117 return KTX_INVALID_OPERATION;
118 break;
119
120 case 2:
121 if (createInfo->baseDepth > 1)
122 return KTX_INVALID_OPERATION;
123 break;
124
125 case 3:
126 /* 3D array textures and 3D cubemaps are not supported by either
127 * OpenGL or Vulkan.
128 */
129 if (createInfo->isArray || createInfo->numFaces != 1
130 || createInfo->numLayers != 1)
131 return KTX_INVALID_OPERATION;
132 break;
133 }
134 This->numDimensions = createInfo->numDimensions;
135 This->baseWidth = createInfo->baseWidth;
136 This->baseDepth = createInfo->baseDepth;
137 This->baseHeight = createInfo->baseHeight;
138
139 if (createInfo->numLayers == 0)
140 return KTX_INVALID_VALUE;

Callers 2

ktxTexture2_constructFunction · 0.85
ktxTexture1_constructFunction · 0.85

Calls 1

ktxHashList_ConstructFunction · 0.85

Tested by

no test coverage detected