WorldWind Series 10: DirectX Rendering analysis in Rendableobject: A case study of Imagelayer

Source: Internet
Author: User
Tags thread

WW has been learning for some time, but if you want to develop your own based on WW Plug-ins, you will inevitably encounter the DirectX rendering problem in Rendableobject. All of the WW three-dimensional plug-ins that need rendering are rendered by inheriting rendableobject and implementing their own initialize (), Update (), Render () methods. To write your own render () method is not a simple matter, you must learn DirectX programming, otherwise, you can not even understand the example of the underlying render () method is difficult to talk about how to develop their own plug-ins.

In order to break through DirectX programming for me to learn the WW plug-in block, I "fast-food" raid learning DirectX, the basic process and the rationale has a certain understanding. This afternoon I also studied the Rendableobject--imagelayer in the BMNG plug-in as an example. Now share with you.

Note: Please be sure to learn first

Direct3D Study (data collection), otherwise look at the following content is tantamount to wasting your precious time.

The Image layer The Initialize () method of the overload implementation.

Initialize Method code

///<summary>


///Layer Initialization code


///</summary>


public override void Initialize (Drawargs drawargs)


         {


Try


             {


//Get Draw device Object


this.device = Drawargs.device;


if (_imagepath = = null && _imageurl!= null && _imageurl.tolower (). StartsWith ("http://"))


                 {


///According to the URL address, build the same level of folder path locally. Here is a knowledge point Getfilepathfromurl () method, oneself localization study


_imagepath = Getfilepathfromurl (_imageurl);





                 }


FileInfo imagefileinfo = null;


if (_imagepath!= null)


imagefileinfo = new FileInfo (_imagepath);


if (downloadthread!= null && downloadthread.isalive)


return;


if (_imagepath!= null &&


cacheexpiration!= timespan.maxvalue &&


cacheexpiration.totalmilliseconds > 0 &&


_imageurl.tolower (). StartsWith ("http://") &&


imagefileinfo!= null &&


imagefileinfo.exists &&


Imagefileinfo.lastwritetime < system.datetime.now-cacheexpiration)


                 {


//attempt to redownload it


//enable new thread, download image image. I will later analyze the Downloadimage () method, which is one of the key


downloadthread = new Thread (new ThreadStart (downloadimage));


downloadthread.name = "Imagelayer.downloadimage";





Downloadthread.isbackground = true;


Downloadthread.start ();


return;


                 }


if (m_texturestream!= null)


{


//From file stream, update texture (texture), focus on


updatetexture (M_texturestream, M_transparentcolor);


verticalexaggeration = World.Settings.VerticalExaggeration;


//Create mesh, focus on analysis later


Createmesh ();


isinitialized = true;


return;


                 }


else if (imagefileinfo!= null && imagefileinfo.exists)


                 {


//update texture from file path


updatetexture (_imagepath);


verticalexaggeration = World.Settings.VerticalExaggeration;


//Create mesh mesh, in order to get the vertex collection.


Createmesh ();


isinitialized = true;


Return


                 }


if (_imageurl!= null && _imageurl.tolower (). StartsWith ("http://"))


                 {


//download it ...


downloadthread = new Thread (new ThreadStart (downloadimage));


downloadthread.name = "Imagelayer.downloadimage";





Downloadthread.isbackground = true;


Downloadthread.start ();


return;


                 }


//No image available


Dispose ();


ISON = false;


return;


             }


Catch


             {


             }


}

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.