当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECT3DDEVICE9::CreateVertexShader方法代码示例

本文整理汇总了C++中LPDIRECT3DDEVICE9::CreateVertexShader方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DDEVICE9::CreateVertexShader方法的具体用法?C++ LPDIRECT3DDEVICE9::CreateVertexShader怎么用?C++ LPDIRECT3DDEVICE9::CreateVertexShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECT3DDEVICE9的用法示例。


在下文中一共展示了LPDIRECT3DDEVICE9::CreateVertexShader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

HRESULT HookIDirect3DDevice9::CreateVertexShader(LPVOID _this,
												 CONST DWORD* pFunction,
												 IDirect3DVertexShader9** ppShader)
{
	LOG_API();
	return pD3Dev->CreateVertexShader(pFunction, ppShader);
}
开发者ID:zxmarcos,项目名称:bg4t_monitor,代码行数:7,代码来源:D3DWrapper.cpp

示例2: CompileShader

void CompileShader()
{
	DWORD dwShaderFlags = 0;

#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3DXSHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3DXSHADER_DEBUG;
    #endif

#ifdef DEBUG_VS
        dwShaderFlags |= D3DXSHADER_SKIPOPTIMIZATION|D3DXSHADER_DEBUG;
    #endif
#ifdef DEBUG_PS
        dwShaderFlags |= D3DXSHADER_SKIPOPTIMIZATION|D3DXSHADER_DEBUG;
    #endif
	
	WCHAR* shader_file = L"torus_shader.hlsl";

	// Compile Vertex Shader
	LPD3DXBUFFER pVertexShaderCode;
	HRESULT hr = D3DXCompileShaderFromFile(shader_file, NULL, NULL, "VS", "vs_3_0", dwShaderFlags, &pVertexShaderCode, NULL, NULL);
	if(FAILED(hr))
	{
		MessageBox(NULL, L"Error", L"Compile Vertex Shader Failed!", 0);
	}

	// Create Vertex Shader
	hr = g_pd3dDevice->CreateVertexShader((DWORD*)pVertexShaderCode->GetBufferPointer(), &g_pVertexShader);
	if(FAILED(hr))
	{
		MessageBox(NULL, L"Error", L"Create Vertex Shader Failed!", 0);
	}

	// Compile Pixel Shader
	LPD3DXBUFFER pPixelShaderCode;
	hr = D3DXCompileShaderFromFile(shader_file, NULL, NULL, "PS", "ps_3_0", dwShaderFlags, &pPixelShaderCode, NULL, NULL);
	if(FAILED(hr))
	{
		MessageBox(NULL, L"Error", L"Compile Pixel Shader Failed!", 0);
	}

	// Create Pixel Shader
	hr = g_pd3dDevice->CreatePixelShader((DWORD*)pPixelShaderCode->GetBufferPointer(), &g_pPixelShader);
	if(FAILED(hr))
	{
		MessageBox(NULL, L"Error", L"Create Pixel Shader Failed!", 0);
	}

	// cleanup
	pVertexShaderCode->Release();
	pPixelShaderCode->Release();
}
开发者ID:BillyKim,项目名称:directxcode,代码行数:55,代码来源:Z-Buffer_Shader.cpp

示例3: InitVS

HRESULT InitVS()
{
	D3DVERTEXELEMENT9	decl[MAX_FVF_DECL_SIZE];
	// FVF를 사용해서 정점선언값을 자동으로 채워넣는다
	D3DXDeclaratorFromFVF( MYVERTEX::FVF, decl );
	// 정점선언값으로 g_pDecl을 생성한다.
	g_pd3dDevice->CreateVertexDeclaration( decl, &g_pDecl );
	LPD3DXBUFFER pCode;

	// simple.vs 파일을 읽어와서 정점쉐이더 인터페이스를 생성한다.
	if( FAILED( D3DXAssembleShaderFromFile( "simple.vs", NULL, NULL, 0, &pCode, NULL ) ) )
		return E_FAIL;

	g_pd3dDevice->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(), &g_pVS);

	S_REL( pCode );

	return S_OK;
}
开发者ID:blastingzone,项目名称:ComputerGraphicsAdvenced,代码行数:19,代码来源:main.cpp

