+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-\r
-#include <d3d10.h>\r
-#include <d3dx10.h>\r
-#include <vcclr.h>\r
-\r
-#include "Direct3D10Exception.h"\r
-\r
-#include "../DataStream.h"\r
-#include "EffectPool.h"\r
-#include "Device10.h"\r
-#include "Effect10.h"\r
-\r
-using namespace System;\r
-using namespace System::IO;\r
-\r
-using namespace SlimDX::D3DCompiler;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D10\r
-{ \r
- Effect^ EffectPool::AsEffect()\r
- {\r
- ID3D10Effect* effect = InternalPointer->AsEffect();\r
- if( effect == 0 )\r
- return nullptr;\r
- return Effect::FromPointer( effect, this, ComObjectFlags::IsAncillary );\r
- }\r
-\r
- EffectPool^ EffectPool::FromFile( Device^ device, String^ fileName, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags )\r
- {\r
- String^ compilationErrors;\r
- return (FromFile( device, fileName, profile, shaderFlags, effectFlags, compilationErrors ));\r
- }\r
- \r
- EffectPool^ EffectPool::FromFile( Device^ device, String^ fileName, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, [Out] String^ %compilationErrors )\r
- {\r
- pin_ptr<const wchar_t> pinnedFileName = PtrToStringChars( fileName );\r
- array<unsigned char>^ profileBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( profile );\r
- pin_ptr<unsigned char> pinnedProfile = &profileBytes[0];\r
- ID3D10EffectPool* effectPool;\r
- ID3D10Blob* errorBlob;\r
-\r
- HRESULT hr = D3DX10CreateEffectPoolFromFile( pinnedFileName, NULL, NULL, reinterpret_cast<LPCSTR>( pinnedProfile ),\r
- static_cast<UINT>(shaderFlags), static_cast<UINT>(effectFlags ), device->InternalPointer,\r
- NULL, &effectPool, &errorBlob, NULL );\r
-\r
- if( errorBlob != 0 )\r
- {\r
- compilationErrors = gcnew String( reinterpret_cast<const char*>( errorBlob->GetBufferPointer() ) );\r
- errorBlob->Release();\r
- }\r
- else\r
- {\r
- compilationErrors = String::Empty;\r
- }\r
- \r
- RECORD_D3D10( hr );\r
- if( effectPool == NULL)\r
- return nullptr;\r
- return gcnew EffectPool( effectPool, nullptr );\r
- }\r
- \r
- EffectPool^ EffectPool::FromStream( Device^ device, Stream^ stream, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags )\r
- {\r
- String^ compilationErrors;\r
- return FromStream( device, stream, profile, shaderFlags, effectFlags, compilationErrors );\r
- }\r
- \r
- EffectPool^ EffectPool::FromStream( Device^ device, Stream^ stream, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, [Out] String^ %compilationErrors )\r
- {\r
- DataStream^ ds = nullptr;\r
- array<Byte>^ memory = Utilities::ReadStream( stream, &ds );\r
-\r
- if( memory == nullptr )\r
- {\r
- SIZE_T size = static_cast<SIZE_T>( ds->RemainingLength );\r
- return FromMemory_Internal( device, ds->SeekToEnd(), size,\r
- profile, shaderFlags, effectFlags, compilationErrors );\r
- }\r
-\r
- return FromMemory( device, memory, profile, shaderFlags, effectFlags, compilationErrors );\r
- }\r
- \r
- EffectPool^ EffectPool::FromMemory( Device^ device, array<Byte>^ memory, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags )\r
- {\r
- String^ compilationErrors;\r
- return FromMemory( device, memory, profile, shaderFlags, effectFlags, compilationErrors );\r
- }\r
-\r
- EffectPool^ EffectPool::FromMemory_Internal( Device^ device, const void* data, SIZE_T size, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, [Out] String^ %compilationErrors )\r
- {\r
- ID3D10EffectPool* effectPool;\r
- ID3D10Blob* errorBlob;\r
- \r
- array<unsigned char>^ profileBytes = System::Text::ASCIIEncoding::ASCII->GetBytes( profile );\r
- pin_ptr<unsigned char> pinnedProfile = &profileBytes[0];\r
-\r
- HRESULT hr = D3DX10CreateEffectPoolFromMemory( data, size, "<no file name>", NULL, NULL,\r
- reinterpret_cast<LPCSTR>( pinnedProfile ), static_cast<UINT>(shaderFlags), static_cast< UINT>(effectFlags ), device->InternalPointer,\r
- NULL, &effectPool, &errorBlob, NULL );\r
-\r
- if( errorBlob != 0 )\r
- {\r
- compilationErrors = gcnew String( reinterpret_cast<const char*>( errorBlob->GetBufferPointer() ) );\r
- errorBlob->Release();\r
- }\r
- else\r
- {\r
- compilationErrors = String::Empty;\r
- }\r
- \r
- RECORD_D3D10( hr );\r
- if( effectPool == NULL)\r
- return nullptr;\r
- return gcnew EffectPool( effectPool, nullptr );\r
- }\r
- \r
- EffectPool^ EffectPool::FromMemory( Device^ device, array<Byte>^ memory, String^ profile, ShaderFlags shaderFlags, EffectFlags effectFlags, [Out] String^ %compilationErrors )\r
- {\r
- pin_ptr<unsigned char> pinnedData = &memory[0];\r
- return FromMemory_Internal( device, pinnedData, static_cast<SIZE_T>( memory->Length ), profile,\r
- shaderFlags, effectFlags, compilationErrors );\r
- }\r
-}\r
-}\r