57 #include <GLES3/gl3.h>
70 #include <GLES2/gl2ext.h>
81 #include <android/log.h>
96 using std::ostringstream;
97 using namespace MaliSDK;
100 const string resourceDirectory =
"/data/data/com.arm.malideveloper.openglessdk.multisampledfbo/";
116 { 0.0706f, 0.5490f, 0.6706f },
117 { 0.9882f, 0.9961f, 0.0157f },
118 { 0.9882f, 0.6039f, 0.0157f },
119 { 0.9882f, 0.4000f, 0.0196f },
120 { 0.9882f, 0.1961f, 0.0157f },
121 { 0.8000f, 0.0078f, 0.0157f },
122 { 0.6118f, 0.0078f, 0.3922f },
127 { 0.0000f, 0.0000f, 0.0000f },
128 { 0.3922f, 0.0200f, 0.3922f },
129 { 0.0156f, 0.0118f, 0.3922f },
130 { 0.0157f, 0.1961f, 0.6118f },
131 { 0.0157f, 0.4000f, 0.3922f },
132 { 0.2039f, 0.6039f, 0.0157f },
133 { 0.3922f, 0.8078f, 0.0157f },
218 string extensions =
reinterpret_cast<const char*
>(glGetString(GL_EXTENSIONS));
219 return extensions.find(extName) != string::npos;
250 GL_CHECK(glBindTexture(GL_TEXTURE_2D, *texture));
253 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
258 LOGD(
"Creating a %dx%d %smultisampled FBO (%d samples).", textureSize, textureSize, samples ?
"" :
"non-", samples);
261 GL_CHECK(glDeleteFramebuffers(1, fbo));
262 GL_CHECK(glGenFramebuffers(1, fbo));
263 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, *fbo));
266 GL_CHECK(glDeleteTextures(1, colorBuffer));
267 GL_CHECK(glGenTextures(1, colorBuffer));
268 GL_CHECK(glBindTexture(GL_TEXTURE_2D, *colorBuffer));
269 GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, textureSize, textureSize));
273 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
274 GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
276 GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
279 GL_CHECK(glDeleteRenderbuffers(1, depthBuffer))
280 GL_CHECK(glGenRenderbuffers(1, depthBuffer));
281 GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, *depthBuffer));
283 GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, *depthBuffer));
284 GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, 0));
287 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
289 LOGE(
"%s framebuffer is incomplete! Error code %d", (samples ?
"Multisampled" :
"Non-multisampled"), glGetError());
298 ostringstream maxSamplesStringStream;
299 ostringstream texFormatStringStream;
300 ostringstream descriptionStringStream;
302 maxSamplesStringStream <<
"Max number of samples (all texture formats): " <<
maxSamples;
308 descriptionStringStream <<
"Left: No anti-aliasing. Right: Multisampled anti-aliasing (" <<
currentSamples <<
" samples)";
319 text->
addString(0, 0,
"Multisampled framebuffer objects.", 0, 255, 255, 255);
325 LOGD(
"setupGraphics(%d, %d)", width, height);
328 LOGD(
"Available extensions:");
329 LOGD(
"GL_EXT_multisampled_render_to_texture = %s",
extensionAvailable(
"GL_EXT_multisampled_render_to_texture") ?
"YES" :
"NO");
330 LOGD(
"GL_EXT_color_buffer_half_float = %s",
extensionAvailable(
"GL_EXT_color_buffer_half_float") ?
"YES" :
"NO");
339 LOGD(
"Max samples for internal texture formats:");
363 LOGE(
"Couldn't get function pointer to glFramebufferTexture2DMultisampleEXT()!");
370 LOGE(
"Couldn't get function pointer to glRenderbufferStorageMultisampleEXT()!");
385 GLuint teapotVertexShaderID = 0;
386 GLuint teapotFragmentShaderID = 0;
387 GLuint quadVertexShaderID = 0;
388 GLuint quadFragmentShaderID = 0;
397 GLint bestSamples = 0;
398 GLint bestTextureFormat = 0;
404 bestTextureFormat = i;
423 Shader::processShader(&teapotFragmentShaderID, teapotFragmentShaderPath.c_str(), GL_FRAGMENT_SHADER);
427 LOGD(
"teapotVertexShaderID = %d", teapotVertexShaderID);
428 LOGD(
"teapotFragmentShaderID = %d", teapotFragmentShaderID);
429 LOGD(
"quadVertexShaderID = %d", quadVertexShaderID);
430 LOGD(
"quadFragmentShaderID = %d", quadFragmentShaderID);
437 LOGE(
"Could not create program.");
450 GL_CHECK(glDeleteShader(teapotVertexShaderID));
451 GL_CHECK(glDeleteShader(teapotFragmentShaderID));
452 GL_CHECK(glDeleteShader(quadVertexShaderID));
453 GL_CHECK(glDeleteShader(quadFragmentShaderID));
498 GL_CHECK(glClearColor(bg.r, bg.g, bg.b, 1.0f));
499 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
589 GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0));
604 modelViewMatrix[14] -= 1.0f;
614 GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
617 GL_CHECK(glActiveTexture(GL_TEXTURE0));
629 GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
649 (JNIEnv *env, jclass jcls)
655 (JNIEnv *env, jclass jcls)
662 (JNIEnv *env, jclass jcls)
670 (JNIEnv *env, jclass jcls)
686 (JNIEnv *env, jclass jcls)
708 (JNIEnv *env, jclass jcls)
720 (JNIEnv *env, jclass jcls)
730 (JNIEnv *env, jclass jcls, jfloat scaleFactor)
GLuint texColorBufferMSAA
static const float quadVertices[]
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchSamples(JNIEnv *env, jclass jcls)
float projectionMatrix[16]
Functions for drawing text in OpenGL ES.
PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC glFramebufferTexture2DMultisampleEXT
static Matrix identityMatrix
The identity matrix.
const GLenum textureFormats[]
float modelViewMatrix[16]
GLint GLsizei GLsizei height
const float teapotNormals[]
float min(float x, float y)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchTextureSize(JNIEnv *env, jclass jcls)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_step(JNIEnv *env, jclass jcls)
const string teapotVertexShaderFilename
Functions for manipulating matrices.
static Matrix matrixInvert(Matrix *matrix)
Get the inverse of a matrix.
const GLubyte vertexIndices[]
static Matrix createTranslation(float x, float y, float z)
Create and return a translation matrix.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_toggleTextureFiltering(JNIEnv *env, jclass jcls)
void clear(void)
Removes the current string from the class.
const GLchar *const textureFormatStrings[]
GLint textureFormatSamples[]
GLint iLocTeapotMVPMatrix
GLuint texColorBufferNoAA
static Matrix matrixPerspective(float FOV, float ratio, float zNear, float zFar)
Create and return a perspective projection matrix.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_toggleAnim(JNIEnv *env, jclass jcls)
GLint iLocTeapotNormalMatrix
float * getAsArray(void)
Get the matrix elements as a column major order array.
static const int textureCharacterHeight
The height (in pixels) of the characters in the text texture.
GLuint currentTextureFormat
void findTeapotDimensions()
GLfloat pinchZoomScaleFactor
typedef GLboolean(GL_APIENTRYP PFNGLISENABLEDIOESPROC)(GLenum target
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_setDragRotation(JNIEnv *env, jclass jcls, jfloat rotationX, jfloat rotationY)
GLfloat GLfloat GLfloat GLfloat maxX
void addString(int xPosition, int yPosition, const char *string, int red, int green, int blue, int alpha)
Add a std::string to be drawn to the screen.
GLboolean textureFormatSupported[]
#define M_PI
The value of pi.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchColor(JNIEnv *env, jclass jcls)
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_setScaleFactor(JNIEnv *env, jclass jcls, jfloat scaleFactor)
const string resourceDirectory
static Matrix createRotationY(float angle)
Create and return a rotation matrix around the y-axis matrix.
static Matrix createRotationZ(float angle)
Create and return a rotation matrix around the z-axis matrix.
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
static void matrixTranspose(Matrix *matrix)
Transpose a matrix in-place.
GLboolean canFilterHalfFloat
bool setupFBO(GLuint *fbo, GLuint *colorBuffer, GLuint *depthBuffer, GLuint textureSize, GLenum internalFormat, GLuint samples)
string quadFragmentShaderFilename
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC glRenderbufferStorageMultisampleEXT
const float teapotPositions[]
string quadVertexShaderFilename
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_uninit(JNIEnv *, jclass)
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
GLboolean linearFilteringEnabled
void setTextureFiltering(GLuint *texture)
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
const unsigned int teapotIndices[]
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
const string teapotFragmentShaderFilename
bool setupGraphics(int width, int height)
static void processShader(GLuint *shader, const char *filename, GLint shaderType)
Create shader, load in source, compile, and dump debug as necessary.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_init(JNIEnv *env, jclass jcls, jint width, jint height)
void draw(void)
Draw the text to the screen.
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
static Matrix createRotationX(float angle)
Create and return a rotation matrix around the x-axis matrix.
const Color backgrounds[]
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchTextureFormat(JNIEnv *env, jclass jcls)
GLuint currentTextureSize
bool extensionAvailable(const char *extName)