示例4: must

bool CObject3D::InitStaticDeviceObjects(LPDIRECT3DDEVICE9 device)
{
	D3DVERTEXELEMENT9 decl[] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
		{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
		{ 0, 20, D3DDECLTYPE_SHORT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
		{ 0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
		{ 0, 36, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()
	};

	if (FAILED(device->CreateVertexDeclaration(decl, &s_skinVertexDeclaration)))
	{
		qCritical("Can't create skin vertex declaration. You must (re)install the lastest DirectX9 runtime on http://www.microsoft.com/en-us/download/details.aspx?id=8109");
		return false;
	}

	LPD3DXBUFFER code;
	if (FAILED(D3DXAssembleShaderFromResource(NULL, MAKEINTRESOURCE(IDR_SKINVS), NULL, NULL, 0, &code, NULL)))
	{
		qCritical("Can't assemble skin vertex shader from resource. You must (re)install the lastest DirectX9 runtime on http://www.microsoft.com/en-us/download/details.aspx?id=8109");
		return false;
	}

	if (FAILED(device->CreateVertexShader((DWORD*)code->GetBufferPointer(), &s_skinVS)))
	{
		qCritical("Can't create skin vertex shader. You must (re)install the lastest DirectX9 runtime on http://www.microsoft.com/en-us/download/details.aspx?id=8109");
		Release(code);
		return false;
	}
	Release(code);

	s_reflectTexture.SetDevice(device);
	if (!s_reflectTexture.Load("Model/Texture/etc_reflect.tga"))
	{
		qCritical("Can't load Model/Texture/etc_reflect.tga");
		return false;
	}

	return true;
}
开发者ID:ServerGame,项目名称:ATools,代码行数:42,代码来源:Object3D.cpp

示例5: Create_VS

bool Create_VS(char* hlsl, char* name, LPDIRECT3DVERTEXSHADER9* shader, LPD3DXCONSTANTTABLE* table, LPDIRECT3DDEVICE9 pDevice)
{
	HRESULT hr;
	LPD3DXBUFFER err;
	LPD3DXBUFFER code;
	// hlsl読み込み
	hr = D3DXCompileShaderFromFile(hlsl, NULL, NULL, name, "vs_3_0", 0, &code, &err, table);
	if (FAILED(hr)){
		MessageBox(NULL, (LPCSTR)err->GetBufferPointer(), name, MB_OK);
		err->Release();
		return false;
	}
	// ピクセルシェーダ作成 
	hr = pDevice->CreateVertexShader((DWORD*)code->GetBufferPointer(), shader);
	if (FAILED(hr)){
		MessageBox(NULL, (LPCSTR)err->GetBufferPointer(), name, MB_OK);
		return false;
	}
	return true;
}
开发者ID:yumina1021,项目名称:miso1510,代码行数:20,代码来源:exten_common.cpp

示例6: CompileVertexShader

bool CompileVertexShader(const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, LPD3DXCONSTANTTABLE *pShaderTable, std::string &errorMessage) {
	ID3DXBuffer* pShaderCode = NULL;
	ID3DXBuffer* pErrorMsg = NULL;

	HRESULT hr = -1;

	// Compile pixel shader.
	hr = dyn_D3DXCompileShader(code,
		(UINT)strlen(code),
		NULL,
		NULL,
		"main",
		"vs_2_0",
		0,
		&pShaderCode,
		&pErrorMsg,
		pShaderTable);

	if (pErrorMsg) {
		errorMessage = (CHAR *)pErrorMsg->GetBufferPointer();
		pErrorMsg->Release();
	} else {
		errorMessage = "";
	}

	if (FAILED(hr)) {
		if (pShaderCode)
			pShaderCode->Release();
		return false;
	}

	// Create pixel shader.
	pD3Ddevice->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), 
		pShader );

	pShaderCode->Release();

	return true;
}
开发者ID:adamgamer,项目名称:ppsspp,代码行数:39,代码来源:global.cpp

示例7: LoadVertexShader

// Load and compiler a HLSL vertex shader from a file. Provide the source code filename and pointers
// to the variables to hold the resultant shader and it associated constant table
bool LoadVertexShader( const string& fileName, LPDIRECT3DVERTEXSHADER9* vertexShader,
					   LPD3DXCONSTANTTABLE* constants )
{
	// Temporary variable to hold compiled pixel shader code
    LPD3DXBUFFER pShaderCode;

	// Compile external HLSL pixel shader into shader code to submit to the hardware
	string fullFileName = ShaderFolder + fileName;
	HRESULT hr = 
		D3DXCompileShaderFromFile( fullFileName.c_str(),// File containing pixel shader (HLSL)
			                       NULL, NULL,       // Advanced compilation options - not needed here
								   "main",           // Name of main function in the shader
								   "vs_3_0",         // Target vertex shader hardware - vs_1_1 is lowest level
												     // and will work on all video cards with a pixel shader
								   SHADER_FLAGS,     // Additional compilation flags (such as debug flags)
								   &pShaderCode,     // Ptr to variable to hold compiled shader code
								   NULL,             // Ptr to variable to hold error messages (not needed)
								   constants );      // Ptr to variable to hold constants for the shader
    if (FAILED(hr))
	{
		// Return if compilation failed
		return false;
	}

	// Create the pixel shader using the compiled shader code
    hr = g_pd3dDevice->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), vertexShader );
    
	// Discard the shader code now the shader has been created 
	pShaderCode->Release();

	// If the creation failed then return (wait until after shader code has been discarded)
    if (FAILED(hr))
	{
		return false;
	}

	return true;
}
开发者ID:Nixxus,项目名称:GamesDevelopment2,代码行数:40,代码来源:RenderMethod.cpp

