| Home | Contents or SiteMap | Feedback | Search in this site | |
|
|
---|
Special Topic
|
Cenci's Home > SiteMap > My Articles > Direct3D Direct3D Pengenalan Microsoft telah merekabentuk dan melancarkan game development library called DirectX (DX). Sebahagian daripada perpustakaan ini ialah 3D graphics immediate mode rendering API called Direct3D. DirectX merupakan set API yang dibangunkan oleh Microsoft Corporation untuk pembangunan aplikasi Windows masa-nyata yang bermutu. DirectX terdiri dari DirectDraw, DirectSound, DirectPlay, DirectInput dan Direct3D. Setiap satu dari komponen-komponen ini menjurus kepada kawasan atau bahagian berlainan yang diperlukan dalam pembangunan aplikasi permainan dan multimedia.
Application
Programming Interfaces (API)? First is the notion of an Application Programming Interface, or API. An API is essentially a library of small functions that a software developer pieces together to form a complete computer program. For example, a 3D graphics API might include functions that draw objects, simulate the effects of lights, and determine which objects are visible from a given point of view. A software developer could use these functions to build a flight simulation game: drawing mountains and buildings that would be visible through the cockpit canopy of an airplane, and lighting them as they would be lit by the sun. The design of a 3D graphics API determines what can be drawn, how quickly it can be drawn, and how easy it is for a software developer to achieve a desired effect. Thus the API is of fundamental technical and business importance to the software developers who use it. Direct3D adalah sebahagian dari DirectDraw (API for accessing video hardware). Direct3D tak boleh wujud tanpa DirectDraw, selagi ia adalah sebahagian antara-muka DirectDraw. Oleh itu, ini bermakna kita perlu mengetahui asas DirectDraw sebelum kita boleh menggunakan Direct3D. DirectDraw a)
Overview As
mentioned above DirectDraw has an advantage over the standard windows
Graphics Device Interface (GDI). Whereas the GDI has to go through windows
to draw, Directdraw talks directly to the video memory. Besides faster
video access DirectDraw also provides automatic video configuration, the
automatic use of graphics acceleration hardware, and a set of standard
graphics functions. b)
Overall architecture - HEL/HAL DirectDraw's
Hardware Abstraction Layer (HAL) in combination with its Hardware Emulation
Layer allows applications to automatically make the best use out of the
graphics card that they own. If there is a computer that has the appropriate
hardware a request from Directdraw will be sent directly to the HAL. If
on the otherhand the hardware does not support a particular operation
the request will go to the HEL were the appropriate command is emulated
(albeit slower) in software. This makes the process totally transparent
to the application. c)
Direct draw objects DirectDraw
is composed of 4 main object classes, DirectDraw itself, IDirectDrawSurface
IDirectDrawPalette and IDirectDrawClipper. e)
DirectDraw This
object that needs to be created for starting off DirectDraw. The Directdraw
object represents the display device, and is responsible for setting up
the properties of the display, such as resolution and how the Directdraw
window will interact in the windows environment. In a system with multiple
display devices one might have one DirectDraw object for each one. This
object also provides the means for creating the other 3 types of objects.
The DirectDraw object does all this through member functions that are
contained in its class. e)
Surfaces DirectDraw
surfaces are the pieces of memory that are used for drawing on. A surface
contains the image data, sprites, bitmaps, the actual screen etc. A surface
is created through a member function of the DirectDraw object.
f)
Clippers Clippers
are another object created by the DirectDraw object. Clippers can be used
to control where in a window Directdraw is allowed to draw. This is particularly
useful in a windowing type environment because it easily allows you to
make sure your application doesn't keep writing to portions of the screen
that have been covered by by another window. The boundaries of a clipper
are defined by giving the clipper a clip-list, which is a list of rectangles
that the application is allowed to draw in. After creation a clipper is
attached a surface by passing it to one of the member functions of that
surface. g)
Pallettes The
remaining object type that can be created is the a Pallete object. This
object is obviously responsible for the management of the colors for a
particular surface. The pallete entries are specified in the standard
RGB triplets, and each pallette object is associated with a surface in
a similar way to how the clippers are. Using the pallete objects member
function you can do all the neccassary manipulations or a palette. f)
Directly Drawing on the Surface As mentioned before you can draw on a surface either by using the GDI commands of by bliting from surface to surface. However if neither of those suit your needs you also have the option of getting at the surface memory directly. By retrieving the memory pointer from a surface method you can then access the surface memory much in the same way you would access video memory directly in a Dos session. This allows you to implement your own drawing/bliting functions if you wish to. In order to ensure that the surface can only be acceseed by one object at a time whenever you wish to modify a surface you can Lock it. Direct3D
digunakan untuk membangunkan aplikasi/program 3-dimensi,masa-sebenar(real-time)
dan interaktif. Bagi menghasilkan aplikasi seperti yang tersebut, DirectX
menyediakan fungsi/kemudahan berikut: Ketidakbergantungan
terhadap peralatan - aplikasi tidak bergantung kepada peralatan (device)
dan menjadi lebih mudah-alih(portable) Mudah
melakukan penambahan 3D ke aplikasi - oleh kerana Direct3D menyediakan
mekanisma piawai dan set algorithma piawai, aplikasi yang memerlukan kemudahan
berikut dapat dibangunkan dengan lebih cepat. Alternatif
capaian ke peralatan - satu daripada fungsi kemudahan Direct3D iaitu,
ia menggunakan sokongan peralatan, jika boleh. Dalam keadaan dimana peralatan
tidak menyokong fungsi tertentu Direct3D, Direct3D menyediakan alternatif
lain dimana fungsi tersebut akan dijalankan dan diimplimentasikan menggunakan
perisian(software). Dalam masa perlaksanaan, perisian tersebut boleh mengesan
kebolehan peralatan dan menggunakan peralatan tersebut jika boleh. Common driver model to hardware - guarantees to applications, that all the drivers supporting Direct3D will support a defined minimal set of features and capabilities. Dengan ini, aplikasi-aplikasi yang dibangunkan menggunakannya boleh dijalankan pada semua jenis peralatan. Sebagai tambahan, Direct3D meAdditionally, Direct3D provides a specification to all hardware developers, which help their cards support the various Direct3D features. Applications using these features will see a boost in performance. Pemacu-pemacu
peralatan (Device Drivers)? Second
is the notion of a device driver. A device driver (driver for short) is
a piece of software that implements an API on a given hardware device.
For example, the functions of a 3D graphics API might be implemented differently
on the video card in a Compaq PC than they would be implemented on another
video card in a Dell PC. In such a case, the two hardware vendors (Compaq
and Dell) would each write drivers for the 3D graphics API on their respective
video cards. Note that the API would be used in the same way on both machines;
only its implementation details (the drivers) would differ. A driver is key to the viability of its associated API and all the application programs that use it. The existence of a driver determines whether a given API is even available on a particular machine. The quality of the driver (its completeness, performance, and reliability) in large measure determines the quality of the software that uses it on that machine. A driver typically requires a significant amount of effort for development and testing, and is therefore of major importance to the hardware vendor who must supply it as well as the software developers and consumers who will use it. Direct3D terdiri dari dua distinct APIs iaitu higher-level Retained-Mode API (offers scene- and object-management services and a built-in geometry engine, freeing application developers from having to maintain and manipulate object databases) dan lower-level Immediate-Mode API (provides direct access to the hardware and allows experienced 3-D programmers to implement their own rendering and scene management. This supplies both flexibility and performance advantages over Retained Mode). Kebanyakan documentation untuk Direct3D menyatakan dua APIs ini secara berasingan. Dan ramai yang menganggap that the APIs are mutually exclusive. In fact, there are several instances in which we may wish to use functionality dari kedua-dua API dalam satu aplikasi. Apa
sebenarnya RetainedMode dan Immediate Mode? Perbezaan
ketara antara retained mode dengan immediate mode that has lead to this
classification is the ability to address the data even after it has been
rendered. If an application has access to the data being displayed, after
it is rendered, without change in its basic structure, then the application
is said to have the ability to retain the object information and hence
an application working in this mode or using such a facility is working
in the retained mode. For example, if the application is able to address
the data points of a cube even after it has been rendered, then the application
is said to retain the data being rendered and hence is working in the
retained mode. As compared to this, if the application cannot access the
data that was rendered, after rendering its, then the application is said
to be working in the immediate mode. In the immediate mode, once the data
is rendered, it is lost for ever to the developer. Data yang telah dirender
masih available, tetapi data tersebut bukan lagi data 3D, tapi pixel-pixel
2D. Kedudukan
dan hubungan Gambarajah
1 menunjukkan perbezaan bahagian-bahagian Direct3D, dalam hubungan dengan
modul-modul lain system Win32. Daripada gambarajah 1, it is clear that the retained mode uses the immediate mode, transparent to the developer using the retained mode. The developer is not made aware of this usage. From the figure, it is also clear that the retained mode also uses some features of DirectDraw. Retained mode, immediate mode and the Direct3D HAL, bersama, membentuk Direct3d komponen DirectX. Though many of the existing programs for 3D graphics on the Windows platform talk to the different parts directly, it is envisaged that the DirectDraw dan Direct3D components of DirectX will be incorporated into future versions of Win32 systems. Any system providing 3D, will have to use Direct3D to provide its own features. Lapisan (Layers) Direct3D
menggunakan dua lapisan, dipanggil
All of the features of Direct3D are built on top of the HAL, which provides hardware independence and makes applications portable. The HEL is a companion of Direct3D and provides software emulation for the features of the 3D rendering pipeline, not supported by the hardware. This layer is tightly integrated with the DirectDraw HAL and the Graphics Device Interface (GDI) driver of the Win32 system. This layer helps provide a unified driver model for accelerated 3D. Enjin Merender (Rendering Engine) The
rendering engine forms an important part of Direct3D. It is responsible
for taking a scene definition in terms of points in 3D, the different
texture specifications, the lights and the camera specifications, and
rendering ready, so that it can be displayed on the display device. The
functionality of the rendering engine is provided using three modules,
namely
Each
of these modules can be hardware accelerated, transparent to the user
of the application. The application developer only has to put the detection
facility into the application, which will allow it to query the hardware
to find and use its capabilities, if present. Gambarajah 2 shows the three modules of the rendering engine and their interactions with the Direct3D API, before displaying the results on the rendering target, which is the 2D display surface. The diagram shows the sequence of operations performed on the data, before it is displayed. Gambarajah 2: Rendering Engine Modules The
3D data to be displayed, is given to the transformation module, which
maps the 3D data onto its equivalent 2D data. This 2D data is then given
to the lighting module, which calculates the light received by the data,
considering the lights in the scene. The lit data is then given to the
rasterization module, which calculates the transparency and applies the
texture to the data. After rasterization, the data is 2D, lit using the
different lights in the scene and may also have the specified texture
maps applied to them. Let us now consider each of the modules in a bit more detail. 1. Transformation Module The
transformation module is the first of the three modules of the rendering
engine. This module handles the geometry transformations in the rendering
engine. To do this, it uses three four-by-four (4x4) matrices, namely
the view transformation matrix, the world transformation matrix and the
projection matrix. For an explanation of these three matrices, refer [5],
[6], [11], [12], [13] and [14]. The three matrices are maintained in three
state registers, namely the viewing matrix, the world matrix and the projection
matrix, repectively. This module uses one more state register, the viewport,
for holding the dimensions of the 2D display area. The
transformation module combines all the matrices into one composite matrix
and uses this for computations, as using only one matrix, as opposed to
four, speeds up the calculations in the application. It
is possible to set the states of the state registers separately, in addition
to setting the value of the composite matrix. But, it is advisible to
let Direct3D calculate the composite matrix, as the matrix multiplication
operations required, have been specially optimized in Direct3D. Additionally,
the newer versions of DirectX make use of MMX technology. Gambarajah 3 menunjukkan a diagrammatic representation of the transformation module. Gambarajah 3: Transformation Module 2. Lighting Module The
lighting module of the rendering engine is the second of the three modules.
It uses the data provided by the transformation module and calculates
the lighting information for the received data. This module maintains a stack of the current lights and the ambient light level and the different material properties of the data. All this information is used while calculating the light falling at a particular point in the scene. Gambarajah 4 shows a diagrammatic representation of the lighting module. Gambarajah 4: Lighting Module The
lighting module can be operated in any one of the two lighting models
it supports. The two models supported are:
3. Rasterization Module The
rasterization module is the last of the three modules of the rendering
engine. This module takes only execute calls and the data and displays
it onto the display surface. On
being given the execute call, the module goes through the list of vertices
to be displayed and generates the transfomed vertices to be rendered.
Clipping parameters can also be specified in this module. The module also
culls back-facing triangles, viz. the triangles whose surface normals
face away from the camera. An important point about this module is that
it renders only clockwise oriented triangles. Gambarajah 5 shows a diagrammatic representation of the rasterization module. Gambarajah 5: Rasterization Module Singkatan DD
- DirectDraw AuthorCENCI LastUpdate October 21, 2001
|
| Home | Contents or SiteMap | Feedback | Search in this site |
|