Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Structs versus Vectors



I don't believe there's any case where immediate mode wins, no. At some point it may be diminishing returns, of course, but I certainly wouldn't write to the slow path just because I can.
At the end of the day I am pretty sure that glEnd() is just going to turn around and submit the vertices with the equivalent of a glDrawArrays call anyway, so if it were me I'd cut out the middleman.



Richard S. Wright Jr. wrote:
Even for very small batches? I've always heard (and repeated) that for very small batches (at one point Apple's performance notes said 11 or less), you might as well use Immediate mode as the overhead is virtually the same.

Richard


On May 8, 2008, at 4:33 PM, John Stiles wrote:

I'm surprised that no one has yet said "avoid immediate mode."
Immediate mode is not really recommended for real development; it's slow and doesn't really match the design of the hardware any more.
You should really use glDrawElements or something like that. That's more important than whether you use a struct array or a float array (since the compiler will generate basically the same code either way).




Jocelyn Houle wrote:
You can always do:

NSPoint p;
glVertex2fv((float *)&p);

Careful, NSPoint is a typedef of CGPoint in 64-bit (and optionally in 32-bit) with the 10.5 SDK, and CGFloat is a double in 64-bit.

Indeed... I assumed too much...

So, let's come back to Richard's original question, which was:
---
So I am thinking that the OpenGL vector data type and corresponding function looks extremely loop friendly. Maybe I should pattern my geometric primitives and associated functions after OpenGL not Cocoa. I have not gotten into Core Data yet so I am not sure which data type would be more compatible a struct or a vector (array).


Any comments or suggestions on structs versus vectors?
---


I usually write a small class (or struct, same difference) such as: struct MyPoint { float x; float y; };

To loop by index, I redefine the operator[] in C++ and/or write a small ptr() method return the address of the first member.

And if you want to go crazy, you can go with unions:
 struct MyPoint
 {
   union
   {
     struct
     {
       float x;
       float y;
     };
     float ptr;
   }
 };
where you can access things like:
 MyPoint pt;
 pt.x = 1.0f;
 pt.ptr[1] = 2.0f;

Of course, I've got full-fledge interface beyond that, but it gives an idea.

So, in the end, I've got BOTH struct and vector forms... Best of both worlds. ;-)

Enjoy!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden



This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >Structs versus Vectors (From: Richard Somers <email@hidden>)
 >Re: Structs versus Vectors (From: "Wesley Smith" <email@hidden>)
 >Re: Structs versus Vectors (From: "Keith Bauer" <email@hidden>)
 >Re: Structs versus Vectors (From: Jocelyn Houle <email@hidden>)
 >Re: Structs versus Vectors (From: John Stiles <email@hidden>)
 >Re: Structs versus Vectors (From: "Richard S. Wright Jr." <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.