concentrate on c/c++ related technology

plan,refactor,daily-build, self-discipline,

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  37 Posts :: 1 Stories :: 12 Comments :: 0 Trackbacks

常用链接

留言簿(9)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

computer display = a single graphics adapter + a display monitor.
graphics adapter contains the hardware needed store and display images on a monitor or other display device.
all of these adapters stored a representation of the displayed image in a bank of dual-ported memeory called a frame buffer.
the system uses one of the ports to read and write images into the frame buffer.the second port is used by the video scan out circuitry of the adapter to create a signal for the monitor.Direct3D only supports VGA compatible adapters.

Frame                               Color Lookup
Buffer                               Table


2D Pixel                           D/A
Engine                              Converter

Host CPU                        CRT Monitor

Direct3D abstractions include :device, swap chains, surfaces, and resource .

an application enumerates the devices available on each adapter, examining their capablities and supported display modes to find an acceptable device.
device is the object that expose the rendering operations of the hardware. its properties control the rendering behavior or provide information about rendering, while the device's methods are used to perform the rendering itself.

devices always contain at least one swap chain and a collection of resources used for rendering.
resources are application specific data stored in or near the device hardware for use during rendering Direct3D provides resources for scene geometry(vertices and indices) and appearance(images, textures, and volumes).

a surface is a resource containing a rectangular collection of pixel data such as color, alpha, depth/stencil or texture information.
a swap chain contains one or more back buffer surfaces where scenes are rendered and presented for display on the monitor, is a collection of back buffers.

a device's render target is the back buffer surface, with an optional depth/stencil surface, in which rendering will occur.

while all back buffers are valid render targets, not all render targets are back buffers.
it is also possible to have a texture as a render target allowing dynamic rendering effects.

to obtain a device object, Direct3D provides an object for device enumeration and creation. all other objects are created through the device. an application first obtains the runtime interface, then selects and creates a device from those available, and using the device creates the necessary resources for rendering.

most COM methods return HRESULT to indicate success or failure.
in windowed mode: the results of graphic rendering are presented for display insidei the client area of a window on the desktop.
Direct3D cooperates with GDI to make the results of rendering visible, using a ::StretchBlt operation to present a back buffer in the window's client region
in exclusive mode: Direct3D communicates directly with the display driver avoiding GDI. when an exclusive mode application is running, no other applications have access to display hardware and no GDI is visible on the screen.

HAL(hardware abstraction layer): has hardware acceleration of graphics rendering, making it fastest device type.

reference device: useful for debugging, when developing software applications that target new features not yet common in hardware, the reference device maybe your obly choice for generating an image with those Direct3D features.

the null reference device: does nothing and all rendering will result in a black screen.useful for manipulating resources on a machine that provides no hardware or software  implementation of the runtime.

the pluggable software device: RegisterSoftwareDevice method,

each resource has Type, Pool, Format, and Usage attributes, each of these attributes of a resource are specified at the time the resource is created and remain constant for the lifetime of the resource object.
type attributes describes the kind of resource and is defined by D3DRESOURCETYPE.
pool attribute of a resource describes how it is managed by the Direct3D runtime and is defined by the D3DPOOL enumeration.
resources in the default pool exist only in device memory.
resources in the managed pool exist in system memory and will be copied into the device's memory by the runtime when needed.
resource in the system memory pool exist only in system memory
resource in the scratch pool reside only in system memory and are not bound  by format constraints of the device
when a device is lost, all resources in the default pool are lost and should be released and recreated by the application when the device is regained.
Format attribute of a resource describes the layout of the resources's data in memory and is defined by the D3DFORMAT enumeration.

all resources have a format, but most of the format enumerants define the memory layout for pixel data.
D3DFMT_D24S8: D:depth buffer, S:stencil buffer.

