Exemple #1
0
    //-------------------------------------------------------------------------
    //                                  r u n 
    //-------------------------------------------------------------------------
    void CApplication::run()
    {
        ITimer* timer = m_device->getTimer();
        u32 current, last = timer->getRealTime();
        u32 delta = 0;

        m_running = true;
        while(m_device->run() && m_running)
        {
            // calc seconds since last frame
            current = timer->getRealTime();
            delta = current-last;
            last = current;

            m_videoDriver->beginScene(true, true, SColor(255,100,101,140));
            preRender(delta);

            m_sceneManager->drawAll();
            m_gui->drawAll();

            postRender();
            m_videoDriver->endScene();

        }

        logMessage("Exiting Run Loop");
        stringc msg = "Frame Rate - Avg: ";
        msg += m_fpsAvg;
        msg += ", Min: ";
        msg += m_fpsMin;
        msg += ", Max: ";
        msg += m_fpsMax;
        logMessage(msg);
    }
Exemple #2
0
int
main( int argc, char** argv )
{
    osg::notify( osg::ALWAYS ) <<
// cols:  12345678901234567890123456789012345678901234567890123456789012345678901234567890
         "This is an example of doing render to texture in OSG, with the result displayed" << std::endl <<
         "on a fullscreen triangle pair. It uses only one osgWorks OSG version feature to" << std::endl <<
         "configure the destination textures and RTT Cameras appropriately, and uses the" << std::endl <<
         "plane shape <osgwTools/Shapes.h> for the final texture display." << std::endl;

    osg::ArgumentParser arguments( &argc, argv );
    osg::ref_ptr< osg::Group > root( new osg::Group );
    root->addChild( osgDB::readNodeFiles( arguments ) );
    if( root->getNumChildren() == 0 )
    {
        // Load default cow model.
        std::string fileName( "cow.osg" );
        root->addChild( osgDB::readNodeFile( fileName ) );
    }
    if( root->getNumChildren() == 0 )
        return( 1 );

    osgViewer::Viewer viewer;
    viewer.setUpViewInWindow( 10, 30, winW, winH );
    viewer.setSceneData( root.get() );
    viewer.realize();

    root->addChild( postRender( viewer ) );

    // Clear to white to make AA extremely obvious.
    viewer.getCamera()->setClearColor( osg::Vec4( 1., 1., 1., 1. ) );

    return( viewer.run() );
}
int
main( int argc, char** argv )
{
    osg::ArgumentParser arguments( &argc, argv );

    bool plainMode( false );
    osg::notify( osg::NOTICE ) << "  -p\tPlain mode. Runs with FFP and no RTT. Disabled by default (emulate BDFX with shaders and RTT)." << std::endl;
    if( arguments.read( "-p" ) )
    {
        plainMode = true;
        osg::notify( osg::INFO ) << "-p (plain mode)" << std::endl;
    }

    osg::ref_ptr< osg::Group > root( new osg::Group );
    root->addChild( osgDB::readNodeFiles( arguments ) );
    if( root->getNumChildren() == 0 )
        return( 1 );

    osgViewer::Viewer viewer;
    viewer.setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
    viewer.setUpViewInWindow( 30, 30, winW, winH );
    viewer.setSceneData( root.get() );
    viewer.addEventHandler( new osgViewer::StatsHandler );
    viewer.realize();

    if( !plainMode )
    {
        root->addChild( postRender( viewer ) );
        root->getOrCreateStateSet()->setAttribute( createPerfProgram( "dumb" ) );
    }

    return( viewer.run() );
}
Exemple #4
0
void TUICore<T>::doRenderAll()
{
    prevRender();
    render();
    postRender();

    bool bClipTest = _this()->haveChildClipTest();

    if ( bClipTest )
    {
        for( TUICore<T>* child = getChild(); child ; child = child->getNext() )
        {
            if ( !child->isShow() )
                continue;
            if ( !child->clipTest() )
                continue;
            child->renderAll();
        }
    }
    else
    {
        for( TUICore<T>* child = getChild(); child ; child = child->getNext() )
        {
            if ( !child->isShow() )
                continue;
            child->renderAll();
        }
    }
    postRenderChildren();
}
Exemple #5
0
		void CheckBox::render() {
			if (parent == NULL) { preRender(); }
			renderBackground();
			if (m_checked) { renderTick(); }
			renderOverlay();
			if (parent == NULL) { postRender(); }
		}
