예제 #1
0
	void OpenVG_SVGHandler::draw() {
		
		vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
		
		// clear out the transform stack
		_transform_stack.clear();
		
		float m[9];
		vgGetMatrix( m );
		// assume the current openvg matrix is like the camera matrix and should always be applied first
		Transform2d top;
		Transform2d::multiply( top, Transform2d(m), rootTransform() );	// multiply by the root transform
		pushTransform( top );
		
		// SVG is origin at the top, left (openvg is origin at the bottom, left)
		// so need to flip
//		Transform2d flip;
//		flip.setScale( 1, -1 );
//		pushTransform( flip );
		
		if( _batch ) {
			vgLoadMatrix( topTransform().m );
			vgDrawBatchMNK( _batch );
		} else {
			draw_recursive( _root_group );
		}
		
		vgLoadMatrix( m );	// restore matrix
		_transform_stack.clear();
	}
예제 #2
0
void OpenVG_SVGHandler::draw_recursive( group_t& group ) {

    // push the group matrix onto the stack
    pushTransform( group.transform );
    vgLoadMatrix( topTransform().m );

    for ( list<path_object_t>::iterator it = group.path_objects.begin(); it != group.path_objects.end(); it++ ) {
        path_object_t& po = *it;
        uint32_t draw_params = 0;
        if ( po.fill ) {
            vgSetPaint( po.fill, VG_FILL_PATH );
            draw_params |= VG_FILL_PATH;
        }

        if ( po.stroke ) {
            vgSetPaint( po.stroke, VG_STROKE_PATH );
            vgSetf( VG_STROKE_LINE_WIDTH, po.stroke_width );
            draw_params |= VG_STROKE_PATH;
        }

        if( draw_params == 0 ) {	// if no stroke or fill use the default black fill
            vgSetPaint( _blackBackFill, VG_FILL_PATH );
            draw_params |= VG_FILL_PATH;
        }

        // set the fill rule
        vgSeti( VG_FILL_RULE, po.fill_rule );
        // trasnform
        pushTransform( po.transform );
        vgLoadMatrix( topTransform().m );
        vgDrawPath( po.path, draw_params );
        popTransform();
        vgLoadMatrix( topTransform().m );
    }

    for ( list<group_t>::iterator it = group.children.begin(); it != group.children.end(); it++ ) {
        draw_recursive( *it );
    }

    popTransform();
    vgLoadMatrix( topTransform().m );
}
예제 #3
0
bool Label::update(const glm::mat4& _mvp, const glm::vec2& _screenSize, float _zoomFract) {
    if (m_state == State::dead) {
        return false;
    }

    m_occluded = false;

    bool ruleSatisfied = updateScreenTransform(_mvp, _screenSize, true);

    // one of the label rules has not been satisfied
    if (!ruleSatisfied) {
        if (m_state == State::wait_occ) {
            // go to dead state, this breaks determinism, but reduce potential
            // label set since a lot of discarded labels are discared for line
            // exceed (lots of tiny small lines on a curve for example), which
            // won't have their rule satisfied
            enterState(State::dead, 0.0);
            pushTransform();
        } else {
            enterState(State::sleep, 0.0);
            pushTransform();
        }
        return false;

    }

    // update the view-space bouding box
    updateBBoxes(_zoomFract);

    // checks whether the label is out of the viewport
    if (offViewport(_screenSize)) {
        enterState(State::out_of_screen, 0.0);
    }

    return true;
}
예제 #4
0
void OpenVG_SVGHandler::optimize() {

    if( _batch ) {
        vgDestroyBatchMNK( _batch );
        _batch = 0;
    }
    // use the monkvg batch extension to greatly optimize rendering.  don't need this for
    // other OpenVG implementations
    _batch = vgCreateBatchMNK();

    vgBeginBatchMNK( _batch );
    { // draw

        // clear out the transform stack
        _transform_stack.clear();

        float m[9];
        vgGetMatrix( m );
        // assume the current openvg matrix is like the camera matrix and should always be applied first
        Transform2d top;
        Transform2d::multiply( top, Transform2d(m), rootTransform() );	// multiply by the root transform
        pushTransform( top );

        // SVG is origin at the top, left (openvg is origin at the bottom, left)
        // so need to flip
        //		Transform2d flip;
        //		flip.setScale( 1, -1 );
        //		pushTransform( flip );

        draw_recursive( _root_group );

        vgLoadMatrix( m );	// restore matrix
        _transform_stack.clear();


    }
    vgEndBatchMNK( _batch );

}
Action::ResultE TransformPushGraphOp::traverseLeave(
    Node * const node, Action::ResultE res)
{
    if(isInExcludeList(node))
        return Action::Skip;
    
    if(isInPreserveList(node))
        return Action::Continue;
    
    Transform *trans = dynamic_cast<Transform *>(node->getCore());
    
    if(trans == NULL)
        return Action::Continue;
    
    // if not a leaf, search children recursively to find push targets
    if(!node->getMFChildren()->empty())
    {
        _pushPossible = true;
        _pushTargets.clear();
        
        OSG::traverse(
                      *(node->getMFChildren()),
                        boost::bind(&TransformPushGraphOp::traverseTargetsEnter, this, _1));
        
        if(_pushPossible == true)
        {
            // push transform into targets
            pushTransform(trans);
            
            // replace transform with group
            GroupUnrecPtr replaceCore = Group::create();
            node->setCore(replaceCore);
        }
    }

    return Action::Continue;
}
예제 #6
0
    void OpenVG_SVGHandler::dump(void **vertices, size_t *size) {
        
        VGBatchMNK temp;
        temp = vgCreateBatchMNK();
		
		vgBeginBatchMNK( temp ); 
        
        {
            
			// clear the transform stack
			_transform_stack.clear();
            
            // save matrix
			VGfloat m[9];
			vgGetMatrix( m );
            
			// assume the current openvg matrix is like the camera matrix and should always be applied first
			Transform2d top;
			Transform2d::multiply( top, Transform2d(m), rootTransform() );	// multiply by the root transform
			pushTransform( top );
			
            // draw
			draw_recursive( _root_group );
			
            // restore matrix
			vgLoadMatrix( m );
            
            // clear the transform stack
            _transform_stack.clear();
            
		} 
        
        vgDumpBatchMNK( temp, vertices, size );
        vgEndBatchMNK( temp );
        vgDestroyBatchMNK( temp );
        
    }