42 #include <android/log.h>
58 using namespace MaliSDK;
61 const string resourceDirectory =
"/data/data/com.arm.malideveloper.openglessdk.minMaxBlending/files/";
129 -1.0f, 1.0f, -1.0f, 1.0f,
130 1.0f, 1.0f, -1.0f, 1.0f,
131 -1.0f, -1.0f, -1.0f, 1.0f,
132 -1.0f, -1.0f, -1.0f, 1.0f,
133 1.0f, 1.0f, -1.0f, 1.0f,
134 1.0f, -1.0f, -1.0f, 1.0f,
187 GLint inputUVWCoordinatesLocation =
GL_CHECK(glGetAttribLocation(
programID,
"inputUVWCoordinates"));
189 ASSERT(positionLocation != -1,
"Could not find attribute location for: inputPosition");
190 ASSERT(inputUVWCoordinatesLocation != -1,
"Could not find attribute location for: inputUVWCoordinates");
204 GL_CHECK(glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, 0, 0));
205 GL_CHECK(glEnableVertexAttribArray(positionLocation));
215 GL_CHECK(glVertexAttribPointer(inputUVWCoordinatesLocation, 3, GL_FLOAT, GL_FALSE, 0, 0));
216 GL_CHECK(glEnableVertexAttribArray(inputUVWCoordinatesLocation));
223 const string vertexShaderPath =
resourceDirectory +
"Min_Max_Blending_shader.vert";
225 const string fragmentShaderPath =
resourceDirectory +
"Min_Max_Blending_shader.frag";
232 Shader::processShader(&vertexShaderID, vertexShaderPath.c_str(), GL_VERTEX_SHADER);
233 Shader::processShader(&fragmentShaderID, fragmentShaderPath.c_str(), GL_FRAGMENT_SHADER);
239 GL_CHECK(glAttachShader(programID, vertexShaderID));
240 GL_CHECK(glAttachShader(programID, fragmentShaderID));
258 ASSERT(frontLayersCount >= 0 && backLayersCount >= 0,
259 "Too low textureDepth value or too many images have been tried to be loaded.");
270 "3D texture not completely loaded.");
277 GLint cameraMatrixLocation =
GL_CHECK(glGetUniformLocation(
programID,
"cameraMatrix"));
278 GLint projectionMatrixLocation =
GL_CHECK(glGetUniformLocation(
programID,
"projectionMatrix"));
280 GLint textureSamplerLocation =
GL_CHECK(glGetUniformLocation(
programID,
"textureSampler"));
282 GLint instancesCountLocation =
GL_CHECK(glGetUniformLocation(
programID,
"instancesCount"));
283 GLint minBlendingThresholdLocation =
GL_CHECK(glGetUniformLocation(
programID,
"minBlendingThreshold"));
289 ASSERT(cameraMatrixLocation != -1,
"Could not find location for uniform: cameraMatrix");
290 ASSERT(projectionMatrixLocation != -1,
"Could not find location for uniform: projectionMatrix");
292 ASSERT(textureSamplerLocation != -1,
"Could not find location for uniform: textureSampler");
294 ASSERT(instancesCountLocation != -1,
"Could not find location for uniform: instancesCount");
295 ASSERT(minBlendingThresholdLocation != -1,
"Could not find location for uniform: minBlendingThreshold");
300 const float cameraTranslation = -2.0f;
302 Matrix cameraMatrix = Matrix::createTranslation(0.0
f,
312 GL_CHECK(glUniformMatrix4fv(cameraMatrixLocation,
317 GL_CHECK(glUniformMatrix4fv(projectionMatrixLocation,
323 GL_CHECK(glUniform1i(textureSamplerLocation, 0));
336 for (
int currentImageIndex = 1; currentImageIndex <=
imagesCount; ++currentImageIndex)
340 const int digitsCount = 3;
343 std::stringstream stringStream;
344 stringStream << currentImageIndex;
345 string numericExtension = stringStream.str();
370 (
short**) &textureData);
373 for (
int i = 0; i <
count; ++i)
379 delete [] (
unsigned char *)textureData;
398 static float angleX = 0.0f;
399 static float angleY = 0.0f;
400 static float angleZ = 0.0f;
403 const float angleXIncrement = 0.75f;
404 const float angleYIncrement = 1.0f;
405 const float angleZIncrement = 0.5f;
411 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
422 angleX += angleXIncrement;
423 angleY += angleYIncrement;
424 angleZ += angleZIncrement;
427 if(angleX >= 360.0
f) angleX = 0.0f;
428 if(angleY >= 360.0
f) angleY = 0.0f;
429 if(angleZ >= 360.0
f) angleZ = 0.0f;
void initializeTextureData()
Fills 3D texture with images.
void loadData(const char *filename, unsigned char **textureData)
Load texture data from a file into memory.
float getTime()
Returns the time passed since object creation or since reset() was last called.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_uninit(JNIEnv *, jobject)
float projectionMatrix[16]
void initializeAttribArrays()
Initializes input vertex data for shaders.
const string resourceDirectory
GLint GLsizei GLsizei height
void setNextTextureImage(GLvoid *textureData)
Fills next empty 3D texture layer with textureData.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_step(JNIEnv *, jobject)
Functions for manipulating matrices.
const float squareVertices[]
const GLfloat minBlendingThreshold
Provides a platform independent high resolution timer.
GLenum GLenum GLsizei count
void matrixPerspective(float *matrix, float fieldOfView, float aspectRatio, float zNear, float zFar)
Create a perspective projection matrix and store the results in the first parameter.
float * getAsArray(void)
Get the matrix elements as a column major order array.
void loadImages()
Loads imagesCount images located in resourceDirectory.
const string imagesFilename
void initializeProgram()
Creates program and attaches shaders to it.
void initializeUniformData()
Initializes uniform variables in program.
const GLint textureHeight
void reset()
Resets the timer to 0.0f.
typedef GLboolean(GL_APIENTRYP PFNGLISENABLEDIOESPROC)(GLenum target
void uninit()
Delete created objects and free allocated memory.
const float resetTimeInterval
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_minMaxBlending_NativeLibrary_init(JNIEnv *, jobject, jint width, jint height)
void loadUniformTextures(int count)
Creates and loads count unicolor layers to a 3D texture.
unsigned char * textureData
GLint isMinBlendingLocation
void initialize3DTexture()
Initializes OpenGL ES texture components.
bool createTexture(std::string filename, GLuint *textureLocation)
void setBlendEquation(GLboolean isMinBlending)
Sets current blending equation.
GLint rotationVectorLocation
const short fillerLuminance
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
const float uvwCoordinates[]