// -------------------------------------------------------------------------- // ========================================================================== // File: TD3DVertexElement.CPP // Authors: BCB_Code_Generator v2.00, // Darren Dwyer (source code, documentation, demos, website), // Hugh Edwards (documentation, icons) // Description: This file contains the code for the TD3DVertexElement // Component // // "TDx9_Graphics_Library v1.00" // (c) 2005 BCB-Tools.com Pty. Ltd., Sydney, Australia. // All Rights Reserved. // // Refer to the 'Licence.Txt' file for licencing & copyright information. // ========================================================================== // -------------------------------------------------------------------------- // #includes ... // -------------------------------------------------------------------------- #include #pragma hdrstop // -------------------------------------------------------------------------- #include "TD3DVertexElement.H" // -------------------------------------------------------------------------- #pragma link "TDx_Library_Defns" #pragma link "TDx_Library_Functions" #pragma link "TDx9_Graphics_Library_Defns" #pragma link "TDx9_Graphics_Library_Functions" // -------------------------------------------------------------------------- // Object Registration... // -------------------------------------------------------------------------- #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ #pragma package(smart_init) #endif // -------------------------------------------------------------------------- static inline void ValidCtrCheck(TD3DVertexElement*) { new TD3DVertexElement(NULL); } // -------------------------------------------------------------------------- namespace Td3dvertexelement { #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ void __fastcall PACKAGE Register() #else void __fastcall Register() #endif { TComponentClass classes[1] = {__classid(TD3DVertexElement)}; RegisterComponents("TDx9_Graphics", classes, 0); } } // -------------------------------------------------------------------------- // Constructor: TD3DVertexElement::TD3DVertexElement() // Description: The default constructor for the TD3DVertexElement object. // -------------------------------------------------------------------------- __fastcall TD3DVertexElement::TD3DVertexElement(TComponent* Owner) : TComponent(Owner) { fD3DVERTEXELEMENT9=NULL; fArraySize=0; ArraySize=1; ClearAll(); } // -------------------------------------------------------------------------- // Destructor: TD3DVertexElement::~TD3DVertexElement() // Description: The destructor for the TD3DVertexElement object. // -------------------------------------------------------------------------- __fastcall TD3DVertexElement::~TD3DVertexElement() { // destroy internals if (ArraySize!=0) ArraySize = 0; } // -------------------------------------------------------------------------- // Property: ArraySize // Description: The ArraySize property contains the number of internal // D3DVERTEXELEMENT9 structures wrapped inside the // TD3DVertexElement component. // By default the ArraySize is initialized to 1, meaning that // this TD3DVertexElement component wraps a single // D3DVERTEXELEMENT9 structure. To wrap multiple structures, set // the TD3DVertexElement::ArraySize to the total number of // internal structures desired. // -------------------------------------------------------------------------- dword __fastcall TD3DVertexElement::FGetArraySize() { return fArraySize; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetArraySize( dword pArraySize ) { // check for size==0 if (pArraySize==0) { // de-allocate old memory delete[] fD3DVERTEXELEMENT9; fD3DVERTEXELEMENT9 = NULL; fArraySize = 0; return; } // is anything allocated? if (fArraySize==0) { // nope. need to allocate memory for pointers to internal structures fD3DVERTEXELEMENT9 = new D3DVERTEXELEMENT9[pArraySize]; if (fD3DVERTEXELEMENT9==NULL) { fArraySize = 0; fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TD3DVERTEXELEMENT9::FSetArraySize()", "TDX_ERROR", "Could not allocate memory for storing internal D3DVERTEXELEMENT9 structure pointers."); return; } // setup defaults fArraySize = pArraySize; ClearAll(); } else // already allocated... has the size increased? if (pArraySize>fArraySize) { // allocate space for the new structures D3DVERTEXELEMENT9* temp_D3DVERTEXELEMENT9 = new D3DVERTEXELEMENT9[pArraySize]; if (temp_D3DVERTEXELEMENT9==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TD3DVERTEXELEMENT9::FSetArraySize()", "TDX_ERROR", "Could not allocate extra memory for storing internal D3DVERTEXELEMENT9 structures."); return; } // clear new data areas ZeroMemory( &temp_D3DVERTEXELEMENT9[fArraySize], sizeof(D3DVERTEXELEMENT9)*(pArraySize-fArraySize) ); // duplicate existing data CopyMemory( &temp_D3DVERTEXELEMENT9[0], &fD3DVERTEXELEMENT9[0], sizeof(D3DVERTEXELEMENT9)*fArraySize); // de-allocate old memory delete[] fD3DVERTEXELEMENT9; // re-assign the new memory fD3DVERTEXELEMENT9 = temp_D3DVERTEXELEMENT9; // store new array size fArraySize = pArraySize; } else // already allocated... has the size reduced? if (pArraySize=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetMethod()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return (byte) NULL; } return fD3DVERTEXELEMENT9[pArrayIndex].Method; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetMethod( dword pArrayIndex, byte pMethod ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetMethod()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetMethod()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } fD3DVERTEXELEMENT9[pArrayIndex].Method = pMethod; } // -------------------------------------------------------------------------- // Property: Offset // Description: The Offset property defines how far the particular data type // is offset from the start of the vertex data. // -------------------------------------------------------------------------- byte __fastcall TD3DVertexElement::FGetOffset( dword pArrayIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetOffset()", "TDX_ERROR", "Internal Array size is 0."); return (byte) NULL; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetOffset()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return (byte) NULL; } return fD3DVERTEXELEMENT9[pArrayIndex].Offset; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetOffset( dword pArrayIndex, byte pOffset ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetOffset()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetOffset()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } fD3DVERTEXELEMENT9[pArrayIndex].Offset = pOffset; } // -------------------------------------------------------------------------- // Property: Size // Description: The Size property contains the size in bytes of a single // internal D3DVERTEXELEMENT9 structure. // -------------------------------------------------------------------------- dword __fastcall TD3DVertexElement::FGetSize() { return fSize; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetSize( dword pSize ) { fSize = pSize; } // -------------------------------------------------------------------------- // Property: SizeAll // Description: The SizeAll property contains the size in bytes of all // internal D3DVERTEXELEMENT9 structures. This result is the // same as multiplying TD3DVertexElement::ArraySize and // TD3DVertexElement::Size. // -------------------------------------------------------------------------- dword __fastcall TD3DVertexElement::FGetSizeAll() { return fArraySize * fSize; } // -------------------------------------------------------------------------- // Property: Stream // Description: The Stream property defines the stream number of this // element. // -------------------------------------------------------------------------- byte __fastcall TD3DVertexElement::FGetStream( dword pArrayIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetStream()", "TDX_ERROR", "Internal Array size is 0."); return (byte) NULL; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetStream()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return (byte) NULL; } return fD3DVERTEXELEMENT9[pArrayIndex].Stream; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetStream( dword pArrayIndex, byte pStream ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetStream()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetStream()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } fD3DVERTEXELEMENT9[pArrayIndex].Stream = pStream; } // -------------------------------------------------------------------------- // Property: Type // Description: The Type property holds a member of the D3DDECLTYPE // enumerated type specifying the data size/type for this // element. // Some values of the Method property have an implied type. // -------------------------------------------------------------------------- byte __fastcall TD3DVertexElement::FGetType( dword pArrayIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetType()", "TDX_ERROR", "Internal Array size is 0."); return (byte) NULL; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetType()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return (byte) NULL; } return fD3DVERTEXELEMENT9[pArrayIndex].Type; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetType( dword pArrayIndex, byte pType ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetType()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetType()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } fD3DVERTEXELEMENT9[pArrayIndex].Type = pType; } // -------------------------------------------------------------------------- // Property: Usage // Description: The Usage property holds member(s) of the D3DDECLUSAGE // enumerated type specifying what uses the data will be put to. // // This property determines the interoperability between vertex // data layouts and the vertex shaders. Thus, each usage acts to // bind a declaration to a vertex shader. // The D3DDECLUSAGE_TEXCOORD setting can be used for user // defined fields which don't have an existing usage defined. // -------------------------------------------------------------------------- byte __fastcall TD3DVertexElement::FGetUsage( dword pArrayIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetUsage()", "TDX_ERROR", "Internal Array size is 0."); return (byte) NULL; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetUsage()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return (byte) NULL; } return fD3DVERTEXELEMENT9[pArrayIndex].Usage; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetUsage( dword pArrayIndex, byte pUsage ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetUsage()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetUsage()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } fD3DVERTEXELEMENT9[pArrayIndex].Usage = pUsage; } // -------------------------------------------------------------------------- // Property: UsageIndex // Description: The UsageIndex property modifies Usage data so multiple usage // types can be specified. // -------------------------------------------------------------------------- byte __fastcall TD3DVertexElement::FGetUsageIndex( dword pArrayIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetUsageIndex()", "TDX_ERROR", "Internal Array size is 0."); return (byte) NULL; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FGetUsageIndex()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return (byte) NULL; } return fD3DVERTEXELEMENT9[pArrayIndex].UsageIndex; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetUsageIndex( dword pArrayIndex, byte pUsageIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetUsageIndex()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::FSetUsageIndex()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } fD3DVERTEXELEMENT9[pArrayIndex].UsageIndex = pUsageIndex; } // -------------------------------------------------------------------------- // Method: Clear() // Description: The Clear() method can be used to clear the contents of the // TD3DVertexElement's internal D3DVERTEXELEMENT9 structure. // Note: if you have manually linked a structure member to a // chunk of memory, make sure you release this memory before // calling Clear(). // Params: pArrayIndex - // The ArrayIndex parameter determines which internal structure // needs to be cleared. Correct values range from 0 to // TD3DVertexElement::ArraySize-1. // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::Clear( dword pArrayIndex ) { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::Clear()", "TDX_ERROR", "Internal Array size is 0."); return; } // range check supplied index if (pArrayIndex>=fArraySize) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::Clear()", "TDX_ERROR", "Supplied index ["+IntToStr(pArrayIndex)+"] is out of bounds [0.."+IntToStr(fArraySize-1)+"]"); return; } ZeroMemory( &fD3DVERTEXELEMENT9[pArrayIndex], sizeof(D3DVERTEXELEMENT9) ); } // -------------------------------------------------------------------------- // Method: ClearAll() // Description: The ClearAll() method can be used to clear the contents of // all the internal D3DVERTEXELEMENT9 structures of the // TD3DVertexElement component. // Note: if you have manually linked a structure member to a // chunk of memory, make sure you release this memory before // calling Clear(). // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::ClearAll() { // array is allocated? if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError( this, "TD3DVertexElement::Clear()", "TDX_ERROR", "Internal Array size is 0."); return; } ZeroMemory( &fD3DVERTEXELEMENT9[0], sizeof(D3DVERTEXELEMENT9)*fArraySize ); } // -------------------------------------------------------------------------- // Internal Structure Access // -------------------------------------------------------------------------- D3DVERTEXELEMENT9* __fastcall TD3DVertexElement::FGetInternal_D3DVERTEXELEMENT9_Ptr() { // check for errors if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TD3DVertexElement::FGetInternal_D3DVERTEXELEMENT9_Ptr()", "TDX_ERROR", "Internal Array size is 0." ); return NULL; } return fD3DVERTEXELEMENT9; } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::FSetInternal_D3DVERTEXELEMENT9( dword pArrayIndex, D3DVERTEXELEMENT9* pD3DVERTEXELEMENT9 ) { // check for errors if (fArraySize==0) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TD3DVertexElement::FSetInternal_D3DVERTEXELEMENT9()", "TDX_ERROR", "Internal Array size is 0." ); return; } if (pD3DVERTEXELEMENT9==NULL) { fErrorValue = TDX_ERROR; if (FOnError) FOnError(this, "TD3DVertexElement::FSetInternal_D3DVERTEXELEMENT9()", "TDX_ERROR", "The supplied D3DVERTEXELEMENT9* was NULL" ); return; } CopyMemory( &fD3DVERTEXELEMENT9[pArrayIndex], pD3DVERTEXELEMENT9, sizeof(D3DVERTEXELEMENT9) ); Internal_D3DVERTEXELEMENT9_Update(); } // -------------------------------------------------------------------------- void __fastcall TD3DVertexElement::Internal_D3DVERTEXELEMENT9_Update() { } // --------------------------------------------------------------------------