Functions
Using the Pixel Shader

Functions

HRESULT D3DConfigureShaderFilter (CVD3DSHADER d3dShader, DWORD dwWidth, DWORD dwHeight)
 The function configures a shader that executes a filter operation.
 
HRESULT D3DCreateShaderFromFile (CVD3D d3d, const char *pFileName, const char *pFunctionName, BOOL bDisplayErrorMessage, TShaderVersion shaderVersion, CVD3DSHADER &d3dShader)
 Creates a shader from a HLSL file.
 
HRESULT D3DCreateShaderFromString (CVD3D d3d, const char *pShader, const char *pFunctionName, BOOL bDisplayErrorMessage, TShaderVersion shaderVersion, CVD3DSHADER &d3dShader)
 Creates a shader from a HLSL string.
 
HRESULT D3DCreateTexture (CVD3D d3d, DWORD dwWidth, DWORD dwHeight, TColorFormat tcf, CVD3DOBJECT &d3dObject)
 Creates a texture render target.
 
HRESULT D3DCreateTextureEntrance (CVD3D d3d, DWORD dwWidth, DWORD dwHeight, TColorFormat tcf, CVD3DOBJECT &d3dObject)
 Creates a source texture.
 
HRESULT D3DGetFloat (CVD3DSHADER d3dShader, const char *VarName, float &VarValue)
 The function reads the value of a global float variable in the given shader.
 
HRESULT D3DGetInfo (CVD3D d3d, DWORD &dwWidth, DWORD &dwHeight, HWND &hWnd)
 Returns information about the given CVD3D object.
 
HRESULT D3DGetObjectInfo (CVD3DOBJECT d3dObject, DWORD &dwWidth, DWORD &dwHeight, TColorFormat &tcf)
 This function returns information about the given CVD3DOBJECT object.
 
HRESULT D3DGetShaderConstantInfo (CVD3DSHADER d3dShader, DWORD dwIndex, TConstantInfo &ConstantInfo)
 The function returns information about variables and constants used in the given shader function.
 
HRESULT D3DGetShaderFunctionName (CVD3DSHADER d3dShader, char *FuncName, size_t &Length)
 This function returns the name of the function used by the given shader program.
 
BOOL D3DIsRenderSource (CVD3DOBJECT d3dObject)
 This function checks if the given object can be used as a source for render operations or not.
 
BOOL D3DIsRenderTarget (CVD3DOBJECT d3dObject)
 This function checks if the given object can be used as a target for render operations or not.
 
BOOL D3DIsShader (OBJ d3dShader)
 This function checks if the given handle points to a CVD3DSHADER type or not.
 
HRESULT D3DRender (CVD3DOBJECT d3dObjectSource, CVD3DOBJECT d3dObjectTarget, CVD3DSHADER d3dShader)
 This function renders a given source texture to a given destination texture using the given shader.
 
HRESULT D3DSetFloat (CVD3DSHADER d3dShader, const char *VarName, float VarValue)
 The function writes the value of a global float variable in the given shader.
 
HRESULT D3DSetTextureIndex (CVD3DSHADER d3dShader, CVD3DOBJECT d3dObject, DWORD dwIndex)
 This function is used to set the texture index of a given CVD3DOBJECT for the given shader program.
 

Detailed Description

Function Documentation

HRESULT D3DConfigureShaderFilter ( CVD3DSHADER  d3dShader,
DWORD  dwWidth,
DWORD  dwHeight 
)

The function configures a shader that executes a filter operation.

During the execution the pixel shader has to access pixels in a neighbourhood of the current pixel. These pixels' addresses are constant offsets which normally have to be calculated for each and every pixel. For performance reasons it may make sense to pre-calculate these offsets which is the purpose of the D3DConfigureShaderFilter function. The function estimates the size of the filter kernel based on the name of the pixel shader function. If the shader function name is e.g., MyFilter5x5 then the function assumes a kernel size of 5 and it will pre-calculate the offset to the individual kernel elements for a 2x5x5 (x and y coordinates * kernel size) floating point array. Instead of calculating the pixel addresses in the shader program you can use the pre-calculated array.

