Beispiel #1
0
        static void createVS( 
            unsigned int target,
            const ShaderScripts& ss, 
            nlEngineContext& cxt )
        {
            const ShaderScript& shaderScript = ss.vsScripts.scripts[target];
            const nlInt8* script   = shaderScript.script;
            const nlInt8* funcName = "main";
            const nlInt8* unitName = shaderScript.name;
            nlVertexShader& vs = cxt.vss[target];
            NL_ASSERT( !vs.shader_ );
            /**/
            ID3DBlob* pBlob = NULL;
            ID3DBlob* pErrorBlob = NULL;
            /* commonと連結 */
            const nlInt8* commonScript = ss.commonScripts.script;
            const nlUint32 scriptLen = nlStrlen( script ) + nlStrlen( commonScript );
            nlInt8* conbinedScript = (nlInt8*)nlMalloc( (scriptLen+1)*sizeof(nlInt8) );
            nlStrcat( conbinedScript, commonScript );
            nlStrcat( conbinedScript, script );

            //printf( conbinedScript );

#ifndef INTROMODE
            const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
            HRESULT hr = D3D10CompileShader( conbinedScript, nlStrlen(conbinedScript), unitName, shaderMacros, NULL, funcName, "vs_4_0", flag, &pBlob, &pErrorBlob );
            /* ロードが失敗したらエラーを出力した後に確実にロードが成功するシェーダをロードする */
            if(FAILED( hr ) )
            {
                /**/
                NL_ERR( ERR_005, (nlInt8*)pErrorBlob->GetBufferPointer() );
                /**/
                const nlInt8 script[] =
                {
                    "cbuffer Const0 : register(b0){ f4x4 world; }"
                    "cbuffer Const2 : register(b2){ f4x4 viewProj; }"
                    "float4 main( float4 in_pos:P, float4 in_normal:N, float4 in_col:C ):SV_POSITION"
                    "{ return mul( in_pos, mul(world,viewProj)); }"
                };
                HRESULT hr = D3D10CompileShader( script, sizeof(script)/sizeof(nlInt8), unitName, shaderMacros, NULL, "main", "vs_4_0", flag, &pBlob, &pErrorBlob );
            }
#else
            const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR | D3D10_SHADER_OPTIMIZATION_LEVEL3;
            HRESULT hr = D3DX11CompileFromMemory( conbinedScript, nlStrlen(conbinedScript), funcName, shaderMacros, NULL, funcName, "vs_4_0", flag, 0, NULL, &pBlob, &pErrorBlob, NULL );
            if(FAILED( hr ) )
            {
                MessageBoxA(NULL,(nlInt8*)pErrorBlob->GetBufferPointer(),"",MB_OK);
            }
#endif
            /**/
            nlFree( (void*)conbinedScript );
            /* create shader */
            NL_HR_VALID( cxt.d3dDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &vs.shader_ ) );
            /* create inputlayout */
            NL_HR_VALID( cxt.d3dDevice->CreateInputLayout(NLM_INPUT_ELEMENT, _countof(NLM_INPUT_ELEMENT), pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &vs.inputLayout_  ) );
        }
