Exemplo n.º 1
0
bool cDirectX9HLShader::getShaderConstHandle( bool bVs, const s8 *sVarName, h32 &out )
{
	ID3DXConstantTable* pkTable = bVs ? mpkVsTable : mpkPsTable;
		/* check top level params */
	out = (h32)pkTable->GetConstantByName(0,sVarName);
	if( XISVALIDHANDLE(out) )
		return true;
	return false;
}
Exemplo n.º 2
0
BOOL RenderMultiTex::Init(UINT width, UINT height, HWND hwnd, BOOL windowed, D3DDEVTYPE devType) {
    HRESULT hr = Render::Init(width, height, hwnd, windowed, devType);
    SGL_FAILED_DO(hr, MYTRACE_DX("Render::Init", hr); return FALSE);

    // Create geometry.

    IDirect3DVertexBuffer9* vb;
    m_D3DDev->CreateVertexBuffer(6 * sizeof(MultiTexVertex), D3DUSAGE_WRITEONLY, MultiTexVertex::FVF, D3DPOOL_MANAGED, &vb, NULL);
    m_QuadVB.Attach(vb);

    MultiTexVertex* v = NULL;
    vb->Lock(0, 0, (void**) &v, 0);

    v[0] = MultiTexVertex(-10.0f, -10.0f, 5.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
    v[1] = MultiTexVertex(-10.0f,  10.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
    v[2] = MultiTexVertex( 10.0f,  10.0f, 5.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

    v[3] = MultiTexVertex(-10.0f, -10.0f, 5.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
    v[4] = MultiTexVertex( 10.0f,  10.0f, 5.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
    v[5] = MultiTexVertex( 10.0f, -10.0f, 5.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);

    vb->Unlock();

    // Compile shader
    ID3DXBuffer* shaderBuf = NULL;
    ID3DXBuffer* errBuf = NULL;

    ID3DXConstantTable* constTbl;
    hr = D3DXCompileShaderFromFile(MultiTexPSFile, NULL, NULL, "Main", "ps_1_1", D3DXSHADER_DEBUG | D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, &shaderBuf, &errBuf, &constTbl);
    // output any error messages
    if (errBuf != NULL) {
        MYTRACEA("D3DXCompileShaderFromFile failed: %s", (char*) errBuf->GetBufferPointer());
        SGL::Release(errBuf);
    }
    SGL_FAILED_DO(hr, MYTRACE_DX("D3DXCompileShaderFromFile", hr); return FALSE);
    m_MultiTexCT.Attach(constTbl);

    // Create Pixel Shader
    IDirect3DPixelShader9* shader;
    hr = m_D3DDev->CreatePixelShader((DWORD*) shaderBuf->GetBufferPointer(), &shader);
    SGL_FAILED_DO(hr, MYTRACE_DX("CreatePixelShader", hr); return FALSE);
    m_MultiTexPS.Attach(shader);

    SGL::Release(shaderBuf);

    // Load textures.

    IDirect3DTexture9* tex;
    D3DXCreateTextureFromFile(m_D3DDev, BaseTexFile, &tex);
    SGL_FAILED_DO(hr, MYTRACE_DX("D3DXCreateTextureFromFile", hr); return FALSE);
    m_BaseTex.Attach(tex);

    D3DXCreateTextureFromFile(m_D3DDev, SpotLightTexFile, &tex);
    SGL_FAILED_DO(hr, MYTRACE_DX("D3DXCreateTextureFromFile", hr); return FALSE);
    m_SpotLightTex.Attach(tex);

    D3DXCreateTextureFromFile(m_D3DDev, StringTexFile, &tex);
    SGL_FAILED_DO(hr, MYTRACE_DX("D3DXCreateTextureFromFile", hr); return FALSE);
    m_StringTex.Attach(tex);

    // Set Projection Matrix
    D3DXMATRIX P;
    D3DXMatrixPerspectiveFovLH(&P, D3DX_PI * 0.25f, (float) width / (float) height, 1.0f, 1000.0f);
    m_D3DDev->SetTransform(D3DTS_PROJECTION, &P);

    // Disable lighting.
    m_D3DDev->SetRenderState(D3DRS_LIGHTING, FALSE);

    // Get Handles
    m_BaseTexHandle      = constTbl->GetConstantByName(NULL, "BaseTex");
    m_SpotLightTexHandle = constTbl->GetConstantByName(NULL, "SpotLightTex");
    m_StringTexHandle    = constTbl->GetConstantByName(NULL, "StringTex");

    // Set constant descriptions:
    UINT count;
    constTbl->GetConstantDesc(m_BaseTexHandle, &m_BaseTexDesc, &count);
    constTbl->GetConstantDesc(m_SpotLightTexHandle, &m_SpotLightTexDesc, &count);
    constTbl->GetConstantDesc(m_StringTexHandle, &m_StringTexDesc, &count);
    constTbl->SetDefaults(m_D3DDev);

    if (!InitFont())
        return FALSE;

    return TRUE;
}