Re: copy texture to another texture

Tech-Archive recommends: Speed Up your PC by fixing your registry



[Please do not mail me a copy of your followup]

"brekehan" <cpisz@xxxxxxxxxxxxx> spake the secret code
<1169152547.426282.188650@xxxxxxxxxxxxxxxxxxxxxxxxxxx> thusly:

I was thinking about the latter, not realizing the first was an option.
I think sharing the resource is viable. Where is the resource contained
and managed? What will happen when I release a texture object and
texture object is still in use?

A COM object remains "live" as long as someone else holds a reference
to it. So if you have two objects A and B that both have a reference
to a texture object T, then the texture object T will live for as long
as A and B have a reference to it. If the constructor for A and B
calls Release on the texture interface, then the texture will be
released (assuming only A and B have references to it) when the second
object is destroyed. Note that setting a texture on a device adds a
reference to it -- the device needs the texture to stay alive as long
as its set on the device.

To create the text area a font object is passed as an argument and
"copy constructed" to its member
Thus why I wanted to copy the texture

A copy constructor alone doesn't define the resource ownership
semantics here. For instance, I can see situations where either of
these design assumptions are valid:

1) assigning object A to object B transfers ownership of resources
from A to B

2) assigning object A to object B means ownership of resources is
shared between A and B

3) assigning object A to object B means that B gets its own
distinct copy of A's resources

You can do any of these with the texture resources in Direct3D. In
1), no AddRef or Release is done, but someone A must be signalled to
know that it doesn't "own" the resource anymore, B does. In 2), B
does an AddRef on the texture interface at the time of the copy. In
3), B does a complete level by level copy of A's texture, creating its
own texture that it owns. No AddRef/Release is performed.

The idea is that the dialog parser can create a bunch of fonts and pass
in whatever font is needed for any text area it comes across. There may
be several text areas that use the same font. Since, the font contains
the texture, I wanted to copy it over in the text areas constructor.

If it were me, I'd lazy create font resources for this sort of
scenario. That means that you can copy around these font "objects" as
much as you want and there's no Direct3D resource consumed until you
actually use one of the fonts. Its a little more complex, but if
you're doing lots of manipulation of stuff that might *not* appear on
the screen, its a win. If you know that everything is going to appear
on the screen regardless, then you might as well do the resource
allocation up front because you'll need all those resources anyway.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
.



Relevant Pages

  • Re: copy texture to another texture
    ... I think sharing the resource is viable. ... texture object is still in use? ... A COM object remains "live" as long as someone else holds a reference ... in whatever font is needed for any text area it comes across. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Rendering to Multiple GPUs
    ... related to when or if sharing resources might be permitted. ... > I understand that DirectX doesn't render from system memory. ... even resource management. ... when you create a managed texture, ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: copy texture to another texture
    ... arisen for me to write a copy constructor. ... Do you need to create a new texture resource whose contents are ... It comes across a font which is an art image of glyphs. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: adding a texture resource
    ... > The memory stream issue was discussed lately... ... >> I am trying to add asteroid.bmp as a texture resource and my program just ... >> I also tried changing the Build Action property of the bitmap to Embedded ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: copy texture to another texture
    ... I think sharing the resource is viable. ... texture object is still in use? ... A COM object remains "live" as long as someone else holds a reference ... in whatever font is needed for any text area it comes across. ...
    (microsoft.public.win32.programmer.directx.graphics)