Beispiel #2
0
/* @NOTE この関数は近い将来撤去されます */
nlPixelShader nlCreatePixelShader( 
                                  const nlInt8* script, 
                                  unsigned int scriptSize, 
                                  const nlInt8* funcName,
                                  nlEngineContext& cxt )
{
    ID3DBlob* pBlob = NULL;
    ID3DBlob* pErrorBlob = NULL;
    nlPixelShader pixelShader;
    pixelShader.shader_ = NULL;
#ifndef INTROMODE
    const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
    HRESULT hr = D3D10CompileShader( script, scriptSize, funcName, shaderMacros, NULL, funcName, "ps_4_0", flag, &pBlob, &pErrorBlob );
    if( FAILED(hr) )
    {
        std::string error = std::string("[")+std::string(funcName)+std::string("]")+std::string(DXGetErrorDescriptionA(hr));
        error.resize(error.size()-1);/* 改行コードを取り除く */
        if(pErrorBlob)
        { 
            error += std::string( (nlInt8*)pErrorBlob->GetBufferPointer() );
            error.resize(error.size()-1);/* 改行コードを取り除く */
        }
        NL_ERR( ERR_018, error.c_str() );
        /* ファイルに書き出す */
        QString fileName;
        QTime now = QDateTime::currentDateTime().time();
        fileName.sprintf("err_%s_%d_%d_d.log",funcName,now.hour(),now.minute(),now.second() );
        QString path = sandboxPath(SP_APP)+fileName;
        QFile dataFile(path);
        dataFile.open(QIODevice::WriteOnly|QIODevice::Text);
        dataFile.write( script );
        /**/
        pixelShader.shader_ = NULL;
        return pixelShader;
    }
#else
    const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR|D3D10_SHADER_OPTIMIZATION_LEVEL3;
    HRESULT hr = D3D10CompileShader( script, scriptSize, funcName, shaderMacros, NULL, funcName, "ps_4_0", flag, &pBlob, &pErrorBlob );
    if( FAILED(hr) )
    {
        MessageBox( NULL, (nlInt8*)pErrorBlob->GetBufferPointer(), "", MB_OK );
    }
#endif
    NL_HR_VALID( cxt.d3dDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &pixelShader.shader_ ) );

    return pixelShader;
}
Beispiel #3
0
EResult CompileShader(
	const char *	szFileName,
	const char *	szSource,
	const char *	szEntryPoint,
	const char *	szProfile,
	ID3D10Blob **	ppShaderByteCode )
{
	if ( ( NULL == szFileName ) || ( NULL == szSource ) || ( NULL == ppShaderByteCode ) )
		return R_INVALID_ARG;

	size_t nSize = strlen( szSource );

	if ( 0 == nSize )
		return R_INVALID_ARG;

	ID3D10Blob * pErrorMsg = NULL;

	HRESULT hRes = D3D10CompileShader(
		szSource,			// file data
		nSize,				// file data size
		NULL,				// file name (set to null if prev args not null)
		NULL,				// macro array (defines)
		NULL,				// ? include
		szEntryPoint,
		szProfile,
		0,					// shader compile flags
		ppShaderByteCode,	
		&pErrorMsg );

	if ( FAILED( hRes ) )
	{
		if ( NULL != pErrorMsg )
		{
			const char * szErr = Va(
				"\tShader compilation failed, file \"%s\"\n\t\t%s",
				szFileName, (const char *)pErrorMsg->GetBufferPointer() );

			SysWrite( szErr );
			DEBUG_MSG( szErr );
		}

		return R_GENERIC_ERROR;
	}

	return R_OK;
}
Beispiel #4
0
	//inizializza
	void ShaderDX::loadShader(bool  geometry, 
							  const Utility::Path& vs,
							  const Utility::Path& ps, 
							  const Utility::Path& gs,
		                      const std::vector<String>& defines){

		HRESULT hr = NULL;
		DWORD vShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
		//vShaderFlags |= D3D10_SHADER_DEBUG;
		//vShaderFlags |= D3D10_SHADER_FORCE_VS_SOFTWARE_NO_OPT;
#endif

		String vShaderFile = textFileRead(vs);
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		ID3D10Blob* vErrors = NULL;
		hr = D3D10CompileShader(vShaderFile, vShaderFile.size(), String(vs.getFilename()), NULL, NULL, "main", "vs_4_0", vShaderFlags, &vShaderBinary, &vErrors);
		dxShaderError(vErrors);
		DX_ASSERT_MSG(hr);
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		DX_ASSERT_MSG(render->d3dDevice->CreateVertexShader((DWORD*)vShaderBinary->GetBufferPointer(), vShaderBinary->GetBufferSize(), &vShader));
		getContants(render->d3dDevice, "vs", vVariablesRef, vShaderBinary, &vConstantBuffer10, vSizeConstantBuffer);
		getResources(render->d3dDevice, "vs", vResourcesRef, vSamplerRef, vShaderBinary);
		if (vSizeConstantBuffer)
			vBufferCpu.resize(vSizeConstantBuffer);
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		DWORD pShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
		//pShaderFlags |= D3D10_SHADER_DEBUG;
		//pShaderFlags |= D3D10_SHADER_FORCE_PS_SOFTWARE_NO_OPT;
#endif
		String pShaderFile = textFileRead(ps);
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		ID3D10Blob* pErrors = NULL;
		hr = D3D10CompileShader(pShaderFile, pShaderFile.size(), String(ps.getFilename()), NULL, NULL, "main", "ps_4_0", pShaderFlags, &pShaderBinary, &pErrors);
		dxShaderError(pErrors);
		DX_ASSERT_MSG(hr);
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		DX_ASSERT_MSG(render->d3dDevice->CreatePixelShader((DWORD*)pShaderBinary->GetBufferPointer(), pShaderBinary->GetBufferSize(), &pShader));
		getContants(render->d3dDevice, "ps", pVariablesRef, pShaderBinary, &pConstantBuffer10, pSizeConstantBuffer);
		getResources(render->d3dDevice, "ps", pResourcesRef, pSamplerRef, pShaderBinary);
		if (pSizeConstantBuffer)
			pBufferCpu.resize(pSizeConstantBuffer);
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (geometry){
			DWORD gShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
			#if defined( DEBUG ) || defined( _DEBUG )
			//gShaderFlags |= D3D10_SHADER_DEBUG;
			//gShaderFlags |= D3D10_SHADER_FORCE_PS_SOFTWARE_NO_OPT;
			#endif
			String gShaderFile = textFileRead(gs);
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			ID3D10Blob* gErrors = NULL;
			hr = D3D10CompileShader(gShaderFile, gShaderFile.size(), String(gs.getFilename()), NULL, NULL, "main", "gs_4_0", gShaderFlags, &gShaderBinary, &gErrors);
			dxShaderError(gErrors);
			DX_ASSERT_MSG(hr);
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			DX_ASSERT_MSG(render->d3dDevice->CreateGeometryShader((DWORD*)gShaderBinary->GetBufferPointer(), gShaderBinary->GetBufferSize(), &gShader));
			getContants(render->d3dDevice, "gs", gVariablesRef, gShaderBinary, &gConstantBuffer10, gSizeConstantBuffer);
			getResources(render->d3dDevice, "gs", gResourcesRef, gSamplerRef, gShaderBinary);
			if (gSizeConstantBuffer)
				gBufferCpu.resize(gSizeConstantBuffer);
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		}
	}
