OpenGL ES SDK for Android
ARM Developer Center
|
The application simulates cellular automata phenomenon following Rule 30. It uses two programs which operate on two textures used in a ping-pong manner. More...
#include <jni.h>
#include <android/log.h>
#include <GLES3/gl3.h>
#include "Common.h"
#include "CubeModel.h"
#include "Mathematics.h"
#include "Matrix.h"
#include "PlaneModel.h"
#include "IntegerLogic.h"
#include "Shader.h"
#include "Texture.h"
#include "Timer.h"
#include <cstring>
Go to the source code of this file.
Functions | |
void | generateRule30Input (unsigned int xoffset, unsigned int width, unsigned int height, unsigned int nComponents, GLvoid **textureData) |
Generates input for Rule 30 Cellular Automaton, setting a white dot in the top line of the texture on the given horizontal offset. More... | |
void | generateRule30Input (unsigned int width, unsigned int height, unsigned int nComponents, GLvoid **textureData) |
Generates random input for Rule 30 Cellular Automaton, setting random white dots in the top line of the texture. More... | |
void | performOffscreenRendering () |
void | renderFrame () |
void | renderToBackBuffer () |
void | resetTextures () |
void | setupGraphics (int width, int height) |
void | uninit () |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_integerLogic_NativeLibrary_init (JNIEnv *env, jobject obj, jint width, jint height) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_integerLogic_NativeLibrary_step (JNIEnv *env, jobject obj) |
JNIEXPORT void JNICALL | Java_com_arm_malideveloper_openglessdk_integerLogic_NativeLibrary_uninit (JNIEnv *env, jobject obj) |
Variables | |
GLsizei | windowHeight = 0 |
GLsizei | windowWidth = 0 |
GLuint | rule30ProgramID = 0 |
GLuint | mergeProgramID = 0 |
const GLuint | pingTextureUnit = 0 |
const GLuint | pongTextureUnit = 1 |
GLvoid * | pingTextureData = NULL |
GLuint | pingTextureID = -1 |
GLuint | pongTextureID = -1 |
GLuint | framebufferID = -1 |
GLuint | linePositionBOID = -1 |
GLuint | lineUVBOID = -1 |
GLuint | quadPositionBOID = 0 |
GLuint | quadUVBOID = 0 |
GLuint | lineVAOID = -1 |
GLuint | quadVAOID = 0 |
Matrix | modelViewProjectionMatrix |
MergeProgramLocations | mergeProgramLocations |
Rule30ProgramLocations | rule30ProgramLocations |
Timer | timer |
const float | timeInterval = 5.0f |
The application simulates cellular automata phenomenon following Rule 30. It uses two programs which operate on two textures used in a ping-pong manner.
The first program takes the ping texture ("ping") as the input and renders the output to a second texture ("pong"). Rendering in this case is performed by drawing one row at a time, with each row having height of 1 pixel and being of screen width. Excluding the first row, each row is drawn by reading one row above the currently processed one and applying the cellular automata rule. The first row's contents are set by the application. Since we cannot draw and read from the same texture at a single time, the drawing is performed one row at a time. After a row is drawn to texture A, the application binds texture B for drawing and uses texture A for reading the previous line. In the end, texture A contains even rows and texture B stores odd rows.
Having finished drawing lines to these two textures, we run another GL program that merges both textures into a single one by using texture A for even lines and texture B for odd ones.
In order to be able to render to a texture, we use a custom frame-buffer.
For the first run, the input line has only one pixel lit, so it generates the commonly known Rule 30 pattern. Then, every 5 seconds, textures are reset and the input is randomly generated.
Definition in file Native.cpp.
void generateRule30Input | ( | unsigned int | xoffset, |
unsigned int | width, | ||
unsigned int | height, | ||
unsigned int | nComponents, | ||
GLvoid ** | textureData | ||
) |
Generates input for Rule 30 Cellular Automaton, setting a white dot in the top line of the texture on the given horizontal offset.
[in] | xoffset | Horizontal position of the stripe. |
[in] | width | Width of the texture. |
[in] | height | Height of the texture. |
[in] | nComponents | Number of components defining the colors in the texture. |
[out] | textureData | Output texture. |
Definition at line 161 of file Native.cpp.
void generateRule30Input | ( | unsigned int | width, |
unsigned int | height, | ||
unsigned int | nComponents, | ||
GLvoid ** | textureData | ||
) |
Generates random input for Rule 30 Cellular Automaton, setting random white dots in the top line of the texture.
[in] | width | Width of the texture. |
[in] | height | Height of the texture. |
[in] | nComponents | Number of components defining the colors in the texture. |
[out] | textureData | Output texture. |
Definition at line 178 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_integerLogic_NativeLibrary_init | ( | JNIEnv * | env, |
jobject | obj, | ||
jint | width, | ||
jint | height | ||
) |
Definition at line 624 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_integerLogic_NativeLibrary_step | ( | JNIEnv * | env, |
jobject | obj | ||
) |
Definition at line 637 of file Native.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_integerLogic_NativeLibrary_uninit | ( | JNIEnv * | env, |
jobject | obj | ||
) |
Definition at line 630 of file Native.cpp.
void performOffscreenRendering | ( | ) |
Definition at line 202 of file Native.cpp.
Definition at line 572 of file Native.cpp.
void renderToBackBuffer | ( | ) |
Definition at line 267 of file Native.cpp.
void resetTextures | ( | ) |
Definition at line 585 of file Native.cpp.
Definition at line 279 of file Native.cpp.
void uninit | ( | ) |
Definition at line 611 of file Native.cpp.
GLuint framebufferID = -1 |
Definition at line 86 of file Native.cpp.
GLuint linePositionBOID = -1 |
Definition at line 88 of file Native.cpp.
GLuint lineUVBOID = -1 |
Definition at line 90 of file Native.cpp.
GLuint lineVAOID = -1 |
Definition at line 96 of file Native.cpp.
GLuint mergeProgramID = 0 |
Definition at line 69 of file Native.cpp.
MergeProgramLocations mergeProgramLocations |
Definition at line 104 of file Native.cpp.
Matrix modelViewProjectionMatrix |
Definition at line 101 of file Native.cpp.
GLvoid* pingTextureData = NULL |
Definition at line 79 of file Native.cpp.
GLuint pingTextureID = -1 |
Definition at line 81 of file Native.cpp.
const GLuint pingTextureUnit = 0 |
Definition at line 73 of file Native.cpp.
GLuint pongTextureID = -1 |
Definition at line 83 of file Native.cpp.
const GLuint pongTextureUnit = 1 |
Definition at line 75 of file Native.cpp.
GLuint quadPositionBOID = 0 |
Definition at line 92 of file Native.cpp.
GLuint quadUVBOID = 0 |
Definition at line 94 of file Native.cpp.
GLuint quadVAOID = 0 |
Definition at line 98 of file Native.cpp.
GLuint rule30ProgramID = 0 |
Definition at line 67 of file Native.cpp.
Rule30ProgramLocations rule30ProgramLocations |
Definition at line 106 of file Native.cpp.
const float timeInterval = 5.0f |
Definition at line 110 of file Native.cpp.
Timer timer |
Definition at line 108 of file Native.cpp.
GLsizei windowHeight = 0 |
Definition at line 62 of file Native.cpp.
GLsizei windowWidth = 0 |
Definition at line 64 of file Native.cpp.