English 中文(简体)
多功能系统
原标题:Multiple render systems

不久的将来,我将开始开发一个游戏引擎。 我想包括的一个特征是,有多个系统,例如直接的S 9/10/11和开放式GL。 这样,利用这一发动机的游戏将能够支持更多的参与者,因为如果一个系统能够运作,它就会恢复另一个系统。

因此,我的问题是,我如何这样做? 我研究了一条轨道,并看到Ogre3D使用了类似的东西,但我不知道他们是如何这样做的。 我基本上想能够分散不同的系统,并使用相同的代码来管理。

最佳回答

你可以设立一个接口班,使你能够进一步扩展,使你希望扩大。

我过去曾这样做,以创建一名直接X911名投标者,我希望很快将此事扩大到开放的利比里亚人。 这项任务有把握,但很容易解释其基本工作。 不幸的是,我所参加的项目是封闭的,因此,如果你对此有任何问题,请不要犹豫。

首先,你想设立一个单独的项目,作为校准/票,我称之为“性别接口”。 这将包括VertexBuffer s、 IndexBuffer s、Shaders等基本接口,最重要的是,IRenderInterface和IRenderUtility,这些接口在随后的实施中可能持有诸如ID3D11DeviceContext和ID3D11Device等物品。

我在“两性间”项目中的两个最重要的项目是“两性间交流”和“透明度”。 这里的想法是,要让电视广播公司进行大量升级,例如设定目标、提出和初步采用APIC。 如果IRenderUtility将做更多的共同事,例如建立垂直/指数缓冲、制造沙子和制造。 我更经常地在初始化和投放方面通过IRenderUtility,而且很少通过IRenderInterface。 这样做是为了防止用户在不需要时进行意外操作。 该项目还将包括在整个法典基础使用的一些共同结构。

我随后又设立了另一个项目,如D3D11RenderInterface。 该D3D11RenderInterface将实施IRender Interface、IRenderUtlity、IVertexShader、IVertexBuffer等。

An overlysimple example would be

class IRenderUtility
{
public:
    virtual void Draw(unsigned int vertexCount, unsigned int vertexStartOffset) = 0;
};

class D3D11RenderUtility : public IRenderUtility
{
protected:
    ID3D11DeviceContext *mD3D11DeviceContext;
public:
    void Draw(unsigned int vertexCount, unsigned int vertexStartOffset)
    {
        mD3D11DeviceContext->Draw(vertexCount, vertexStartOffset);
    };
};

这样做的办法是,在IRenderUtility:Draw打电话之前,用电话确定VertexBuffer和IVertexBuffer。

Then, in your application will only need to load the RenderInterface project, and api implementation. There are other ways to do this, such as a #define ing code throughout your code base, but imo, that is just messy.

问题回答

利用C++接口的力量!

create an abstract that defines the interface to you rendering system

class Renderer
{
 //...
    virtual void DrawRect(Color c, Vector2 Pos) = 0;
 //...
}

之后在每一系统实施:

class D3DRenderer : Renderer
{
    void DrawRect(Color c, Vector2 Pos);
}

this method is fast, simple, and efficient, which is why it is used in many game engines. It should be note that it does require one to be aware of certain API restrictions when building things like this (even small thing like row major vs column major matrices).

首先,我认为,执行开放式的GL和直接X背书的努力是值得的。 你们只是通过不同的转机使用同样的硬件。 d 转而使用开放式广播公司,因为它具有开放的标准,并且支持更多的操作系统,包括有直接X的Windows。

Second, you should understand the differences between OpenGL (or DirectX) versions. Usually, a new version adds new features and deprecates some old features - which are still usable though. Rarely, old functionality is actually abandoned, as e.g. has been done with the fixed function pipeline in DirectX 10. This is another reason why I d suggest to rather use OpenGL - it s more backwards compatible and you can more easily support multiple versions.

支持更新的开放式GL版本通常意味着你正在使用旧版本中可用的新特征。 为了与旧版本保持一致,你基本上有两个选择:

  • Provide two implementations for the part of your application using OpenGL features that are not available in older versions. You then have to write an alternate implementation for the feature that only uses OpenGL features that are available in older versions.
  • Disable the functionality that uses new OpenGL features if the features are not available. This usually means that some effects are not rendered when the OpenGL version does not support them. This is not an option for functions of your rendering engine that are required and not just for "looking better".

If you want to support both DirectX and OpenGL, you d have to provide a complete abstract interface for your rendering subsystem and probably three implementations - DirectX 9, DirectX 10 / 11 and OpenGL. As mentioned, you can compensate the backwards-compatible API updates within your implementation.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签