Parameters
[in]d3dShaderThe shader object to be initialised.
[in]dwWidthThe width of the image to be filtered.
[in]dwHeightThe height of the image to be filtered.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromFile
D3DCreateShaderFromString
D3DIsShader
D3DSetFloat
D3DRender
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DCreateShaderFromFile ( CVD3D  d3d,
const char *  pFileName,
const char *  pFunctionName,
BOOL  bDisplayErrorMessage,
TShaderVersion  shaderVersion,
CVD3DSHADER d3dShader 
)

Creates a shader from a HLSL file.

A HLSL file is a simple text file containing one or more shader functions. The default extension of a shader file is *.FX. The shader file might be stored encrypted in an encrypted form using a CVB serial number. To encrypt a shader file use the Shader Protection tool installed in the CVB%/Applications directory. The file extension of an encrypted shader file is *.FXENC.

The shader program will be compiled at load time.

Attention
Reference counting is implemented using the ShareObject and ReleaseObject functions of the Image Manager. To finally free the object use ReleaseObject.
Parameters
[in]d3dThe D3D context.
[in]pFileNameThe filename to the HLSL shader file.
[in]pFunctionNameThe name of the HLSL function to be loaded.
[in]bDisplayErrorMessageFlag to control compiler messages to be displayed or not.
If TRUE a MessageBox will be shown on any HLSL compiler errors showing the compiler error message, FALSE otherwise.
[in]shaderVersionThe version of the shader used to compile the file. See TShaderVersion for supported shader versions.
[out]d3dShaderHandle to the newly created CVD3DSHADER object.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromString
D3DCreate
D3DRender
D3DIsShader
D3DSetFloat
D3DConfigureShaderFilter
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DCreateShaderFromString ( CVD3D  d3d,
const char *  pShader,
const char *  pFunctionName,
BOOL  bDisplayErrorMessage,
TShaderVersion  shaderVersion,
CVD3DSHADER d3dShader 
)

Creates a shader from a HLSL string.

A HLSL string is a simple memory file containing one or more shader functions.

The shader program will be compiled at load time.

Attention
Reference counting is implemented using the ShareObject and ReleaseObject functions of the Image Manager. To finally free the object use ReleaseObject.
Parameters
[in]d3dThe D3D context.
[in]pShaderThe shader code as a string.
[in]pFunctionNameThe name of the HLSL function to be loaded.
[in]bDisplayErrorMessageFlag to control compiler messages to be displayed or not.
If TRUE a MessageBox will be shown on any HLSL compiler errors showing the compiler error message
[in]shaderVersionThe version of the shader used to compile the file. See TShaderVersion for supported shader versions.
[out]d3dShaderHandle to the newly created CVD3DSHADER object.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromFile
D3DCreate
D3DRender
D3DIsShader
D3DSetFloat
D3DConfigureShaderFilter
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DCreateTexture ( CVD3D  d3d,
DWORD  dwWidth,
DWORD  dwHeight,
TColorFormat  tcf,
CVD3DOBJECT d3dObject 
)

Creates a texture render target.

The object can be used to render another object to itself. It can also be used as a source for rendering operations. To transfer the image back to the host call D3DUpdate after rendering.

Attention
Reference counting is implemented using the ShareObject and ReleaseObject functions of the Image Manager. To finally free the object use ReleaseObject.
Parameters
[in]d3dThe D3D context.
[in]dwWidthThe width of the image (has to be less or equal to the maximum width of the D3D context).
[in]dwHeightThe height of the image (has to be less or equal to the maximum height of the D3D context).
[in]tcfThe colour format of the image. See TColorFormat for possible values.
[out]d3dObjectHandle to the newly created CVD3DOBJECT object.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DGetObjectInfo
D3DCreate
D3DCreateTextureEntrance
D3DCreateSurfaceEntrance
D3DCreateSurface
D3DCreateMirror
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DCreateTextureEntrance ( CVD3D  d3d,
DWORD  dwWidth,
DWORD  dwHeight,
TColorFormat  tcf,
CVD3DOBJECT d3dObject 
)

Creates a source texture.

Typically you will write a host image to this texture using D3DWriteImageToObject and use it as a source for render operations.

