21 #include <GLES3/gl3.h>
33 GL_CHECK(glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, numberOfTextureFormats));
35 *textureFormats = (GLint *)calloc(*numberOfTextureFormats,
sizeof(GLint));
36 if(*textureFormats == NULL)
38 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
42 GL_CHECK(glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, *textureFormats));
52 unsigned char *randomTexture =
new unsigned char [width * height * 4];
53 if(randomTexture == NULL)
55 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
60 for(
unsigned int allTexels = 0; allTexels < width *
height; allTexels ++)
63 randomTexture[allTexels * 4 + 3] = 255;
65 for (
int allChannels = 0; allChannels < 3; allChannels++)
68 int randomNumber = (
int)(255 * (rand() / (
float)RAND_MAX));
69 randomTexture[allTexels * 4 + allChannels] = randomNumber;
73 *textureData = randomTexture;
76 void Texture::createTexture(
unsigned int width,
unsigned int height,
unsigned int red, GLvoid **textureData)
78 unsigned char* newTexture =
new unsigned char [width *
height];
80 if(newTexture == NULL)
82 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
86 for (
unsigned int texelIndex = 0; texelIndex < width *
height; ++texelIndex)
88 newTexture[texelIndex] = red;
90 *textureData = newTexture;
95 *textureData =
new short [width *
height];
97 if (*textureData == NULL)
99 LOGE(
"Out of memory at %s:%i\n", __FILE__, __LINE__);
103 for (
unsigned int texelIndex = 0; texelIndex < width *
height; ++texelIndex)
105 (*textureData)[texelIndex] = red;
111 delete[] (
unsigned char*)*textureData;
117 FILE *file = fopen(filename,
"rb");
121 LOGE(
"Failed to open '%s'\n", filename);
125 fseek(file, 0, SEEK_END);
127 unsigned int length = ftell(file);
128 unsigned char *loadedTexture = (
unsigned char *)calloc(length,
sizeof(
unsigned char));
130 ASSERT(loadedTexture != NULL,
"Could not allocate memory to store PKM file data.")
132 fseek(file, 0, SEEK_SET);
134 size_t read = fread(loadedTexture, sizeof(
unsigned char), length, file);
136 ASSERT(read == length, "Failed to read PKM file.");
140 *textureData = loadedTexture;
148 for (
int pixelIndex = 0; pixelIndex < lineWidth; ++pixelIndex)
150 memcpy(destination + pixelIndex * rgbComponentsCount,
151 source + (lineWidth - pixelIndex - 1) * rgbComponentsCount,
152 rgbComponentsCount *
sizeof(
float));
const int rgbComponentsCount
static void createTexture(unsigned int width, unsigned int height, GLvoid **textureData)
Create a texture using random data.
const GLenum textureFormats[]
GLint GLsizei GLsizei height
static void getCompressedTextureFormats(GLint **textureFormats, int *numberOfTextureFormats)
Uses glGetIntegerv to get the number of compressed texture formats and the formats themselves...
static void deleteTextureData(GLvoid **textureData)
Deletes previously created texture.
GLsizei GLsizei GLchar * source
static void reversePixelLine(float *destination, const float *source, int lineWidth)
Copies float pixel data of one line of the image from source to destination in the reverse direction...
unsigned char * textureData
static void loadData(const char *filename, unsigned char **textureData)
Load texture data from a file into memory.
GLenum GLuint GLenum GLsizei length
static bool isETCSupported(bool verbose=false)
Reports whether or not ETC (Ericsson Texture Compression) is supported.