Doom 3 Source code review
fabiensanglard.net
fabiensanglard.net
John Carmack said [1]:
"The patent [2] situation well and truly sucks. We were prepared to use a two-pass algorithm that gave equivalent results at a speed hit, but we negotiated the deal with Creative so that we were able to use the zfail method without having to actually pay any cash. It was tempting to take a stand and say that our products were never going to use any advanced Creative/3dlabs products because of their position on patenting gaming software algorithms, but that would only have hurt the users."
[1] http://newenthusiast.com/carmacks-reverse-still-an-issue-200...
[2] The patent number 6,384,822, "Method For Rendering Shadows Using A Shadow Volume And A Stencil Buffer", can be read here: http://www.google.com/patents/about?id=Om0LAAAAEBAJ
Here is the patent work-around in the Doom 3 source code. Check out the RB_T_Shadow method in draw_common.cpp at line 1151 [3]:
// patent-free work around
if ( !external ) {
// "preload" the stencil buffer with the number of volumes
// that get clipped by the near or far clip plane
qglStencilOp( GL_KEEP, tr.stencilDecr, tr.stencilDecr );
GL_Cull( CT_FRONT_SIDED );
RB_DrawShadowElementsWithCounters( tri, numIndexes );
qglStencilOp( GL_KEEP, tr.stencilIncr, tr.stencilIncr );
GL_Cull( CT_BACK_SIDED );
RB_DrawShadowElementsWithCounters( tri, numIndexes );
}
[3] https://github.com/TTimo/doom3.gpl/blob/master/neo/renderer/...Further reading on the general topic can be found here: https://en.wikipedia.org/wiki/Shadow_volume
I use Opera with Javascript and Cookies disabled because most things work fine and are much less annoying with that setup.
"That's bullshit. What if my connection is slow and I want to leave the page loading whilst I do some other things."
Thanks for the snark though.
> Thanks for the snark though.
I appreciate taking it in good nature :)
Computers in 2012 are less powerful than a few years ago - many (most?) people will be using tablets or smart phones and thus using ARM processors with low clock speeds. Internet connection is also problematic. People may be using nice fibre-optic broadband with low contention. Or they may be stuck on dial up. Or in a country like Australia with very expensive connections. Or on mobile connections with poor bandwidth and high charges.
[1] I'm not saying this website's javascript is poor.
I actually thought this was well known and documented as I've known it for years. Guess not :)
AFAIK you can use OpenGL in other threads, but you must lock the context to the current thread, which I believe means you're still only rendering from one thread at a time and possibly this is OpenGL 3+ ???
In my own multithreaded OpenGL code, my main thread always became the render thread after starting up the other subsystems. Well, render thread and input gathering thread (as that often needs to be done in the main thread too - at least in SDL).
They didn't argue that the restriction was obvious or well-known, only that it didn't need to be documented because good programmers never thought of violating it. (I feel more than a little vindicated with Carmack in my corner :-) ) Strangely enough, they also implied that it might be fixed in the future, and now the SDL docs imply that what I did would work [1], though I wouldn't bet on it because they have a FAQ item that seems to say otherwise [2].
It's something for people to keep in mind when they're writing documentation: document the limitations of your software even if you can't imagine why someone would violate them. People coming from a different background, such as a non-game programmer picking up a game library for some simple animation, might approach your software with different assumptions.
[1] http://www.libsdl.org/cgi/docwiki.cgi/Multi-threaded_Program... [2] http://wiki.libsdl.org/moin.cgi/FAQDevelopment
Don't call SDL video/event functions from separate threads
most graphics back ends are not thread-safe, so you should only call SDL video functions from the main thread of your application
The second one specifically says from the main thread, while the first one only says "separate threads". I was always under the illusion that it didn't matter which thread, as long as its the one you cal SDL_Init from. Your experience shows otherwise...
I agree - documentation should be clear about limitations and assumptions.
In case there are any resources that describe the technical details, would be nice If someone could post a link.
Seriously ? There may be reasons to think Visual Studio is an inferior product, these are not among them.
I took a look at Whole Tomato: http://www.wholetomato.com/products/featureRefactoring.asp
A couple of those features Xcode implements using code completion. It looks like Whole Tomato may be slightly better, but your comment is clearly wrong.
Also, XCode has a nice feature where you can switch between .h and .c files with CMD+Up. This is missing from VS, but you can add a macro and map it to a key, for me it's ALT+O. See here:
http://www.codeproject.com/Articles/2223/Switch-between-Head...
I never said they did?!?
Doesn't matter though. Even the version before the current is still pretty new tech & interesting to study.
Havign said that, they still do get cash from the engine, through existing licensing deals.
I haven't checked this specific license that doom3 was released under, but it's common for the code to be released under a free license for non commercial use, but a paid license would be required for commercial variants.
http://fabiensanglard.net/doom3/interviews.php
The blog author goes full nerd, like (paraphrasing) "You did this genius thing making a frontend/backend pipeline for rendering. Was this inspired by LCC? What are the advantages to a monolithic renderer?" and Cormack answers practically "Oh, didn't help that much, because of an unexplainable quirk of OpenGL it only worked well on my developer machine."
:-p
Does anybody have additional recommendation of similar reviews of interesting open source code?
I think it must be a little bit hard to be John Carmack. He probably has a hard time getting balanced feedback on his stuff.
>Dmap source code is very well commented, just look at the amount of green: There is more comments than code !
You know, in my experience that's not a good thing. I work on similar, heavily-commented code and find it extremely painful. At some point it becomes a burden to see the code behind the comments. (And just so no one misinterprets me: I am not against comments /per se/.)
It's like when you read code written by someone who simply loved whitespace and who appended a useless "banner comment" after each real comment[1]:
// If x is less than 3, do stuff 50 times.
// -----------------------------
if ( x < 3 )
{
// While i goes from 0 to 50.
// --------------------------
for ( int i = 0; i < 50; i++ )
{
// Do stuff.
// ---------------
doStuff ( ) ;
}
}
So what would've fitted in one screen of text, if written in a sensible fashion, now requires one and a half screen and lots of scrolling.
[1] The comments in the example are actually both crappy and pointless. Sadly, the program I work on is riddled with them. Please don't write out what the programming language constructs do in English.
Then use an editor/IDE that can automatically hide or fold the comments?
Not sure how that helps or hinders, its just an observation.
Exactly this. Comment the why, not the what.
It's true that I don't want to see a comment like "loop through this 50 times". But what may not be obvious is the purpose of the loop, the significance of the number 50. Putting in "why" can save hours.
The only exception where I would want a comment that just says what a line of code is for a really complex line, like a complicated regex for example.
It got to the point where the comments were so lengthy and prosaic, you were deterred from reading them just by their very existence.
// --------------------------
for ( int i = 0; i < 50; i++ )
Well, doStuff() only happens while i goes from 0 to 49, so maybe this comment reveals a bug.