Beispiel #5
0
        /* PSの生成 */
        static void createPS(
            unsigned int target,
            const ShaderScripts& ss,
            nlEngineContext& cxt )
        {
            /**/
            ID3DBlob* pBlob = NULL;
            ID3DBlob* pErrorBlob = NULL;
            nlPixelShader& pixelShader = cxt.pss[target];
            const nlInt8* script = ss.psScripts.scripts[target].script;
            const nlInt8* funcName = "main";

            /**/
            NL_ASSERT(!pixelShader.shader_);

            /* commonと連結 */
            const nlInt8* commonScript = ss.commonScripts.script;
            const unsigned int scriptLen = nlStrlen( script ) + nlStrlen( commonScript );
            nlInt8* conbinedScript = (nlInt8*)nlMalloc( (scriptLen+1)*sizeof(nlInt8) );
            nlStrcat( conbinedScript, commonScript );
            nlStrcat( conbinedScript, script );

#ifndef INTROMODE
            const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
            HRESULT hr = D3D10CompileShader( conbinedScript, nlStrlen(conbinedScript), funcName, shaderMacros, NULL, funcName, "ps_4_0", flag, &pBlob, &pErrorBlob );
            if( SUCCEEDED(hr) )
            {
                if( SUCCEEDED( cxt.d3dDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &pixelShader.shader_ ) ) )
                { return ;}
                else
                {
                    NL_ASSERT(!"このパスには来ないことになっている");
                    //goto RELOAD;
                    return ;
                }
            }
            else
            {
                /* 失敗した場合はエラーを出力し確実に成功するシェーダをロードする */
                const nlInt8* name = ss.psScripts.scripts[target].name;
                std::string error = std::string("[")+std::string(name)+std::string("]")+std::string(DXGetErrorDescriptionA(hr));
                error.resize(error.size()-1);/* 改行コードを取り除く */
                if(pErrorBlob)
                { 
                    error += std::string( (nlInt8*)pErrorBlob->GetBufferPointer() );
                    error.resize(error.size()-1);/* 改行コードを取り除く */
                }
                NL_ERR( ERR_006, error.c_str());
                /**/
                const nlInt8 script[] = 
                {
                    "float4 main():SV_Target0"
                    "{return float4(1,0,0,1);}"
                };
                pixelShader = nlCreatePixelShader(script, sizeof(script)/sizeof(nlInt8), "main", cxt );
            }
            return;

#else
            const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR | D3D10_SHADER_OPTIMIZATION_LEVEL3;
            HRESULT hr = D3D10CompileShader( conbinedScript, nlStrlen(conbinedScript), funcName, shaderMacros, NULL, funcName, "ps_4_0", flag, &pBlob, &pErrorBlob );
            if( FAILED(hr) )
            {
                MessageBox( NULL, "failed to load pixel shader", "", MB_OK );
                if(pErrorBlob)
                {
                    MessageBox( NULL, (nlInt8*)pErrorBlob->GetBufferPointer(), "", MB_OK );
                }
                return;
            }
            NL_HR_VALID( cxt.d3dDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &pixelShader.shader_ ) );
#endif
        }
Beispiel #6
0
        /* GSの生成 */
        static void createGS(
            nlUint32 target,
            const ShaderScripts& ss,
            nlEngineContext& cxt )
        {
           /**/
            ID3DBlob* pBlob = NULL;
            ID3DBlob* pErrorBlob = NULL;
            nlGeometoryShader& geometoryShader = cxt.gss[target];
            const nlInt8* script = ss.gsScripts.scripts[target].script;
            const nlInt8* funcName = "main";
            /**/
            NL_ASSERT(!geometoryShader.shader);
            /* commonと連結 */
            const nlInt8* commonScript = ss.commonScripts.script;
            const nlUint32 scriptLen = nlStrlen( script ) + nlStrlen( commonScript );
            nlInt8* conbinedScript = (nlInt8*)nlMalloc( (scriptLen+1)*sizeof(nlInt8) );
            nlStrcat( conbinedScript, commonScript );
            nlStrcat( conbinedScript, script );

#ifndef INTROMODE
            const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
			HRESULT hr = D3D10CompileShader(
				conbinedScript, nlStrlen(conbinedScript), 
				funcName, shaderMacros, NULL, 
				funcName, "gs_4_0", flag, &pBlob, &pErrorBlob);
			
            if( SUCCEEDED(hr) )
            {
                if( SUCCEEDED( cxt.d3dDevice->CreateGeometryShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &geometoryShader.shader ) ) )
                { return ;}
                else
                {
                    NL_ASSERT(!"このパスには来ないことになっている");
                    //goto RELOAD;
                    return ;
                }
            }
            else
            {
                /* 失敗した場合はエラーを出力し確実に成功するシェーダをロードする */
                const nlInt8* name = ss.gsScripts.scripts[target].name;
                std::string error = std::string("[")+std::string(name)+std::string("]")+std::string(DXGetErrorDescriptionA(hr));
                error.resize(error.size()-1);/* 改行コードを取り除く */
                if(pErrorBlob)
                {
                    error += std::string( (nlInt8*)pErrorBlob->GetBufferPointer() );
                    error.resize(error.size()-1);/* 改行コードを取り除く */
                }
                NL_ERR( ERR_006, error.c_str());
                /**/
                const nlInt8 script[] = 
                {
                    "struct GSSceneIn\n"
                    "{\n"
                    "   float4 Pos	: POS;\n"
	                "   float3 Norm : NORMAL;\n"
	                "   float2 Tex	: TEXCOORD0;\n"
                    "};\n"
                    "struct PSSceneIn\n"
                    "{\n"
                    "	float4 Pos  : SV_Position;\n"
                    "   float3 Norm : TEXCOORD0;\n"
                    "   float2 Tex  : TEXCOORD1;\n"
                    "};\n"
                    "[maxvertexcount(3)]\n"
                    "void GSScene( triangleadj GSSceneIn input[6], inout TriangleStream<PSSceneIn> OutputStream )\n"
                    "{\n"
                    "   PSSceneIn output = (PSSceneIn)0;\n"
                    "   for( uint i=0; i<6; i+=2 )\n"
                    "   {\n"
                    "       output.Pos = input[i].Pos;\n"
                    "       output.Norm = input[i].Norm;\n"
                    "       output.Tex = input[i].Tex;\n"
                    "       OutputStream.Append( output );\n"
                    "   }\n"
                    "   OutputStream.RestartStrip();\n"
                    "}\n"
                };
                geometoryShader = nlCreateGeometoryShader(script, sizeof(script)/sizeof(nlInt8), "main", cxt );
            }
            return;