Usage attribute describes how the application will be use the resource and is defined by a collection of flag bits. static reources are typically loaded with data once and used repeatedly without change, while dynamic resources are repeatedly modified bu the application.
a direct3D application starts by obtaining the IDirect3D9 COM interface pointer by calling Direct3DCreate9.
GetAdapterCount is to determine the number of adapters in the system. each adapter provides a number of video display modes. each display mode contains a screen dimention, refresh rate and pixel format and is described by D3DDISPLAYMODE structure.
the back buffer surface format of a device must be compatible with the display mode's format. CheckDeviceFormat method can be used to discover compatible formats.
GetAdapterModeCount: the number of display modes.
EnumAdapterModes: the display mode information.
GetAdapterDisplayMode: the display mode currently in use by the adapter.
two display modes can have the same width, height and format values but different values for the RefreshRates.
the CheckDeviceType method tells us if a particular combination of display format and back buffer format are valid for a device of a given type operating in windowed or exclusive mode.
with a valid device type, we can check the device's capabilities for rendering required by our application with GetDeviceCaps.

we can validate all the resources required by our application with the CheckDeviceFormat, checkDeviceFormat should be used to validate all the format of all resources used by the application: back buffer surfaces, depth/stencil surfaces, texture surfaces, and volume texture formats. if the application requires a depth buffer for viaiblitiy determination, it should use CheckDepthStencilMatch to find a depth buffer that can be used with its render target formats in a given display mode.
CheckDeviceMultiSampleType: check multisampling needs.
GetAdapterIdentifier: allows an application to identify a specific brand of adapter from a specific vendor.
D3DCREATE_ADAPTERGROUP_DEVICE: allows an application to drive both video outputs through a single device interface, allowing resources to be shaed for both outputs.
Direct3D uses single precision floating point computations. if an application requires higher precision from FPU.there are two choices, either the application can ensure that the FPU is in single precision mode when calling into Direct3D, or ir can request that the device preserve the application's FPU precision before Direct3D performs any floating -point operations and restore the precision before returning to the application.
D3DCREATE_SOFTWARE_VERTEXPROCESSING: select software vertex processing, which is always available from the runtime.the runtime used an efficient implementation of software vertex processing that is optimized for the CPU.
D3DCREATE_MIXED_VEVERTEXPROCESSING: select a combination of software and hardware vertex processing selected by SetSoftwareVertexProcessing mixed vertex processing is incompatible with a pure device and will fail if both are requested together.

D3DPRESENTFLAG_DEVICECLIP: restricts the results of a present operation to the client area of the device window in windowed mode.
D3DPRESENTFLAG_DISCARDDEPTHSTENCIL: instructs the runtime to discard the contents of the depth stencil surface after a call to Present, or when a new depth stencil surface is set on the device.
D3DPRESENTFLAG_LOCKABLEBACKBUFFER: requests a default swap chain with back buffer surfaces that can be directly accessed by the application.
in windowed mode: hDeviceWindow specifies the window whose client area will be used for presentation in windowed operation  if hDeviceWindow is zero, then the focus window willbe used for presentation.
in exclusive mode, hDeviceWindow specifies the top-level window used by the application

D3DPRESENT_RATE_DEFAULT: instructs the runtime to choose a suitable refresh rate in exclusive mode, and uses the current refresh rate in windowed mode.
an application may wish to create a full-screen display on a specific monitor.
GetAdapterMonitor: return an HMONITOR handle for an adapter, once you have the handle to the device 's montior, u can determine what part of the virtual desktop is covered by the monitor.

a scene is a collection of three dimensional objects that are projected onto the render target surface from the viewpoint of a syntheitic camera
each object in a scene is described by a collection of geometric primitives, such as points, lines, and triangles, with the device's action methods. 
the pipeline converts geometric descriptions into pixels on the render target surface through the process of rasterization. graphic primitives are rendered in the order in which they are described to the devices similar to the way a CPU executes binary instructions sequentially through memory.
the entire graphics pipeline is controlled through the properties of the device.
the properites are manipulated through the Get/Set methods of the device.
every device has a distinct set of capabilities. Direct3D specifies an abstract machine interface, but does not provide a software emulation for a feature not provided directly by the hardware's driver.
 a device provides specific information on its capabilities to allow an application to adapt to the capabilities of the device.
