本文整理汇总了C++中IVideoDriver::getShaderManager方法的典型用法代码示例。如果您正苦于以下问题:C++ IVideoDriver::getShaderManager方法的具体用法?C++ IVideoDriver::getShaderManager怎么用?C++ IVideoDriver::getShaderManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVideoDriver
的用法示例。
在下文中一共展示了IVideoDriver::getShaderManager方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
IDevice* device = gf::createDevice(EDT_DIRECT3D11, 800, 600);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->createSceneManager();
IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager();
resourceGroupManager->init("Resources.cfg");
ITimer* timer = device->getTimer();
timer->reset();
ITextureManager* textureManager = ITextureManager::getInstance();
IShaderManager* shaderMgr = driver->getShaderManager();
IShader* shader = shaderMgr->load(EST_COMPUTE_SHADER, "matmul.hlsl", "cs_main");
const u32 dimension = 512;
const u32 sq_dimension = dimension * dimension;
std::vector<f32> A(sq_dimension);
std::vector<f32> B(sq_dimension);
std::vector<f32> C(sq_dimension);
std::vector<f32> D(sq_dimension);
// init data
for (u32 i = 0; i < sq_dimension; i++)
{
A[i] = math::RandomFloat(0, 10.0f);
B[i] = math::RandomFloat(0, 10.0f);
}
f32 start_time, end_time;
start_time = timer->getTime();
// store the right answers to D
for (u32 i = 0; i < dimension; i++)
{
for (u32 j = 0; j < dimension; j++)
{
f32 sum = 0;
for (u32 k = 0; k < dimension; k++)
{
sum += A[i * dimension + k] * B[k * dimension + j];
}
D[i * dimension + j] = sum;
}
}
end_time = timer->getTime();
printf("The computation time by CPU: %fs\n", end_time - start_time);
start_time = timer->getTime();
ITexture* inputTexture1 = textureManager->createTexture2D("input1", dimension, dimension,
ETBT_SHADER_RESOURCE, &A[0], 1, EGF_R32_FLOAT, 0);
ITexture* inputTexture2 = textureManager->createTexture2D("input2", dimension, dimension,
ETBT_SHADER_RESOURCE, &B[0], 1, EGF_R32_FLOAT, 0);
ITexture* outputTexture = textureManager->createTexture2D("output", dimension, dimension,
ETBT_UNORDERED_ACCESS, nullptr, 1, EGF_R32_FLOAT, 0);
ITexture* copyTexture = textureManager->createTexture2D("copy", dimension, dimension,
ETBT_CPU_ACCESS_READ, nullptr, 1, EGF_R32_FLOAT, 0);
shader->setTexture("gInputA", inputTexture1);
shader->setTexture("gInputB", inputTexture2);
shader->setTexture("gOutput", outputTexture);
u32 blockNum = dimension / 8;
if (blockNum * 8 != dimension)
blockNum++;
driver->runComputeShader(shader, blockNum, blockNum, 1);
//driver->resetRWTextures();
//driver->resetTextures();
outputTexture->copyDataToAnotherTexture(copyTexture);
STextureData outputData;
copyTexture->lock(ETLT_READ, &outputData);
u8* data = (u8*)outputData.Data;
for (u32 i = 0; i < dimension; i++)
{
// copy each row.
memcpy(&C[i * dimension], data + outputData.RowPitch * i, dimension * sizeof(f32));
}
copyTexture->unlock();
end_time = timer->getTime();
printf("The computation time by GPU: %fs\n", end_time - start_time);
for (u32 i = 0; i < sq_dimension; i++)
{
assert(math::FloatEqual(C[i], D[i]));
}
// destory textures.
if (!textureManager->destroy(inputTexture1))
printf("Destory texture failed!");
if (!textureManager->destroy(inputTexture2))
//.........这里部分代码省略.........
示例2: main
int main()
{
int d = 1;
GF_PRINT_CONSOLE_INFO("Hello:%d\n", d);
SDeviceContextSettings settings;
settings.MultiSamplingCount = 4;
settings.MultiSamplingQuality = 32;
IDevice* device = createDevice(EDT_DIRECT3D11, 800, 600, EWS_NONE, true, settings);
IVideoDriver* driver = device->getVideoDriver();
IShaderManager* shaderManager = driver->getShaderManager();
IInputLayoutManager* inputlayoutManager = driver->getInputLayoutManager();
IPipelineManager* pipelineMgr = driver->getPipelineManager();
IShader* vs = shaderManager->load(EST_VERTEX_SHADER, "color.hlsl", "ColorVertexShader");
IShader* ps = shaderManager->load(EST_PIXEL_SHADER, "PixelShader.hlsl", "ColorPixelShader");
std::vector<SInputLayoutElement> elements;
elements.resize(2);
elements[0].SemanticName = "POSITION";
elements[0].SemanticIndex = 0;
elements[0].Format = EGF_R32G32B32_FLOAT;
elements[0].Offset = 0;
elements[1].SemanticName = "COLOR";
elements[1].SemanticIndex = 0;
elements[1].Format = EGF_R32G32B32A32_FLOAT;
elements[1].Offset = 12;
IInputLayout* layout = inputlayoutManager->create(elements, vs);
IShader* shaders[2] = { vs, ps };
IPipeline* pipeline = pipelineMgr->create("color", shaders, 2, layout, EPT_TRIANGLELIST);
ISceneManager* smgr = device->getSceneManager();
Vertex vertices[3];
vertices[0] = Vertex(XMFLOAT3(-1.0f, -0.6f, 0.0f), XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f));
vertices[1] = Vertex(XMFLOAT3(0.0f, 0.6f, 0.0f), XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f));
vertices[2] = Vertex(XMFLOAT3(1.0f, -0.6f, 0.0f), XMFLOAT4(1.0f, 0.0f, 1.0f, 1.0f));
//IMesh* mesh = smgr->createSimpleMesh(&vertices, 3, sizeof(Vertex), nullptr, 0, 0);
IMesh* mesh = smgr->createCubeMesh();
IMeshNode* meshNode = smgr->addMeshNode(mesh, pipeline);
//CD3D11ShaderManager* s = new CD3D11ShaderManager(nullptr);
XMVECTOR eye = XMVectorSet(0.0f, 0.0f, -5.0f, 1.0f);
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMVECTOR at = XMVectorZero();
XMMATRIX view = XMMatrixLookAtLH(eye, at, up);
XMMATRIX proj = XMMatrixPerspectiveFovLH(0.25f * 3.14f,
static_cast<float>(SCREEN_WIDTH) / static_cast<float>(SCREEN_HEIGHT),
1.0f, 1000.0f);
meshNode->translate(0, 0, 5.0f);
XMMATRIX world = meshNode->getAbsoluteTransformation();
//XMMATRIX world = XMMatrixIdentity();
pipeline->setMatrix("viewMatrix", reinterpret_cast<f32*>(&view));
pipeline->setMatrix("projectionMatrix", reinterpret_cast<f32*>(&proj));
SShaderAutoVariable var;
var.Type = ESAVT_WORLD_MATRIX;
var.ShaderType = EST_VERTEX_SHADER;
var.VariableName = "worldMatrix";
pipeline->addShaderAutoVariable(var);
std::cout << "Hello World" << std::endl;
ITimer* timer = device->createTimer();
timer->reset();
while (device->run())
{
const float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
driver->beginScene(true, true, clearColor);
f32 dt = timer->tick();
//std::cout << dt << std::endl;
meshNode->setPosition(0, 0, -2.0f);
meshNode->yaw(1.0f * dt);
smgr->drawAll();
//XMMATRIX world = meshNode->getAbsoluteTransformation();
//pipeline->setMatrix("worldMatrix", reinterpret_cast<f32*>(&world));
driver->endScene();
}
return 0;
}