Exemple #6
0
	void TextField2::render(float dt)
	{
		if (!mVisible || mFont == NULL || !mFont->isLoaded())
		{
			return;
		}

		mCurrentLine = 0;
		preRender(dt);
		mFont->getAsset()->getTexture()->bindTexture();
		glBegin(GL_QUADS);
		while (mCurrentNode.get() != NULL)
		{
			if (mNewLineDirty)
			{
				Node::NodeHitboxList &list = mCurrentNode->getHitboxes();
				list.clear();
				Handle<NodeHitbox> hitbox(new NodeHitbox(mCurrentNode));
				mTextHitboxes->addChild(hitbox.get());
				hitbox->setPosition(mCurrXpos, mCurrYpos - mTextHitboxes->getPositionY());
				hitbox->setHeight(mFont->getCharHeight());
				hitbox->addEventListener(MOUSE_UP, this);
				list.push_back(hitbox);
			}
			TextStyle currentStyle = mCurrentNode->getTextStyle();
			GfxEngine::getEngine()->popColourStack();
			if (currentStyle.hasColour())
			{
				GfxEngine::getEngine()->pushColourStack(currentStyle.getColour());
			}
			else
			{
				if (mGfxComponent)
				{
					GfxEngine::getEngine()->pushColourStack(mGfxComponent->getColour());
				}
				else
				{
					GfxEngine::getEngine()->pushColourStack(Colour::WHITE);
				}
			}
			GfxEngine::getEngine()->applyColourStack();
			renderText(mCurrentNode->getText());
			mCurrentNode = mCurrentNode->nextSibling();
		}
		glEnd();
		mScrollbar->setMaxValue(getTotalNumLines() - mDisplayNumLines - 1);
		mNewLineDirty = false;

		for (ChildList::iterator iter = mChildren.begin(); iter != mChildren.end(); ++iter)
		{
			if (mGfxComponent)
			{
				mGfxComponent->getColour().applyColour();
			}
			(*iter)->render(dt);
		}

		postRender(dt);
	}
    void
    PhysicsDebugDrawer::drawAll
    ()
    {
        #ifdef DREAM_LOG
        auto log = getLog();
        log->debug( "Drawing {} lines" , mVertexBuffer.size()/2 );
        #endif
        preRender();

        // Enable shader program
        glUseProgram(mShaderProgram);

        glBindVertexArray(mVAO);
        ShaderRuntime::CurrentShaderProgram = mShaderProgram;

        // Set the projection matrix
        GLint projUniform = glGetUniformLocation(mShaderProgram, "projection");
        if (projUniform == -1)
        {
            #ifdef DREAM_LOG
            log->error( "Unable to find Uniform Location for projection" );
            checkGLError();
            #endif
            return;
        }
        else
        {
            mat4 projectionMatrix = mCamera->getProjectionMatrix();
            glUniformMatrix4fv(projUniform, 1, GL_FALSE, glm::value_ptr(projectionMatrix));
        }

        // Set the view matrix
        GLint viewUniform = glGetUniformLocation(mShaderProgram, "view");
        if (viewUniform == -1)
        {
            #ifdef DREAM_LOG
            log->error( "Unable to find Uniform Location for view" );
            checkGLError();
            #endif
            return;
        }
        else
        {
            mat4 viewMatrix = mCamera->getViewMatrix();
            glUniformMatrix4fv(viewUniform, 1, GL_FALSE, glm::value_ptr(viewMatrix));
        }

        glBindBuffer(GL_ARRAY_BUFFER, mVBO);
        glBufferData(GL_ARRAY_BUFFER, static_cast<GLint>(mVertexBuffer.size() * sizeof(PhysicsDebugVertex)), &mVertexBuffer[0], GL_STATIC_DRAW);

        // Draw
        glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(mVertexBuffer.size()));
        // Unbind
        postRender();
        // Clear old buffer
        mVertexBuffer.clear();
    }
Exemple #8
0
 void Model::traverse(RenderContext &ctx, const std::string& operation)
 {
   if (operation == "render") {
     preRender(ctx);
     postRender(ctx);
   }
   else
     Node::traverse(ctx,operation);
 }
Exemple #9
0
	void IRenderSystem::endRender()
	{
		for ( ; mNextRenderNode != mRenderList.end(); ++mNextRenderNode )
		{
			RNODE& node = *mNextRenderNode;
			renderNode( node );
		}

		postRender();
	}