Attention
Reference counting is implemented using the ShareObject and ReleaseObject functions of the Image Manager. To finally free the object use ReleaseObject.
Parameters
[in]d3dThe D3D context.
[in]dwWidthThe width of the image (has to be less or equal to the maximum width of the D3D context).
[in]dwHeightThe height of the image (has to be less or equal to the maximum height of the D3D context).//The height of the surface
[in]tcfThe colour format of the image. See TColorFormat for possible values.
[out]d3dObjectHandle to the newly created CVD3DOBJECT object.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DGetObjectInfo
D3DCreate
D3DCreateTexture
D3DCreateSurfaceEntrance
D3DCreateSurface
D3DCreateMirror
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DGetFloat ( CVD3DSHADER  d3dShader,
const char *  VarName,
float &  VarValue 
)

The function reads the value of a global float variable in the given shader.

Variables can't be read back to the host so the function always caches the values when D3DSetFloat is called. If you need to physically access a variable used in a shader program by the host application you can write the value of the variable to a pixel in the image (e.g., the last or the first pixel).

Parameters
[in]d3dShaderThe shader object.
[in]VarNameThe name of the variable to be read within the shader.
[out]VarValueThe value assigned in the last call to D3DSetFloat.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DSetFloat
D3DCreateShaderFromFile
D3DCreateShaderFromString
D3DIsShader
D3DConfigureShaderFilter
D3DRender
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DGetInfo ( CVD3D  d3d,
DWORD &  dwWidth,
DWORD &  dwHeight,
HWND &  hWnd 
)

Returns information about the given CVD3D object.

Parameters
[in]d3dThe CVD3D object.
[out]dwWidthMaximum width of an image that can be created.
[out]dwHeightMaximum height of an image that can be created.
[out]hWndThe window handle associated with the object.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
Glossary
D3DCreate
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DGetObjectInfo ( CVD3DOBJECT  d3dObject,
DWORD &  dwWidth,
DWORD &  dwHeight,
TColorFormat tcf 
)

This function returns information about the given CVD3DOBJECT object.

Parameters
[in]d3dObjectThe CVD3DOBJECT object.
[out]dwWidthThe width of the image.
[out]dwHeightThe height of the image.
[out]tcfThe colour format of the image. See TColorFormat for possible values.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreate
D3DCreateTextureEntrance
D3DCreateTexture
D3DCreateSurfaceEntrance
D3DCreateSurface
D3DCreateMirror
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DGetShaderConstantInfo ( CVD3DSHADER  d3dShader,
DWORD  dwIndex,
TConstantInfo ConstantInfo 
)

The function returns information about variables and constants used in the given shader function.

The variables and constants are accessed using a zero based index. To enumerate available variables/constants call this function with increasing values for dwIndex until it returns with an error code, meaning any value different to 0.

Parameters
[in]d3dShaderThe shader object to be initialised.
[in]dwIndexZero based index of the variable/constant list of the shader program.
[out]ConstantInfoInformation about the variable/constant. See TConstantInfo of its structure.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromFile
D3DCreateShaderFromString
TConstantInfo
TConstantType
TConstantClass
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DGetShaderFunctionName ( CVD3DSHADER  d3dShader,
char *  FuncName,
size_t &  Length 
)

This function returns the name of the function used by the given shader program.

The retrieve the required length of the string to hold the function name pass NULL as FuncName to the function. In this case Length is filled with the required length.

Parameters
[in]d3dShaderThe shader object.
[out]FuncNameA pointer to a string allocated by the caller to be filled with the name of the shader function. The buffer must be long enough to hold the function name. A length of 128 byte may be used as a reasonable default.
[out]LengthThe length of the string returned when NULL being passed as FuncName.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromFile
D3DIsShader
Glossary
Sample Code in Visual C++:
...
char pFunctionName[128];
D3DGetShaderFunctionName (d3dShader, pFunctionName);
...
BOOL D3DIsRenderSource ( CVD3DOBJECT  d3dObject)

This function checks if the given object can be used as a source for render operations or not.

Parameters
[in]d3dObjectHandle to the object to be processed.
Returns
If TRUE it can be used as a render source, FALSE otherwise.
Supported platforms:
Win32
Win64
Related Topics:
Glossary
D3DCreateTextureEntrance
D3DCreateTexture
D3DCreateSurfaceEntrance
D3DCreateSurface
D3DRender
D3DRenderText
D3DIsRenderTarget
D3DIsBltSource
D3DIsBltTarget
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
BOOL D3DIsRenderTarget ( CVD3DOBJECT  d3dObject)