much of the behavior of the graphics pipeline is controlled by render states.
groups of device properties, including render states, can be cached and set as a group with state blocks.
the device object represents the rendering pipeline, we get images from the pipeline by supplying it with scene data and instructing it to render scenes into images.
scene data consists of geometric data defining shapes in space and data defining the appearance of the shapes.
we can break the pipeline up into large sections consisting of vertex data assembly, vertex processing, promitive assembly and rasterization, pixel processing, the frame buffer,a dn video scan out.

vertex data assembly section gathers together vertex components from a collection of data streams to assemble a compute vertex and its associated data.
vertex processing performs computations on each vertex such as the transformation and lighting of vertices.the processed vertex data is then assembled into graphic primitives and rasterized into a stream of pixels.
pixel processing performs a computations on each rasterized pixel to determine the final color of the pixel that will be written into the frame buffer.
frame buffer performs a read/modify/write operations combining processed pixels from the rasterizer with the existing pixels in the render ttarget.
video scan out reads the pixels out of the frame buffer for conversion into video signals displayed by the monitor.

scenes are rendered to the render target selected on the device. if the render target is part of a swap chain, the render target can be made viaible on the device through presentation.
the render target may not be part of a swap chain if the render target is a texture resource.
you present renderings for display through a swap chain as the last thing you do when rendering a scene.
a swap chain consists of one or more back color buffers into which images are rendered. a device is always associated with at least one swap chain and in windowed mode additional swap chains can be created to obtain multiple presentable surfaces.
the philosophy of the Direct3D object is to expose the capabilities of the hardware to the application programmer and let the application adapt to the hardware.
GetDeviceCaps: return the capabilities of an actual device, while GetDeviceCaps method on the Direct3D object returns the generic capabilities of a device.
IUnknown 
      IDirect3DVolume9
      IDirect3DResource9
           IDirect3DIndexBuffer9
           IDirect3DVertexBuffer9
           IDirect3DSurface9
           IDirect3DBaseTexture9
               IDirect3DTexture9
               IDirect3DCubeTexture9
               IDirect3DVolumeTexture9
resource objects are used as containers for the scene data rendered by the device such as primitive vertices, indices intto vertex arrays, surface textures and volumes. 
two and three dimensional textures expose their contents as collections of sutfaces and volumes, respectively. the back buffer, depth/stencil buffer and render target properties of the device are also exposed as surfaces.
volume objects do not inherit from IDirect3DResoutce9 and therefore do not participate in the resource management exposed by this interface.
managed resources are assigned an unsigned integer priority, with higher priority taking precedence so that resources with a lower priority are discarded from device memory first.
non-managed resources always return a priority of zero. within the same priority, Direct3D uses a least-recently used strategy to discard old resoucrs in preference to newly created resources.
when the application attempts to use more resources than the card can hold while rendering a scene, Direct3D switches to a most-recently used first strategy for discarding memory.
resources in D3DPOOL_DEFAULT are not managed and are never discarded from device memory by the resource manager.
if u need to allocate new resources in the default pool after managed resources have been loaded, you should evict all managed resources before allocating new resources in the default pool.
resources in pool D3DPOOL_SYSTEMMEM are never located in device memory, so that they do not participate in resource management.
GetAvailableTextureMem: obtain an estimate of the available texture memory.
the GetDevice method returns the device with which this resource is associated. resources cannot be shared across devices.
GetPrivateData/SetPrivateData: allow an application to associate its own arbitrary chunks of data with any Direct3D erouces.
each distinct item of private data is identified by a GUID. all private data associated with a resource is freed when the associated resource itself is freed.
methods and functions in Direct3D that create COM objects, such as CreateDevice, add a reference to the object for the caller before they return the interface pointer, the application must release these objects when they are no longer needed to avoid a memory leak.
Device queries allow you to obtain information from the driver layer of the device, the two main uses for driver queries are for obtaining rendering statistics and event notifications from the device.
D3DQUERYTYPE enumeration gives the possible kinds of queries: vertex cache description queries, resource manager statistics queries, vertex statistics queries, event queries, occlusion queries, timestamp queries, time queries and cache utilization queries.
a query exists in one of three state: signaled, building, or issued.
Issue: used by the application to signal a state transition on the query.
the device driver can also change the state of a query when it has returned the data requested by the query.
the query will report the results for primitives issued between the begining of the query and the end of the query.
occlusion queries return the number of pixels that passed the depth test for primitives rendered between the begin and end of the query.
the resource manager statistics query returns a D3DDEVINFO_RESOURCEMANAGER structure, which contains an array of D3DRESOURCESTATS structure, one for each resource type.
the vertex cache is a memory cache close to the GPU that avoids access to vertex memory for a small number of recently used vertices.
PIX: is a performance measurement tool for DirectX applications. the remaining query types return data for performance measurements with tools like PIX.
the device object's properties control the behavior of the rendering pipeline while its methods supply data for the pipeline to render.

