<commit_before>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 <NAME> 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * OpenSceneGraph Public License for more details.
*/
#include <osgUtil/SceneView>
#include <osgUtil/UpdateVisitor>
#include <osgUtil/GLObjectsVisitor>

#include <osg/Timer>
#include <osg/Notify>
#include <osg/Texture>
#include <osg/VertexProgram>
#include <osg/FragmentProgram>
#include <osg/AlphaFunc>
#include <osg/TexEnv>
#include <osg/ColorMatrix>
#include <osg/LightModel>
#include <osg/CollectOccludersVisitor>

#include <osg/GLU>

using namespace osg;
using namespace osgUtil;

SceneView::SceneView(DisplaySettings* ds)
{
    _displaySettings = ds;

    _clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);


    _fusionDistanceMode = PROPORTIONAL_TO_SCREEN_DISTANCE;
    _fusionDistanceValue = 1.0f;

    _lightingMode=NO_SCENEVIEW_LIGHT;
    
    _prioritizeTextures = false;
    
    _viewport = new Viewport;
    
    _initCalled = false;

    
    _drawBufferValue = GL_BACK;

    _requiresFlush = true;
}


SceneView::~SceneView()
{
}


void SceneView::setDefaults(unsigned int options)
{
    _projectionMatrix.makePerspective(50.0f,1.4f,1.0f,10000.0f);
    _viewMatrix.makeIdentity();

    _globalStateSet = new osg::StateSet;

    if ((options & HEADLIGHT) || (options & SKY_LIGHT))
    {
        _lightingMode=(options&HEADLIGHT) ? HEADLIGHT : SKY_LIGHT;
        _light = new osg::Light;
        _light->setLightNum(0);
        _light->setAmbient(Vec4(0.00f,0.0f,0.00f,1.0f));
        _light->setDiffuse(Vec4(0.8f,0.8f,0.8f,1.0f));
        _light->setSpecular(Vec4(1.0f,1.0f,1.0f,1.0f));

        _globalStateSet->setAssociatedModes(_light.get(),osg::StateAttribute::ON);

        osg::LightModel* lightmodel = new osg::LightModel;
        lightmodel->setAmbientIntensity(osg::Vec4(0.1f,0.1f,0.1f,1.0f));
        _globalStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);

        // enable lighting by default.
        _globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);

    }
    
    _state = new State;
    
    _rendergraph = new RenderGraph;
    _renderStage = new RenderStage;


    if (options & COMPILE_GLOBJECTS_AT_INIT)
    {
        GLObjectsVisitor::Mode  dlvMode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;

    #ifdef __sgi
        dlvMode = GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
    #endif

        // sgi's IR graphics has a problem with lighting and display lists, as it seems to store 
        // lighting state with the display list, and the display list visitor doesn't currently apply
        // state before creating display lists. So will disable the init visitor default, this won't
        // affect functionality since the display lists will be created as and when needed.
        GLObjectsVisitor* dlv = new GLObjectsVisitor(dlvMode);
        dlv->setNodeMaskOverride(0xffffffff);
        _initVisitor = dlv;

    }
    
    _updateVisitor = new UpdateVisitor;

    _cullVisitor = new CullVisitor;

    _cullVisitor->setRenderGraph(_rendergraph.get());
    _cullVisitor->setRenderStage(_renderStage.get());

    _globalStateSet->setGlobalDefaults();
    
    
    // enable depth testing by default.
    _globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);

    // set up an alphafunc by default to speed up blending operations.
    osg::AlphaFunc* alphafunc = new osg::AlphaFunc;
    alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f);
    _globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON);

    // set up an texture environment by default to speed up blending operations.
     osg::TexEnv* texenv = new osg::TexEnv;
     texenv->setMode(osg::TexEnv::MODULATE);
     _globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);


    _clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);
}

void SceneView::init()
{

    _initCalled = true;

    if (_sceneData.valid() && _initVisitor.valid())
    {
        _initVisitor->reset();
        _initVisitor->setFrameStamp(_frameStamp.get());
        
        GLObjectsVisitor* dlv = dynamic_cast<GLObjectsVisitor*>(_initVisitor.get());
        if (dlv) dlv->setState(_state.get());
        
        if (_frameStamp.valid())
        {
             _initVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
        }
        
        _sceneData->accept(*_initVisitor.get());
        
    } 
}