#else
            const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR | D3D10_SHADER_OPTIMIZATION_LEVEL3;
            HRESULT hr = D3D10CompileShader( conbinedScript, nlStrlen(conbinedScript), funcName, shaderMacros, NULL, funcName, "gs_4_0", flag, &pBlob, &pErrorBlob );
            if( FAILED(hr) )
            {
                MessageBox( NULL, "failed to load geometory shader", "", MB_OK );
                if(pErrorBlob)
                {
                    MessageBox( NULL, (nlInt8*)pErrorBlob->GetBufferPointer(), "", MB_OK );
                }
                return;
            }
            NL_HR_VALID( cxt.d3dDevice->CreateGeometryShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &geometoryShader.shader ) );
#endif
        }
Beispiel #7
0
/* @NOTE この関数は近い将来撤去されます */
nlVertexShader nlCreateVertexShader(
                                    const nlInt8* script, 
                                    unsigned int scriptSize, 
                                    const nlInt8* funcName,
                                    nlEngineContext& cxt )
{
    struct GOD_VERTEX
    {
        nlVec4    pos_;
        nlVec4    normal_;
        nlVec4    uv_;
        D3DCOLOR  color_;
    };

    ID3DBlob* pBlob = NULL;
    ID3DBlob* pErrorBlob = NULL;
    nlVertexShader vertexShader;
    vertexShader.inputLayout_ = NULL;
    vertexShader.shader_ = NULL;

    
#ifdef INTROMODE
    const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR | D3D10_SHADER_OPTIMIZATION_LEVEL3;
    HRESULT hr = D3D10CompileShader( script, scriptSize, funcName, shaderMacros, NULL, funcName, "vs_4_0", flag, &pBlob, &pErrorBlob );
    if(FAILED( hr ) )
    {
        MessageBoxA(NULL,(nlInt8*)pErrorBlob->GetBufferPointer(),"",MB_OK);
    }
#else 
    const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
    HRESULT hr = D3D10CompileShader( script, scriptSize, funcName, shaderMacros, NULL, funcName, "vs_4_0", flag, &pBlob, &pErrorBlob );
#endif

#ifndef INTROMODE
    if( FAILED(hr) )
    {
        std::string error = std::string("[")+std::string(funcName)+std::string("]")+std::string(DXGetErrorDescriptionA(hr));
        if(pErrorBlob)
        {
            error += std::string( (nlInt8*)pErrorBlob->GetBufferPointer() ); 
            error.resize(error.size()-1);/* 改行コードを取り除く */
        }
        NL_ERR( ERR_005, error.c_str() );
        /* ファイルに書き出す */
        QString fileName;
        QTime now = QDateTime::currentDateTime().time();
        fileName.sprintf("err_%s_%d_%d_d.log",funcName,now.hour(),now.minute(),now.second() );
        QString path = sandboxPath(SP_APP)+fileName;
        QFile dataFile(path);
        dataFile.open(QIODevice::WriteOnly|QIODevice::Text);
        dataFile.write( script );
        /**/
        return vertexShader;
    }
#endif
    /* create shader */
    NL_HR_VALID( cxt.d3dDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &vertexShader.shader_ ) );
    /* create inputlayout */
    NL_HR_VALID( cxt.d3dDevice->CreateInputLayout(NLM_INPUT_ELEMENT, _countof(NLM_INPUT_ELEMENT), pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &vertexShader.inputLayout_  ) );
    /**/
    return vertexShader;
}
Beispiel #8
0
void ntGenerateTextures(const ShaderScripts& shaderScript, 
                        nlEngineContext* cxt )
{
#if 0
    /* この関数が呼ばれる前にテクスチャは解放されている事が期待される */
    for( int i=0;i<MAX_TEXTURE_NUM;++i){ NL_ASSERT( !cxt->texs[i].texture );}
    const ShaderScriptGroup& tsScripts = shaderScript.tsScripts;
    const ShaderScript& commonScrips = shaderScript.commonScripts;
    /**/
    NL_ASSERT( 0 < tsScripts.numScript );
    /**/
    ID3D11Device* d3dDevice = cxt->d3dDevice;
    ID3D11DeviceContext* d3dContext = cxt->d3dContext;

    tsScripts.numScript;
    tsScripts.scripts[0].script;
    tsScripts.scripts[0].name;

    //const nlInt8* script = tsScripts.scripts;
    nlTexture* texuters = &(cxt->texs[0]);
    /**/
    const unsigned int scriptLen = nlStrlen(script);
    /* 全シェーダを作成 */
    ID3D11PixelShader* texturShaders[MAX_TEXTURE_NUM];
    nlMemset( texturShaders, 0, sizeof(ID3D11PixelShader*)*MAX_TEXTURE_NUM );
    /**/
    const unsigned int numTexture = textureScripts.numTexture;
    /**/
    for( unsigned int i=0;i<numTexture;++i)
    {
        ID3DBlob* pBlob = NULL;
        ID3DBlob* pErrorBlob = NULL;
        const nlInt8* funcName = textureScripts.funcs[i];
        const DWORD flag = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
        /* ピクセルシェーダの作成 */
        if( FAILED(
            D3D10CompileShader(
            script, scriptLen, funcName, shaderMacros, NULL, 
           "main", "ps_4_0",flag, &pBlob, &pErrorBlob ) ) )
        {
            NL_ERR(ERR_009);
            MessageBoxA( NULL, "load texshader error", "", MB_OK );
            if(pErrorBlob)
            {
                NL_ERR(ERR_003, pErrorBlob->GetBufferPointer() );
                MessageBoxA( NULL, (nlInt8*)pErrorBlob->GetBufferPointer(), "", MB_OK );
            }
            return;
        }
        if( pBlob )
        {
            d3dDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &texturShaders[i] );
        }
        ++i;
    }

    /* 書きこむのに必要なシェーダを作成 */
    ID3D11VertexShader* vsRenderQuad;
    ID3DBlob* pBlob = NULL;
    ID3DBlob* pErrorBlob = NULL;    

    NL_HR_ASSSERT( D3D10CompileShader(script, scriptLen, "vs", shaderMacros, NULL, 
        "main","vs_4_0",(D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR),
        &pBlob, &pErrorBlob ) ) ;
    d3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &vsRenderQuad );

    /* 全テクスチャを作成 */
    for(unsigned int i=0;i<numTexture;++i)
    {
        /**/
        nlTexture& tex = texuters[i];
        /**/
        tex.width  = 512; /* HACK サイズは適当 */
        tex.height = 512; /* HACK サイズは適当 */
        int mipLevel = 1;
        int CPUAccessFlags = 0;
        D3D11_TEXTURE2D_DESC descTarget = 
        {
            tex.width, tex.height,
            mipLevel, 1,
            DXGI_FORMAT_B8G8R8A8_UNORM,
            {1,0}, D3D11_USAGE_DEFAULT,
            (D3D11_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE),
            CPUAccessFlags, 0
        };
        d3dDevice->CreateTexture2D( &descTarget, NULL, &tex.texture );
        d3dDevice->CreateRenderTargetView( tex.texture, NULL, &tex.rtView );
        d3dDevice->CreateShaderResourceView( tex.texture, NULL ,&tex.shaderView );
    }

    /* 現在のRasterStateを取得 */
    ID3D11RasterizerState* oldRasterState;
    d3dContext->RSGetState(&oldRasterState);
    /**/
    D3D11_RASTERIZER_DESC rasterDesc;
    rasterDesc.AntialiasedLineEnable = false;
    rasterDesc.CullMode = D3D11_CULL_NONE;
    rasterDesc.DepthBias = 0;
    rasterDesc.DepthBiasClamp = 0.0f;
    rasterDesc.DepthClipEnable = true;
    rasterDesc.FillMode = D3D11_FILL_SOLID;
    rasterDesc.FrontCounterClockwise = false;
    rasterDesc.MultisampleEnable = false;
    rasterDesc.ScissorEnable = false;
    rasterDesc.SlopeScaledDepthBias = 0.0f;
    ID3D11RasterizerState* rasterState;
    d3dDevice->CreateRasterizerState(&rasterDesc, &rasterState);
    d3dContext->RSSetState(rasterState);
    rasterState->Release();

    /* 全テクスチャを焼き込む */
    for(unsigned int i=0;i<numTexture;++i)
    {
        /**/
        nlTexture& tex = texuters[i];
        /* ビューポートの設定 */
        D3D11_VIEWPORT viewport;
        viewport.Width = tex.width;
        viewport.Height = tex.height;
        viewport.MinDepth = 0.0f;
        viewport.MaxDepth = 1.0f;
        viewport.TopLeftX = 0.0f;
        viewport.TopLeftY = 0.0f;
        d3dContext->RSSetViewports(1, &viewport);
        /* シェーダを設定する */
        d3dContext->VSSetShader( vsRenderQuad, NULL, 0);
        d3dContext->PSSetShader( texturShaders[i], NULL, 0);
        /* レンダーターゲットを設定する */
        const float clearColor[4] = {0.0f, 0.0f, 1.0f, 0.0f};
        d3dContext->ClearRenderTargetView( tex.rtView, clearColor );
        d3dContext->OMSetRenderTargets( 1, &tex.rtView, NULL );

        /* 全てのテクスチャを設定する */
        /* TODO 毎回全てのテクスチャを設定せずに、このループで設定したテクスチャを省くようにだけする?*/
        for( unsigned int j=0;j<numTexture;++j)
        {
            if( i != j )
            {
                nlTexture& texSamp = texuters[j];
                d3dContext->PSSetShaderResources(j, 1, &texSamp.shaderView );
            }
        }

        /* 描画する */
        d3dContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
        d3dContext->Draw( 4, 0 );
    }
    /**/
    d3dContext->VSSetShader( NULL, NULL, 0);
    d3dContext->PSSetShader( NULL, NULL, 0);

    /* ビューポート設定を元に戻す */
    /* 現在のビューポート設定を取得しておく */
    D3D11_VIEWPORT oldViewports = {0.0,0.0,cxt->rendertargets[0].width_,cxt->rendertargets[0].height_,0.0f,1.0f};
    d3dContext->RSSetViewports( 1, &oldViewports );

    /* RasterState設定を元に戻す */
    d3dContext->RSSetState(oldRasterState);
    if( oldRasterState ){ oldRasterState->Release(); }

    /* PSを解放 */
    for(unsigned int i=0;i<numTexture;++i)
    {
        if( texturShaders[i] ){ texturShaders[i]->Release(); }
    }
#endif
}