38 #include <android/log.h>
40 #include <GLES3/gl3.h>
47 using namespace MaliSDK;
135 for (
int allComponents = 0;
144 for (
int allComponents = 4 * numberOfSpheresToGenerate;
180 const float radius = 10.0f;
222 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
226 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
233 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
235 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
244 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
246 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
250 GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER,
252 GL_CHECK(glBufferData(GL_ARRAY_BUFFER,
273 const GLchar* varyingNames[] = {
"location",
"velocity"};
304 GL_SEPARATE_ATTRIBS));
319 ASSERT(transformationUniformBlockIndex != GL_INVALID_INDEX,
"Could not find uniform block: inputData");
368 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
370 GL_CHECK(glBufferSubData(GL_ARRAY_BUFFER,
383 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
409 GL_CHECK(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
414 GL_CHECK(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
417 sizeof(
float) * 4 * numberOfSpheresToGenerate,
418 sizeof(
float) * 4 * numberOfSpheresToGenerate));
422 GL_CHECK(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
427 GL_CHECK(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
430 sizeof(
float) * 4 * numberOfSpheresToGenerate,
431 sizeof(
float) * 4 * numberOfSpheresToGenerate));
456 GL_CHECK(glEnable(GL_RASTERIZER_DISCARD));
459 GL_CHECK(glBeginTransformFeedback(GL_POINTS));
466 GL_CHECK(glDisable(GL_RASTERIZER_DISCARD));
470 GL_CHECK(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0));
471 GL_CHECK(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, 0));
472 GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0));
484 GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER,
490 GL_CHECK(glBindBufferBase(GL_UNIFORM_BUFFER,
496 GL_CHECK(glDrawArraysInstanced(GL_TRIANGLES,
536 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
547 GL_CHECK(glBindBuffer (GL_ARRAY_BUFFER,
582 JNIEnv * env, jobject obj, jint
width, jint
height)
588 JNIEnv * env, jobject obj)
595 JNIEnv * env, jobject obj)
int numberOfSphereTrianglePoints
GLint perspectiveMatrixLocation
GLuint sphereCoordinatesBufferObjectId
GLint cameraPositionLocation
float getTime()
Returns the time passed since object creation or since reset() was last called.
GLuint spherePingPositionAndVelocityBufferObjectId
void generateStartPositionAndVelocity()
Generate random positions and velocities of spheres which are used during first draw call...
static void getTriangleRepresentation(const float radius, const int numberOfSamples, int *numberOfCoordinates, float **coordinates)
Create triangular representation of a sphere.
GLint GLsizei GLsizei height
const int numberOfSpheresToGenerate
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_step(JNIEnv *env, jobject obj)
Provides a platform independent high resolution timer.
GLuint renderingProgramId
#define MOVEMENT_VERTEX_SHADER_FILE_NAME
#define VERTEX_SHADER_FILE_NAME
GLuint movementUniformBlockIndex
float startPositionAndVelocity[spherePositionsAndVelocitiesLength]
void reset()
Resets the timer to 0.0f.
void uninit()
Delete created objects and free allocated memory.
const int spherePositionsAndVelocitiesLength
float * sphereTrianglesCoordinates
int numberOfSphereTriangleCoordinates
#define FRAGMENT_SHADER_FILE_NAME
GLint scalingMatrixLocation
void initializeData()
Initializes data used for rendering.
bool usePingBufferForTransformFeedbackOutput
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_init(JNIEnv *env, jobject obj, jint width, jint height)
void createSpheresData()
Initialize data for spheres.
#define MOVEMENT_FRAGMENT_SHADER_FILE_NAME
void fillVertexColorsArray()
Fill vertexColors array with random color for each triangle vertex.
GLuint bufferObjectIds[numberOfBufferObjectIds]
GLuint sphereColorsBufferObjectId
GLuint spherePongPositionAndVelocityBufferObjectId
const int numberOfSamples
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_boids_NativeLibrary_uninit(JNIEnv *env, jobject obj)
GLuint movementFragmentShaderId
const GLuint numberOfBufferObjectIds
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
GLuint movementVertexShaderId
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
GLint sphereVertexColorLocation