quick paramter help

Started by
13 comments, last by Njguy 15 years, 5 months ago
I am using the directx sdk samples and am a little confused by the 7th paramter. D3DXCreateEffectFromFile( g_engine->GetDevice(), str, NULL, NULL, g_dwShaderFlags, g_pEffectPool, &m_pMaterials.m_pEffect, NULL ); I don't quite understand this part. &m_pMaterials.m_pEffect Anyone have any ideas?
Advertisement
Each material in the material array pointed to by m_pMaterials has a pointer member to an ID3DXEffect. The call is passing the address of this member pointer to the Create function, which will modify the value of the pointer to point at the newly created effect.

What is effectively happening is that the CreateEffect call is "filling" one of the members of the elements of the array.

If you're having trouble with the actual syntax, I'd recommend reviewing some of the C++ syntax as it is quite basic.
Sirob Yes.» - status: Work-O-Rama.
Thanks for the info. My application stores the material array in this.

In my header file
Material **materials;

Would you know how I could replace the parameter so it would work here. I have tried unsuccessfully multiple times.
It looks like you are using an array of Material pointers. Why not use an array of Materials? (or an std::vector of them, for that matter.)

Anyway, as you have it now, it should be:

&materials->m_pEffect

If it was an array of Materials (and not pointers to them), it would be:

&materials.m_pEffect
Doesn't work errors say

error C2065: 'materials' : undeclared identifier
error C2227: left of '->m_pEffect' must point to class/struct/union/generic type
This is what I am using to load materials into an array

