void DSLightChunk::activate(DrawEnv *drawEnv, UInt32 index)
{
    glErr("dslight:activate:precheck");

    Matrix matMV;
    calcModelView(drawEnv, matMV);

    glPushMatrix();
    glLoadMatrixf(matMV.getValues());

    glLightfv( GL_LIGHT0 + index, 
               GL_DIFFUSE,
              _sfDiffuse.getValue().getValuesRGBA());

    glLightfv( GL_LIGHT0 + index, 
               GL_AMBIENT,
              _sfAmbient.getValue().getValuesRGBA());

    glLightfv( GL_LIGHT0 + index, 
               GL_SPECULAR,
              _sfSpecular.getValue().getValuesRGBA());
    glLightfv( GL_LIGHT0 + index, 
               GL_POSITION,
              _sfPosition.getValue().getValues());

    glLightf ( GL_LIGHT0 + index, 
               GL_CONSTANT_ATTENUATION,
              _sfConstantAttenuation.getValue());

    glLightf ( GL_LIGHT0 + index, 
               GL_LINEAR_ATTENUATION,
              _sfLinearAttenuation.getValue());

    glLightf ( GL_LIGHT0 + index, 
               GL_QUADRATIC_ATTENUATION,
              _sfQuadraticAttenuation.getValue());

    glLightf( GL_LIGHT0 + index, 
              GL_SPOT_CUTOFF, 
             _sfCutoff.getValue());

    if(_sfCutoff.getValue() < 180.f)
    {
        glLightfv( GL_LIGHT0 + index, 
                   GL_SPOT_DIRECTION,
                  _sfDirection.getValue().getValues());

        glLightf( GL_LIGHT0 + index, 
                  GL_SPOT_EXPONENT, 
                 _sfExponent.getValue());
    }

    glEnable(GL_LIGHT0 + index);

    glPopMatrix();

    glErr("dslight:activate:postcheck");
}
Ejemplo n.º 2
0
// activate the window: bind the OGL context    
void XWindow::doActivate(void)
{
    Bool res;

    res = glXMakeCurrent(getDisplay(), getWindow(), getContext());
    
    if(res != True)
    {
        FWARNING(("XWindow::activate: makeCurrent failed!\n"));
        glErr("XWindow::activate");
        glErr("XWindow::activate");
        glErr("XWindow::activate");
    }
}
Ejemplo n.º 3
0
void TexGenChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
{
    glErr("TexGenChunk::deactivate precheck");

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    Window *win = pEnv->getWindow();   

    Real32 ntexcoords;
    if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
       Window::unknownConstant
      )
    {
        ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(ntexcoords == Window::unknownConstant)
            ntexcoords = 1.0f;
    }

    if(idx >= static_cast<UInt32>(ntexcoords))
    {
#ifdef OSG_DEBUG
        FWARNING(("TexGenChunk::deactivate: Trying to bind texcoord unit %d,"
                  " but Window %p only supports %lf!\n",
                  idx, 
                  static_cast<void *>(win), 
                  ntexcoords));
#endif
        return;        
    }

    TextureBaseChunk::activateTexture(win, idx);

    if(getGenFuncS() != GL_NONE || getSBeacon() != NULL)
        glDisable(GL_TEXTURE_GEN_S);

    if(getGenFuncT() != GL_NONE || getTBeacon() != NULL)
        glDisable(GL_TEXTURE_GEN_T);

    if(getGenFuncR() != GL_NONE || getRBeacon() != NULL)
        glDisable(GL_TEXTURE_GEN_R);

    if(getGenFuncQ() != GL_NONE || getQBeacon() != NULL)
        glDisable(GL_TEXTURE_GEN_Q);
#else
    OSG_ASSERT(false);
