void OptimizationApp::initRendering(void) {
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

    NvAssetLoaderAddSearchPath("es2-aurora/OptimizationApp");

#ifdef GL_OES_texture_3D
    if (requireExtension("GL_EXT_framebuffer_blit", false)) {
        glBlitFramebufferFunc = (void (KHRONOS_APIENTRY *) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter))
                                getGLContext()->getGLProcAddress("glBlitFramebufferEXT");
    } else if (getGLContext()->getConfiguration().apiVer != NvGfxAPIVersionES2()) {
        glBlitFramebufferFunc = (void (KHRONOS_APIENTRY *) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter))
                                getGLContext()->getGLProcAddress("glBlitFramebuffer");
    } else {
        glBlitFramebufferFunc = NULL;
    }
#else
    glBlitFramebufferFunc = glBlitFramebuffer;
#endif

    if (getGLContext()->getConfiguration().apiVer == NvGfxAPIVersionES2()) {
        gFloatTypeEnum = 0x8D61; // GL_HALF_FLOAT_OES, not declared in GL
        gLumaTypeEnum = GL_LUMINANCE;
    } else {
        gFloatTypeEnum = GL_FLOAT;
        gLumaTypeEnum = 0x1903; // GL_RED, not declared in ES
    }

    m_sceneRenderer = new SceneRenderer(
        getGLContext()->getConfiguration().apiVer == NvGfxAPIVersionES2());
    CHECK_GL_ERROR();

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glClearColor(0.0, 0.0, 1.0, 1.0);
}
Example #2
0
void MotionBlur::initRendering(void) {
    // This sample requires at least OpenGL ES 2.0
    if (!requireMinAPIVersion(NvGfxAPIVersionES2())) 
        return;

    cleanRendering();

    NvAssetLoaderAddSearchPath("es2-aurora/MotionBlur");

    mSceneColorShader  = new SceneColorShader;
    mSkyboxColorShader = new SkyboxColorShader;
    mMotionBlurShader  = new MotionBlurShader;

    // Load model data for scene geometry
    int32_t length;
    char *modelData = NvAssetLoaderRead("models/house.obj", length);

    mHouseModel = new NvGLModel();
    mHouseModel->loadModelFromObjData(modelData);
    mHouseModel->initBuffers();

    NvAssetLoaderFree(modelData);

    modelData = NvAssetLoaderRead("models/fan.obj", length);

    mSailsModel = new NvGLModel();
    mSailsModel->loadModelFromObjData(modelData);
    mSailsModel->initBuffers();

    NvAssetLoaderFree(modelData);

    // Load some scene textures
    mHouseTexID =
        NvImage::UploadTextureFromDDSFile("textures/windmill_diffuse.dds");
    glBindTexture(GL_TEXTURE_2D, mHouseTexID);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glBindTexture(GL_TEXTURE_2D, 0);
    CHECK_GL_ERROR();

    mSkyBoxTexID = NvImage::UploadTextureFromDDSFile("textures/sky_cube.dds");
    glBindTexture(GL_TEXTURE_CUBE_MAP, mSkyBoxTexID);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
    CHECK_GL_ERROR();

    // Assign some uniform values that never change.
    nv::vec4f lightPositionEye(1.0f, 1.0f, 1.0f, 0.0f);

    mSceneColorShader->enable();
    glUniform4fv(mSceneColorShader->lightPositionUHandle, 1,
                 lightPositionEye._array);
    glUniform1f(mSceneColorShader->lightAmbientUHandle,    0.1f);
    glUniform1f(mSceneColorShader->lightDiffuseUHandle,    0.7f);
    glUniform1f(mSceneColorShader->lightSpecularUHandle,   1.0f);
    glUniform1f(mSceneColorShader->lightShininessUHandle, 64.0f);
    CHECK_GL_ERROR();
    mSceneColorShader->disable();

    // Set some pipeline state settings that do not change
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    CHECK_GL_ERROR();
}
Example #3
0
void MotionBlur::configurationCallback(NvEGLConfiguration& config)
{ 
    config.depthBits   = 24; 
    config.stencilBits = 0; 
    config.apiVer      = NvGfxAPIVersionES2();
}
Example #4
0
////////////////////////////////////////////////////////////////////////////////
//
//  Method: SkinningApp::initRendering()
//
//    Sets up initial rendering state and creates the skinned character mesh
//
////////////////////////////////////////////////////////////////////////////////
void SkinningApp::initRendering(void) {
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);    

    NvAssetLoaderAddSearchPath("es2-aurora/SkinningApp");

    m_mesh.m_useES2 = getGLContext()->getConfiguration().apiVer == NvGfxAPIVersionES2();

    // Initialize the mesh
    int32_t vertexCount = sizeof(g_characterModelVertices) / (10*sizeof(float)); // 3x pos, 3x norm, (2+2)x bone
    int32_t indexCount = sizeof(g_characterModelIndices) / (sizeof(g_characterModelIndices[0]));

    // Convert the float data in the vertex array to half data
    // On Android, this may have already been converted during a previous run and
    // kept in-core.  We MUST skip this step in that case.
    if (!g_convertedToSkinnedVertex) {
        int32_t index = 0;
        for(int32_t i=0; i<vertexCount; i++)
        {
            SkinnedVertex& v = ((SkinnedVertex*)g_characterModelVertices)[i];
            v.m_position[0] = half(g_characterModelVertices[index++]);
            v.m_position[1] = half(g_characterModelVertices[index++]);
            v.m_position[2] = half(g_characterModelVertices[index++]);
            v.m_normal[0] = half(g_characterModelVertices[index++]);
            v.m_normal[1] = half(g_characterModelVertices[index++]);
            v.m_normal[2] = half(g_characterModelVertices[index++]);
            v.m_weights[0] = half(g_characterModelVertices[index++]);
            v.m_weights[1] = half(g_characterModelVertices[index++]);
            v.m_weights[2] = half(g_characterModelVertices[index++]);
            v.m_weights[3] = half(g_characterModelVertices[index++]);
        }
        g_convertedToSkinnedVertex = true;
    }

    // Stick the half float data into the mesh
    m_mesh.update(reinterpret_cast<const SkinnedVertex*>(g_characterModelVertices), vertexCount, g_characterModelIndices, indexCount);      


    //
    // Initialize the shaders
    //

    m_skinningProgram = NvGLSLProgram::createFromFiles("shaders/skinning.vert", "shaders/simple.frag");

    // Get the locations of the uniforms
    m_ModelViewProjectionLocation = m_skinningProgram->getUniformLocation("ModelViewProjection");
    m_BonesLocation = m_skinningProgram->getUniformLocation("Bones");
    m_RenderModeLocation = m_skinningProgram->getUniformLocation("RenderMode");
    m_LightDir0Location = m_skinningProgram->getUniformLocation("LightDir0");
    m_LightDir1Location = m_skinningProgram->getUniformLocation("LightDir1");

    // Get the locations of the attributes
    m_iPositionLocation = m_skinningProgram->getAttribLocation("iPosition");
    m_iNormalLocation = m_skinningProgram->getAttribLocation("iNormal");
    m_iWeightsLocation = m_skinningProgram->getAttribLocation("iWeights");

    // Initialize some view parameters
    m_transformer->setRotationVec(nv::vec3f(0.0f, NV_PI*0.25f, 0.0f));
    m_transformer->setTranslationVec(nv::vec3f(0.0f, 0.0f, -25.0f));
    m_transformer->setMaxTranslationVel(50.0f); // seems to work decently.

    CHECK_GL_ERROR();
}
Example #5
0
    // member variables

    //! Start of measurement
    struct timeval  start_time;

    //! Time difference between the last start and stop
    float  diff_time;

    //! Number of times clock has been started
    //! and stopped to allow averaging
    int32_t clock_sessions;
};


static NvEGLConfiguration sDefaultConfig(NvGfxAPIVersionES2(), 8, 8, 8, 8, 16, 0);

static bool localEGLChooser(EGLDisplay disp, EGLint apiSupport, EGLConfig& bestConfig, EGLint& api, EGLint& apiMajVer, EGLint& apiMinVer)
{

    EGLint count = 0;
    if (!eglGetConfigs(disp, NULL, 0, &count))
    {
        EGL_ERROR_LOG("defaultEGLChooser cannot query count of all configs");
        return false;
    }

    LOGI("Config count = %d", count);

    EGLConfig* configs = new EGLConfig[count];
    if (!eglGetConfigs(disp, configs, count, &count))