OpenGL ES SDK for Android
ARM Developer Center
|
A sample which shows how to use multisampled frame buffer objects with render-to-texture. More...
#include <GLES3/gl3.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <math.h>
#include <jni.h>
#include <android/log.h>
#include "MultisampledFBO.h"
#include "Teapot.h"
#include "Text.h"
#include "AndroidPlatform.h"
#include "Shader.h"
#include "Matrix.h"
Go to the source code of this file.
Classes | |
struct | Color |
A sample which shows how to use multisampled frame buffer objects with render-to-texture.
This demo draws a side-by-side comparison of a non-antialiased framebuffer object, and another FBO with multisampling enabled. The Utah Teapot is used an example model to illustrate how edges are affected by antialiasing.
Additionally the demo shows how to check for float and half-float support, and setup framebuffer objects using these formats.
The device is queried for the following extensions, and the results logged: GL_EXT_multisampled_render_to_texture - for actually rendering to texture with MSAA GL_EXT_color_buffer_half_float - for GL_RGBA16F texture support GL_EXT_color_buffer_float - for GL_RGBA32F texture support OES_texture_half_float_linear - for linear filtering on GL_RGBA16F textures OES_texture_float_linear - for linear filtering on GL_RGBA32F textures
To resolve the multisampled FBOs and present them to the user, we render them to textured quads, instead of using glBlitFramebuffer(). This is because with our tile-based rendering, using glBlitFrameBuffer() would incur additional memory copying overheads and would be suboptimal. Rendering textured quads is faster and also allows us the flexibility to do shader-based post- processing as well as being able to use a custom projection.
The demo initially uses the highest supported texture format with the maximum number of samples. The user is able to interact with the demo and change the settings as follows: Tap on screen: toggle rotation animation Long-press on screen: cycle through different colors Pinch-to-zoom gesture: change distance of model Drag on screen: rotate model Volume up: switch multisampling level Volume down: switch texture resolution Long-press on volume up: switch texture format Long press on volume down: toggle texture filtering on/off
Definition in file MultisampledFBO.cpp.
void drawTeapot | ( | ) |
Definition at line 489 of file MultisampledFBO.cpp.
bool extensionAvailable | ( | const char * | extName | ) |
Definition at line 216 of file MultisampledFBO.cpp.
void findTeapotDimensions | ( | ) |
Definition at line 222 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_init | ( | JNIEnv * | env, |
jclass | jcls, | ||
jint | width, | ||
jint | height | ||
) |
Definition at line 637 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_setDragRotation | ( | JNIEnv * | env, |
jclass | jcls, | ||
jfloat | rotationX, | ||
jfloat | rotationY | ||
) |
Definition at line 738 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_setScaleFactor | ( | JNIEnv * | env, |
jclass | jcls, | ||
jfloat | scaleFactor | ||
) |
Definition at line 730 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_step | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 649 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchColor | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 662 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchSamples | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 670 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchTextureFormat | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 686 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_switchTextureSize | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 708 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_toggleAnim | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 655 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_toggleTextureFiltering | ( | JNIEnv * | env, |
jclass | jcls | ||
) |
Definition at line 720 of file MultisampledFBO.cpp.
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_multisampledfbo_MultisampledFBO_uninit | ( | JNIEnv * | , |
jclass | |||
) |
Definition at line 748 of file MultisampledFBO.cpp.
Definition at line 564 of file MultisampledFBO.cpp.
Definition at line 240 of file MultisampledFBO.cpp.
bool setupFBO | ( | GLuint * | fbo, |
GLuint * | colorBuffer, | ||
GLuint * | depthBuffer, | ||
GLuint | textureSize, | ||
GLenum | internalFormat, | ||
GLuint | samples | ||
) |
Definition at line 256 of file MultisampledFBO.cpp.
Definition at line 322 of file MultisampledFBO.cpp.
void setupText | ( | ) |
Definition at line 296 of file MultisampledFBO.cpp.
GLboolean animate = true |
Definition at line 204 of file MultisampledFBO.cpp.
const Color backgrounds[] |
Definition at line 125 of file MultisampledFBO.cpp.
GLboolean canFilterFloat |
Definition at line 154 of file MultisampledFBO.cpp.
GLboolean canFilterHalfFloat |
Definition at line 153 of file MultisampledFBO.cpp.
const Color colors[] |
Definition at line 114 of file MultisampledFBO.cpp.
Definition at line 198 of file MultisampledFBO.cpp.
GLuint currentColor = 0 |
Definition at line 156 of file MultisampledFBO.cpp.
GLint currentSamples = 0 |
Definition at line 157 of file MultisampledFBO.cpp.
GLuint currentTextureFormat = 0 |
Definition at line 158 of file MultisampledFBO.cpp.
GLuint currentTextureSize = 5 |
Definition at line 159 of file MultisampledFBO.cpp.
GLuint depthBufferMSAA |
Definition at line 185 of file MultisampledFBO.cpp.
GLuint depthBufferNoAA |
Definition at line 184 of file MultisampledFBO.cpp.
GLfloat dragRotateX = 0.0f |
Definition at line 210 of file MultisampledFBO.cpp.
GLfloat dragRotateY = 0.0f |
Definition at line 211 of file MultisampledFBO.cpp.
GLuint frameBufferMSAA |
Definition at line 179 of file MultisampledFBO.cpp.
GLuint frameBufferNoAA |
Definition at line 178 of file MultisampledFBO.cpp.
PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC glFramebufferTexture2DMultisampleEXT = NULL |
Definition at line 92 of file MultisampledFBO.cpp.
PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC glRenderbufferStorageMultisampleEXT = NULL |
Definition at line 93 of file MultisampledFBO.cpp.
GLint iLocQuadMVPMatrix = -1 |
Definition at line 175 of file MultisampledFBO.cpp.
GLint iLocQuadPosition = -1 |
Definition at line 173 of file MultisampledFBO.cpp.
GLint iLocQuadTexCoord = -1 |
Definition at line 174 of file MultisampledFBO.cpp.
GLint iLocTeapotColor = -1 |
Definition at line 168 of file MultisampledFBO.cpp.
GLint iLocTeapotMVMatrix = -1 |
Definition at line 169 of file MultisampledFBO.cpp.
GLint iLocTeapotMVPMatrix = -1 |
Definition at line 170 of file MultisampledFBO.cpp.
GLint iLocTeapotNormal = -1 |
Definition at line 167 of file MultisampledFBO.cpp.
GLint iLocTeapotNormalMatrix = -1 |
Definition at line 171 of file MultisampledFBO.cpp.
GLint iLocTeapotPosition = -1 |
Definition at line 166 of file MultisampledFBO.cpp.
GLboolean linearFilteringEnabled = true |
Definition at line 160 of file MultisampledFBO.cpp.
GLint maxSamples = 0 |
Definition at line 150 of file MultisampledFBO.cpp.
Definition at line 191 of file MultisampledFBO.cpp.
GLfloat maxXYZ = 0.0f |
Definition at line 194 of file MultisampledFBO.cpp.
Definition at line 192 of file MultisampledFBO.cpp.
Definition at line 193 of file MultisampledFBO.cpp.
GLfloat minX = 0.0f |
Definition at line 188 of file MultisampledFBO.cpp.
Definition at line 189 of file MultisampledFBO.cpp.
Definition at line 190 of file MultisampledFBO.cpp.
GLfloat pinchZoomScaleFactor = 1.0f |
Definition at line 207 of file MultisampledFBO.cpp.
string quadFragmentShaderFilename = "MultisampledFBO_quad.frag" |
Definition at line 104 of file MultisampledFBO.cpp.
GLuint quadProgramID |
Definition at line 164 of file MultisampledFBO.cpp.
string quadVertexShaderFilename = "MultisampledFBO_quad.vert" |
Definition at line 103 of file MultisampledFBO.cpp.
const string resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.multisampledfbo/" |
Definition at line 100 of file MultisampledFBO.cpp.
GLfloat rotationDegree1 = 0.0f |
Definition at line 196 of file MultisampledFBO.cpp.
GLfloat rotationDegree2 = 0.0f |
Definition at line 197 of file MultisampledFBO.cpp.
const string teapotFragmentShaderFilename = "MultisampledFBO_teapot.frag" |
Definition at line 102 of file MultisampledFBO.cpp.
GLuint teapotProgramID |
Definition at line 163 of file MultisampledFBO.cpp.
const string teapotVertexShaderFilename = "MultisampledFBO_teapot.vert" |
Definition at line 101 of file MultisampledFBO.cpp.
GLuint texColorBufferMSAA |
Definition at line 182 of file MultisampledFBO.cpp.
GLuint texColorBufferNoAA |
Definition at line 181 of file MultisampledFBO.cpp.
Text* text |
Definition at line 214 of file MultisampledFBO.cpp.
const GLenum textureFormats[] = { GL_RGBA4, GL_RGBA8, GL_RGBA16F, GL_RGBA32F } |
Definition at line 137 of file MultisampledFBO.cpp.
GLint textureFormatSamples[] = { 0, 0, 0, 0 } |
Definition at line 144 of file MultisampledFBO.cpp.
const GLchar* const textureFormatStrings[] = { "GL_RGBA4", "GL_RGBA8", "GL_RGBA16F", "GL_RGBA32F" } |
Definition at line 138 of file MultisampledFBO.cpp.
GLboolean textureFormatSupported[] = { false, false, false, false } |
Definition at line 141 of file MultisampledFBO.cpp.
GLuint textureSizes[] = { 32, 64, 128, 256, 512, 1024 } |
Definition at line 147 of file MultisampledFBO.cpp.
GLint windowHeight = -1 |
Definition at line 201 of file MultisampledFBO.cpp.
GLint windowWidth = -1 |
Definition at line 200 of file MultisampledFBO.cpp.