MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCL-CTS / CreateGLTexture2DArray

Function CreateGLTexture2DArray

test_common/gl/helpers.cpp:149–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149void * CreateGLTexture2DArray(size_t width, size_t height, size_t length,
150 GLenum target, GLenum glFormat, GLenum internalFormat, GLenum glType,
151 ExplicitType type, GLuint *outTextureID, int *outError,
152 bool allocateMem, MTdata d)
153{
154 *outError = 0;
155
156 char * buffer;
157 unsigned int size = 0;
158
159 if ( (glType == GL_UNSIGNED_INT_2_10_10_10_REV) || (glType == GL_UNSIGNED_INT_10_10_10_2) )
160 {
161 size = width * height * length;
162 }
163 else
164 {
165 size = width * height * length * 4;
166 }
167
168 buffer = (char *)CreateRandomData(type, size, d);
169
170 if( type == kFloat && allocateMem )
171 {
172 // Re-fill the created buffer to just have [0-1] floats, since that's what it'd expect
173 cl_float *p = (cl_float *)buffer;
174 for( size_t i = 0; i < size; i++ )
175 {
176 p[ i ] = (float) genrand_real1( d );
177 }
178 }
179 else if( !allocateMem )
180 memset( buffer, 0, size * get_explicit_type_size( type ) );
181
182 glGenTextures( 1, outTextureID );
183
184 glBindTexture( target, *outTextureID );
185 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
186 glTexParameteri( target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
187 glTexParameteri( target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
188
189 glGetError();
190 //the default alignment in OpenGL is 4 bytes and need to be changed for GL_DEPTH_COMPONENT16 which is aligned to 2 bytes
191 if (internalFormat == GL_DEPTH_COMPONENT16)
192 glPixelStorei(GL_UNPACK_ALIGNMENT, get_explicit_type_size( type ));
193
194 glTexImage3D( target, 0, internalFormat, (GLsizei)width, (GLsizei)height,
195 (GLsizei)length, 0, glFormat, glType, buffer );
196
197 if (internalFormat == GL_DEPTH_COMPONENT16)
198 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
199
200 GLenum err = glGetError();
201 if( err != GL_NO_ERROR )
202 {
203 if (err != GL_OUT_OF_MEMORY) {
204 log_error( "ERROR: Unable to load data into GL texture (%s) format %s "
205 "type %s internal format %s\n", gluErrorString( err ),
206 GetGLFormatName( glFormat ), get_explicit_type_name( type ),

Callers 4

test_image_format_readFunction · 0.85
test_image_format_writeFunction · 0.85

Calls 6

genrand_real1Function · 0.85
get_explicit_type_sizeFunction · 0.85
get_explicit_type_nameFunction · 0.85
CreateRandomDataFunction · 0.70
gluErrorStringFunction · 0.70
GetGLFormatNameFunction · 0.70

Tested by 4

test_image_format_readFunction · 0.68
test_image_format_writeFunction · 0.68