Thread: DirectX10 friendly vertex declarations

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001

    DirectX10 friendly vertex declarations

    Yes it's time to get rid of the flexible vertex format flags in D3D. They won't be supported in DX10 so if you code for it now, you will hate yourself later.

    It also may be a wise idea to move away from D3DMATERIAL9, D3DLIGHT9 and other fixed function functionality like SetTextureStageState(), SetFVF(), and other functions that utilize the fixed function pipeline.

    Here are my newest vertex formats. This is similar to what I read in my new book about DirectX by Frank Luna. I just took what he had and expanded it a bit to suit my own needs.

    These vertex declarations can be used later in vertex and pixel shaders.

    #include "d3d9.h"
    struct VertexPNT1
      D3DXVECTOR3 vecPos;
      D3DXVECTOR3 vecNormal;
      D3DXVECTOR2 tex0;
                   tex0(0.0f,0.0f) { }
      VertexPNT1(float x,float y,float z,float u,float v):
                 tex0(u,v) { }
      static IDirect3DVertexDeclaration9 *pDecl;  
    struct VertexTLT1
      D3DXVECTOR3 vecPos;
      float rhw;
      D3DXVECTOR2 tex;
      VertexTLT1():vecPos(0.0f,0.0f,0.0f),rhw(0.0f),tex(0.0f,0.0f) { }
      VertexTLT1(float x,float y,float z,float u,float v):
                 vecPos(x,y,z),rhw(1.0f),tex(u,v) { }
      static IDirect3DVertexDeclaration9 *pDecl;  
    struct VertexBBT1
      D3DXVECTOR3 vecPos;
      D3DCOLOR    dwDiffuse;
      D3DCOLOR    dwSpecular;
      D3DXVECTOR2 tex;
                   tex(0.0f,0.0f) { }
      VertexBBT1(float x,float y,float z,float u,float v,D3DCOLOR dwDiffuse=0xFFFFFFFF,
                 D3DCOLOR dwSpecular=0xFFFFFFFF):
                 tex(u,v) { }
      static IDirect3DVertexDeclaration9 *pDecl;  
    void CreateVertexDecls(IDirect3DDevice9 *pDevice);
    void DestroyVertexDecls();
    #include "VertexTypes.h"
    #include "dxutil.h"
    IDirect3DVertexDeclaration9 *VertexPNT1::pDecl=NULL;
    IDirect3DVertexDeclaration9 *VertexTLT1::pDecl=NULL;
    IDirect3DVertexDeclaration9 *VertexBBT1::pDecl=NULL;
    void CreateVertexDecls(IDirect3DDevice9 *pDevice)
      D3DVERTEXELEMENT9 VertexPNT1_Elements[] =
      D3DVERTEXELEMENT9 VertexTLT1_Elements[] =
      D3DVERTEXELEMENT9 VertexBBT1_Elements[]=
    void DestroyVertexDecls()
    Also all objects now have Shader ID's as well as Texture ID's and my own material ID's. The material is passed onto the shader as a series of constants, the textures are grabbed from the texture manager using the ID's, and the actual ID3DXEffect that encapsulates the shader is grabbed and ran from the effect manager.

    Once I get through this transition I hope to have some screenshots of the new system in action as well as some post-processing shaders I'm anxious to try out.

    Many of you ask how hard is it to make a game like this. Well we are not even to the game yet and here is a list of the source files.

    CBillBoard.cpp CBillBoard.h CCamera.cpp CCamera.h CD3DApp.cpp CD3DApp.h CD3DXMesh.cpp CD3DXMesh.h
    CDXAudio.cpp CDXAudio.h CDXInput.cpp CDXInput.h CDXShowWnd.cpp CDXShowWnd.h CEngineException.h
    CFileLog.h CGameObject.cpp CGameObject.h CHUDGauge.h CHUDPipper.cpp CHUDPipper.h CHUDSpeedGauge.cpp
    CHUDSpeedGauge.h CHUDSys.cpp CHUDSys.h CKeyBinder.h CKeyboard.cpp CKeyboard.h CMouse.cpp CMouse.h
    CObjectMgr.h common.h COrient3D.cpp COrient3D.h CParticleObject.h CPixelShader.h CPlanet.cpp CPlanet.h
    CResMgr.h CResource.h CShaderMgr.h CShaderRes.h CShip.cpp CShip.h CShipEngine.h CShipMgr.cpp CShipMgr.h
    CShipSystem.h CSkyBox.cpp CSkyBox.h CStars.cpp CStars.h CStarXApp.cpp CStarXApp.h CSun.cpp CSun.h
    CTexMgr.h CTexture.h CTimer.h CVertexShader.cpp CVertexShader.h CWeapon.h GameControls.h Glare.fx
    ScriptCmn.h StarXMain.cpp VertexTypes.cpp VertexTypes.h
    Last edited by VirtualAce; 11-26-2006 at 06:47 AM.

  2. #2
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Except how likely is it game developers will switch to using just DirectX 10? Remember how long it took Windows XP to catch on? I'm sure most companies for a while will be doing both so as to get the most sales. Have fun keeping up with both.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple (?) problem rendering a vertex buffer
    By Dark_Phoenix in forum Game Programming
    Replies: 4
    Last Post: 08-11-2007, 07:32 PM
  2. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 07:55 PM
  3. Vertex buffer hell
    By cboard_member in forum Game Programming
    Replies: 2
    Last Post: 12-03-2006, 06:07 AM
  4. DX9 visualization problem
    By darcome in forum Game Programming
    Replies: 4
    Last Post: 03-05-2003, 12:40 PM
  5. Pixel Shaders.
    By Cheeze-It in forum Game Programming
    Replies: 1
    Last Post: 05-21-2002, 01:16 AM