OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Texture.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #include "Texture.h"
22 
23 namespace MaliSDK
24 {
25 void Texture::createTexture(unsigned int width, unsigned int height, GLvoid **textureData)
26  {
27  unsigned char *randomTexture = new unsigned char [width * height * 4];
28  if(randomTexture == NULL)
29  {
30  LOGE("Out of memory at %s:%i\n", __FILE__, __LINE__);
31  exit(1);
32  }
33 
34  /* Initialize texture with random shades. */
35  for(unsigned int allTexels = 0; allTexels < width * height; allTexels ++)
36  {
37  /* Use 255 (fully opaque) for the alpha value */
38  randomTexture[allTexels * 4 + 3] = 255;
39  /* Set each colour component (Red, Green, Blue) of the texel to a different random number. */
40  for (int allChannels = 0; allChannels < 3; allChannels++)
41  {
42  /* Generate a random number between 0 and 255 */
43  int randomNumber = (int)(255 * (rand() / (float)RAND_MAX));
44  randomTexture[allTexels * 4 + allChannels] = randomNumber;
45  }
46  }
47 
48  *textureData = randomTexture;
49  }
50 
51  void Texture::createTexture(unsigned int width, unsigned int height, unsigned int red, GLvoid **textureData)
52  {
53  unsigned char* newTexture = new unsigned char [width * height];
54 
55  if(newTexture == NULL)
56  {
57  LOGE("Out of memory at %s:%i\n", __FILE__, __LINE__);
58  exit(1);
59  }
60 
61  for (unsigned int texelIndex = 0; texelIndex < width * height; ++texelIndex)
62  {
63  newTexture[texelIndex] = red;
64  }
65  *textureData = newTexture;
66  }
67 
68  void Texture::createTexture(unsigned int width, unsigned int height, short red, short **textureData)
69  {
70  *textureData = new short [width * height];
71 
72  if (*textureData == NULL)
73  {
74  LOGE("Out of memory at %s:%i\n", __FILE__, __LINE__);
75  exit(1);
76  }
77 
78  for (unsigned int texelIndex = 0; texelIndex < width * height; ++texelIndex)
79  {
80  (*textureData)[texelIndex] = red;
81  }
82  }
83 
84  void Texture::deleteTextureData(GLvoid** textureData)
85  {
86  delete[] (unsigned char*)*textureData;
87  }
88 }
static void createTexture(unsigned int width, unsigned int height, GLvoid **textureData)
Create a texture using random data.
Definition: Texture.cpp:103
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
precision highp int
Definition: hiz_cull.cs:38
static void deleteTextureData(GLvoid **textureData)
Deletes previously created texture.
Definition: Texture.cpp:162
unsigned char * textureData
Definition: ThreadSync.cpp:109
#define LOGE(...)
Definition: Texture.cpp:32
GLint GLsizei width
Definition: gl2ext.h:179