本文整理汇总了C++中LPD3DXBUFFER类的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXBUFFER类的具体用法?C++ LPD3DXBUFFER怎么用?C++ LPD3DXBUFFER使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPD3DXBUFFER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitHLSL
//---------------------------------------------//
//HLSL読み込み
//---------------------------------------------//
HRESULT HLSLShader::InitHLSL(LPCTSTR filename,LPDIRECT3DDEVICE9 pD3DDev)
{
m_pD3DDevice = pD3DDev;
//シェーダの読み込み
LPD3DXBUFFER pErr = NULL;
HRESULT hr = S_OK;
if( FAILED( hr = D3DXCreateEffectFromFile(
pD3DDev,
filename,
NULL,
NULL,
0,
NULL,
&m_pEffect,
&pErr ) ) )
{
HRESULTCheck(hr);
LPSTR s = (LPSTR)pErr->GetBufferPointer();
LPTCH t[MAX_PATH*10];
//アスキーからユニコード
MultiByteToWideChar(
CP_ACP,
MB_PRECOMPOSED,
s,
MAX_PATH*2,
(LPTSTR)t,
MAX_PATH*2);
MessageBox(NULL,(LPCTSTR)t,TEXT("失敗"),MB_OK);
}else{
m_hTechnique = m_pEffect->GetTechniqueByName("TShader");
m_hmWorld = m_pEffect->GetParameterByName(NULL,"g_mWorld");
m_hmVP = m_pEffect->GetParameterByName(NULL,"g_mVP");
m_hmWVP = m_pEffect->GetParameterByName(NULL,"g_mWVP");
m_hmWVPB = m_pEffect->GetParameterByName(NULL,"g_mWVPB");
m_hmWLP = m_pEffect->GetParameterByName(NULL,"g_mWLP");
m_hmLP = m_pEffect->GetParameterByName(NULL,"g_mLP");
m_hmWLPB = m_pEffect->GetParameterByName(NULL,"g_mWLPB");
m_hmB = m_pEffect->GetParameterByName(NULL,"g_mB");
m_hmWorldMatrixArray = m_pEffect->GetParameterByName(NULL,"g_mWorldMatrixArray");
m_hiNumBones = m_pEffect->GetParameterByName(NULL,"g_NumBones");
m_hTex = m_pEffect->GetParameterByName(NULL,"g_Tex");
m_hShadowTex = m_pEffect->GetParameterByName(NULL,"g_ShadowTex");
m_hRenderTex = m_pEffect->GetParameterByName(NULL,"g_RenderTex");
m_hvLight = m_pEffect->GetParameterByName(NULL,"g_vLight");
m_hvRealLightPos = m_pEffect->GetParameterByName(NULL,"g_vRealLightPos");
m_hvRealLightVec = m_pEffect->GetParameterByName(NULL,"g_vRealLightVec");
m_hvRealCameraPos = m_pEffect->GetParameterByName(NULL,"g_vRealCameraPos");
m_hvRealCameraVec = m_pEffect->GetParameterByName(NULL,"g_vRealCameraVec");
m_hvLightAmb = m_pEffect->GetParameterByName(NULL,"g_vLightAmb");
m_hvLightDif = m_pEffect->GetParameterByName(NULL,"g_vLightDif");
m_hvEyePos = m_pEffect->GetParameterByName(NULL,"g_vEyePos");
m_hDecay_c0 = m_pEffect->GetParameterByName(NULL,"decay_c0");
m_hDecay_c1 = m_pEffect->GetParameterByName(NULL,"decay_c1");
m_hDecay_c2 = m_pEffect->GetParameterByName(NULL,"decay_c2");
m_hsBaias = m_pEffect->GetParameterByName(NULL,"g_sBaias");
m_hShadowLange = m_pEffect->GetParameterByName(NULL,"g_ShadowLange");
}
if(pErr!=NULL)pErr->Release();
return hr;
}
示例2: ZeroMemory
HRESULT SampleShaderPluginVertexShader::InitValid(Mesh *mesh, INode *node)
{
HRESULT hr = S_OK;
m_pINode = node;
// Create a vertex shader for doing the effect
LPD3DXBUFFER *ppCode = &pCode;
LPD3DXBUFFER pBuffer = NULL;
//! VertexShader Declarations
//! VertexShader Constants
Constants.SetCount(20);
//! set up the material vertex color ...
D3DMATERIAL8 mtrl;
ZeroMemory( &mtrl, sizeof(D3DMATERIAL8) );
mtrl.Diffuse.r = mtrl.Ambient.r = m_MtlColor.r;
mtrl.Diffuse.g = mtrl.Ambient.g = m_MtlColor.g;
mtrl.Diffuse.b = mtrl.Ambient.b = m_MtlColor.b;
mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
pd3dDevice->SetMaterial( &mtrl );
pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );
/*!
* D3DXAssembleShader
* Assembles an ASCII description of a shader into binary form, where the shader source is in memory.
*
* @param pSrcData : [in] Pointer to the source code.
* @param SrcDataLen : [in] Size of the source code, in bytes.
* @param Flags : [in] A combination of the following flags, specifying assembly options.
* D3DXASM_DEBUG Inserts debugging information as comments in the assembled shader.
* D3DXASM_SKIPVALIDATION Do not validate the generated code against known capabilities and constraints. This option is recommended only when assembling a shader you know will function (that is, the shader has been assembled before without this option.)
* @param ppConstants : [out] Returns a pointer to an ID3DXBuffer interface, representing the returned constant declarations. These constants are returned as a vertex shader declaration fragment. It is up to the application to insert the contents of this buffer into their declaration. For pixel shaders this parameter is meaningless because constant declarations are included in the assembled shader. This parameter is ignored if it is NULL.
* @param ppCompiledShader : [out] Returns a pointer to an ID3DXBuffer interface, representing the returned compiled object code. This parameter is ignored if it is NULL.
* @param ppCompilationErrors : [out] Returns a pointer to an ID3DXBuffer interface, representing the returned ASCII error messages. This parameter is ignored if it is NULL.
*
* @return HRESULT :
HRESULT D3DXAssembleShader(
LPCVOID pSrcData,
UINT SrcDataLen,
DWORD Flags,
LPD3DXBUFFER* ppConstants,
LPD3DXBUFFER* ppCompiledShader,
LPD3DXBUFFER* ppCompilationErrors
);
*/
//! Specify the vertex format that the vertex shader will be using for doing the effect
DWORD dwVertexFormatDefinition[] =
{
D3DVSD_STREAM( 0 ), D3DVSD_REG( 0, D3DVSDT_FLOAT3 ), // v0 = Position
D3DVSD_REG( 1, D3DVSDT_FLOAT3 ), // v1 = Normal
D3DVSD_END()
};
#if 0
TCHAR *vertexShaderPath = FindMapFile("ambient.njv");
hr = D3DXAssembleShaderFromFile(vertexShaderPath , 0, NULL, &pCode, NULL);
#else
hr = D3DXAssembleShader( SurfaceShader , sizeof(SurfaceShader)-1 , 0 , NULL , &pCode , NULL );
#endif
hr = pd3dDevice->CreateVertexShader(dwVertexFormatDefinition,(LPDWORD)pCode->GetBufferPointer(), &dwVertexShader, 0);
initDone = true;
return hr;
}
示例3: FreeMemory
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");
}
示例4: if
//--------------------------------------------------------------------------------------------------------------
SVS* CResourceManager::_CreateVS (LPCSTR _name)
{
string_path name;
strcpy_s (name,_name);
if (0 == ::Render->m_skinning) strcat(name,"_0");
if (1 == ::Render->m_skinning) strcat(name,"_1");
if (2 == ::Render->m_skinning) strcat(name,"_2");
LPSTR N = LPSTR (name);
map_VS::iterator I = m_vs.find (N);
if (I!=m_vs.end()) return I->second;
else
{
SVS* _vs = xr_new<SVS> ();
_vs->dwFlags |= xr_resource_flagged::RF_REGISTERED;
m_vs.insert (mk_pair(_vs->set_name(name),_vs));
if (0==stricmp(_name,"null")) {
_vs->vs = NULL;
return _vs;
}
includer Includer;
LPD3DXBUFFER pShaderBuf = NULL;
LPD3DXBUFFER pErrorBuf = NULL;
LPD3DXSHADER_CONSTANTTABLE pConstants = NULL;
HRESULT _hr = S_OK;
string_path cname;
strconcat (sizeof(cname),cname,::Render->getShaderPath(),_name,".vs");
FS.update_path (cname, "$game_shaders$", cname);
// LPCSTR target = NULL;
IReader* fs = FS.r_open(cname);
R_ASSERT3 (fs, "shader file doesnt exist", cname);
// Select target
LPCSTR c_target = "vs_2_0";
LPCSTR c_entry = "main";
/*if (HW.Caps.geometry.dwVersion>=CAP_VERSION(3,0)) target="vs_3_0";
else*/ if (HW.Caps.geometry_major>=2) c_target="vs_2_0";
else c_target="vs_1_1";
LPSTR pfs = xr_alloc<char>(fs->length() + 1);
strncpy (pfs, (LPCSTR)fs->pointer(), fs->length());
pfs [fs->length()] = 0;
if (strstr(pfs, "main_vs_1_1")) { c_target = "vs_1_1"; c_entry = "main_vs_1_1"; }
if (strstr(pfs, "main_vs_2_0")) { c_target = "vs_2_0"; c_entry = "main_vs_2_0"; }
xr_free(pfs);
// vertex
R_ASSERT2 (fs,cname);
_hr = ::Render->shader_compile(name,LPCSTR(fs->pointer()),fs->length(), NULL, &Includer, c_entry, c_target, D3DXSHADER_DEBUG | D3DXSHADER_PACKMATRIX_ROWMAJOR /*| D3DXSHADER_PREFER_FLOW_CONTROL*/, &pShaderBuf, &pErrorBuf, NULL);
// _hr = D3DXCompileShader (LPCSTR(fs->pointer()),fs->length(), NULL, &Includer, "main", target, D3DXSHADER_DEBUG | D3DXSHADER_PACKMATRIX_ROWMAJOR, &pShaderBuf, &pErrorBuf, NULL);
FS.r_close (fs);
if (SUCCEEDED(_hr))
{
if (pShaderBuf)
{
_hr = HW.pDevice->CreateVertexShader ((DWORD*)pShaderBuf->GetBufferPointer(), &_vs->vs);
if (SUCCEEDED(_hr)) {
LPCVOID data = NULL;
_hr = D3DXFindShaderComment ((DWORD*)pShaderBuf->GetBufferPointer(),MAKEFOURCC('C','T','A','B'),&data,NULL);
if (SUCCEEDED(_hr) && data)
{
pConstants = LPD3DXSHADER_CONSTANTTABLE(data);
_vs->constants.parse (pConstants,0x2);
} else _hr = E_FAIL;
}
}
else _hr = E_FAIL;
} else {
VERIFY (pErrorBuf);
Log ("! error: ",(LPCSTR)pErrorBuf->GetBufferPointer());
}
_RELEASE (pShaderBuf);
_RELEASE (pErrorBuf);
pConstants = NULL;
R_CHK (_hr);
return _vs;
}
}
示例5: glCreateShader
void Shader::Internal::reload()
{
if (opengl) {
GLint status;
const GLchar *p = (const GLchar *)vertex_source.c_str();
opengl_vertex_shader = glCreateShader(GL_VERTEX_SHADER);
printGLerror("glCreateShader");
glShaderSource(opengl_vertex_shader, 1, &p, 0);
printGLerror("glShaderSource");
glCompileShader(opengl_vertex_shader);
printGLerror("glCompileShader");
glGetShaderiv(opengl_vertex_shader, GL_COMPILE_STATUS, &status);
printGLerror("glGetShaderiv");
if (status != GL_TRUE) {
char buffer[512];
glGetShaderInfoLog(opengl_vertex_shader, 512, 0, buffer);
errormsg("Vertex shader error: %s\n", buffer);
}
p = (const GLchar *)fragment_source.c_str();
opengl_fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
printGLerror("glCreateShader");
glShaderSource(opengl_fragment_shader, 1, &p, 0);
printGLerror("glShaderSource");
glCompileShader(opengl_fragment_shader);
printGLerror("glCompileShader");
glGetShaderiv(opengl_fragment_shader, GL_COMPILE_STATUS, &status);
printGLerror("glGetShaderiv");
if (status != GL_TRUE) {
char buffer[512];
glGetShaderInfoLog(opengl_fragment_shader, 512, 0, buffer);
errormsg("Fragment shader error: %s\n", buffer);
}
opengl_shader = glCreateProgram();
glAttachShader(opengl_shader, opengl_vertex_shader);
printGLerror("glAttachShader");
glAttachShader(opengl_shader, opengl_fragment_shader);
printGLerror("glAttachShader");
glLinkProgram(opengl_shader);
printGLerror("glLinkProgram");
}
#ifdef NOOSKEWL_ENGINE_WINDOWS
else {
LPD3DXBUFFER errors;
std::string shader_source = vertex_source + fragment_source;
shader_source +=
"technique TECH"
"{"
" pass p1"
" {"
" VertexShader = compile vs_2_0 vs_main();"
" PixelShader = compile ps_2_0 ps_main();"
" }"
"}";
DWORD result = D3DXCreateEffect(noo.d3d_device, shader_source.c_str(), shader_source.length(), 0, 0, D3DXSHADER_PACKMATRIX_ROWMAJOR, 0, &d3d_effect, &errors);
if (result != D3D_OK) {
char *msg = (char *)errors->GetBufferPointer();
throw Error("Shader error: " + std::string(msg));
}
d3d_technique = d3d_effect->GetTechniqueByName("TECH");
d3d_effect->ValidateTechnique(d3d_technique);
d3d_effect->SetTechnique(d3d_technique);
}
#endif
}
示例6:
//-----------------------------------------------------------------------------
// Name:
// Desc:
//-----------------------------------------------------------------------------
HRESULT CD3DMesh::Create( LPDIRECT3DDEVICE8 pd3dDevice, TCHAR* strFilename )
{
TCHAR strPath[MAX_PATH];
CHAR strPathANSI[MAX_PATH];
LPD3DXBUFFER pAdjacencyBuffer = NULL;
LPD3DXBUFFER pMtrlBuffer = NULL;
HRESULT hr;
// Find the path for the file, and convert it to ANSI (for the D3DX API)
DXUtil_FindMediaFile( strPath, strFilename );
DXUtil_ConvertGenericStringToAnsi( strPathANSI, strPath );
// Load the mesh
if( FAILED( hr = D3DXLoadMeshFromX( strPathANSI, D3DXMESH_SYSTEMMEM, pd3dDevice,
&pAdjacencyBuffer, &pMtrlBuffer,
&m_dwNumMaterials, &m_pSysMemMesh ) ) )
{
return hr;
}
// Optimize the mesh for performance
if( FAILED( hr = m_pSysMemMesh->OptimizeInplace(
D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE,
(DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL ) ) )
{
SAFE_RELEASE( pAdjacencyBuffer );
SAFE_RELEASE( pMtrlBuffer );
return hr;
}
// Get material info for the mesh
// Get the array of materials out of the buffer
if( pMtrlBuffer && m_dwNumMaterials > 0 )
{
// Allocate memory for the materials and textures
D3DXMATERIAL* d3dxMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer();
m_pMaterials = new D3DMATERIAL8[m_dwNumMaterials];
m_pTextures = new LPDIRECT3DTEXTURE8[m_dwNumMaterials];
// Copy each material and create its texture
for( DWORD i=0; i<m_dwNumMaterials; i++ )
{
// Copy the material
m_pMaterials[i] = d3dxMtrls[i].MatD3D;
m_pMaterials[i].Ambient = m_pMaterials[i].Diffuse;
m_pTextures[i] = NULL;
// Create a texture
if( d3dxMtrls[i].pTextureFilename )
{
TCHAR strTexture[MAX_PATH];
TCHAR strTextureTemp[MAX_PATH];
DXUtil_ConvertAnsiStringToGeneric( strTextureTemp, d3dxMtrls[i].pTextureFilename );
DXUtil_FindMediaFile( strTexture, strTextureTemp );
if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, strTexture,
&m_pTextures[i] ) ) )
m_pTextures[i] = NULL;
}
}
}
SAFE_RELEASE( pAdjacencyBuffer );
SAFE_RELEASE( pMtrlBuffer );
return S_OK;
}
示例7: _stprintf
bool CDirect3D::SetShaderHLSL(const TCHAR *file)
{
//MUDLORD: the guts
//Compiles a shader from files on disc
//Sets LUT textures to texture files in PNG format.
TCHAR folder[MAX_PATH];
TCHAR rubyLUTfileName[MAX_PATH];
TCHAR *slash;
TCHAR errorMsg[MAX_PATH + 50];
shaderTimer = 1.0f;
shaderTimeStart = 0;
shaderTimeElapsed = 0;
if(effect) {
effect->Release();
effect = NULL;
}
for(int i = 0; i < MAX_SHADER_TEXTURES; i++) {
if (rubyLUT[i] != NULL) {
rubyLUT[i]->Release();
rubyLUT[i] = NULL;
}
}
if (file == NULL || *file==TEXT('\0'))
return true;
CXML xml;
if(!xml.loadXmlFile(file))
return false;
TCHAR *lang = xml.getAttribute(TEXT("/shader"),TEXT("language"));
if(lstrcmpi(lang,TEXT("hlsl"))) {
_stprintf(errorMsg,TEXT("Shader language is <%s>, expected <HLSL> in file:\n%s"),lang,file);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
return false;
}
TCHAR *shaderText = xml.getNodeContent(TEXT("/shader/source"));
if(!shaderText) {
_stprintf(errorMsg,TEXT("No HLSL shader program in file:\n%s"),file);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"),
MB_OK|MB_ICONEXCLAMATION);
return false;
}
LPD3DXBUFFER pBufferErrors = NULL;
#ifdef UNICODE
HRESULT hr = D3DXCreateEffect( pDevice,WideToCP(shaderText,CP_ACP),strlen(WideToCP(shaderText,CP_ACP)),NULL, NULL,
D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, NULL, &effect,
&pBufferErrors );
#else
HRESULT hr = D3DXCreateEffect( pDevice,shaderText,strlen(shaderText),NULL, NULL,
D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, NULL, &effect,
&pBufferErrors );
#endif
if( FAILED(hr) ) {
_stprintf(errorMsg,TEXT("Error parsing HLSL shader file:\n%s"),file);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
if(pBufferErrors) {
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (const TCHAR*)pCompilErrors, TEXT("FX Compile Error"),
MB_OK|MB_ICONEXCLAMATION);
}
return false;
}
lstrcpy(folder,file);
slash = _tcsrchr(folder,TEXT('\\'));
if(slash)
*(slash+1)=TEXT('\0');
else
*folder=TEXT('\0');
SetCurrentDirectory(S9xGetDirectoryT(DEFAULT_DIR));
for(int i = 0; i < MAX_SHADER_TEXTURES; i++) {
_stprintf(rubyLUTfileName, TEXT("%srubyLUT%d.png"), folder, i);
hr = D3DXCreateTextureFromFile(pDevice,rubyLUTfileName,&rubyLUT[i]);
if FAILED(hr){
rubyLUT[i] = NULL;
}
}
D3DXHANDLE hTech;
effect->FindNextValidTechnique(NULL,&hTech);
effect->SetTechnique( hTech );
shader_type = D3D_SHADER_HLSL;
return true;
}
示例8: create_shader
//.........这里部分代码省略.........
sh_name[len]='0'+char(3==m_skinning); ++len;
if (4==m_skinning) {
defines[def_it].Name = "SKIN_4";
defines[def_it].Definition = "1";
def_it ++;
}
sh_name[len]='0'+char(4==m_skinning); ++len;
// finish
defines[def_it].Name = 0;
defines[def_it].Definition = 0;
def_it ++;
R_ASSERT (def_it<128);
HRESULT _result = E_FAIL;
string_path folder_name, folder;
xr_strcpy ( folder, "r1\\objects\\r1\\" );
xr_strcat ( folder, name );
xr_strcat ( folder, "." );
char extension[3];
strncpy_s ( extension, pTarget, 2 );
xr_strcat ( folder, extension );
FS.update_path ( folder_name, "$game_shaders$", folder );
xr_strcat ( folder_name, "\\" );
m_file_set.clear( );
FS.file_list ( m_file_set, folder_name, FS_ListFiles | FS_RootOnly, "*");
string_path temp_file_name, file_name;
if ( !match_shader_id(name, sh_name, m_file_set, temp_file_name) ) {
string_path file;
xr_strcpy ( file, "shaders_cache\\r1\\" );
xr_strcat ( file, name );
xr_strcat ( file, "." );
xr_strcat ( file, extension );
xr_strcat ( file, "\\" );
xr_strcat ( file, sh_name );
FS.update_path ( file_name, "$app_data_root$", file);
}
else {
xr_strcpy ( file_name, folder_name );
xr_strcat ( file_name, temp_file_name );
}
if (FS.exist(file_name))
{
IReader* file = FS.r_open(file_name);
if (file->length()>4)
{
u32 crc = 0;
crc = file->r_u32();
boost::crc_32_type processor;
processor.process_block ( file->pointer(), ((char*)file->pointer()) + file->elapsed() );
u32 const real_crc = processor.checksum( );
if ( real_crc == crc ) {
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), file_name, result, o.disasm);
}
}
file->close();
}
if (FAILED(_result))
{
includer Includer;
LPD3DXBUFFER pShaderBuf = NULL;
LPD3DXBUFFER pErrorBuf = NULL;
LPD3DXCONSTANTTABLE pConstants = NULL;
LPD3DXINCLUDE pInclude = (LPD3DXINCLUDE)&Includer;
_result = D3DXCompileShader((LPCSTR)pSrcData,SrcDataLen,defines,pInclude,pFunctionName,pTarget,Flags|D3DXSHADER_USE_LEGACY_D3DX9_31_DLL,&pShaderBuf,&pErrorBuf,&pConstants);
if (SUCCEEDED(_result)) {
IWriter* file = FS.w_open(file_name);
boost::crc_32_type processor;
processor.process_block ( pShaderBuf->GetBufferPointer(), ((char*)pShaderBuf->GetBufferPointer()) + pShaderBuf->GetBufferSize() );
u32 const crc = processor.checksum( );
file->w_u32 (crc);
file->w ( pShaderBuf->GetBufferPointer(), (u32)pShaderBuf->GetBufferSize());
FS.w_close (file);
_result = create_shader(pTarget, (DWORD*)pShaderBuf->GetBufferPointer(), pShaderBuf->GetBufferSize(), file_name, result, o.disasm);
}
else {
Log ("! ", file_name);
if ( pErrorBuf )
Log ("! error: ",(LPCSTR)pErrorBuf->GetBufferPointer());
else
Msg ("Can't compile shader hr=0x%08x", _result);
}
}
return _result;
}
示例9: defined
bool CD3D8ShaderMaterialRenderer::createVertexShader(const char* vtxsh, E_VERTEX_TYPE type)
{
if (!vtxsh)
return true;
// compile shader
#if defined( _IRR_XBOX_PLATFORM_)
return false;
#else
LPD3DXBUFFER code = 0;
LPD3DXBUFFER errors = 0;
#ifdef _IRR_D3D_NO_SHADER_DEBUGGING
// compile shader without debug info
D3DXAssembleShader(vtxsh, (UINT)strlen(vtxsh), 0, 0, &code, &errors);
#else
// compile shader and emitt some debug informations to
// make it possible to debug the shader in visual studio
static int irr_dbg_file_nr = 0;
++irr_dbg_file_nr;
char tmp[32];
sprintf(tmp, "irr_d3d8_dbg_shader_%d.vsh", irr_dbg_file_nr);
FILE* f = fopen(tmp, "wb");
fwrite(vtxsh, strlen(vtxsh), 1, f);
fflush(f);
fclose(f);
D3DXAssembleShaderFromFile(tmp, D3DXASM_DEBUG, 0, &code, &errors);
#endif
if (errors)
{
// print out compilation errors.
os::Printer::log("Vertex shader compilation failed:", ELL_ERROR);
os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
if (code)
code->Release();
errors->Release();
return false;
}
DWORD* decl = 0;
DWORD dwStdDecl[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0, D3DVSDT_FLOAT3), // position 0
D3DVSD_REG(1, D3DVSDT_FLOAT3), // normal 1
D3DVSD_REG(2, D3DVSDT_D3DCOLOR ),// color 2
D3DVSD_REG(3, D3DVSDT_FLOAT2 ), // tex1 3
D3DVSD_REG(4, D3DVSDT_FLOAT2 ), // tex2 4
D3DVSD_END()
};
DWORD dwTngtDecl[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0 , D3DVSDT_FLOAT3), // position 0
D3DVSD_REG(1 , D3DVSDT_FLOAT3), // normal 1
D3DVSD_REG(2 , D3DVSDT_D3DCOLOR ),// color 2
D3DVSD_REG(3 , D3DVSDT_FLOAT2 ), // tex1 3
D3DVSD_REG(4, D3DVSDT_FLOAT3 ), // tangent 4
D3DVSD_REG(5, D3DVSDT_FLOAT3 ), // binormal 5
D3DVSD_END()
};
if (type == EVT_TANGENTS)
decl = dwTngtDecl;
else
decl = dwStdDecl;
if (FAILED(pID3DDevice->CreateVertexShader(decl,
(DWORD*)code->GetBufferPointer(), &VertexShader, 0)))
{
os::Printer::log("Could not create vertex shader.", ELL_ERROR);
code->Release();
return false;
}
code->Release();
return true;
#endif
}
示例10: D3DXVECTOR3
bool Box::Init(IDirect3DDevice9* pDevice, float width, float height, float x, float y, D3DCOLOR color)
{
/*VertexData vertex [] =
{
//X Y Z RHW Color
{ D3DXVECTOR3(x, y, 0), 1.0, color },
{ D3DXVECTOR3(x + width, y, 0), 1.0, color },
{ D3DXVECTOR3(x, y + height, 0), 1.0, color },
{ D3DXVECTOR3(x + width, y + height, 0), 1.0, color }
};*/
VertexData vertex[] =
{
//X Y Z RHW Color
{ D3DXVECTOR3(x, y, 0), 1.0, color, D3DXVECTOR2(0.0, 0.0) },
{ D3DXVECTOR3(x + width, y, 0), 1.0, color, D3DXVECTOR2(1.0, 0.0) },
{ D3DXVECTOR3(x, y + height, 0), 1.0, color, D3DXVECTOR2(0.0, 1.0) },
{ D3DXVECTOR3(x + width, y + height, 0), 1.0, color, D3DXVECTOR2(1.0, 1.0) }
};
/*VertexData vertex[] =
{
//X Y Z RHW Color
{ D3DXVECTOR3(x, y, 1), color },
{ D3DXVECTOR3(x + width, y, 1), color },
{ D3DXVECTOR3(x, y + height, 1), color },
{ D3DXVECTOR3(x + width, y + height, 1), color }
};*/
VOID* pVoid = nullptr;
//Set up the vertex buffer
unsigned long vertexSize = 4 * sizeof(VertexData);
if (FAILED(pDevice->CreateVertexBuffer(vertexSize, 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL)))
{
CLog::Write("Box::Init - Couldn't create the vertex buffer");
return false;
}
v_buffer->Lock(0, 0, (void**) &pVoid, 0);
{
memcpy(pVoid, vertex, sizeof(vertex));
}
v_buffer->Unlock();
//Set up the index buffer
short indices [] =
{
0, 1, 2, 3
};
if (FAILED(pDevice->CreateIndexBuffer(4 * sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIndexBuffer, 0)))
{
CLog::Write("Box::Init - Couldn't create the index buffer");
return false;
}
m_pIndexBuffer->Lock(0, 0, (void**) &pVoid, 0);
{
memcpy(pVoid, indices, sizeof(indices));
}
m_pIndexBuffer->Unlock();
//Create the index declaration
D3DVERTEXELEMENT9 decl [] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
D3DDECL_END()
};
if (FAILED(pDevice->CreateVertexDeclaration(decl, &m_pDeclaration)))
return false;
//Create the shader
LPD3DXBUFFER pErr = nullptr;
if (FAILED(D3DXCreateEffectFromResource(pDevice, GetModuleHandle("sampp_client.asi"), MAKEINTRESOURCE(IDR_RCDATA1), 0, 0, 0, 0, &m_pShader, &pErr)))
{
CLog::Write("D3DXCreateEffectFromResource failed: %s", (char*) pErr->GetBufferPointer());
pErr->Release();
pErr = nullptr;
return false;
}
//Create the texture
if (FAILED(D3DXCreateTextureFromFile(pDevice, "rocks.jpg", &m_pTexture)))
{
CLog::Write("D3DXCreateTextureFromFile failed");
return false;
}
//.........这里部分代码省略.........
示例11: D3DXVECTOR3
//.........这里部分代码省略.........
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;
}
示例12: InitDeviceObjects
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMeshRender::InitDeviceObjects()
{
DWORD cVerticesPerMesh;
// Load mesh
LPD3DXBUFFER pAdjacencyBuffer = NULL;
LPDIRECT3DVERTEXBUFFER9 pVertexBuffer = NULL;
LPD3DXMESH pMesh = NULL;
LPD3DXPMESH pPMesh = NULL;
LPD3DXMESH pTempMesh;
LPD3DXBUFFER pD3DXMtrlBuffer = NULL;
void* pVertices;
TCHAR strMediaPath[512];
HRESULT hr;
DWORD dw32BitFlag;
DWORD cVerticesMin;
DWORD cVerticesMax;
DWORD iPMesh;
D3DXWELDEPSILONS Epsilons;
DWORD i;
D3DXMATERIAL* d3dxMaterials;
// Find the path to the mesh
if( FAILED( DXUtil_FindMediaFileCb( strMediaPath, sizeof(strMediaPath), m_strMeshFilename ) ) )
return E_FAIL;//D3DAPPERR_MEDIANOTFOUND;
// Load the mesh from the specified file
if( FAILED( hr = D3DXLoadMeshFromX( strMediaPath, D3DXMESH_MANAGED, m_pd3dDevice,
&pAdjacencyBuffer, &pD3DXMtrlBuffer, NULL,
&m_dwNumMaterials, &pMesh ) ) )
{
// hide error so that device changes will not cause exit, shows blank screen instead
goto End;
}
dw32BitFlag = (pMesh->GetOptions() & D3DXMESH_32BIT);
// perform simple cleansing operations on mesh
if( FAILED( hr = D3DXCleanMesh( pMesh, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), &pTempMesh,
(DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL ) ) )
{
m_dwNumMaterials = 0;
goto End;
}
SAFE_RELEASE(pMesh);
pMesh = pTempMesh;
// Perform a weld to try and remove excess vertices like the model bigship1.x in the DX9.0 SDK (current model is fixed)
// Weld the mesh using all epsilons of 0.0f. A small epsilon like 1e-6 works well too
memset(&Epsilons, 0, sizeof(D3DXWELDEPSILONS));
if( FAILED( hr = D3DXWeldVertices( pMesh, 0, &Epsilons,
(DWORD*)pAdjacencyBuffer->GetBufferPointer(),
(DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL ) ) )
{
m_dwNumMaterials = 0;
goto End;
}
// verify validity of mesh for simplification
if( FAILED( hr = D3DXValidMesh( pMesh, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL ) ) )
{
m_dwNumMaterials = 0;
goto End;
}
// Allocate a material/texture arrays
d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
m_mtrlMeshMaterials = new D3DMATERIAL9[m_dwNumMaterials];
m_pMeshTextures = new LPDIRECT3DTEXTURE9[m_dwNumMaterials];
// Copy the materials and load the textures
for( i=0; i<m_dwNumMaterials; i++ )
{
m_mtrlMeshMaterials[i] = d3dxMaterials[i].MatD3D;
m_mtrlMeshMaterials[i].Ambient = m_mtrlMeshMaterials[i].Diffuse;
// Find the path to the texture and create that texture
DXUtil_FindMediaFileCb( strMediaPath, sizeof(strMediaPath), d3dxMaterials[i].pTextureFilename );
if( FAILED( D3DXCreateTextureFromFile( m_pd3dDevice, strMediaPath,
&m_pMeshTextures[i] ) ) )
m_pMeshTextures[i] = NULL;
}
pD3DXMtrlBuffer->Release();
pD3DXMtrlBuffer = NULL;
// Lock the vertex buffer, to generate a simple bounding sphere
hr = pMesh->GetVertexBuffer( &pVertexBuffer );
if( FAILED(hr) )
goto End;
hr = pVertexBuffer->Lock( 0, 0, &pVertices, D3DLOCK_NOSYSLOCK );
if( FAILED(hr) )
goto End;
hr = D3DXComputeBoundingSphere( (D3DXVECTOR3*)pVertices, pMesh->GetNumVertices(),
//.........这里部分代码省略.........
示例13: Objects_Init
//-----------------------------------【Object_Init( )函数】--------------------------------------
// 描述:渲染资源初始化函数,在此函数中进行要被渲染的物体的资源的初始化
//--------------------------------------------------------------------------------------------------
HRESULT Objects_Init(HWND hwnd)
{
//创建字体
if(FAILED(D3DXCreateFont(g_pd3dDevice, 36, 0, 0, 1000, false, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("Calibri"), &g_pTextFPS)))
return E_FAIL;
if (FAILED(D3DXCreateFont(g_pd3dDevice, 20, 0, 1000, 0, false, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("华文中宋"), &g_pTextAdaperName)))
return E_FAIL;
if (FAILED(D3DXCreateFont(g_pd3dDevice, 23, 0, 1000, 0, false, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("微软雅黑"), &g_pTextHelper)))
return E_FAIL;
if (FAILED(D3DXCreateFont(g_pd3dDevice, 26, 0, 1000, 0, false, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, _T("黑体"), &g_pTextInfo)))
return E_FAIL;
LPD3DXBUFFER pAdjBuffer = NULL;
LPD3DXBUFFER pMtrlBuffer = NULL;
if (FAILED(D3DXLoadMeshFromX(L"Warden.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh)))
//if (FAILED(D3DXLoadMeshFromX(L"miki.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh)))
//if (FAILED(D3DXLoadMeshFromX(L"65.X", D3DXMESH_MANAGED, g_pd3dDevice, &pAdjBuffer, &pMtrlBuffer, NULL, &g_dwNumMtrls, &g_pMesh)))
return E_FAIL;
D3DXMATERIAL *pMtrls = (D3DXMATERIAL *)pMtrlBuffer->GetBufferPointer();
g_pMaterials = new D3DMATERIAL9[g_dwNumMtrls];
g_pTextures = new LPDIRECT3DTEXTURE9[g_dwNumMtrls];
for (DWORD i = 0; i < g_dwNumMtrls; i++)
{
g_pMaterials[i] = pMtrls[i].MatD3D;
g_pMaterials[i].Ambient = g_pMaterials[i].Diffuse;
g_pMaterials[i].Diffuse.a = 0.3f;
g_pTextures[i] = NULL;
//D3DXCreateTextureFromFileA(g_pd3dDevice, pMtrls[i].pTextureFilename, &g_pTextures[i]);
}
SAFE_RELEASE(pAdjBuffer);
SAFE_RELEASE(pMtrlBuffer);
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
light.Specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
light.Direction = D3DXVECTOR3(1.0f, 0.0f, 1.0f);
g_pd3dDevice->SetLight(0, &light);
g_pd3dDevice->LightEnable(0, true);
g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
g_pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, true);
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
Matrix_Set();
return S_OK;
}
示例14: defined
bool CD3D9HLSLMaterialRenderer::createHLSLPixelShader(const char* pixelShaderProgram,
const char* shaderEntryPointName,
const char* shaderTargetName)
{
if (!pixelShaderProgram)
return true;
LPD3DXBUFFER buffer = 0;
LPD3DXBUFFER errors = 0;
DWORD flags = 0;
#ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY
if (Driver->queryFeature(video::EVDF_VERTEX_SHADER_2_0) || Driver->queryFeature(video::EVDF_VERTEX_SHADER_3_0))
// this one's for newer DX SDKs which don't support ps_1_x anymore
// instead they'll silently compile 1_x as 2_x when using this flag
flags |= D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY;
#endif
#if defined(_IRR_D3D_USE_LEGACY_HLSL_COMPILER) && defined(D3DXSHADER_USE_LEGACY_D3DX9_31_DLL)
#ifdef D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY
else
#endif
flags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL;
#endif
#ifdef _IRR_D3D_NO_SHADER_DEBUGGING
// compile without debug info
HRESULT h = stubD3DXCompileShader(
pixelShaderProgram,
strlen(pixelShaderProgram),
0, // macros
0, // no includes
shaderEntryPointName,
shaderTargetName,
flags,
&buffer,
&errors,
&PSConstantsTable);
#else
// compile shader and emitt some debug informations to
// make it possible to debug the shader in visual studio
static int irr_dbg_hlsl_file_nr = 0;
++irr_dbg_hlsl_file_nr;
char tmp[32];
sprintf(tmp, "irr_d3d9_dbg_hlsl_%d.psh", irr_dbg_hlsl_file_nr);
FILE* f = fopen(tmp, "wb");
fwrite(pixelShaderProgram, strlen(pixelShaderProgram), 1, f);
fflush(f);
fclose(f);
HRESULT h = stubD3DXCompileShaderFromFile(
tmp,
0, // macros
0, // no includes
shaderEntryPointName,
shaderTargetName,
flags | D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION,
&buffer,
&errors,
&PSConstantsTable);
#endif
if (FAILED(h))
{
os::Printer::log("HLSL pixel shader compilation failed:", ELL_ERROR);
if (errors)
{
os::Printer::log((c8*)errors->GetBufferPointer(), ELL_ERROR);
errors->Release();
if (buffer)
buffer->Release();
}
return false;
}
if (errors)
errors->Release();
if (buffer)
{
if (FAILED(pID3DDevice->CreatePixelShader((DWORD*)buffer->GetBufferPointer(),
&PixelShader)))
{
os::Printer::log("Could not create hlsl pixel shader.", ELL_ERROR);
buffer->Release();
return false;
}
buffer->Release();
return true;
}
return false;
}
示例15: InitVertexShader
bool InitVertexShader()
{
#if DIRECTX_VERSION == 8
// shader decl
DWORD decl[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0, D3DVSDT_FLOAT3 ), // D3DVSDE_POSITION
D3DVSD_REG(1, D3DVSDT_FLOAT3 ), // D3DVSDE_NORMAL
D3DVSD_REG(2, D3DVSDT_D3DCOLOR ), // D3DVSDE_DIFFUSE
D3DVSD_REG(3, D3DVSDT_FLOAT2 ), // D3DVSDE_TEXCOORD0
D3DVSD_END()
};
#else
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 28, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
#endif
LPD3DXBUFFER pCode;
LPD3DXBUFFER ppCompilationErrors;
HRESULT res;
#ifdef _DEBUG
#if DIRECTX_VERSION == 8
LPD3DXBUFFER ppConstants;
res = D3DXAssembleShaderFromFile("shader.vsh", D3DXASM_DEBUG, &ppConstants, &pCode, &ppCompilationErrors);
#else
res = D3DXAssembleShaderFromFileA("D:\\n64developing\\RiceVideo\\shaderdx9.vsh", NULL, NULL, D3DXSHADER_DEBUG, &pCode, &ppCompilationErrors);
//res = D3DXAssembleShaderFromFileA("D:\\n64developing\\RiceVideo\\shaderdx9-2.vsh", NULL, NULL, D3DXSHADER_DEBUG, &pCode, &ppCompilationErrors);
#endif
#else
#if DIRECTX_VERSION == 8
LPD3DXBUFFER ppConstants;
res = D3DXAssembleShader(shaderstr, strlen(shaderstr), 0, &ppConstants, &pCode, &ppCompilationErrors);
#else
res = D3DXAssembleShader(shaderstr2, strlen(shaderstr2), NULL, NULL, D3DXSHADER_DEBUG, &pCode, &ppCompilationErrors);
#endif
#endif
if( CDXGraphicsContext::IsResultGood(res,true) )
{
#if DIRECTX_VERSION == 8
res = g_pD3DDev->CreateVertexShader( decl, (DWORD*)pCode->GetBufferPointer(), &gVertexShader, 0 );
#else
res = g_pD3DDev->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(), &gVertexShader );
//FILE *fp = fopen("D:\\n64developing\\RiceVideo\\shaderdx9.vso","rb");
//BYTE buf[4000];
//int num = fread(buf, 1, 4000, fp);
//res = g_pD3DDev->CreateVertexShader( (DWORD*)buf, &gVertexShader );
//fclose(fp);
#endif
pCode->Release();
if( !CDXGraphicsContext::IsResultGood(res,true) )
return false;
res = g_pD3DDev->SetVertexShader( gVertexShader );
InitVertexShaderConstants();
return true;
}
else
{
if( ppCompilationErrors )
{
char* str = (char*)(ppCompilationErrors->GetBufferPointer());
TRACE0(str);
}
return false;
}
}