示例8: CompileVertexShader

bool CompileVertexShader(const char * code, LPDIRECT3DVERTEXSHADER9 * pShader, LPD3DXCONSTANTTABLE * pShaderTable) {
	LPD3DXCONSTANTTABLE shaderTable = *pShaderTable;

	ID3DXBuffer* pShaderCode = NULL;
	ID3DXBuffer* pErrorMsg = NULL;

	HRESULT hr = -1;

	// Compile pixel shader.
#ifdef _XBOX
	hr = D3DXCompileShader( code, 
		(UINT)strlen( code ),
		NULL, 
		NULL, 
		"main", 
		"vs_3_0", 
		0, 
		&pShaderCode, 
		&pErrorMsg,
		pShaderTable );
#endif
	if( FAILED(hr) )
	{
		OutputDebugStringA((CHAR*)pErrorMsg->GetBufferPointer());
		DebugBreak();
		return false;
	}

	// Create pixel shader.
	pD3Ddevice->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), 
		pShader );

	pShaderCode->Release();

	return true;
}
开发者ID:18859966862,项目名称:ppsspp,代码行数:36,代码来源:global.cpp

示例9: file

void D3D9VertexShader::Reset(LPDIRECT3DDEVICE9 Device)
{
    FreeMemory();

    HRESULT hr;

    _Device = Device;
    Assert(Device != NULL, "Device == NULL");

    _Decl.Init(Device);

    // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the 
    // shader debugger. Debugging vertex shaders requires either REF or software vertex 
    // processing, and debugging pixel shaders requires REF.  The 
    // D3DXSHADER_FORCE_*_SOFTWARE_NOOPT flag improves the debug experience in the 
    // shader debugger.  It enables source level debugging, prevents instruction 
    // reordering, prevents dead code elimination, and forces the compiler to compile 
    // against the next higher available software target, which ensures that the 
    // unoptimized shaders do not exceed the shader model limitations.  Setting these 
    // flags will cause slower rendering since the shaders will be unoptimized and 
    // forced into software.  See the DirectX documentation for more information about 
    // using the shader debugger.
    DWORD dwShaderFlags = 0;
    #ifdef DEBUG_VS
        dwShaderFlags |= D3DXSHADER_SKIPOPTIMIZATION|D3DXSHADER_DEBUG;
    #endif

    LPD3DXBUFFER pCode = NULL;
    LPD3DXBUFFER pErrors = NULL;

    PersistentAssert(Utility::FileExists(_ShaderFile), String(_ShaderFile) + String(" not found."));

    // Assemble the vertex shader from the file
    hr = D3DXCompileShaderFromFile( _ShaderFile.CString(), NULL, NULL, "VShaderEntry",
                                    "vs_3_0", dwShaderFlags, &pCode,
                                    &pErrors, &_ConstantTable );
    
    if(pErrors)
    {
        char *ErrorMessage = (char *)pErrors->GetBufferPointer();
        DWORD ErrorLength = pErrors->GetBufferSize();

        ofstream file("ShaderDebug.txt");
        for(UINT i = 0; i < ErrorLength; i++)
        {
            file << ErrorMessage[i];
        }
        file.close();
    }

    Assert(!FAILED(hr), "D3DXCompileShaderFromFile failed.  See ShaderDebug.txt for details.");

    // Create the vertex shader
    hr = Device->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(),
                                            &_Shader );

    if(pErrors)
    {
        pErrors->Release();
    }
    if(pCode)
    {
        pCode->Release();
    }
    Assert(!FAILED(hr), "CreateVertexShader failed");
}
开发者ID:ghsoftco,项目名称:basecode14,代码行数:66,代码来源:D3D9VertexShader.cpp

示例10: Provoke


//.........这里部分代码省略.........
	if (!pcDevice)
	{
		OutputDebugString(L"Oculus Renderer Node : No device !");
		return nullptr;
	}

	// Original code (LibOVR) :
	// pShaderCode = ShaderCompile("precompiledVertexShaderSrc",VertexShaderSrc,"vs_2_0");
	// pShaderCode = ShaderCompile("precompiledVertexShaderTimewarpSrc",VertexShaderTimewarpSrc,"vs_3_0");
	// pShaderCode = ShaderCompile("precompiledPixelShaderSrc",PixelShaderSrc,"ps_3_0");

	// pixel shader created ?
	if (!m_pcOculusPixelShader)
	{
		LPD3DXBUFFER pShader;

		// compile and create shader
		if (SUCCEEDED(D3DXCompileShader(PixelShaderSrc,strlen(PixelShaderSrc),NULL,NULL,"main","ps_3_0",NULL,&pShader,NULL,&m_pcOculusPixelShaderCT)))
		{
			OutputDebugString(L"Pixel shader compiled!");
			pcDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &m_pcOculusPixelShader);
		}
	}

	// vertex shader created ?
	if (!m_pcOculusVertexShader)
	{
		LPD3DXBUFFER pShader;

		// compile and create shader
		if (SUCCEEDED(D3DXCompileShader(VertexShaderSrc,strlen(VertexShaderSrc),NULL,NULL,"main","vs_2_0",NULL,&pShader,NULL,&m_pcOculusVertexShaderCT)))
		{
			OutputDebugString(L"Vertex shader compiled!");
			pcDevice->CreateVertexShader((DWORD*)pShader->GetBufferPointer(), &m_pcOculusVertexShader);
		}
	}

	// side by side pixel shader ?
	if (!m_pcSideBySidePixelShader)
	{
		LPD3DXBUFFER pShader;

		// compile and create shader
		if (SUCCEEDED(D3DXCompileShader(PixelShaderSrcSideBySide,strlen(PixelShaderSrcSideBySide),NULL,NULL,"SBS","ps_2_0",NULL,&pShader,NULL,&m_pcSideBySidePixelShaderCT)))
		{
			OutputDebugString(L"Pixel shader compiled!");
			pcDevice->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), &m_pcSideBySidePixelShader);
		}

	}

	// test textures created ?
	if ((!m_pcTextureRightTest) || (!m_pcTextureLeftTest))
	{
		HMODULE hModule = GetModuleHandle(L"OculusRenderer.dll");

		if (!m_pcTextureLeftTest)
		{
			// create a test texture
			if (SUCCEEDED(D3DXCreateTextureFromResource(pcDevice, hModule, MAKEINTRESOURCE(IMG_BACKGROUND01), &m_pcTextureLeftTest)))
				OutputDebugString(L"Texture created !");
			else m_pcTextureLeftTest = nullptr;
		}
		if (!m_pcTextureRightTest)
		{
			// create a test texture
开发者ID:Innovative-Ideas,项目名称:Perception,代码行数:67,代码来源:OculusRenderer.cpp

示例11: Init


//.........这里部分代码省略.........
		m_pD3DVtxBuff->Unlock();
	}

	{//インデックスバッファの中身を埋める
		WORD *pIdx;

		// インデックスデータの範囲をロックし、頂点バッファへのポインタを取得
		m_pD3DIndexBuff->Lock(0, 0, (void**)&pIdx, 0);

		int nCntIdx = 0;
		for(int nCntVtxZ = 0; nCntVtxZ < m_nNumBlockZ; nCntVtxZ++)
		{
			if(nCntVtxZ > 0)
			{// 縮退ポリゴンのためのダブりの設定
				pIdx[nCntIdx] = (nCntVtxZ + 1) * (m_nNumBlockX + 1) + 0;
				nCntIdx++;
			}

			for(int nCntVtxX = 0; nCntVtxX < (m_nNumBlockX + 1); nCntVtxX++)
			{
				pIdx[nCntIdx] = (nCntVtxZ + 1) * (m_nNumBlockX + 1) + nCntVtxX;
				nCntIdx++;
				pIdx[nCntIdx] = nCntVtxZ * (m_nNumBlockX + 1) + nCntVtxX;
				nCntIdx++;
			}

			if(nCntVtxZ < (m_nNumBlockZ - 1))
			{// 縮退ポリゴンのためのダブりの設定
				pIdx[nCntIdx] = nCntVtxZ * (m_nNumBlockX + 1) + m_nNumBlockX;
				nCntIdx++;
			}
		}

		// インデックスデータをアンロックする
		m_pD3DIndexBuff->Unlock();
	}

	HRESULT hr;
	LPD3DXBUFFER err;
	LPD3DXBUFFER code;

	//ピクセルシェーダー用に変換
	hr = D3DXCompileShaderFromFile("source/shader/basicPS.hlsl", NULL, NULL, "PS_SHADOW", "ps_2_0", 0, &code, &err, &_psc);

	if (FAILED(hr))
	{
		MessageBox(NULL, (LPCSTR)err->GetBufferPointer(), "D3DXCompileShaderFromFile", MB_OK);
		err->Release();
		return false;
	}
	//シェーダーの登録
	hr = pDevice->CreatePixelShader((DWORD*)code->GetBufferPointer(), &_ps);

	if (FAILED(hr))
	{
		MessageBox(NULL, "FAILED", "CreatePixelShader", MB_OK);
		return false;
	}

	//バーテックスシェーダー用に変換1
	hr = D3DXCompileShaderFromFile("source/shader/basicVS.hlsl", NULL, NULL, "VS_SHADOW", "vs_2_0", 0, &code, &err, &_vsc[0]);
	if (FAILED(hr))
	{
		MessageBox(NULL, (LPCSTR)err->GetBufferPointer(), "D3DXCompileShaderFromFile", MB_OK);
		err->Release();
		return false;
	}
	//シェーダーの登録
	hr = pDevice->CreateVertexShader((DWORD*)code->GetBufferPointer(), &_vs[0]);
	if (FAILED(hr))
	{
		MessageBox(NULL, "FAILED", "CreateVertexShader", MB_OK);
		return false;
	}

	//バーテックスシェーダー用に変換1
	hr = D3DXCompileShaderFromFile("source/shader/basicVS.hlsl", NULL, NULL, "VS", "vs_2_0", 0, &code, &err, &_vsc[1]);
	if (FAILED(hr))
	{
		MessageBox(NULL, (LPCSTR)err->GetBufferPointer(), "D3DXCompileShaderFromFile", MB_OK);
		err->Release();
		return false;
	}
	//シェーダーの登録
	hr = pDevice->CreateVertexShader((DWORD*)code->GetBufferPointer(), &_vs[1]);
	if (FAILED(hr))
	{
		MessageBox(NULL, "FAILED", "CreateVertexShader", MB_OK);
		return false;
	}

	// マテリアルの設定
	m_material.Ambient = D3DXCOLOR(0.25f, 0.25f, 0.25f, 1.0f);
	m_material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	m_material.Emissive = D3DXCOLOR(0, 0, 0, 0);
	m_material.Specular = D3DXCOLOR(0, 0, 0, 0);
	m_material.Power = 2.0f;

	return S_OK;
}
开发者ID:yumina1021,项目名称:miso1510,代码行数:101,代码来源:Field.cpp