// Check if the mesh has any materials.
if( m_staticMesh->NumMaterials > 0 )
{
// Create the array of materials.
m_staticMesh->materials = new Material*[m_staticMesh->NumMaterials];

// Get the list of materials from the material buffer.
D3DXMATERIAL *materials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();

// Load each material into the array via the material manager.
for( unsigned long m = 0; m < m_staticMesh->NumMaterials; m++ )
Quote:Doesn't work errors say

error C2065: 'materials' : undeclared identifier
error C2227: left of '->m_pEffect' must point to class/struct/union/generic type


I assume that you are trying to do this inside the loop of the code snippet you posted, so we'll need to see that as well.

Also, earlier you said that you have a variable called 'materials' in a header file (is it a global variable?), and now you're creating a local variable with the same name...

In short, we need to see more code.
Ok this should be enough code hopefully. Its set up with an oop design, unlike the directx sample. This code is obviously unfinished as I am trying to merge the sdk sample with my application. Currently working on the materials. As you can see my application uses materials differently from the sdk. Blue coding equals code from the dx SDK. Black coding is from my application.

Header File (snippet)



//-----------------------------------------------------------------------------
// Mesh Container Structure
//-----------------------------------------------------------------------------
struct MeshContainer : public D3DXMESHCONTAINER
{
char **materialNames; // Temporary array of material (texture) names.
Material **materials; // Array of materials used by the mesh container.
ID3DXMesh *originalMesh; // Original mesh.
ID3DXEffect *m_pEffect;
D3DXATTRIBUTERANGE *attributeTable; // Mesh's attribute table.
unsigned long totalAttributeGroups; // Total number of attribute groups.
D3DXMATRIX **boneMatrixPointers; // Array of pointers to the bone transformation matrices.
};

//-----------------------------------------------------------------------------
// Mesh Class
//-----------------------------------------------------------------------------
class Mesh : public BoundingVolume, public Resource< Mesh >
{
public:
Mesh( char *name, char *path = "./" );
virtual ~Mesh();

void Update();
void Render();

void CloneAnimationController( ID3DXAnimationController **animationController );

MeshContainer *GetStaticMesh();
Vertex *GetVertices();
unsigned short *GetIndices();

LinkedList< Frame > *GetFrameList();
Frame *GetFrame( char *name );
Frame *GetReferencePoint( char *name );

private:
void PrepareFrame( Frame *frame );
void UpdateFrame( Frame *frame, D3DXMATRIX *parentTransformationMatrix = NULL );
void RenderFrame( Frame *frame );

private:
Frame *m_firstFrame; // First frame in the mesh's frame hierarchy.
ID3DXAnimationController *m_animationController; // Animation controller.

D3DXMATRIX *m_boneMatrices; // Array of bone transformation matrices.
unsigned long m_totalBoneMatrices; // Number of bones in the array.

MeshContainer *m_staticMesh; // A static (non-animated) version of the mesh.
Vertex *m_vertices; // Array of vertices from the static mesh.
unsigned short *m_indices; // Array of indices into the vertex array.

LinkedList< Frame > *m_frames; // Linked list of pointers to all the frames in the mesh.
LinkedList< Frame > *m_refPoints; // Linked list of pointers to all the reference points in the mesh.
};




CPP File(Snippet)



/ Check if the mesh has any materials.
if( m_staticMesh->NumMaterials > 0 )
{
// Create the array of materials.
m_staticMesh->materials = new Material*[m_staticMesh->NumMaterials];

// Get the list of materials from the material buffer.
D3DXMATERIAL *materials = (D3DXMATERIAL*)materialBuffer->GetBufferPointer();

// Load each material into the array via the material manager.
for( unsigned long m = 0; m < m_staticMesh->NumMaterials; m++ )
{
// Ensure the material has a texture.
if( materials[m].pTextureFilename )
{
// Get the name of the material's script and load it.
char *name = new char[strlen( materials[m].pTextureFilename ) + 5];
sprintf( name, "%s.txt", materials[m].pTextureFilename );
m_staticMesh->materials[m] = g_engine->GetMaterialManager()->Add( name, GetPath() );
SAFE_DELETE_ARRAY( name );
}
else
m_staticMesh->materials[m] = NULL;
}
}
//create effect
D3DXEFFECTINSTANCE *pEI = (D3DXEFFECTINSTANCE *)pEffectInstance->GetBufferPointer();
for( UINT i = 0; i < m_staticMesh->NumMaterials; ++i )
{
// Obtain the effect

hr = S_OK;
// Try the mesh's directory
StringCchCopyW( str, MAX_PATH, wszMeshPath );
MultiByteToWideChar( CP_ACP, 0, pEI.pEffectFilename, -1, str + lstrlenW( str ), MAX_PATH );

if( pEI.pEffectFilename == NULL )


hr = E_FAIL;

WCHAR wszFxName[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, pEI.pEffectFilename, -1, wszFxName, MAX_PATH );

if( SUCCEEDED( hr ) )
D3DXCreateEffectFromFile( g_engine->GetDevice(), str, NULL, NULL, g_dwShaderFlags, g_pEffectPool,
&materials->m_pEffect, NULL ); <-------------This is where I originally posted.
if( !m_pMaterials.m_pEffect )
{
// No valid effect for this material. Use the default.
m_pMaterials.m_pEffect = g_pEffect;
m_pMaterials.m_pEffect->AddRef();
}

// Set the technique this material should use
D3DXHANDLE hTech;
m_pMaterials.m_pEffect->FindNextValidTechnique( NULL, &hTech );
m_pMaterials.m_pEffect->SetTechnique( hTech );

// Create a parameter block to include all parameters for the effect.
m_pMaterials.m_pEffect->BeginParameterBlock();
for( UINT param = 0; param < pEI.NumDefaults; ++param )
{
D3DXHANDLE hHandle = m_pMaterials.m_pEffect->GetParameterByName( NULL, pEI.pDefaults[param].pParamName );
D3DXPARAMETER_DESC desc;
if( hHandle != NULL )
{
m_pMaterials.m_pEffect->GetParameterDesc( hHandle, &desc );
if( desc.Type == D3DXPT_BOOL ||
desc.Type == D3DXPT_INT ||
desc.Type == D3DXPT_FLOAT ||
desc.Type == D3DXPT_STRING )
{
m_pMaterials.m_pEffect->SetValue( pEI.pDefaults[param].pParamName,
pEI.pDefaults[param].pValue,
pEI.pDefaults[param].NumBytes );
}
}
}




[Edited by - Njguy on November 18, 2008 8:14:11 PM]
I'm confused.

First you said that 'materials' is of type Material**. In the second code snippet, you are creating a local variable with the same name, that is of type D3DXMATERIAL*. In the third code snippet, in the blue section, you use 'materials' as if it was an array of pointers. Actually in that code snippet, it looks like you wanted to use m_pMaterials instead.

So I'm not sure what's going on, perhaps you could clarify.
Basically if you look under the CPP section, in the black coding, I make an array of materials that I get out of the directx file(didn't show that part its above). I am trying to get the blue coding to use that array. Basically they are two different coding styles that im trying to merge and its throwing me off completely. The blue coding is trying to get the materials array, but my application's array is set up slightly differently. Thanks for the help you have given me so far by the way.

This topic is closed to new replies.

Advertisement