zoukankan      html  css  js  c++  java
  • dx11 入门 Tutorial 06: 明白context->updateSubsource和setConstantBuffers DirectXSampleBrowser(June 2010)

    需要明白constantBuffer传入数据到shader的正确使用::

    虽然vs和ps等shader在一个fx中,但需要各自setConstantBuffer进行 常量的读取设置

    如果没有使用到constantBuffer数据,可以不用设置

    记得set前需要update相应的buffer数据

    cb1.vOutputColor = XMFLOAT4(0, 0, 0, 0);
    	g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb1, 0, 0 );
    //更新cube的数据 // // Render the cube // g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 ); g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
    //VS shader里需要constant数据
    g_pImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 ); g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
    //PS shader里传入constant数据
    g_pImmediateContext->DrawIndexed( 36, 0, 0 ); // // Render each light // for( int m = 0; m < 2; m++ ) { XMMATRIX mLight = XMMatrixTranslationFromVector( 5.0f * XMLoadFloat4( &vLightDirs[m] ) ); XMMATRIX mLightScale = XMMatrixScaling( 0.2f, 0.2f, 0.2f ); mLight = mLightScale * mLight; // Update the world variable to reflect the current light cb1.mWorld = XMMatrixTranspose( mLight ); cb1.vOutputColor = vLightColors[m]; g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb1, 0, 0 );
    //更新lightCube的位置 g_pImmediateContext->PSSetShader( g_pPixelShaderSolid, NULL, 0 );
    //由于light没有使用constant数据,所以不需要PSSetConstantBuffers
    g_pImmediateContext->DrawIndexed( 36, 0, 0 ); }

      

  • 相关阅读:
    如何在 Linux 上用 IP转发使内部网络连接到互联网
    python 基础-文件读写'r' 和 'rb'区别
    处理HTTP状态码
    国内可用免费语料库(已经整理过,凡没有标注不可用的链接均可用)
    java读取大文件
    struts.properties的参数描述
    ResourceBundle使用
    linux定时任务的设置
    杂记
    JAVA动态加载JAR包的实现
  • 原文地址:https://www.cnblogs.com/dust-fly/p/4232895.html
Copyright © 2011-2022 走看看