示例12: Create

	bool CShaderHLSL::Create(P3D::sShaderDesc &desc)
	{
		const char *pData;
		ULONG fsize;
		IFileSystem* pFS = CRenderer::mEngine()->mFilesystem();
		wchar path[P3DMAX_PATH];
		wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get());
		FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true);
		if (!fp)
		{
			CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get());
			return false;
		}

		ID3DXBuffer *pShaderBlob = NULL;
		ID3DXBuffer *pErrors = NULL;
		DWORD flags = D3DXSHADER_DEBUG;  //D3DXSHADER_OPTIMIZATION_LEVEL3

		char profile[128];
		switch(desc.ShaderType)
		{
		case SHADERTYPE_VERTEX_SHADER:
			strcpy(profile, D3DXGetVertexShaderProfile(g_pD3ddev));
			break;
		case SHADERTYPE_PIXEL_SHADER:
			strcpy(profile, D3DXGetPixelShaderProfile(g_pD3ddev));
			break;
		case SHADERTYPE_GEOMETRY_SHADER:
			CON(MSG_ERR, _W("DX9 does not support geometry shaders."));
			return false;
		default:
			CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given."));
			return false;
		}

		CIncludeHandler includeHandler;
		
		D3DXMACRO Shader_Macros[] = 
		{
			{ "DX9", NULL },
			{ "SM3", NULL },
			NULL
		};

		if(FAILED(D3DXCompileShader(
			pData, 
			fsize, 
			Shader_Macros, 
			&includeHandler, 
			_W2A(desc.EntryFunction.Get()), 
			profile, 
			flags,
			&pShaderBlob, 
			&pErrors,
			&m_pConstTable
			)))
		{
			if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer()));
			else CON(MSG_ERR, _W("Error description not given"));
			CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get());
			SAFE_RELEASE(pErrors);
			return false;
		}

		pFS->UnLoad(fp, (BYTE *)pData);

		//save to cache
		fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb"));
		const char* cs = (const char*)pShaderBlob->GetBufferPointer();
		pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp);
		pFS->Close(fp);

		bool shaderCreated = false;
		switch(desc.ShaderType)
		{
		case SHADERTYPE_VERTEX_SHADER:
			shaderCreated = SUCCEEDED(g_pD3ddev->CreateVertexShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pVS));
			break;
		case SHADERTYPE_PIXEL_SHADER:
			shaderCreated = SUCCEEDED(g_pD3ddev->CreatePixelShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pPS));
			break;
		}

		if(!shaderCreated)
		{
			CON(MSG_ERR, _W("Shader creation error"));
			return false;
		}

		//set constant to their default values 
		m_pConstTable->SetDefaults(g_pD3ddev);

		//create vertex declaration
		if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER)
			m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob);

		SAFE_RELEASE(pShaderBlob);

		m_desc = desc;