Exemple #10
0
void Object::render()
{
	preRender();
	
	if (material) material->select();
	
	draw();
	
	if (material) material->unselect();
	
	postRender();
}
Exemple #11
0
void ModelObjectContainer::render()
{
	preRender();

	if (material) material->select();

	draw();

	postRender();

	if (material) material->unselect();
}
Exemple #12
0
	void ParticleSystem::render(float dt)
	{
		preRender(dt);

		unsigned int newParticles = 0;
		if (mParticleList.size() < static_cast<unsigned int>(mMaxParticles))
		{
			mCurrentParticleCount += dt * mParticlesPerSecond;
			newParticles = static_cast<unsigned int>(mCurrentParticleCount);
			if (mParticleList.size() + newParticles > static_cast<unsigned int>(mMaxParticles)) 
			{
				newParticles = mMaxParticles - mParticleList.size();
			}
			mCurrentParticleCount -= static_cast<float>(newParticles);
		}
		else
		{
			mCurrentParticleCount = 0.0f;
		}

		if (newParticles > 0)
		{
			for (unsigned int i = 0; i < newParticles; i++)
			{
				newParticle();
			}
		}

		float accX = getAccelerationX() * dt;
		float accY = getAccelerationY() * dt;
		float ageResp = 1.0f / mMaxAge;
		float alphaRange = mEndAlpha - mStartAlpha;
		for (size_t i = 0; i < mParticleList.size(); i++)
		{
			Particle *particle = mParticleList[i];

			float t = particle->getAge() * ageResp;
			particle->getGfxComponent()->setAlpha(t * alphaRange + mStartAlpha);
			particle->preRender(*this, accX, accY, dt);
			if (particle->getAge() >= mMaxAge)
			{
				particle->postRender(dt);
				mParticleList.erase(mParticleList.begin() + i);
				i--;
				continue;
			}
			particle->render(dt);
			particle->postRender(dt);
		}

		postRender(dt);
	}
Exemple #13
0
	void Sprite::render(float dt)
	{
		if (!mVisible)
		{
			return;
		}

		if (mAsset == NULL || mAsset->getTexture() == NULL || !mAsset->getTexture()->isLoaded())
		{
			if (!mGfxComponent || (mGfxComponent && mGfxComponent->getColour().getAlpha() > 0.05f))
			{
				preRender(dt);
				Texture::bindTexture(0);

				if (mGfxComponent)
				{
					mGfxComponent->getColour().applyColour();
				}
				glBegin(GL_QUADS);
					glVertex2f(0.0f, 0.0f);
					glVertex2f(getWidth(), 0.0f);
					glVertex2f(getWidth(), getHeight());
					glVertex2f(0.0f, getHeight());
				glEnd();

				postRender(dt);
			}

			return;
		}

		preRender(dt);
		
		updateSprite(dt);
		renderSprite();

		postRender(dt);
	}
