Esempio n. 1
0
// #### updateRegistry
//
//      Evaluates dirty flags and updates the effect registry if any
//      attributes have changed that require the shader to be rebuilt
//
void
OpenSubdivShader::updateRegistry()
{
    /* If adaptive flag has changed, update the effectRegistry accordingly */
    if (_adaptiveDirty) {
        g_effectRegistry.setIsAdaptive(_adaptive);
        _adaptiveDirty = false;
    }

    MHWRender::MRenderer *theRenderer = MHWRender::MRenderer::theRenderer();
    _theTextureManager = theRenderer->getTextureManager();

    /* If diffuse texture has changed, update the effectRegistry accordingly */
    if (_diffuseMapDirty) {
        GLuint diffMapId = bindTexture( _diffuseMapFile, DIFF_TEXTURE_UNIT );
        g_effectRegistry.setDiffuseId(diffMapId);
        _diffuseMapDirty = false;
    }

    /* If shader source has changed, update the effectRegistry accordingly */
    if (_shaderSourceDirty) {
        if ( _shaderSource.empty() ) {
            if ( g_effectRegistry.getShaderSource() != defaultShaderSource ) {
                g_effectRegistry.setShaderSource(defaultShaderSource);
            }
        } else {
            if ( g_effectRegistry.getShaderSource() != _shaderSource ) {
                g_effectRegistry.setShaderSource(_shaderSource);
            }
        }
        _shaderSourceDirty = false;
    }
}
//
//      updateRegistry
//
//      When attributes change which affect the shader compilation the
//      effectRegistry needs to be updated with the new values
//
void
OpenSubdivPtexShader::updateRegistry()
{
    // adaptive toggle
    if (_adaptiveDirty) {
        effectRegistry.setIsAdaptive(_adaptive);
        _adaptiveDirty = false;
    }

    // ptex color file
    if (_ptexColorDirty) {
        bool ptexColorValid = bindPtexTexture(_colorFile, &_ptexColor, CLR_TEXTURE_UNIT);
        effectRegistry.setPtexColorValid(ptexColorValid);
        _ptexColorDirty = false;
    }

    // ptex displacement file
    if (_ptexDisplacementDirty) {
        bool ptexDisplacementValid = bindPtexTexture(_displacementFile, &_ptexDisplacement, DISP_TEXTURE_UNIT);
        effectRegistry.setPtexDisplacementValid(ptexDisplacementValid);
        _ptexDisplacementDirty = false;
    }

    // ptex occlusion file
    if (_ptexOcclusionDirty) {
        bool ptexOcclusionValid = bindPtexTexture(_occlusionFile, &_ptexOcclusion, OCC_TEXTURE_UNIT);
        effectRegistry.setPtexOcclusionValid(ptexOcclusionValid);
        _ptexOcclusionDirty = false;
    }


    MHWRender::MRenderer *theRenderer = MHWRender::MRenderer::theRenderer();
    _theTextureManager = theRenderer->getTextureManager();

    // diffuse environment map file
    if (_diffEnvMapDirty) {
        GLuint diffEnvMapId = bindTexture( _diffEnvMapFile, DIFF_TEXTURE_UNIT );
        effectRegistry.setDiffuseEnvironmentId(diffEnvMapId);
        _diffEnvMapDirty = false;
    }

    // specular environment map file
    if (_specEnvMapDirty) {
        GLuint specEnvMapId = bindTexture( _specEnvMapFile, ENV_TEXTURE_UNIT );
        effectRegistry.setSpecularEnvironmentId(specEnvMapId);
        _specEnvMapDirty = false;
    }

    // shader source
    if (_shaderSourceDirty) {
        if ( _shaderSource.empty() ) {
            if ( effectRegistry.getShaderSource() != defaultShaderSource ) {
                effectRegistry.setShaderSource(defaultShaderSource);
            }
        } else {
            if ( effectRegistry.getShaderSource() != _shaderSource ) {
                effectRegistry.setShaderSource(_shaderSource);
            }
        }
        _shaderSourceDirty = false;
    }
}