state blocks are COM objects that provide a way for your application to cache a group of device properties for later use.
each state block is associated with a device, returned by the GetDevice method.once  a state block has been created, the state block can be applied to the device by calling apply on the state block, calling capture on an existing state block captures the current values of the device properties into the state block.
there are two ways to create a state block object and fill it with specific device property values.
the first way: call CreateStateBlock with D3DSTATEBLOCKTYPE value identifying the kind of state you  want recorded in the block.
the second way of obtaining a state block object is to call BeginStateBlock, set device properties and then call EndStateBlock.
when EndStateBlock is called, each device property marked for capture is recorded into the state block. if a device property is set multiple times between BeginStateBlock and EndStateBlock, only the last value set in the property is captureed into the state block.
release the state block COM object when you are finished with a state block.
a pure device has a performance advantage because the runtime and driver do not have to keep a copy of the non-queryable state for the application.
scenes contain one or more objects that are positioned relative to each other and to the virtual camera that views the scene. such objects are called "models", and contain data that define their shape and apperance. the shape of a model is described by a collection of a simple geometric shapes, called graphic primitives.
when we draw a three dimensional scene, we need to solve the problem of visibility: objects in the foreground should occlude objects in the background. Two- dimensional applications use a painter's algorithm to determine visibility. Direct3D can use depth/stencil surfaces to resolve visibility.

using either a flexible vertex format or a vertex shader declaration, Direct3D describes colors, textures corrdinates,vertex blending weights and arbitrary shader data at each vertex.the vertex data is supplied to the device through a collection of streams, each associated with a vertex buffer.
the streams can be driven through a level of indirection with an index buffer.the streams can be driven though a level of indirection with an index buffer.
the scene is described to the device one primitive at a time. each primitive  is rasterized into a collection of pixels written to the render target property of the device.
All Direct3D rendering is done within a scene. each successive frame draws the models at successive moments in time, as in cel animation used for cartoons.
frame rates of greater than 15 fps can be preceived as "real-time", the z-buffer algorithm solution to the visibility problem works at each pixels on the render target instead of on models, as models are rasterized, each pixel that is associated with z value is used to determine which pixel is cloest to the camera.the closer pixels are stored into the render target, while pixels farther away are discarded. the depth/stencil buffer holds each pixel's depth from the camera. to use the Z-buffer for resolving visibility, set RS_Z Enable to D3DZB_TRUE, RS_Z Write Enable to TRUE, and RS_Z Func to D3DCMP_LESS.

if the D3DPRASTERCAPS_ZBUFFERLESSHSR bit of D3DCAPS9:RasterCaps is set, it indicates the device has an alternative visivility algorithm for hidden surface removal that doesn't use a Z-buffer. how visibility is determined is hardware dependent and application transparent. 

all back buffers on swap chains are valid render targets, but render targets are not restricted to back buffer surfaces, when the device is created or reset, the render target is back buffer zero of the device's default swap chain. when present is called on the device, the render target  advances to the next back buffer so that after present returns, render target is back buffer zero again.

setting the render target to a surface other than a back buffer surface allows the device to render directly into an imanage surface instead of rendering into a swap chain's back buffer and using stretchrect to obtain the results of the rendering, which could stall the pipeline.

D3DPT_POINTLIST draws a collection of points,
D3DPT_LINELIST draws a squence of possibly disjoint line segments.
posted on 2009-02-17 15:49 jolley 阅读(658) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理