#endif

    glErr("TexGenChunk::deactivate");
}
void RenderBuffer::processPreDeactivate (DrawEnv *pEnv, UInt32 index)
{
    if(_sfReadBack.getValue() == true)
    {
        Image *pImg = this->getImage();
        
        if(pImg == NULL)
            return;
                           
        if(pImg->getData() == NULL)
        {
            SINFO << "TextureBuffer::render: (Re)Allocating image "
                  << "for read-back."
                  << endLog;
            
            pImg->set(pImg->getPixelFormat(),
                      pImg->getWidth      (),
                      pImg->getHeight     ());
        }
       
        // select GL_COLORATTACHMENTn and read data into image
        glReadBuffer(index);
        glReadPixels(0, 0, 
                     pImg->getWidth      (), 
                     pImg->getHeight     (),
                     pImg->getPixelFormat(), 
                     pImg->getDataType   (),
                     pImg->editData      ());

        glReadBuffer(GL_NONE);

        glErr("renderbuffer:predeactivate");
    }
}
Ejemplo n.º 5
0
// activate the window: bind the OGL context    
void XWindow::doActivate(void)
{
    Bool res;

#ifdef OSG_DEBUG
    if(getDisplay() == NULL)
    {
        SWARNING << "XWindow::doActivate: Display is NULL, can not activate context."
                 << std::endl;
    }

    if(getWindow() == 0)
    {
        SWARNING << "XWindow::doActivate: Window is NULL, can not activate "
                 << "context."
                 << std::endl;
    }

    if(getContext() == NULL)
    {
        SWARNING << "XWindow::doActivate: Context is NULL, can not activate "
                 << "context."
                 << std::endl;
    }
#endif

    res = glXMakeCurrent(getDisplay(), getWindow(), getContext());
    
    if(res != True)
    {
        FWARNING(("XWindow::activate: makeCurrent failed!\n"));
        glErr("XWindow::activate");
        glErr("XWindow::activate");
        glErr("XWindow::activate");
    }
}
void CubeTextureObjChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
{
    // does the window support cubemaps?
    if(pEnv->getWindow()->hasExtension(_arbCubeTex) == false)
        return;
        
    Window *win = pEnv->getWindow();   

    Real32 nteximages, ntexcoords;
    if((nteximages = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
       Window::unknownConstant )
    {
        nteximages = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);

        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(nteximages == Window::unknownConstant)
            nteximages = 1.0f;
    }

    if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
       Window::unknownConstant )
    {
        ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);

        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(ntexcoords == Window::unknownConstant)
            ntexcoords = 1.0f;
    }

    if(idx >= static_cast<UInt32>(nteximages))
    {
#ifdef OSG_DEBUG
        FWARNING(("CubeTextureObjChunk::deactivate: Trying to bind image unit"
                  " %d, but Window %p only supports %lf!\n",
                  idx, win, nteximages));
#endif
        return;        
    }

    TextureBaseChunk::activateTexture(win, idx);

    glDisable(GL_TEXTURE_CUBE_MAP_ARB);

    pEnv->setActiveTexTarget(idx, GL_NONE);

    glErr("CubeTextureObjChunk::deactivate");
}
void ShaderStorageBufferObjRefChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
{
    Window *pWin = pEnv->getWindow();

    OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
                             osgGlBindBuffer,
                            _funcBindBuffer, 
                             pWin);

    OSGGETGLFUNCBYID_GL3_ES( glBindBufferBase, 
                             osgGlBindBufferBase,
                            _funcBindBufferBase, 
                             pWin);

    osgGlBindBufferBase(GL_SHADER_STORAGE_BUFFER, idx, 0);
    osgGlBindBuffer    (GL_SHADER_STORAGE_BUFFER, 0);

    glErr("ShaderStorageBufferObjRefChunk::deactivate");
}
void ShaderStorageBufferObjRefChunk::activate(DrawEnv *pEnv, UInt32 idx)
{
    Window *pWin = pEnv->getWindow();

    validate(pEnv);
    GLuint id = this->getOpenGLId(pEnv);

    OSGGETGLFUNCBYID_GL3_ES( glBindBuffer,
                             osgGlBindBuffer,
                            _funcBindBuffer, 
                             pWin);

    OSGGETGLFUNCBYID_GL3_ES( glBindBufferBase, 
                             osgGlBindBufferBase,
                            _funcBindBufferBase, 
                             pWin);

    osgGlBindBuffer    (GL_SHADER_STORAGE_BUFFER, id);
    osgGlBindBufferBase(GL_SHADER_STORAGE_BUFFER, idx, id);

    glErr("ShaderStorageBufferObjRefChunk::activate");
}
Ejemplo n.º 9
0
void RegisterCombinersChunk::deactivate ( DrawActionBase *, UInt32 )
{
    glDisable(GL_REGISTER_COMBINERS_NV);

    glErr("RegisterCombinersChunk::deactivate");
}
Ejemplo n.º 10
0
void RegisterCombinersChunk::activate( DrawActionBase *action, UInt32  )
{
    Window *win = action->getWindow();

    if(! win->hasExtension(_nvRegisterCombiners))
        return;

    // setup register combiners

    // functions

    void (OSG_APIENTRY*CombinerParameterfv)(GLenum pname, GLfloat *params) =
        reinterpret_cast<void (OSG_APIENTRY*)(GLenum pname, GLfloat *params)>(
            win->getFunction(_funcCombinerParameterfv));

    void (OSG_APIENTRY*CombinerStageParameterfv)(GLenum stage,
            GLenum pname,
            GLfloat *params) =
                reinterpret_cast<void (OSG_APIENTRY*)(GLenum stage,
                        GLenum pname,
                        GLfloat *params)>(
                    win->getFunction(_funcCombinerStageParameterfv));

    void (OSG_APIENTRY*CombinerInput)(GLenum stage,
                                      GLenum portion,
                                      GLenum variable,
                                      GLenum input,
                                      GLenum mapping,
                                      GLenum component) =
                                          reinterpret_cast<void (OSG_APIENTRY*)(GLenum stage,
                                                  GLenum portion,
                                                  GLenum variable,
                                                  GLenum input,
                                                  GLenum mapping,
                                                  GLenum component)>(
                                                          win->getFunction(_funcCombinerInput));

    void (OSG_APIENTRY*CombinerOutput)(GLenum stage,
                                       GLenum portion,
                                       GLenum abOut,
                                       GLenum cdOut,
                                       GLenum sumOut,
                                       GLenum scale,
                                       GLenum bias,
                                       GLboolean abdot,
                                       GLboolean cddot,
                                       GLboolean muxSum) =
                                           reinterpret_cast<void (OSG_APIENTRY*)(GLenum stage,
                                                   GLenum portion,
                                                   GLenum abOut,
                                                   GLenum cdOut,
                                                   GLenum sumOut,
                                                   GLenum scale,
                                                   GLenum bias,
                                                   GLboolean abdot,
                                                   GLboolean cddot,
                                                   GLboolean muxSum)>(
                                                           win->getFunction(_funcCombinerOutput));

    void (OSG_APIENTRY*FinalCombinerInput)(GLenum variable,
                                           GLenum input,
                                           GLenum mapping,
                                           GLenum component) =
                                                   reinterpret_cast<void (OSG_APIENTRY*)(GLenum variable,
                                                           GLenum input,
                                                           GLenum mapping,
                                                           GLenum component)>(
                                                                   win->getFunction(_funcFinalCombinerInput));

    // how many combiners do we need?

    Int32 ncomb;

    for(ncomb = OSG_NUM_COMBINERS - 1; ncomb >= 0; ncomb--)
    {
        if(getVariableArgb(ncomb * 3) != unused)
            break;
    }

    if(ncomb < 0)
    {
        // no combiner active, return

        glDisable(GL_REGISTER_COMBINERS_NV);
        return;
    }

    ncomb++;

    GLfloat dummy = GLfloat(ncomb);
    CombinerParameterfv(GL_NUM_GENERAL_COMBINERS_NV, &dummy);
    CombinerParameterfv(GL_CONSTANT_COLOR0_NV,
                        const_cast<GLfloat *>(getColor0().getValuesRGBA()));

    CombinerParameterfv(GL_CONSTANT_COLOR1_NV,
                        const_cast<GLfloat*>(getColor1().getValuesRGBA()));

    dummy = getColorSumClamp();
    CombinerParameterfv(GL_COLOR_SUM_CLAMP_NV, &dummy);

    // setup the general combiners

    bool hasRC2 = win->hasExtension(_nvRegisterCombiners2);

    for(UInt16 i = 0; i < ncomb; i++)
    {
        if(getVariableArgb(i * 3) != unused)
        {
            // RGB inputs
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_A_NV,
                          getVariableArgb(i * 3),
                          getVariableArgb(i * 3 + 1),
                          getVariableArgb(i * 3 + 2) );
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_B_NV,
                          getVariableBrgb(i * 3),
                          getVariableBrgb(i * 3 + 1),
                          getVariableBrgb(i * 3 + 2) );
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_C_NV,
                          getVariableCrgb(i * 3),
                          getVariableCrgb(i * 3 + 1),
                          getVariableCrgb(i * 3 + 2) );
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_D_NV,
                          getVariableDrgb(i * 3),
                          getVariableDrgb(i * 3 + 1),
                          getVariableDrgb(i * 3 + 2) );

            // RGB output
            CombinerOutput(GL_COMBINER0_NV + i, GL_RGB,
                           getOutputABrgb    (i),
                           getOutputCDrgb    (i),
                           getOutputSumrgb   (i),
                           getScalergb       (i),
                           getBiasrgb        (i),
                           getDotABrgb       (i),
                           getDotCDrgb       (i),
                           getMuxSumrgb      (i) );

        }
        else
        {
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_A_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_B_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_C_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
            CombinerInput(GL_COMBINER0_NV + i, GL_RGB, GL_VARIABLE_D_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);

            CombinerOutput(GL_COMBINER0_NV + i, GL_RGB,
                           GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV,
                           GL_NONE, GL_NONE,
                           GL_FALSE, GL_FALSE, GL_FALSE );

        }

        if(getVariableAalpha(i * 3) != unused)
        {
            // Alpha inputs
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_A_NV,
                          getVariableAalpha(i * 3),
                          getVariableAalpha(i * 3 + 1),
                          getVariableAalpha(i * 3 + 2) );
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_B_NV,
                          getVariableBalpha(i * 3),
                          getVariableBalpha(i * 3 + 1),
                          getVariableBalpha(i * 3 + 2) );
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_C_NV,
                          getVariableCalpha(i * 3),
                          getVariableCalpha(i * 3 + 1),
                          getVariableCalpha(i * 3 + 2) );
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_D_NV,
                          getVariableDalpha(i * 3),
                          getVariableDalpha(i * 3 + 1),
                          getVariableDalpha(i * 3 + 2) );

            // ALPHA output
            CombinerOutput(GL_COMBINER0_NV + i, GL_ALPHA,
                           getOutputABalpha    (i),
                           getOutputCDalpha    (i),
                           getOutputSumalpha   (i),
                           getScalealpha       (i),
                           getBiasalpha        (i),
                           GL_FALSE,
                           GL_FALSE,
                           getMuxSumalpha      (i) );
        }
        else
        {
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_A_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_B_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_C_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
            CombinerInput(GL_COMBINER0_NV + i, GL_ALPHA, GL_VARIABLE_D_NV,
                          GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);

            CombinerOutput(GL_COMBINER0_NV + i, GL_ALPHA,
                           GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV,
                           GL_NONE, GL_NONE,
                           GL_FALSE, GL_FALSE, GL_FALSE );
        }

        if(getPerStageConstants())
        {
            if(hasRC2)
            {
                CombinerStageParameterfv(
                    GL_COMBINER0_NV + i,
                    GL_CONSTANT_COLOR0_NV,
                    const_cast<GLfloat*>(
                        getCombinerColor0(i).getValuesRGBA()));

                CombinerStageParameterfv(
                    GL_COMBINER0_NV + i,
                    GL_CONSTANT_COLOR1_NV,
                    const_cast<GLfloat*>(
                        getCombinerColor1(i).getValuesRGBA()));

            }
            else
            {
                FWARNING(("RegisterCombinersChunk::register_combiners2 not"
                          "supported, constant colors ignored!!\n"));
            }
        }
    }

    if(hasRC2)
    {
        if(getPerStageConstants())
        {
            glEnable(GL_PER_STAGE_CONSTANTS_NV);
        }
        else
        {
            glDisable(GL_PER_STAGE_CONSTANTS_NV);
        }
    }

    glErr("RegisterCombinersChunk::general combiners setup");

    // setup the final combiner

    FinalCombinerInput(GL_VARIABLE_A_NV,
                       getVariableArgb(OSG_NUM_COMBINERS * 3),
                       getVariableArgb(OSG_NUM_COMBINERS * 3 + 1),
                       getVariableArgb(OSG_NUM_COMBINERS * 3 + 2));

    glErr("RegisterCombinersChunk::final combiner var a setup");

    FinalCombinerInput(GL_VARIABLE_B_NV,
                       getVariableBrgb(OSG_NUM_COMBINERS * 3),
                       getVariableBrgb(OSG_NUM_COMBINERS * 3 + 1),
                       getVariableBrgb(OSG_NUM_COMBINERS * 3 + 2));

    glErr("RegisterCombinersChunk::final combiner var b setup");

    FinalCombinerInput(GL_VARIABLE_C_NV,
                       getVariableCrgb(OSG_NUM_COMBINERS * 3),
                       getVariableCrgb(OSG_NUM_COMBINERS * 3 + 1),
                       getVariableCrgb(OSG_NUM_COMBINERS * 3 + 2));

    glErr("RegisterCombinersChunk::final combiner var c setup");

    FinalCombinerInput(GL_VARIABLE_D_NV,
                       getVariableDrgb(OSG_NUM_COMBINERS * 3),
                       getVariableDrgb(OSG_NUM_COMBINERS * 3 + 1),
                       getVariableDrgb(OSG_NUM_COMBINERS * 3 + 2));

    glErr("RegisterCombinersChunk::final combiner var d setup");

    FinalCombinerInput(GL_VARIABLE_E_NV,
                       getVariableE(0),
                       getVariableE(1),
                       getVariableE(2));

    glErr("RegisterCombinersChunk::final combiner var e setup");

    FinalCombinerInput(GL_VARIABLE_F_NV,
                       getVariableF(0),
                       getVariableF(1),
                       getVariableF(2));

    glErr("RegisterCombinersChunk::final combiner var f setup");

    FinalCombinerInput(GL_VARIABLE_G_NV,
                       getVariableG(0),
                       getVariableG(1),
                       getVariableG(2));

    glErr("RegisterCombinersChunk::final combiner setup");
    // and activate everything

    glEnable(GL_REGISTER_COMBINERS_NV);

    glErr("RegisterCombinersChunk::activate");
}
void DSLightChunk::changeFrom(DrawEnv *drawEnv, StateChunk *old, UInt32 index)
{
    glErr("dslight:change:precheck");

    const DSLightChunk *oldChunk = dynamic_cast<const DSLightChunk *>(old);

    // change from me to me?
    // this assumes I haven't changed in the meantime. is that a valid 
    // assumption?

    if(oldChunk == this)
        return;

    Matrix matMV;
    calcModelView(drawEnv, matMV);

    glPushMatrix();
    glLoadMatrixf(matMV.getValues());

    // it could theoretically be more efficient to turn the light off before
    // changing its parameters, have to try that sometime

    glLightfv( GL_LIGHT0 + index, 
               GL_DIFFUSE,
              _sfDiffuse.getValue().getValuesRGBA());

    glLightfv( GL_LIGHT0 + index, 
               GL_AMBIENT,
              _sfAmbient.getValue().getValuesRGBA());

    glLightfv( GL_LIGHT0 + index, 
               GL_SPECULAR,
              _sfSpecular.getValue().getValuesRGBA());

    glLightfv( GL_LIGHT0 + index, 
               GL_POSITION,
              _sfPosition.getValue().getValues());

    glLightf ( GL_LIGHT0 + index, 
               GL_CONSTANT_ATTENUATION,
              _sfConstantAttenuation.getValue());

    glLightf ( GL_LIGHT0 + index, 
               GL_LINEAR_ATTENUATION,
              _sfLinearAttenuation.getValue());

    glLightf ( GL_LIGHT0 + index, 
               GL_QUADRATIC_ATTENUATION,
              _sfQuadraticAttenuation.getValue());

    glLightf( GL_LIGHT0 + index, 
              GL_SPOT_CUTOFF,
             _sfCutoff.getValue());

    if(_sfCutoff.getValue() < 180.f)
    {
        glLightfv( GL_LIGHT0 + index, 
                   GL_SPOT_DIRECTION,
                  _sfDirection.getValue().getValues());

        glLightf( GL_LIGHT0 + index, 
                  GL_SPOT_EXPONENT, 
                 _sfExponent.getValue());
    }

    glPopMatrix();

    glErr("dslight:change:postcheck");
}
Ejemplo n.º 12
0
void TexGenChunk::changeFrom(DrawEnv    *pEnv, 
                             StateChunk *old   , 
                             UInt32      idx)
{
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    // change from me to me?
    // this assumes I haven't changed in the meantime. 
    // is that a valid assumption?
    // No, for TexGen it's not, as TexGen depends on the current 
    // toWorld matrix!!!
    // if(old == this)
    //     return;
    TexGenChunk *oldp      = dynamic_cast<TexGenChunk *>(old);
    
    // If the old one is not a texgen chunk, deactivate it and activate
    // ourselves
    if(!oldp)
    {
        old->deactivate(pEnv, idx);
        activate(pEnv, idx);
        return;
    }

    glErr("TexGenChunk::changeFrom precheck");

    pEnv->incNumChunkChanges();

    Window *win = pEnv->getWindow();   

    Real32 ntexcoords;
    if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
       Window::unknownConstant
      )
    {
        ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(ntexcoords == Window::unknownConstant)
            ntexcoords = 1.0f;
    }

    if(idx >= static_cast<UInt32>(ntexcoords))
    {
#ifdef OSG_DEBUG
        FWARNING(("TexGenChunk::changeFrom: Trying to bind texcoord unit "
                  "%d, but Window %p only supports %lf!\n",
                  idx, win, ntexcoords));
#endif
        return;        
    }
 
    Matrix cameraMat = pEnv->getCameraViewing();   

