Re: newbie question



On Fri, 25 Aug 2006 14:00:21 -0400, "PJ6" <noone@xxxxxxxxxxx> wrote:

I'm just starting to learn DirectX and have taken in a few things that are a
bit hard for me to swallow. Below (end of post) I take a quote from one of
the more newbie-informative posts I've found anywhere (thanks, Stephan). My
impression, coming from a background of developing WinForms controls with
GDI+, is that DirectX is utterly mismatched to the needs of business
applications.

It's utterly mismatched? Hmm...

http://www.somrek.net/iEDA1.jpg
http://www.somrek.net/iEDA2.jpg
http://www.somrek.net/iEDA3.jpg
http://www.somrek.net/iEDA4.jpg

Doesn't look very mismatched to me...=)


Can someone please explain to me why everything has to be in traingles and
textured? To do the simplest things, the code seems so awful. I just don't
get it.

Well your video card cannot do much beyond rasterizing a triangle.
Even all the advanced pixel shaders, and whatnot video cards can do
these days, everything in the end boils down to a triangle that is
beind rasterized. That's most of what that the expensive latest
high-end GeForce can actually really do.

It's not really all that complicated once you get used to it.

Here is the way my 2D Engine is structured and this works very well
for non-textured stuff:

I have various commands to draw things just like GDI+.

DrawPoint
DrawLine
DrawCircle
DrawFilledCircle
etc.

Then internally, the engine has 3 buffers. One for points, one for
1-pixel lines, one for triangles.

If I draw a point, the DrawPoint function adds a vertex to the point
list.

If I draw a line, and the line is only 1 pixel wide, DrawLine adds 2
vertices to the line list. Otherwise it will add 6 vertices to the
triangle list. 3 vertices per triangle, 2 triangles to form a line.

If I draw a circle, same deal. A circle with a line thickness of 1
pixel will add line segments to the line list. A circle with a line
thickness of greater than 1 pixel will add triangles to the triangle
list. Just have to make sure you use enough segments so the circle
actually looks roud since you can't draw a true circle. That's easy to
do though.

And so on for other more complex primitives...

Now when my buffers reach a certain limit, their contents are
submitted to the video card for rendering and then emptied. This
allows me to already submit data to be rendered while I am still
processing the next batch of vertices so that the GPU isn't idle while
my CPU is busy.

Then when all drawing operations are completed, all buffers that are
not empty are submitted to the video card to draw the rest.

Done!

And the way I am passing the data to the video card is actually the
slowest way possible. I could be faster and more efficient (index
lists, triangle strips. etc). However since I am over 90% CPU bound,
there is no point in trying to speed up the GPU...

I can draw over 18,000 objects in less than 100ms and that includes
text which is very complex to render for me as I use a vector font,
not a bitmapped font. Without the text the same scene dropped to less
than 70ms render time.

Over 90% of the measured time is spend triangulating the elements. The
time needed for the video card to render is almost impossible to
measure.

GDI+ needs over 500ms for the same data. I actually ditched support
for GDI+ from my engine as its just not worth it.

So for non-textured stuff, if you structure your engine like above you
should have all the performance you will ever need. That structure
essentially reduces the problem to simply filling buffers with
vertices and sending them off to the video card when they are full.

If you need to draw images, at which point in time you need textures,
how it works doesn't really change all that much. You would just need
a 4th buffer containing the triangles that make up the rectangular
areas for your images.

Only catch is that you can't just dump the coordinates for 1,000
different images into that buffer and draw it all in one shot.

Images, especially if every one is different, you need to draw one at
a time. Which means create 2 triangles forming a quad with the proper
coordinates, set the current active texture, submit to video card.
Repeat for every image.

Now if you draw the same image multiple times, you can optimize this a
bit. Instead of submitting each quad one at a time, you can create a
buffer containing all the quads that image will be shown on and then
submit that in one shot.

You can also optimize drawing multiple different images at the same
time if you can place them onto the same texture. Then you just need
to modifiy your vertex UV coordinates accordingly so they only use the
area of the texture corresponding to the image they are supposed to
show.

Those 2 options though are not something you really need to worry
about unless you are really drawing a LOT of images every frame. Like
a game for instance that has a texture on every triangle needs to
worry about that. If all you have are 10 small bitmaps on the screen,
it isn't gonna make a difference performance-wise if you submit one at
a time or all at once.


I don't want to re-invent the wheel, here. Can someone point me to a few
resources regarding the use of DirectX in business applications?

Most resources online you will find will be geared towards games and
3D Stuff I am afraid.

--
Stephan
2003 Yamaha R6

kimi no koto omoidasu hi
nante nai no wa
kimi no koto wasureta toki ga nai kara
.



Relevant Pages

  • Re: Genealogy question - confirming links
    ... can draw one triangle which shows it isn't true. ... occasion to saying that the only certainly true statement in genealogy ...
    (soc.genealogy.britain)
  • Re: Transparent bitmaps
    ... because code to draw images is there already (e.g. ... the .NET Compact Framework itself. ... > color based on index, if any, is to be transparent in the the image when ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Genealogy question - confirming links
    ... and a biro you can draw one triangle which shows it isn't true. ... Start at any point, draw a quarter of the way round the ball, ... You now have a triangle the angles if which add up ...
    (soc.genealogy.britain)
  • Re: Need some help
    ... teachpack we have to draw a picture and be able to move it if we can. ... my project I need to draw a triangle. ... the problem is to set the color of some squares depending ... You can do this pixel ...
    (comp.lang.scheme)
  • Re: Creating shapes from lines
    ... existing line and then choose fragment will ... When you draw 3 lines to create a triangle it is best if you don't ... If you have draw 3 lines and the second line you draw without releasing ... I edit figure's text then edit box is shown red. ...
    (microsoft.public.visio)