This function checks if the given object can be used as a target for render operations or not.

Parameters
[in]d3dObjectHandle to the object to be processed.
Returns
If TRUE it can be used as a render target, FALSE otherwise.
Supported platforms:
Win32
Win64
Related Topics:
Glossary
D3DCreateTextureEntrance
D3DCreateTexture
D3DCreateSurfaceEntrance
D3DCreateSurface
D3DRender
D3DRenderText
D3DIsRenderSource
D3DIsBltSource
D3DIsBltTarget
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
BOOL D3DIsShader ( OBJ  d3dShader)

This function checks if the given handle points to a CVD3DSHADER type or not.

Parameters
[in]d3dShaderHandle to the object to be processed.
Returns
TRUE if it's a CVD3DSHADER object, FALSE otherwise.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromFile
D3DCreateShaderFromString
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DRender ( CVD3DOBJECT  d3dObjectSource,
CVD3DOBJECT  d3dObjectTarget,
CVD3DSHADER  d3dShader 
)

This function renders a given source texture to a given destination texture using the given shader.

The image will be stretched during rendering if the image sizes don't match. The function is executed in parallel to the host application and it will return immediately.

To fill the source texture with the image data use D3DWriteImageToObject. To transfer the target image back to the host call D3DUpdate. D3DUpdate will wait for the rendering to be finished before it returns.

Attention
As rendering is done by the graphics driver the capability to render from a defined source to a defined target varies from driver to driver. The following table lists the capabilities of a GeForce 9800 graphics card:

XRGB TargetsXRGB Source
 SurfaceEntranceSurfaceTextureEntranceTexture
Render to Backbuffernot applicablenot applicableokok
Render to Surfacenot applicablenot applicableokok
Render to Texturenot applicablenot applicableokok
Parameters
[in]d3dObjectSourceThe source texture.
[in]d3dObjectTargetThe destination texture.
[in]d3dShaderThe shader to be used or NULL to bypass the pixel shader.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
Glossary
D3DRenderText
D3DCreateTextureEntrance
D3DCreateTexture
D3DIsRenderSource
D3DIsRenderTarget
D3DCreateShaderFromFile
D3DCreateShaderFromString
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DSetFloat ( CVD3DSHADER  d3dShader,
const char *  VarName,
float  VarValue 
)

The function writes the value of a global float variable in the given shader.

Cached variables can be read back using D3DGetFloat after calling this function. If you need to physically access a variable used in a shader program by the host application you can write the value of the variable to a pixel in the image (e.g., the last or the first pixel).

Parameters
[in]d3dShaderThe shader object.
[in]VarNameThe name of the variable within the shader.
[in]VarValueThe new value to be assigned.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Supported platforms:
Win32
Win64
Related Topics:
D3DGetFloat
D3DCreateShaderFromFile
D3DCreateShaderFromString
D3DIsShader
D3DConfigureShaderFilter
D3DRender
Examples:
Delphi - Delphi BayerToRGB Example
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo
HRESULT D3DSetTextureIndex ( CVD3DSHADER  d3dShader,
CVD3DOBJECT  d3dObject,
DWORD  dwIndex 
)

This function is used to set the texture index of a given CVD3DOBJECT for the given shader program.

You can use up to 16 textures in one pixel shader program. To identify a texture in your pixel shader program set the index of the texture. Afterwards you can access the texture via a sampler type in your shader program such as sampler texture0 : register(s0); sampler texture1 : register(s1);. Refer to A First Shader Program for more information.

Parameters
[in]d3dShaderThe shader object.
[in]d3dObjectThe texture object.
[in]dwIndexThe index to be used for the texture in this shader program.
Returns
0 if no error occurred, otherwise a value != 0 indicates the error code.
Remarks
Use this function if your shader processes multiple textures.
Supported platforms:
Win32
Win64
Related Topics:
D3DCreateShaderFromFile
D3DCreateShaderFromString
D3DIsShader
D3DConfigureShaderFilter
D3DSetFloat
D3DRender
Glossary
Examples:
Visual Basic .Net - VB.NET GPU Example
Visual C++ - VC GPU Demo