Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
99 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 What is IM?
 Execute Buffers
 Steps to Create
 an Application

 Scene Management
 Sample App
 IM Objects
 DrawPrimitive
 Comparing Modes
 Summary

 Printable version

 


DrawPrimitive

Motivation

As we have seen in the sample application, managing data in immediate mode is not an easy task. Keeping track of the data using offsets into an array is very difficult. Additionally, changes occuring in the data storage can be very disastrous on the code which accesses this data.

To ease the situation, the concept of DrawPrimitive was introduced in Direct3D, in ver 5.0 of DirectX. An interesting point about ver 5.0 is that it is MMX enabled.

Goals

The goals of DrawPrimitive are:

  • Ease of use
  • DirectX compatibility
  • Scaleable performance

Introduction

DrawPrimitive is still for immediate mode programming. The features it provides are very similar to those provided by execute buffers. DrawPrimitive provides a cleaner syntax than that provided by execute buffers.

The DrawPrimitive concept does not provide wrappers for execute buffers. DrawPrimitve completely sidesteps execute buffers, without sacrificing performance. DrawPrimitive provides its own path to the rendering facilities of the hardware, different that the path provided by execute buffers. It still provides direct access to the 3D accelerate hardware and provides emunaltion if the hardware does not support a certain feature.

Drawing Primitives

DrawPrimitive provides support for drawing primitves, like points, lines and triangles. The application can also pass its own data structures to DrawPrimitive.

Data using DrawPrimitve is rendered on a DirectDrawSurface object, using the DrawPrimitve or DrawIndexedPrimitive functions. The data to be rendered can be drawing primitives directly or an array of vertices with the rendering information.

DrawPrimitive Sample

After giving an introduction to DrawPrimitive, let us consider a small piece of code, to illustrate the concept and its ease of use over the execute buffers. The sample source is shown in figure 21.

// Render a triangle D3DTLVERTEX v[3]; v[0] = D3DTLVERTEX(D3DVECTOR(160, 50,0), 1, D3DRGB(1,0,0), D3DRGB(0,0,0), 0, 0); v[1] = D3DTLVERTEX(D3DVECTOR(240,200,0), 1, D3DRGB(0,1,0), D3DRGB(0,0,0), 0, 0); v[2] = D3DTLVERTEX(D3DVECTOR( 80,200,0), 1, D3DRGB(0,0,1), D3DRGB(0,0,0), 0, 0); m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DVT_TLVERTEX, (LPVOID)v, 3, NULL);
Figure 21: DrawPrimitive Sample

For the DrawPrimitve Specification and White Paper, refer [4] and [5]. For a tutorial, refer [6].

For details about 3D graphics, the rendering pipeline and various algorithms, refer [7], [16], [17], [14], [15] and [8].



Next : Comparing Modes