#ifdef OLD_DA
    Viewport *vp = pEnv->getViewport();
	if(vp != NULL)
	{
		pEnv->getCamera()->getViewing(cameraMat, 
                                      vp->getPixelWidth(), 
                                      vp->getPixelHeight());
	}
#endif
   
    TextureBaseChunk::activateTexture(win, idx);

    changeGenFunc(oldp->getGenFuncS(), 
                  oldp->getSBeacon(), 
                  GL_S, 
                  GL_TEXTURE_GEN_S, 
                  getGenFuncS(), 
                  getGenFuncSPlane(), 
                  getSBeacon(), 
                  cameraMat, 
                  _sfEyeModelViewMode.getValue(),
                  _sfEyeModelViewMatrix.getValue());

    changeGenFunc(oldp->getGenFuncT(), oldp->getTBeacon(), GL_T, 
                  GL_TEXTURE_GEN_T, 
                  getGenFuncT(), getGenFuncTPlane(), getTBeacon(), cameraMat, 
                  _sfEyeModelViewMode.getValue(),
                  _sfEyeModelViewMatrix.getValue());

    changeGenFunc(oldp->getGenFuncR(), oldp->getRBeacon(), GL_R, 
                  GL_TEXTURE_GEN_R, 
                  getGenFuncR(), getGenFuncRPlane(), getRBeacon(), cameraMat, 
                  _sfEyeModelViewMode.getValue(),
                  _sfEyeModelViewMatrix.getValue());

    changeGenFunc(oldp->getGenFuncQ(), oldp->getQBeacon(), GL_Q, 
                  GL_TEXTURE_GEN_Q, 
                  getGenFuncQ(), getGenFuncQPlane(), getQBeacon(), cameraMat, 
                  _sfEyeModelViewMode.getValue(),
                  _sfEyeModelViewMatrix.getValue());
