beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

21
Beginning Direct3D Game Programming: 2. Overview of HAL and COM [email protected] Division of Digital Contents, DongSeo University. April 2016

Upload: jintaek-seo

Post on 13-Feb-2017

42 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Beginning Direct3D Game Programming:2. Overview of HAL and

[email protected]

Division of Digital Contents, DongSeo University.April 2016

Page 2: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

HAL: Hardware Abstraction Layer

In DirectX 8.0/9.0 games, you might choose between a HAL, a pluggable software device, or a reference raster-izer; or the application might select one automatically.

You will find this device selection box, called the Direc-t3D Settings dialog box, in every Direct3D example pro-gram delivered with the DirectX 9.0 SDK.

2

Page 3: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

3

Page 4: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

The relationships among the Direct3D API, HAL, and GDI(Graphics Device Interface) APIs.

HAL is the primary device type, and it supports hard-ware-accelerated rasterization and both hardware and software vertex processing.

4

Page 5: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Device Name Use DxDiag to check device name.

5

Page 6: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

HAL is also able to emulate vertex processing in soft-ware completely or in parts.

The following flags control vertex-processing behavior for HAL and reference devices:– D3DCREATE_SOFTWARE_VERTEXPROCESSING– D3DCREATE_HARDWARE_VERTEXPROCESSING– D3DCREATE_MIXED_VERTEXPROCESSING

Pure Device– HAL is able to switch on a so-called pure device.– This device uses a reduced number of state checks and is avail-

able only if specific functions of the Direct3D API are not used.– It is a bit faster than the non-pure hardware vertex-processing

device.

6

Page 7: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Reference Rasterizer The reference device is supplied only with the installa-

tion of the SDK. The reference rasterizer supports all Direct3D features.

You should only use it to test features that your card doesn’t support.

This device is optimized for accuracy, not for speed.

7

Page 8: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Controlling Devices You can configure all con-

trolling devices in the Di-rectX Properties dialog box.

8

Page 9: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

GPU-Z Use GPU-Z tool to measure

GPU memory.

9

Page 10: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Fraps Draw FPS on any DirectX surfaces of running process. Benchmark FPS of DirectX program.

10

Page 11: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Example: BasicHLSL Build and run BasicHLSL project in Sdk. Change device to reference rasterizer and check FPS us-

ing Fraps.

11

Page 12: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

COM: Component Object Model Component Object Model (COM) is a binary-interface

 standard for software components introduced by Microsoftin 1993.

It is used to enable inter-process communication and dynamic object creation in a large range of programming languages.

The essence of COM is a language-neutral way of im-plementing objects that can be used in environments different from the one in which they were created.

12

Page 13: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

COM in DirectX COM provides a versioning strategy, which guarantees

that all games developed in earlier versions of DirectX are guaranteed to run in future versions.

It helps you encapsulate data and provides a consistent interface to different languages.

13

Page 14: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Using COM for IPC Applications that use OLE manage compound docu-

ments—that is, documents made up of data from a vari-ety of different applications.

OLE provides services that make it easy for applications to call on other applications for data editing.

For example, a word processor that uses OLE could em-bed a graph from a spreadsheet. The user could start the spreadsheet automatically from within the word pro-cessor by choosing the embedded chart for editing. 

14

Page 15: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Technical details COM programmers build their software using COM-

aware components. Different component types are identified by class IDs

(CLSIDs), which are Globally Unique Identifiers (GUIDs). Each COM component exposes its functionality through

one or more interfaces. The different interfaces supported by a component are

distinguished from each other using interface IDs (IIDs), which are GUIDs too.

15

Page 16: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

IUnknown All COM components implement the IUnknown (custom)

interface, which exposes methods for reference counting and type conversion (casting).

A custom IUnknown interface consists of a pointer to a virtual method table that contains a list of pointers to the functions that implement the functions declared in the interface.

16

Page 17: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Classes A COM class (coclass) is a concrete implementation of

one or more interfaces, and closely resembles classes in object-oriented programming languages. Classes are created based on their class ID (CLSID) or based on their programmatic identifier string (progid).

Like many object-oriented languages, COM provides a separation of interface from implementation.

17

Page 18: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

Practiceclass IUnknown {public: virtual void CreateInstance() = 0;};

class KFirst : public IUnknown { virtual void CreateInstance() { printf( "Hello First\r\n" ); }};

class KSecond : public IUnknown { virtual void CreateInstance() { printf( "Hello Second\r\n" ); }};

18

Page 19: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks

void main() { IUnknown* pUnknown = nullptr; KFirst first; KSecond second; pUnknown = &first; pUnknown->CreateInstance(); pUnknown = &second; pUnknown->CreateInstance();}

19

Page 21: Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks