35 #include <GLES2/gl2.h>
36 #include <GLES2/gl2ext.h>
42 #include <android/log.h>
49 using std::stringstream;
51 using namespace MaliSDK;
53 string resourceDirectory =
"/data/data/com.arm.malideveloper.openglessdk.etcuncompressedalpha/";
81 FILE *file = fopen(filename,
"rb");
86 unsigned int width = 0;
88 unsigned int range = 0;
89 int readCount = fscanf(file,
"P5 %d %d %d", &width, &height, &range);
92 LOGE(
"Error reading file header of %s", filename);
103 LOGE(
"Alpha file %s has wrong maximum gray value, must be 255", filename);
110 unsigned char *
textureData = (
unsigned char *)calloc(width * height,
sizeof(
unsigned char));
111 size_t result = fread(textureData,
sizeof(
unsigned char), width * height, file);
112 if (result != width * height)
114 LOGE(
"Error reading %s", filename);
117 GL_CHECK(glGenTextures(1, textureID));
118 GL_CHECK(glBindTexture(GL_TEXTURE_2D, *textureID));
119 GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,GL_LUMINANCE,GL_UNSIGNED_BYTE, textureData));
120 GL_CHECK(glGenerateMipmap(GL_TEXTURE_2D));
128 LOGD(
"setupGraphics(%d, %d)", w, h);
139 LOGE(
"ETC1 not supported");
146 GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
150 GL_CHECK(glActiveTexture(GL_TEXTURE1));
158 LOGD(
"vertexShaderID = %d", vertexShaderID);
160 LOGD(
"fragmentShaderID = %d", fragmentShaderID);
165 LOGE(
"Could not create program.");
177 LOGE(
"Attribute not found: \"a_v4Position\"");
186 LOGD(
"Warning: Attribute not found: \"a_v2TexCoord\"");
197 LOGD(
"Warning: Uniform not found: \"u_s2dTexture\"");
208 LOGE(
"Uniform not found at line %i\n", __LINE__);
221 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
237 GL_CHECK(glDrawElements(GL_TRIANGLE_STRIP,
sizeof(
indices) /
sizeof(GLubyte), GL_UNSIGNED_BYTE,
indices));
251 int numberOfImages = 9;
252 for(
int allImages = 0; allImages < numberOfImages; allImages++)
254 stringstream imageNumber;
255 imageNumber << allImages;
256 texturePathFull.replace(
textureFilename.length(), 1, imageNumber.str());
266 (JNIEnv *env, jclass jcls)
int loadUncompressedAlpha(const char *filename, GLuint *textureID)
string fragmentShaderFilename
GLint GLsizei GLsizei height
bool setupGraphics(int w, int h)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_etcuncompressedalpha_ETCUncompressedAlpha_step(JNIEnv *env, jclass jcls)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_etcuncompressedalpha_ETCUncompressedAlpha_uninit(JNIEnv *, jclass)
string vertexShaderFilename
GLfloat GLfloat GLfloat w
GLsizei GLenum const void * indices
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_etcuncompressedalpha_ETCUncompressedAlpha_init(JNIEnv *env, jclass jcls, jint width, jint height)
static void loadCompressedMipmaps(const char *filenameBase, const char *filenameSuffix, GLuint *textureID)
Load compressed mipmaps into memory.
GLfloat GLfloat GLfloat GLfloat h
unsigned char * textureData
static bool isETCSupported(bool verbose=false)
Reports whether or not ETC (Ericsson Texture Compression) is supported.
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
static const GLfloat textureCoordinates[]