Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separation of responsibility between rendering and window #2346

Closed
rtkid-nt opened this issue Jan 8, 2023 · 1 comment
Closed

Separation of responsibility between rendering and window #2346

rtkid-nt opened this issue Jan 8, 2023 · 1 comment

Comments

@rtkid-nt
Copy link
Contributor

rtkid-nt commented Jan 8, 2023

In the current state, the window and rendering are tightly coupled, and you can't use anything trivial other than OpenGL to draw
I know about WindowBase::createVulkanSurface, but to use it, you must write self rendering code.

What do you think about:

  1. Sharing responsibility between rendering and window?
  2. Making the option to choose api for drawing: Vulkan, OpenGL, DirectX

sf::Renderer - some static class representing renderer
sf::Renderer::API - enum or constexpr variable representing available api

class ShaderImpl
{
public:
    virtual ~ShaderImpl() = default;
    virtual void setUniform(const std::string& name, float x) = 0;
};

class Shader
{
public:
    Shader() 
    {
        switch (sf::Renderer::getAPI())
	{
	    case sf::Renderer::API::OpenGL: m_impl = new sf::priv::ShaderImplOpenGL; break;
	    case sf::Renderer::API::Vulkan: m_impl = new sf::priv::ShaderImplVulkan; break;
            case sf::Renderer::API::DirectX: m_impl = new sf::priv::ShaderImplDirectX; break;
	}
    }

    ~Shader()
    {
        delete m_impl;
    }

    virtual void setUniform(const std::string& name, float x)
    {
	m_impl->setUniform(name, x);
    }

private:
    ShaderImpl* m_impl{};
};

class ShaderImplOpenGL final : public ShaderImpl
{
public:
    void setUniform(const std::string& name, float x) override {}
};

class ShaderImplVulkan final : public ShaderImpl
{
public:
    void setUniform(const std::string& name, float x) override {}
};

class ShaderImplDirectX final : public ShaderImpl
{
public:
    void setUniform(const std::string& name, float x) override {}
};
@eXpl0it3r
Copy link
Member

This will certainly be a topic when addressing #2423, as such I'll currently close this as "duplicate".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants