» multiple texture outputs
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

multiple texture outputs

the easiest way to write a plugin with a texture output was by extending the DXTextureOutPluginBase class and overriding the CreateTexture and UpdateTexture methods. this approach lead to several issues though:

  1. the plugin was limited to one texture output. if there was the necessity to have more than one texture output one had to go the long route by implementing IPluginDXTexture2 and doing the resource management manually.
  2. it wasn't possible to reinitialize the textures on a slicewise basis. for example if the size of one texture changed all textures had to be recreated.
  3. dealing with a pin of type texture was completely different than all the other data types. wouldn't it be nice to simply write ISpread<Texture> and be done with it?

well it's nearly as simple as that now. you can create a texture output by writing

[Output("Texture")]
ISpread<TextureResource> FMyTextureOut;

the TextureResource class takes care of the resource management, for example if a renderer is moved to another screen, the directx9 device changes and therefor the texture on the old device needs to be disposed and recreated on the new one.

the resource management is the reason why we can't simply write ISpread<Texture> as there might be multiple textures for one single slice. for example if the texture output is connected to two renderer each using its own directx9 device, two textures have to be created for each slice.

the constructor of the TextureResource class takes up to four arguments:

  1. some arbitrary user data which will be supplied as the first argument to the following functions
  2. a function which creates the texture, taking as first argument the user data, as second the device for which a texture was requested and returning the newly created texture.
  3. a function which updates the texture (optional), taking as first argument the user data and as second argument the texture to be updated.
  4. a function which destroys the texture (optional), taking as first argument the user data and as second argument the texture to be destroyed.

so in order to create a texture we need to do this:

FMyTextureOut[i] = TextureResource.Create(i, CreateTexture);
...
Texture CreateTexture(int slice, Device device) {
  return new Texture(device, ...);
}
the static TextureResource.Create method does nothing more than calling new TextureResource<TMetadata>(...), so you might ask yourself why not calling new directly? well the reason is that using the static factory method we can make use of c#'s type inference. so instead of writing new TextureResource<SomeComplexMetadataType<ContainingInnerTypeArguments>>(...), we let the type inference algorithm figure out the SomeComplex...BlaFoo thing.

if we want to update the texture when some input changes:

FMyTextureOut[i] = TextureResource.Create(i, CreateTexture, UpdateTexture);
...
void UpdateTexture(int slice, Texture texture) {
  // Do something with the texture
}

and if something special needs to be done when destroying the texture:

FMyTextureOut[i] = TextureResource.Create(i, CreateTexture, UpdateTexture, DestroyTexture);
...
void DestroyTexture(int slice, Texture texture) {
  // Destroy the texture
}

in many cases the UpdateTexture call can be quite expensive, in order to disable it set the NeedsUpdate property on the TextureResource to false and set it back to true under a certain condition.

for a full example have a look at the rewritten dynamic plugin template.

oh and all this stuff works for meshes too, simply replace TextureResource with MeshResource.

Elias, Thursday, Jul 26th 2012 Digg | Tweet | Delicious 1 comments  
zeos 26/07/2012 - 19:40

;) looks great

  • 1

anonymous user login

Shoutbox

~3d ago

joreg: vvvvTv S02E01 is out: Buttons & Sliders with Dear ImGui: https://www.youtube.com/live/PuuTilbqd9w

~9d ago

joreg: vvvvTv S02E00 is out: Sensors & Servos with Arduino: https://visualprogramming.net/blog/2024/vvvvtv-is-back-with-season-2/

~10d ago

fleg: hey there! What's the best tool for remote work? Teamviewer feels terrible. Thanks!

~23d ago

joreg: Last call: 6-session vvvv beginner course starting November 4: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-i/

~1mth ago

joreg: Missed the last meetup? You can rewatch it here: https://www.youtube.com/live/MdvTa58uxB0?si=Fwi-9hHoCmo794Ag

~1mth ago

theurbankind: When is the next big event, like node festival ?

~1mth ago

~1mth ago

joreg: Join us for the next vvvv meetup on Oktober 17th: https://visualprogramming.net/blog/2024/25.-vvvv-worldwide-meetup/

~2mth ago

joreg: 6 session beginner course part 2 "Deep Dive" starts January 13th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-ii/