Archived

This topic is now archived and is closed to further replies.

weekee

OOP in opengl

Recommended Posts

weekee    122
hi all, just have a simple question. The current tutorials dun use classes. If implementing opengl in classes and objects, will it affect the performance in anyway? use of opengl is mainly functions calling, will there be any problem if trying to wrap certain code in a class? the reason i am asking this is to try to see how it is possible to manage a project in opengl more efficiently. thanks for the comments

Share this post


Link to post
Share on other sites
jenova    122
yes. because you will be pushing the "this" pointer onto the stack everytime you make a OpenGL call.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
CodeSmith    122
Learn how to program first, then learn how to program well, then worry about optimization. Of course their are instances where thinking about improvments ahead of time will help in the long run, but until you learn to run, try walking.

CodeSmith the Pixel Pusher
CodeSmith Webpage

Share this post


Link to post
Share on other sites
CodeSmith    122
Learn how to program first, then learn how to program well, then worry about optimization. Of course their are instances where thinking about improvments ahead of time will help in the long run, but until you learn to run, try walking.

CodeSmith the Pixel Pusher
CodeSmith Webpage

Share this post


Link to post
Share on other sites
jwace81    160
This is a topic that has probably been debated several times, in a more general sense anyway. Can OOP actually improve performance? The awnser to that is not really simple, as it can go either way. There are some algorithms that are better suited for a procedural implementation, and there are some algorithms that are better suited for a more object oriented approach. In object oriented code, there is more management that has to be done, as jenova said, however, unless you start to worry about small amounts of time, then you will probably not see a major difference between procedural vs object oriented code. What you should look at more that procedural versus OOP are the algorithms that you are using, and other areas where speed could be hindered even more. Just as poorly written procedural code will run poorly, poorly written oop code, will also run poorly.

j.w.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
This is actually a really difficult question ...

I think wrapping it up in an object oriented style,
could be really interesting and could also be a good
idea, but its hard make a good and fast implementation
that''s also ready for reuse. So there is some work to do
especially for the design aspect.

And at last, a bad designed and implemented wrapper could
make the situation worse than before, and not only from the
performance point if view.

Also a procedural wrapper could sometimes do the job as
good as an object oriented one.

Share this post


Link to post
Share on other sites
TheGilb    372
So to summarise what everyone said - dont worry about it m8 *g*

Sure, I have no doubt in my mind whatsoever that C code is faster than C++ code, to what extent I cannot be sure as I haven''t benchmarked C vs C++ code, however I''m sure the difference is negligible.

Most game engine''s these days use C code for the core graphics rendering simply because C is easier to keep a track of in your brain, and thus = less bugs Can''t argue with that, C++ simply -is- more complex than C, but I personally like C++ Also, I have not noticed -any- difference in speed using code wrapped in classes, but I have a 900MHz Athlon CPU

To me, the advantages reaped from object oriented code far outweigh the disadvantages caused by object oriented code... Reusability, being able to overload operators is nice too, templates can offer big speed improvements used in the right place...

Of course, in C++ you have the benefit of choice *g* You could write some code in C and some in C++! Well - you know what I mean, obviously you can''t write pure C code in a C++ compiler, but you can emulate C!

Share this post


Link to post
Share on other sites
Ziphnor    122
"Can''t argue with that, C++ simply -is- more complex than C"

I think that is a matter of taste, or how you plan your program. I find OOP(C++/Java) programming much easier to plan, program, and keeping an overview of than when using straight procedual programming(ie C). I think it has alot to say how you were introduced to programming. I learned programming with Java, so i naturally plan programs in a OO-style.

Share this post


Link to post
Share on other sites
jenova    122
understanding the principles of programming and developing good design skills ensures that you do not have to grasp to a perticular language or programming style, period. the theories of programming are apparent across every programming language.

anyone, ever read the book "Code Complete".

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites