A computer in a computer

The thing about what it takes for your computer to process your game. The computer must receive input from the player, interpret that input, and then apply the results to the game. Once the input is completed, the computer must handle the physics of the game: objects must be moved, collisions must happen, and explosions must ensue. Once the computer has completed updating all of the objects in the game, it must then render these results to the screen. Finally, in order to be convincing, all of this must occur at least 30 times a second and often 60 times a second!

It is truly amazing that computers can process this much information that quickly. In fact, if it were truly up to the central processing unit of your computer to accomplish this, then it wouldn't be able to keep up.

The 3D graphics card solves this problem by taking care of the rendering process so that the main CPU of your computer doesn't have to. All your CPU has to do is deliver the data and the graphics card takes care of the rest, allowing the main CPU to continue processing other things.

A modern 3D graphics card is really an entire computer system that lives on a silicon card inside your main computer. The graphics card is a computer inside your computer! The graphics card has its own input, output, and its own processor known as the graphics processing unit, or GPU. It also contains its own memory, often up to 4 gigabytes or more.

The following diagram shows you the basic structure of a graphics card and how it processes information:

A computer in a computer

The preceding sequence that is depicted is known as the graphics pipeline. A detailed discussion of every step in the process is beyond the scope of our book, but it is good to have a basic understanding of the graphics pipeline, so here are the basics:

  • Graphics bus: In computer lingo, a bus is just a way to move data. Think of a bus as a freeway: the more lanes you have on our freeway, the faster the traffic can move. Inside your computer, the traffic is bits of data, and most modern graphics cards have 64 lanes (known as a 64-bit bus), which allows up to 64-bits (or 8 bytes) of data to be moved simultaneously. The graphics bus receives its data directly from the CPU.
    • Graphics Processing Unit: The GPU does all the work, and as you can see, there is a lot of work to do.
    • Transformation: Each vertex, represented as a point in 3D space, must be properly positioned. There are several frames of reference to deal with. For example, local coordinates may describe how far a car's tires are from its body, while global coordinates describe how far the car is from the upcoming cliff. All of the data must be transformed into a single frame of reference.
    • Lighting: Each vertex must be lit. This means applying light and color to each vertex and interpolating the light and color intensity from one vertex to another. In the same way that the sun lights our world, while fluorescent tubes light our offices, the GPU uses lighting data to correctly light the world of your game.
    • Primitives: These are the simple objects that are used to build more complicated objects. Similarly to a virtual Lego set, the GPU constructs everything in your game using triangles, rectangles, circles, cube, spheres, cones, and cylinders. We will learn more about this later in the chapter.
    • Projection: Once the GPU has constructed a 3D model of the world, it must now create a 3D projection of the world onto 2D space (remember, your display only has two dimensions). This is similar to how the sun projects a 2D shadow of 3D objects.
    • Clipping: Once the 3D scene has been projected into 2D space, some vertices will be behind other vertices, and, therefore, can't actually be seen at this time. Clipping, or removing vertices that can't be seen, removes these vertices from the data, streamlining the entire process.
    • Rasterization: We now have a 2D model that mathematically represents the current image that must be displayed onto the screen. Rasterization is the process of converting this virtual image into actual pixels that must be displayed on the screen.
    • Shading: This final process determines the actual color that must be applied to each pixel on the screen to correctly display the model that has been created in the earlier phases. Code can even be written to manipulate the process to create special visual effects. Code that modifies the shading process in the graphics pipeline is called a shader.
  • Render: Of course, the reason that we do all of this is so that we can display our game on the computer screen. The final output of the graphics pipeline is a representation of the current screen in the render buffer. Now, all the CPU has to do is swap the data in the render buffer to the actual screen buffer, and the result is the next frame in your game!

By the way, you will notice that behind the scenes (the big arrow in the preceding image) everything is supported by dedicated memory on the graphics card. All of the data is moved from the CPU to the memory of the graphics card, where it is manipulated and processed before being sent back to the CPU. This means that memory on the main computer doesn't have to be set aside to handle graphics processing.

Tip

It is important to understand that the preceding diagram is a generic representation of the graphics pipeline. Specific hardware on various graphics cards may handle things differently, and the OpenGL and DirectX specifications are slightly different, but the preceding diagram is still the basic pipeline.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.22.58