#else
    OSG_ASSERT(false);
#endif

    glErr("TexGenChunk::changeFrom");
}
Ejemplo n.º 13
0
void TexGenChunk::activate(DrawEnv *pEnv, UInt32 idx)
{
    glErr("TexGenChunk::activate precheck");

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    pEnv->incNumChunkChanges();

    Window *win = pEnv->getWindow();   

    Real32 ntexcoords;
    if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
       Window::unknownConstant
      )
    {
        ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(ntexcoords == Window::unknownConstant)
            ntexcoords = 1.0f;
    }

    if(idx >= static_cast<UInt32>(ntexcoords))
    {
#ifdef OSG_DEBUG
        FWARNING(("TexGenChunk::activate: Trying to bind texcoord unit %d,"
                  " but Window %p only supports %lf!\n",
                  idx, win, ntexcoords));
#endif
        return;        
    }
        
    TextureBaseChunk::activateTexture(win, idx);

    FDEBUG(("TexGenChunk::activate\n"));

    Matrix cameraMat = pEnv->getCameraViewing(); 
  
#if OLD_DA
    Viewport *vp = pEnv->getViewport();
	if(vp != NULL)
	{
		pEnv->getCamera()->getViewing(cameraMat, 
                                      vp->getPixelWidth(), 
                                      vp->getPixelHeight());
	}
