OSG can draw body drawable

Source: Internet
Author: User
Tags inheritance
1. Introduction

OSG uses the scene tree to organize the scene structure, at the bottom of the scene tree is the leaf node (Geode), which is used to store objects that can be rendered in the scene, including geometry, pictures, text, and so on. The object used to express all of these objects is the drawable mentioned in this article.

Drawable is the base class for all the objects that can be drawn, providing methods and properties for manipulating these drawing objects, as shown in the following figure (OSG3.4.0): drawable derived classes.

This article and subsequent articles describe all of the derived class types in detail, with descriptions of how these classes are used and how they are used. 2. Principle

When writing OpenGL code, all the code that needs to be drawn is written in the Glutdisplayfunc callback function, and there are many types that can be drawn, such as geometry drawn with vertex data, images drawn with pixels, and they are eventually converted to drawable derived classes. And added to the scene, the typical way to convert is as shown in the following figure:

That is to say, drawable the scene really needs to render the part (written in the rendering function body), according to different rendering types, converted to different classes to describe. 3. Callbacks

OSG::D Rawable inherits from Osg::object before the 3.4 release, inherits from Osg::node after the 3.4 version, osg3.4 before OSG release: The callbacks used by:D rawable are different from the callbacks used by Osg::node, After version 3.4, because OSG::D rawable inherits from Osg::node, the callback function unifies the two. 3.1 old-style callback handling

Specifically, before the 3.4 release, the Way to write callbacks:

Node callback (update, event, filter callback: Three types are all using Nodecallback) class Mynodecallback:public Osg::nodecallback {//must be implemented member virtual VO
ID operator () (Node *node, Nodevisitor *nv);}//function to set callback: void Setupdatecallback (Nodecallback *nc);
void Seteventcallback (Nodecallback *nc);
void Setcullcallback (Nodecallback *nc); Callback for-------------------------------------------------------------//drawable node (update callback) class Mydrawableupdatecallback:public OSG::D rawable::updatecallback {//must implement member virtual void update (Osg::nodevisitor *,
OSG::D rawable *); }//drawable node callback (event callback) class Mydrawableeventcallback:public OSG::D rawable::eventcallback {//Member must be implemented virtual void EV
ENT (Osg::nodevisitor *, OSG::D rawable *); }//drawable Node callback (filter callback) class Mydrawablecullcallback:public OSG::D rawable::cullcallback {//must implement member virtual BOOL Cull (
Osg::nodevisitor *nv, OSG::D rawable *drawable, osg::renderinfo *renderinfo) const; The callback for the//drawable node (draw [Render] callback) public mydrawabledrawcallback:public OSG::D rawable::D RawCallback {//must be implemented by the member virtual void drawimplementation (Osg::renderinfo &, const OSG::D rawable *) const;} 

You can see how it was handled before the 3.4 release:
1. Osg::node has 3 callbacks (corresponding to 3 stages in a frame rendering process): Update, event, filter
2. OSG: There are 4 kinds of callbacks in the:D rawable (more than node is a draw, because drawable is the object that can be drawn in the scene, naturally more than one rendering process of node)
3. Each of the different callback classes needs to implement a specific method, which is called during the callback. 3.2 New callback handling methods

After the 3.4 release, OSG has adjusted the class inheritance structure of the callback by modifying the drawable's parent class to Osg::node, and now most of the callbacks in OSG are inherited from a unified callback class--osg::callback, At the same time, because the function parameters of the load callback in the node class are adjusted, these functions can be drawable used, that is, the parameters are uniformly adjusted to the callback type:

void  Setupdatecallback (Callback *nc);
void  Seteventcallback (Callback *nc);
void  Setcullcallback (Callback *nc);

These functions are not required to be re-implemented in the Drawable class, and drawable own updatecallback can be passed into these functions because they inherit from callback.

The new callback class requires all classes that inherit it to implement a method

virtual BOOL  

This method is called in the callback. This eliminates the need for 3.1 different callback classes to have a method to implement (and these methods have different names). In version 3.4, the original osg::nodecallback was marked as deprecated.

OSG modifies the inheritance of drawable and adjusts the class structure of callbacks, making the entire code look clearer and the code more reusable. 4. Accessors and traversal

The Visitor design pattern (Visitor pattern) is used extensively in OSG, which is used in drawable to get internal properties.

Drawable defines a class of 2 pseudo-functions:
1. Attributefunctor
2. Constattributefunctor
It also defines the two accessors associated with the two functor classes:
1. Attributefunctorarrayvisitor
2. Constattributefunctorarrayvisitor

Drawable also defines several class member functions that receive an affine function:
1. virtual void Accept (attributefunctor&)
2. virtual void Accept (constattributefunctor&) const
3. Virtual void Accept (primitivefunctor&) const
4. Virtual void Accept (primitiveindexfunctor&) const

These 4 types of functor are specifically used to draw object data access, where Attributefunctor and constattributefunctor are used to get an array of vertex attributes, Primitivefunctor is used to get the metadata, Primitiveindexfunctor is used to get the meta-index data, and by inheriting and overriding the member functions, you can perform some custom operations on the geometry vertex data while acquiring it.

From these definitions, these ergodic need to access the various data of the vertex, it is clear that not every drawable subclass can use these functions and accessors, it is only for the sub-class with vertex data, specifically the Osg::geometry subclass, others such as OSG::D Rawpixels because it is pixel data and therefore cannot be used, the font class Osg::textbase and its derived classes cannot use these functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.