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

Function ktxTexture1_construct

lib/texture1.c:63–142  ·  view source on GitHub ↗

* @memberof ktxTexture1 @private * @copydoc ktxTexture2_construct */

Source from the content-addressed store, hash-verified

61 * @copydoc ktxTexture2_construct
62 */
63static KTX_error_code
64ktxTexture1_construct(ktxTexture1* This,
65 const ktxTextureCreateInfo* const createInfo,
66 ktxTextureCreateStorageEnum storageAllocation)
67{
68 ktxTexture_protected* prtctd;
69 ktxFormatSize formatSize;
70 GLuint typeSize;
71 GLenum glFormat;
72 KTX_error_code result;
73
74 memset(This, 0, sizeof(*This));
75
76 This->glInternalformat = createInfo->glInternalformat;
77 glGetFormatSize(This->glInternalformat, &formatSize);
78 if (formatSize.blockSizeInBits == 0) {
79 // Most likely a deprecated legacy format.
80 return KTX_UNSUPPORTED_TEXTURE_TYPE;
81 }
82 glFormat= glGetFormatFromInternalFormat(createInfo->glInternalformat);
83 if (glFormat == GL_INVALID_VALUE) {
84 return KTX_INVALID_VALUE;
85 }
86 result = ktxTexture_construct(ktxTexture(This), createInfo, &formatSize);
87 if (result != KTX_SUCCESS)
88 return result;
89
90 result = ktxTexture1_constructCommon(This);
91 if (result != KTX_SUCCESS)
92 return result;
93 prtctd = This->_protected;
94
95 This->isCompressed
96 = (formatSize.flags & KTX_FORMAT_SIZE_COMPRESSED_BIT);
97 if (This->isCompressed) {
98 This->glFormat = 0;
99 This->glBaseInternalformat = glFormat;
100 This->glType = 0;
101 prtctd->_typeSize = 1;
102 } else {
103 This->glBaseInternalformat = This->glFormat = glFormat;
104 This->glType
105 = glGetTypeFromInternalFormat(createInfo->glInternalformat);
106 if (This->glType == GL_INVALID_VALUE) {
107 result = KTX_INVALID_VALUE;
108 goto cleanup;
109 }
110 typeSize = glGetTypeSizeFromType(This->glType);
111 assert(typeSize != GL_INVALID_VALUE);
112
113 /* Do some sanity checking */
114 if (typeSize != 1 &&
115 typeSize != 2 &&
116 typeSize != 4)
117 {
118 /* Only 8, 16, and 32-bit types are supported for byte-swapping.
119 * See UNPACK_SWAP_BYTES & table 8.4 in the OpenGL 4.4 spec.
120 */

Callers 1

ktxTexture1_CreateFunction · 0.85

Calls 10

glGetFormatSizeFunction · 0.85
ktxTexture_constructFunction · 0.85
glGetTypeSizeFromTypeFunction · 0.85
assertFunction · 0.85
ktxTexture1_destructFunction · 0.85
ktxTexture_destructFunction · 0.85

Tested by

no test coverage detected