#endif

    // genfuncs
    setGenFunc(GL_S, GL_TEXTURE_GEN_S, getGenFuncS(), getGenFuncSPlane(),
               getSBeacon(), cameraMat, _sfEyeModelViewMode.getValue(),
               _sfEyeModelViewMatrix.getValue());
    glErr("TexGenChunk::activateS");
    setGenFunc(GL_T, GL_TEXTURE_GEN_T, getGenFuncT(), getGenFuncTPlane(),
                getTBeacon(), cameraMat, _sfEyeModelViewMode.getValue(),
               _sfEyeModelViewMatrix.getValue());
    glErr("TexGenChunk::activateT");
    setGenFunc(GL_R, GL_TEXTURE_GEN_R, getGenFuncR(), getGenFuncRPlane(),
                getRBeacon(), cameraMat, _sfEyeModelViewMode.getValue(),
               _sfEyeModelViewMatrix.getValue());
    glErr("TexGenChunk::activateR");
    setGenFunc(GL_Q, GL_TEXTURE_GEN_Q, getGenFuncQ(), getGenFuncQPlane(),
                getQBeacon(), cameraMat, _sfEyeModelViewMode.getValue(),
               _sfEyeModelViewMatrix.getValue());
#else
    OSG_ASSERT(false);
#endif
	glErr("TexGenChunk::activateQ");
}
void CubeTextureObjChunk::changeFrom(DrawEnv    *pEnv, 
                                  StateChunk *old   , 
                                  UInt32      idx   )
{
    // does the window support cubemaps?
    if(pEnv->getWindow()->hasExtension(_arbCubeTex) == false)
        return;
        
    // change from me to me?
    // this assumes I haven't changed in the meantime. 
    // is that a valid assumption?
    if(old == this)
        return;
    
    // If the old one is not a cube texture chunk, deactivate it and
    // activate ourselves
    if(getTypeId() != old->getTypeId())
    {
        old->deactivate(pEnv, idx);
        activate(pEnv, idx);
        return;
    }

    Window *win = pEnv->getWindow();   

    Real32 nteximages, ntexcoords;

    glErr("CubeTextureObjChunk::changeFrom precheck");

    if((nteximages = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
       Window::unknownConstant)
    {
        nteximages = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);

        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(nteximages == Window::unknownConstant)
            nteximages = 1.0f;
    }

    if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
       Window::unknownConstant)
    {
        ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);

        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(ntexcoords == Window::unknownConstant)
            ntexcoords = 1.0f;
    }

    if(idx >= static_cast<UInt32>(nteximages))
    {
#ifdef OSG_DEBUG
        FWARNING(("TextureObjChunk::activate: Trying to bind image unit %d,"
                  " but Window %p only supports %lf!\n",
                  idx, win, nteximages));
#endif
        return;        
    }

    if(TextureBaseChunk::activateTexture(win, idx))
        return; // trying to use too many textures

    win->validateGLObject(getGLId(), pEnv);
    
    FDEBUG(("CubeTextureObjChunk::activate - %d\n", getGLId()));

    // Update the texture statistics
    StatCollectorP pColl = pEnv->getStatCollector();
    
    if(NULL != pColl)
    {
        pColl->getElem(TextureObjChunk::statNTextures)->inc(getGLId());

        if(getImage() != NULL)
        {
            pColl->getElem(TextureObjChunk::statNTexBytes)->add(
                getGLId(), 
                getImage()->getSize(true,true,true) * 6);
        }
    }

    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, win->getGLObjectId(getGLId()));

    pEnv->setActiveTexTarget(idx, GL_TEXTURE_CUBE_MAP_ARB);


    glErr("CubeTextureObjChunk::changeFrom");
}
void CubeTextureObjChunk::activate(DrawEnv *pEnv, UInt32 idx)
{   
    // does the window support cubemaps?
    if(pEnv->getWindow()->hasExtension(_arbCubeTex) == false)
        return;
        
    Window *win = pEnv->getWindow();
    
    Real32 nteximages, ntexcoords;

    if((nteximages = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
       Window::unknownConstant)
    {
        nteximages = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);

        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(nteximages == Window::unknownConstant)
            nteximages = 1.0f;
    }

    if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
       Window::unknownConstant)
    {
        ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);

        // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
        if(ntexcoords == Window::unknownConstant)
            ntexcoords = 1.0f;
    }

    if(idx >= static_cast<UInt32>(nteximages))
    {
#ifdef OSG_DEBUG
        FWARNING(("CubeTextureObjChunk::activate: Trying to bind image unit "
                  "%d, but Window %p only supports %lf!\n",
                  idx, win, nteximages));
#endif
        return;        
    }
    
    if(TextureBaseChunk::activateTexture(win, idx))
        return; // trying to use too many textures

    glErr("CubeTextureObjChunk::activate precheck");
    
    win->validateGLObject(getGLId(), pEnv);

  
    FDEBUG(("CubeTextureObjChunk::activate - %d\n", getGLId()));


    // Update the texture statistics
    StatCollectorP pColl = pEnv->getStatCollector();
    
    if(NULL != pColl)
    {
        pColl->getElem(TextureObjChunk::statNTextures)->inc(getGLId());

        if(getImage() != NULL)
        {
            pColl->getElem(TextureObjChunk::statNTexBytes)->add(
                getGLId(), 
                getImage()->getSize(true,true,true) * 6);
        }
    }

    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, win->getGLObjectId(getGLId()));

    pEnv->setActiveTexTarget(idx, GL_TEXTURE_CUBE_MAP_ARB);

    glEnable(GL_TEXTURE_CUBE_MAP_ARB);
    glErr("CubeTextureObjChunk::activate");
}