void SceneView::update()
{
    if (!_initCalled) init();<commit_msg>Removed the _initVisitor traversal for update() to prevent OpenGL being called at the wrong time.<commit_after>/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 <NAME> 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * OpenSceneGraph Public License for more details.
*/
#include <osgUtil/SceneView>
#include <osgUtil/UpdateVisitor>
#include <osgUtil/GLObjectsVisitor>

#include <osg/Timer>
#include <osg/Notify>
#include <osg/Texture>
#include <osg/VertexProgram>
#include <osg/FragmentProgram>
#include <osg/AlphaFunc>
#include <osg/TexEnv>
#include <osg/ColorMatrix>
#include <osg/LightModel>
#include <osg/CollectOccludersVisitor>

#include <osg/GLU>

using namespace osg;
using namespace osgUtil;

SceneView::SceneView(DisplaySettings* ds)
{
    _displaySettings = ds;

    _clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);


    _fusionDistanceMode = PROPORTIONAL_TO_SCREEN_DISTANCE;
    _fusionDistanceValue = 1.0f;

    _lightingMode=NO_SCENEVIEW_LIGHT;
    
    _prioritizeTextures = false;
    
    _viewport = new Viewport;
    
    _initCalled = false;

    
    _drawBufferValue = GL_BACK;

    _requiresFlush = true;
}


SceneView::~SceneView()
{
}


void SceneView::setDefaults(unsigned int options)
{
    _projectionMatrix.makePerspective(50.0f,1.4f,1.0f,10000.0f);
    _viewMatrix.makeIdentity();

    _globalStateSet = new osg::StateSet;

    if ((options & HEADLIGHT) || (options & SKY_LIGHT))
    {
        _lightingMode=(options&HEADLIGHT) ? HEADLIGHT : SKY_LIGHT;
        _light = new osg::Light;
        _light->setLightNum(0);
        _light->setAmbient(Vec4(0.00f,0.0f,0.00f,1.0f));
        _light->setDiffuse(Vec4(0.8f,0.8f,0.8f,1.0f));
        _light->setSpecular(Vec4(1.0f,1.0f,1.0f,1.0f));

        _globalStateSet->setAssociatedModes(_light.get(),osg::StateAttribute::ON);

        osg::LightModel* lightmodel = new osg::LightModel;
        lightmodel->setAmbientIntensity(osg::Vec4(0.1f,0.1f,0.1f,1.0f));
        _globalStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);

        // enable lighting by default.
        _globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);

    }
    
    _state = new State;
    
    _rendergraph = new RenderGraph;
    _renderStage = new RenderStage;


    if (options & COMPILE_GLOBJECTS_AT_INIT)
    {
        GLObjectsVisitor::Mode  dlvMode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;

    #ifdef __sgi
        dlvMode = GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES;
    #endif

        // sgi's IR graphics has a problem with lighting and display lists, as it seems to store 
        // lighting state with the display list, and the display list visitor doesn't currently apply
        // state before creating display lists. So will disable the init visitor default, this won't
        // affect functionality since the display lists will be created as and when needed.
        GLObjectsVisitor* dlv = new GLObjectsVisitor(dlvMode);
        dlv->setNodeMaskOverride(0xffffffff);
        _initVisitor = dlv;

    }
    
    _updateVisitor = new UpdateVisitor;

    _cullVisitor = new CullVisitor;

    _cullVisitor->setRenderGraph(_rendergraph.get());
    _cullVisitor->setRenderStage(_renderStage.get());

    _globalStateSet->setGlobalDefaults();
    
    
    // enable depth testing by default.
    _globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);

    // set up an alphafunc by default to speed up blending operations.
    osg::AlphaFunc* alphafunc = new osg::AlphaFunc;
    alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f);
    _globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON);

    // set up an texture environment by default to speed up blending operations.
     osg::TexEnv* texenv = new osg::TexEnv;
     texenv->setMode(osg::TexEnv::MODULATE);
     _globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);


    _clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);
}

void SceneView::init()
{

    _initCalled = true;

    if (_sceneData.valid() && _initVisitor.valid())
    {
        _initVisitor->reset();
        _initVisitor->setFrameStamp(_frameStamp.get());
        
        GLObjectsVisitor* dlv = dynamic_cast<GLObjectsVisitor*>(_initVisitor.get());
        if (dlv) dlv->setState(_state.get());
        
        if (_frameStamp.valid())
        {
             _initVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
        }
        
        _sceneData->accept(*_initVisitor.get());
        
    } 
}

void SceneView::update()
{
    // comment out since the init traversal by default with do OpenGL calls,
    // which you definately don't want to call during update().
    // if (!_initCalled) init();
{'fraction_non_alphanumeric': 0.1108044164037855, 'fraction_numerical': 0.016561514195583597, 'mean_word_length': 3.4909251881363437, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1972624', 'n_tokens_mistral': 3384, 'n_tokens_neox': 3248, 'n_words': 736}