Exemplo n.º 1
0
void oper::setupOperators(uint eType, uint order, geo *inGeo, input *inParams)
{
  // Get access to basic data
  Geo = inGeo;
  params = inParams;

  nDims = Geo->nDims;
  nFields = params->nFields;

  this->eType = eType;
  this->order = order;

  vector<point> loc_spts = Geo->getLocSpts(eType,order);
  vector<point> loc_fpts = Geo->getLocFpts(eType,order);

  // Set up each operator
  setupExtrapolateSptsFpts(loc_spts, loc_fpts);

  setupExtrapolateSptsMpts(loc_spts);

  setupGradSpts(loc_spts);

  setupCorrection(loc_spts,loc_fpts);

}
Exemplo n.º 2
0
bool StGLImageProgram::init(StGLContext&                 theCtx,
                            const StImage::ImgColorModel theColorModel,
                            const StImage::ImgColorScale theColorScale,
                            const FragGetColor           theFilter) {

    // re-configure shader parts when required
    bool isChanged = myActiveProgram.isNull();
    isChanged = setFragmentShaderPart(theCtx, FragSection_Main,    0) || isChanged;
    isChanged = setFragmentShaderPart(theCtx, FragSection_Gamma,
                                      stAreEqual(params.gamma->getValue(), 1.0f, 0.0001f) ? FragGamma_Off : FragGamma_On) || isChanged;
    isChanged = setFragmentShaderPart(theCtx, FragSection_Correct,
                                      params.brightness->isDefaultValue()
                                   && params.saturation->isDefaultValue()
                                   && hasNoColorScale() ? FragCorrect_Off : FragCorrect_On) || isChanged;
    int aToRgb = getColorShader(theColorModel, theColorScale);
    if(aToRgb >= FragToRgb_FromYuvFull
    && theFilter == FragGetColor_Cubemap) {
        aToRgb += FragToRgb_CUBEMAP;
    }

    isChanged = setFragmentShaderPart(theCtx, FragSection_ToRgb,    aToRgb) || isChanged;
    isChanged = setFragmentShaderPart(theCtx, FragSection_GetColor, theFilter) || isChanged;
    isChanged = setVertexShaderPart  (theCtx, 0, theFilter == FragGetColor_Cubemap ? VertMain_Cubemap : VertMain_Normal) || isChanged;
    if(isChanged) {
        if(!initProgram(theCtx)) {
            return false;
        }

        myActiveProgram->uniProjMatLoc  = myActiveProgram->getUniformLocation(theCtx, "uProjMat");
        myActiveProgram->uniModelMatLoc = myActiveProgram->getUniformLocation(theCtx, "uModelMat");
        uniTexMainDataLoc     = myActiveProgram->getUniformLocation(theCtx, "uTexData");
        uniTexUVDataLoc       = myActiveProgram->getUniformLocation(theCtx, "uTexUVData");
        uniTexSizePxLoc       = myActiveProgram->getUniformLocation(theCtx, "uTexSizePx");
        uniTexelSizePxLoc     = myActiveProgram->getUniformLocation(theCtx, "uTexelSize");
        uniColorProcessingLoc = myActiveProgram->getUniformLocation(theCtx, "uColorProcessing");
        uniGammaLoc           = myActiveProgram->getUniformLocation(theCtx, "uGamma");
        myActiveProgram->atrVVertexLoc  = myActiveProgram->getAttribLocation(theCtx, "vVertex");
        myActiveProgram->atrVTCoordLoc  = myActiveProgram->getAttribLocation(theCtx, "vTexCoord");

        StGLVarLocation uniTextureLoc  = myActiveProgram->getUniformLocation(theCtx, "uTexture");
        StGLVarLocation uniTextureULoc = myActiveProgram->getUniformLocation(theCtx, "uTextureU");
        StGLVarLocation uniTextureVLoc = myActiveProgram->getUniformLocation(theCtx, "uTextureV");
        myActiveProgram->use(theCtx);
        theCtx.core20fwd->glUniform1i(uniTextureLoc,  StGLProgram::TEXTURE_SAMPLE_0);
        theCtx.core20fwd->glUniform1i(uniTextureULoc, StGLProgram::TEXTURE_SAMPLE_1);
        theCtx.core20fwd->glUniform1i(uniTextureVLoc, StGLProgram::TEXTURE_SAMPLE_2);
        myActiveProgram->unuse(theCtx);

        /*if (!uniModelMatLoc.isValid()
         || !uniTexMainDataLoc.isValid()
        //|| !uniTexSizePxLoc.isValid()
        //|| !uniTexelSizePxLoc.isValid()
        //|| !uniSmoothFilterLoc.isValid()
        //|| !uniColorProcessingLoc
         || !atrVVertexLoc.isValid()
         || !atrVTCoordLoc.isValid()
         || !uniTextureLoc.isValid()) {
            return false;
        }*/
    }
    if(!isValid()) {
        return false;
    }

    myActiveProgram->use(theCtx);
    if(getFragmentShaderPart(FragSection_Gamma) != FragGamma_Off) {
        GLfloat aReversed = 1.0f / params.gamma->getValue();
        StGLVec4 aVec(aReversed, aReversed, aReversed, 1.0f);
        theCtx.core20fwd->glUniform4fv(uniGammaLoc, 1, aVec);
    }
    setupCorrection(theCtx);
    myActiveProgram->unuse(theCtx);

    const StGLResources aShaders("StGLWidgets");
    return true;
}