前田稔(Maeda Minoru)の超初心者のプログラム入門
struct VertexPosition { DirectX::XMFLOAT3 pos; // position DirectX::XMFLOAT3 norm; // surface normal vector DirectX::XMFLOAT2 tex; // texture coordinate }; |
//bool m_loadingComplete; Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_textureView; Microsoft::WRL::ComPtr<ID3D11SamplerState> m_sampler; |
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; |
VertexPosition cubeVertices[] = { { XMFLOAT3(-0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f), XMFLOAT2(0.0f, 0.0f) }, // +Y (top face) { XMFLOAT3( 0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f) }, ・・・ { XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, -1.0f), XMFLOAT2(0.0f, 1.0f) }, }; |
unsigned short modelIndices[] = { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }; |
BasicReaderWriter^ reader = ref new BasicReaderWriter(); ・ ・ ・ auto textureData = reader->ReadData("texturedata.bin"); D3D11_SUBRESOURCE_DATA textureSubresourceData = {0}; textureSubresourceData.pSysMem = textureData->Data; // Specify the size of a row in bytes, known a priori about the texture data. textureSubresourceData.SysMemPitch = 1024; // As this is not a texture array or 3D texture, this parameter is ignored. textureSubresourceData.SysMemSlicePitch = 0; // Create a texture description from information known a priori about the data. // Generalized texture loading code can be found in the Resource Loading sample. D3D11_TEXTURE2D_DESC textureDesc = {0}; textureDesc.Width = 256; textureDesc.Height = 256; textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; // Most textures contain more than one MIP level. For simplicity, this sample uses only one. textureDesc.MipLevels = 1; // As this will not be a texture array, this parameter is ignored. textureDesc.ArraySize = 1; // Don't use multi-sampling. textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; // Allow the texture to be bound as a shader resource. textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; ComPtr<ID3D11Texture2D> texture; DX::ThrowIfFailed( m_d3dDevice->CreateTexture2D( &textureDesc, &textureSubresourceData, &texture)); // Once the texture is created, we must create a shader resource view of it // so that shaders may use it. In general, the view description will match // the texture description. D3D11_SHADER_RESOURCE_VIEW_DESC textureViewDesc; ZeroMemory(&textureViewDesc, sizeof(textureViewDesc)); textureViewDesc.Format = textureDesc.Format; textureViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; textureViewDesc.Texture2D.MipLevels = textureDesc.MipLevels; textureViewDesc.Texture2D.MostDetailedMip = 0; DX::ThrowIfFailed( m_d3dDevice->CreateShaderResourceView( texture.Get(), &textureViewDesc, &m_textureView)); // Once the texture view is created, create a sampler. This defines how the color // for a particular texture coordinate is determined using the relevant texture data. D3D11_SAMPLER_DESC samplerDesc; ZeroMemory(&samplerDesc, sizeof(samplerDesc)); samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; // The sampler does not use anisotropic filtering, so this parameter is ignored. samplerDesc.MaxAnisotropy = 0; // Specify how texture coordinates outside of the range 0..1 are resolved. samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; // Use no special MIP clamping or bias. samplerDesc.MipLODBias = 0.0f; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; // Don't use a comparison function. samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; // Border address mode is not used, so this parameter is ignored. samplerDesc.BorderColor[0] = 0.0f; samplerDesc.BorderColor[1] = 0.0f; samplerDesc.BorderColor[2] = 0.0f; samplerDesc.BorderColor[3] = 0.0f; DX::ThrowIfFailed( m_d3dDevice->CreateSamplerState( &samplerDesc, &m_sampler)); } |
void Model::Render() { ・ ・ ・ m_d3dContext->PSSetShaderResources(0, 1, m_textureView.GetAddressOf()); m_d3dContext->PSSetSamplers(0, 1, m_sampler.GetAddressOf()); m_d3dContext->DrawIndexed(m_indexCount, 0, 0); } |