//.........这里部分代码省略.........
开发者ID:k3a,项目名称:Panther3D-2,代码行数:101,代码来源:ShaderHLSL.cpp

示例13: CompileShaders

void CompileShaders() {
	ID3DXBuffer* pShaderCode = NULL;
	ID3DXBuffer* pErrorMsg = NULL;
	HRESULT hr = -1;

#ifdef _XBOX

	// Compile vertex shader.
	hr = D3DXCompileShader( vscode, 
		(UINT)strlen( vscode ),
		NULL, 
		NULL, 
		"main", 
		"vs_2_0", 
		0, 
		&pShaderCode, 
		&pErrorMsg,
		NULL );
#endif 

	if( FAILED(hr) )
	{
		OutputDebugStringA((CHAR*)pErrorMsg->GetBufferPointer());
		DebugBreak();
	}

	// Create pixel shader.
	pD3Ddevice->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), 
		&pFramebufferVertexShader );

	pShaderCode->Release();

#ifdef _XBOX
	// Compile pixel shader.
	hr = D3DXCompileShader( pscode, 
		(UINT)strlen( pscode ),
		NULL, 
		NULL, 
		"main", 
		"ps_2_0", 
		0, 
		&pShaderCode, 
		&pErrorMsg,
		NULL );
#endif

	if( FAILED(hr) )
	{
		OutputDebugStringA((CHAR*)pErrorMsg->GetBufferPointer());
		DebugBreak();
	}

	// Create pixel shader.
	pD3Ddevice->CreatePixelShader( (DWORD*)pShaderCode->GetBufferPointer(), 
		&pFramebufferPixelShader );

	pShaderCode->Release();

	pD3Ddevice->CreateVertexDeclaration( VertexElements, &pFramebufferVertexDecl );
	pD3Ddevice->SetVertexDeclaration( pFramebufferVertexDecl );

	pD3Ddevice->CreateVertexDeclaration( SoftTransVertexElements, &pSoftVertexDecl );
}
开发者ID:18859966862,项目名称:ppsspp,代码行数:63,代码来源:global.cpp

示例14: LoadVariant


//.........这里部分代码省略.........
				// get the compiled date out of the file
				memcpy( &storedMTime, pShaderFileData, sizeof(time_t) );
			
				// if the stored modified time in the compiled shader file is the same as the current
				// modified time of the shader file
				if( storedMTime == shaderFilestat.st_mtime )
				{
					// reduce the buffer size by the preamble (mod time)
					shaderLen -= (int)sizeof(time_t);
						
					// copy the compiled shader into the shader buffer
					memcpy( shaderBuf->GetBufferPointer(), ((TCHAR *) pShaderFileData)+ sizeof(time_t), shaderLen);
					bLoadedCompiled = true;
				}
			}
			SAFE_DELETE_ARRAY( pShaderFileData );
		}

		if (!bLoadedCompiled && bCompile)
		{
			if (pDefines)
				EngineGetToolBox()->Log( LOGINFORMATION, _T("Compiling shader %s:%d\n"), GetName()->GetString(), pDefines->GetValuesEncoding().iEncoding );
			else
				EngineGetToolBox()->Log( LOGINFORMATION, _T("Compiling shader %s\n"), GetName()->GetString() );

			hr = D3DXCompileShader( m_Code,
										len,//length of string in bytes
										pMacros, //can add that matrix of macros here
										&includeInterface, //for include directories
										"main",//? temp
										profile, //vs_1_1 for example
										0, //compiling options?
										&shaderBuf,
										&pErrorMsgs,
										NULL );
		}

		//now actually create the shader
		if( hr == D3D_OK &&
			shaderBuf )
		{
			if (!bLoadedCompiled)
			{
				struct _stat shaderFilestat;
				// get the shader file's modified time
				if (_tstat( szFile, &shaderFilestat ) == 0)
				{
					m_ToolBox->Log( LOGINFORMATION, _T("Writing compiled shader file: %s\n"), szCompiledFile.c_str() );
					// open a compiled shader file for writing
					FILE *fp = fopen( szCompiledFile, "wb" );
					if (fp)
					{
						// write shader file's modified time
						fwrite( &shaderFilestat.st_mtime, sizeof(time_t), 1, fp );
						// write compiled shader data
						fwrite( shaderBuf->GetBufferPointer(), shaderBuf->GetBufferSize(), 1, fp );
						fclose(fp);
					}
					else
					{
						m_ToolBox->Log( LOGWARNING, _T("Failed to write compiled shader file: %s\n"), szCompiledFile.c_str() );
					}
				}
			}

			hr = pDevice->CreateVertexShader( (DWORD *) shaderBuf->GetBufferPointer(), &pShader );
			assert( SUCCEEDED(hr) );
			if (!SUCCEEDED(hr))
			{
				m_ToolBox->Log( LOGWARNING, _T("Failed to create shader : %s\n"), szCompiledFile.c_str() );
			}

			SAFE_RELEASE( shaderBuf );
			SAFE_RELEASE( pErrorMsgs );

			if (pDefines == NULL) // we are compiling the default shader with no macro defines
			{
				assert( m_VertexShader == NULL ); // the default shader should only be compiled on Init when this is NULL
				m_VertexShader = pShader;
			}
			else if (pDefines != NULL) // we are compiling a variant of the shader
			{
				unsigned long iEncoding = pDefines->GetValuesEncoding().iEncoding;
				m_ShaderVariants[iEncoding] = pShader;
			}
			return true;
		}
	}	
	if( pErrorMsgs )
	{
		IHashString * name = GetName();
		TCHAR* debug_errors = (TCHAR*)pErrorMsgs->GetBufferPointer();
		m_ToolBox->Log( LOGERROR, _T("Could not create Vertex shader %s\nError message: %s\n"),
			name->GetString(), debug_errors );				
		SAFE_RELEASE( pErrorMsgs );				
	}
	SAFE_RELEASE( shaderBuf );

	return false;
}
开发者ID:klhurley,项目名称:ElementalEngine2,代码行数:101,代码来源:CDX9VertexShader.cpp