BOOL LLViewerTexLayerSetBuffer::requestUpdateImmediate()
{
	mNeedsUpdate = TRUE;
	BOOL result = FALSE;

	if (needsRender())
	{
		preRender(FALSE);
		result = render();
		postRender(result);
	}

	return result;
}
Exemple #15
0
int
main( int argc, char** argv )
{
    osg::notify( osg::ALWAYS ) <<
// cols:  12345678901234567890123456789012345678901234567890123456789012345678901234567890
         "This is an example of doing multisampled rendering to multiple render targets" << std::endl <<
         "in OSG. It uses osgWorks only to check for OSG version and configure the" << std::endl <<
         "destination textures and RTT Cameras appropriately." << std::endl;

    osg::ref_ptr< osg::Group > root( new osg::Group );
    root->addChild( osgDB::readNodeFile( "cow.osg" ) );
    if( root->getNumChildren() == 0 )
        return( 1 );

    // Do not unbind the FBOs after the BlitFramebuffer call.
    root->setCullCallback( new KeepFBOsBoundCallback() );

    // Set fragment program for MRT.
    mrtStateSet( root->getOrCreateStateSet() );


    osgViewer::Viewer viewer;
    viewer.getCamera()->setClearColor( osg::Vec4( 0., 0., 0., 1. ) );
    viewer.setCameraManipulator( new osgGA::TrackballManipulator );
    viewer.setUpViewInWindow( 10, 30, winW, winH );
    viewer.setSceneData( root.get() );
    viewer.realize();

    root->addChild( postRender( viewer ) );


    // Required for osgViewer threading model support.
    // Render at least 2 frames before NULLing the cull callback.
    int frameCount( 2 );

    while( !viewer.done() )
    {
        viewer.frame();

        if( frameCount > 0 )
        {
            frameCount--;
            if( frameCount == 0 )
                // After rendering, set cull callback to NULL.
                root->setCullCallback( NULL );
        }
    }
    return( 0 );
}
Exemple #16
0
void Geometry::render() {
    preRender();
    glDrawArrays(GL_TRIANGLES, 0, verticies.size());
    postRender();
}
Exemple #17
0
void PSystem ::render()
{
	//世界变换
	D3DXMATRIX world;
	D3DXMatrixIdentity(&world);
	_device->SetTransform(D3DTS_WORLD,&world);

	//如果链表中有元素 ,则进入
	if(!_particles.empty ())
	{	
		preRender ();
		_device->SetTexture (0,_tex); //设置材质
		_device->SetFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE); //设置顶点格式
		_device->SetStreamSource (0,_vb,0,sizeof(Particle)); //设置资源流
	
		//检测偏移量是否超过内存大小
		if(_vbOffset>=_vbSize)
			_vbOffset=0;
	
		DWORD numParticlesInBatch =0;

		Particle *v=0;
		_vb->Lock (
			_vbOffset *sizeof(Particle),
			_vbBatchSize * sizeof(Particle),
			(void **)&v,
			_vbOffset? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD );

		//遍历链表 开始画
		std::list <Attribute>::iterator i;
		for(i=_particles.begin();i!=_particles.end ();i++)
		{
			if(i->_isAlive==true)
			{
				v->_color=i->_color;
				v->_position=i->_position;
				v++;
				numParticlesInBatch++;
				if(numParticlesInBatch==_vbBatchSize)
				{
					_vb->Unlock ();
					//所以,这里实际上只是把粒子画出来?和位置无关?
					_device->DrawPrimitive(D3DPT_POINTLIST,_vbOffset,_vbBatchSize);
					_vbOffset+=_vbBatchSize;
					if(_vbOffset>=_vbSize)
						_vbOffset=0;
					numParticlesInBatch=0;
					_vb->Lock (
								_vbOffset *sizeof(Particle),
								_vbBatchSize * sizeof(Particle),
								(void **)&v,
								_vbOffset? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD );
				}
			}
		}
		_vb->Unlock ();

	//还要处理一种情况,当此次渲染中活着的粒子数不是_vbBatchSize的倍数,也即无法满足最后一个片段中(numParticlesInBatch==_vbBatchSize)的条件
	//这时最后一个片段没有被绘制到,所以要来绘制最后一个片段
		if(numParticlesInBatch)  //最后一个片段中有粒子
		{
			_device->DrawPrimitive(D3DPT_POINTLIST,_vbOffset,numParticlesInBatch);
		}
		_vbOffset+=_vbBatchSize;
		postRender();	
	}
}
Exemple #18
0
 void ARenderable::postRenderDebug()
 {
     postRender();
 }
Exemple #19
0
void UIView::drawItself(GraphicsDevice* renderer, const mat4& transform )
{
	// Invisible UIView, stop rendering itself or children
	if(!m_visible)
	{
		return;
	}

	if(m_clipContents)
	{
		renderer->pushClippingRect(FloatRect(mRect.left,mRect.top,mRect.width, mRect.height));
	}

	mat4 absoluteTransform = mat4::identity;

	mat4 localTransform = mat4::translate(position) * mat4::rotatey(rotation_y) * mat4::rotatex(rotation_x);

	absoluteTransform = transform * localTransform;

	// Tel
	draw(renderer, absoluteTransform);


	for(std::size_t i = 0; i < components.size(); ++i)
	{
		components[i]->onRender(renderer, this, absoluteTransform);
	}

	if(m_clipContents)
	{
		renderer->popClippingRect();
	}

	// -- Pre Render Step (Before Children)
	preRender(renderer);
	
	// clip the overflowing children
	if(m_clipChildren)
	{
		if(getContext()->transformPointerCoordinates)
		{
			renderer->pushClippingRect(FloatRect(mRect.left / getContext()->targetWindowSize.x,mRect.top / getContext()->targetWindowSize.y,mRect.width / getContext()->targetWindowSize.x, mRect.height / getContext()->targetWindowSize.y), true);
		}
		else
		{
			renderer->pushClippingRect(FloatRect(mRect.left,mRect.top,mRect.width, mRect.height));
		}
	}

	// Let children render as well
	for(std::vector<UIView*>::const_iterator it = m_children.begin(); it != m_children.end(); it++)
	{
		(*it)->drawItself(renderer, absoluteTransform);
	}

	if(m_clipChildren)
		renderer->popClippingRect();

	// -- Post Render Step (After Children)
	postRender(renderer);
}
Exemple #20
0
	void GameObject::render(Shader* shader, Camera *cam, SceneManager* smgr)
	{
		_render(shader, cam, smgr);
		postRender(shader, cam, smgr);

	}