//-----------------------------------------------------------------------
void GraphicsContextDirect3D11::SetTexture(int index, RenderTarget2D & textureIn)
{
    POMDOG_ASSERT(index >= 0);
    POMDOG_ASSERT(index < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
    POMDOG_ASSERT(index < static_cast<int>(textureResourceViews.size()));
    POMDOG_ASSERT(textureIn.NativeRenderTarget2D() != nullptr);

    auto texture = static_cast<RenderTarget2DDirect3D11*>(textureIn.NativeRenderTarget2D());

    POMDOG_ASSERT(texture != nullptr);
    POMDOG_ASSERT(texture == dynamic_cast<RenderTarget2DDirect3D11*>(textureIn.NativeRenderTarget2D()));

    textureResourceViews[index] = texture->GetShaderResourceView();

    POMDOG_ASSERT(deviceContext);
    deviceContext->PSSetShaderResources(0, 1, &textureResourceViews[index]);
}
Exemple #2
0
//-----------------------------------------------------------------------
void GraphicsContextGL4::SetTexture(int textureUnit, RenderTarget2D & textureIn)
{
    POMDOG_ASSERT(!textures.empty());
    POMDOG_ASSERT(textureUnit >= 0);
    POMDOG_ASSERT(textureUnit < static_cast<int>(textures.size()));

    constexpr GLenum textureType = GL_TEXTURE_2D;

    if (textures[textureUnit] && *textures[textureUnit] != textureType) {
        // Unbind texture
        SetTexture(textureUnit);
    }

    textures[textureUnit] = textureType;

    POMDOG_ASSERT(textureIn.NativeRenderTarget2D());
    auto renderTargetGL4 = dynamic_cast<RenderTarget2DGL4*>(textureIn.NativeRenderTarget2D());

    POMDOG_ASSERT(renderTargetGL4 != nullptr);
    ApplyTexture2D(textureUnit, renderTargetGL4->GetTextureHandle());
}