示例15: InitD3D

//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
	// Create the D3D object.
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
		return E_FAIL;

	// Set up the structure used to create the D3DDevice. Since we are now
	// using more complex geometry, we will create a device with a zbuffer.
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	// Create the D3DDevice
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		return E_FAIL;
	}

	// Turn on the zbuffer
	g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
	//Turn off culling, so we see the front and back of the triangle
	g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
	g_pd3dDevice->LightEnable( 0, TRUE );
	g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
	g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );


	////VS TUTORIAL STUFF

	LPD3DXBUFFER pCode;                  // Buffer with the assembled shader code				////VS TUTORIAL STUFF
	// This is our error buffer
	LPD3DXBUFFER pErrorMsgs = 0;             // Buffer with error messages							////VS TUTORIAL STUFF


	for ( int i = 0;  i < maxShaders;  i++ ) // load all the shader files
	{
		if(FAILED(D3DXAssembleShaderFromFile( shaders[i].c_str(),  NULL, NULL, 0,					////VS TUTORIAL STUFF
			&pCode, &pErrorMsgs )))	{   
				// Error(s) have occured.   
				// Allocate a character buffer the size of the ID3DXBuffer  
				if(pErrorMsgs != 0) {
					char* data = new char[pErrorMsgs->GetBufferSize()];   
					// Copy the buffer data over   
					memcpy( data, pErrorMsgs->GetBufferPointer(), pErrorMsgs->GetBufferSize() );   
					// Open a file and output the error string(s)   
					FILE* file;
					fopen_s(&file,"errors.txt", "w" );   
					fprintf( file, "%s", data );   
					fclose( file );   
					// Release allocated objects   
					delete[] data;   
					pErrorMsgs->Release();   
					MessageBox(hWnd,L"see errors.txt",L"vertex assemble problem",NULL);
				}
				return E_FAIL;
		}

		switch ( i )	// create the vertex shader and assosiate it with the proper variable
		{
			case 0 :	g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),	&g_pVertexShader);
			case 1 :	g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),	&g_pVertexShader2);
			case 2 :	g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),	&g_pVertexShader3);
			case 3 :	g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),	&g_pVertexShader4);
			case 4 :	g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),	&g_pVertexShader5);
			case 5 :	g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(),	&g_pVertexShader6);
		}
		pCode->Release();
	}



	cameraPos.x = 0.0f;
	cameraPos.y = 15.0f;
	cameraPos.z = 20.0f;

	lightPos.x = -10.0f;
	lightPos.y = 0.0f;
	lightPos.z = 3.0f;



	return S_OK;
}
开发者ID:dimivogi,项目名称:MSC.skullShaders,代码行数:94,代码来源:ACW1.cpp


注:本文中的LPDIRECT3DDEVICE9::CreateVertexShader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。