Refactoring to Learn a New Code Base

When you join a team with a large existing code base, it can be intimidating. How long does it take to become familiar with a million lines of code? I don’t have the answer to that question, but based on my past experience it easily takes several years if not more. Meanwhile, the rest of the team is adding and changing code all the time. When I apply small, focused, systemic refactorings to a code base, I visit lots of code that may be unfamiliar to me. Visiting unfamiliar code and making the same kind of systematic change throughout can help me become more familiar with the code.

Read the rest of this entry »

Spring 2014 Utah Code Camp: March 15th, 2014

The Spring 2014 Utah Code Camp is coming up and I’ve got some proposed sessions. Utah Code Camps are by the developer community and for the developer community. Utah Code Camp is always free! Spring 2014 Utah Code Camp will be held on March 15th, 2014 at the University of Utah Spencer Fox Eccles Business Building.

Read the rest of this entry »

Direct3D Programming Tip #9: Use The Managed Resource Pool

Resource management can be a challenge for Direct3D applications. Before DirectX, display adapters had limited amounts of fast device memory and programmers had to manage that memory manually in order to achieve the best performance. The Direct3D API provides different memory pools to allow the application to specify the lifetime management policy of a resource.

Read the rest of this entry »

Direct3D Programming Tip #8: Use Find in Files To Locate API Call Examples

The Direct3D API covers quite a bit of ground, particularly if you include D3DX. A question that arises fairly often in discussion forums is “where can I find an example of xxx?” for some particular API function or method named xxx.

Read the rest of this entry »

Direct3D Programming Tip #7: Use Smart Resource Locks

In Direct3D9, direct CPU access to a resource is obtained by obtaining a lock on the resource. Every time you obtain the lock, you must make sure that you release it. In Direct3D10 and Direct3D11, a similar situation is faced with resources, but the terminology has changed to mapping the resource. Using a helper class to handle the lock and unlock operations on a resource helps you create exception safe code in C++.

Read the rest of this entry »

Direct3D Programming Tip #6: Link Against The Debug D3DX

Just as important as using the Direct3D debug runtime is using the debug D3DX library. D3DX is provided as a DLL library and like the runtime it is provided in two versions: release and debug builds.

Read the rest of this entry »

Direct3D Programming Tip #5: Use The Debug Runtime

Direct3D is a large API that reflects the complex nature of 3D graphics rendering and the complexities of modern video cards.  As one of my peers puts it:

The hard part about computer graphics is that there are too many ways to draw a black screen. — Russ Fish

Read the rest of this entry »

Direct3D Programming Tip #4: Check All HRESULTs

Checking for errors is a good programming habit, but new programmers haven’t yet learned this habit. Most of the methods and functions you can call in Direct3D return an HRESULT, or a COM “handle to a result”, that indicates success or failure. Most of the time, your expectation is that these calls should succeed. This leads people to write “happy path” code that assumes that the call will succeed instead of verifying that it succeeded.

Read the rest of this entry »

Direct3D Programming Tip #3: Use Smart Pointers

Direct3D exposes functionality through COM interface pointers. Managing the reference counts on the obtained interfaces is a common problem for new Direct3D programmers. Managing the reference count on an interface becomes trivial if you use a smart pointer wrapper class, such as CComPtr<T> or boost::shared_ptr<T> and keep in mind the ownership policies established by the smart pointer class.

In addition to managing reference counts for you, smart pointers can make your code exception safe. When an exception is thrown, if an interface pointer is held within a CComPtr declared on the stack, then its destructor will be run when the stack is unwound. The destructor for CComPtr will call IUnknown::Release on any interface pointer it holds, thus cleaning up any locally obtained resources as the exception unwinds the stack to the nearest exception handler.

Read the rest of this entry »

Direct3D Programming Tip #2: Use the Documentation

This is a programming tip? Well yeah, I’m sorry to report that often times its obvious from the questions people post that they either don’t know the documentation exists or they don’t use it. Personally, I don’t know how they can get anything done without the documentation. 3D graphics is hard! I put the shortcut to the documentation in my Quick Launch toolbar on the task bar:

  1. Click Start / Programs… and find the entry for the DirectX SDK.
  2. With the cursor over the DirectX SDK entry, right click to display the context menu and select Open
  3. While holding the Ctrl key, drag and drop the shortcut for the DirectX Documentation on the Quick Launch toolbar. A plus (+) sign should appear as you drop the shortcut to let you know that you’re making a copy of the shortcut and not moving it.

OK, now you’ve got the documentation at your fingertips ready to consult at any time. When I’m writing code that is talking directly to Direct3D interfaces, I usually leave the help browser open and just minimize it when I’m not using it. That way its only a quick Alt+TAB away while I’m coding.

Read the rest of this entry »

Direct3D Programming Tip #1: Getting Started

Inspired by Sara Ford’s Visual Studio Tips, I thought I would start writing a series of tips for Direct3D programmers. I doubt I will be able to be as prolific as Sara, with a new tip each and every single day.

So where do we start? Let’s start with the very basics for a native Direct3D programmer. You will need:

  • A C++ development environment.
  • A DirectX SDK.
  • A version control system.

Once you have these in place, you’re ready to get started writing your own Direct3D programs.

Read the rest of this entry »