Skip to content

Commit

Permalink
D3D/OGL: implement BackbufferState helping to know backbuffer params
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Feb 12, 2024
1 parent eca814a commit aa0647d
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 180 deletions.
194 changes: 94 additions & 100 deletions Engine/gfx/ali3dogl.cpp

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions Engine/gfx/ali3dogl.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,45 @@ class OGLGraphicsDriver : public VideoMemoryGraphicsDriver
int device_screen_physical_width;
int device_screen_physical_height;

// Viewport and scissor rect, in OpenGL screen coordinates (0,0 is at left-bottom)
Rect _viewportRect {};

// Final fbo, depends on platform we run on
GLint _screenFramebuffer = 0u;
// Capability flags
bool _glCapsNonPowerOfTwo = false;
// These two flags define whether driver can, and should (respectively)
// render sprites to texture, and then texture to screen, as opposed to
// rendering to screen directly. This is known as supersampling mode
bool _can_render_to_texture {};
bool _do_render_to_texture {};
bool _canRenderToTexture {};
bool _doRenderToTexture {};
// Backbuffer texture multiplier, used to determine a size of texture
// relative to the native game size.
int _super_sampling {};
int _superSampling {};
// Texture for rendering in native resolution
OGLBitmap *_nativeSurface = nullptr;
GLint _screenFramebuffer = 0;

// TODO: find a way to merge this with Render Targets from sprite batches,
// have a SINGLE STACK of "render target states", where backbuffer is at the bottom
struct BackbufferState
{
GLuint Fbo = 0u;
Size SurfSize;
// Viewport and scissor rect, in OpenGL screen coordinates (0,0 is at left-bottom)
Rect Viewport;
glm::mat4 Projection;
PlaneScaling Scaling;
int Filter = 0;
int TxClamp = 0;

BackbufferState() = default;
BackbufferState(GLuint fbo, const Size &size, const Rect &view, const glm::mat4 &proj,
const PlaneScaling &scale, int filter, int txclamp)
: Fbo(fbo), SurfSize(size), Viewport(view), Projection(proj)
, Scaling(scale), Filter(filter), TxClamp(txclamp) {}
~BackbufferState() = default;
};

BackbufferState _screenBackbuffer;
BackbufferState _nativeBackbuffer;
BackbufferState *_currentBackbuffer = nullptr;

// Sprite batches (parent scene nodes)
OGLSpriteBatches _spriteBatches;
Expand Down Expand Up @@ -370,8 +393,7 @@ class OGLGraphicsDriver : public VideoMemoryGraphicsDriver
const glm::mat4 &projection, const glm::mat4 &matGlobal,
const SpriteColorTransform &color, const Size &surface_size);
void SetupViewport();
// Converts rectangle in top->down coordinates into OpenGL's native bottom->up coordinates
Rect ConvertTopDownRect(const Rect &top_down_rect, int surface_height);

// Sets uniform GL blend settings, same for both RGB and alpha component
void SetBlendOpUniform(GLenum blend_op, GLenum src_factor, GLenum dst_factor);
// Sets GL blend settings for RGB only, and keeps saved alpha blend settings
Expand All @@ -387,13 +409,16 @@ class OGLGraphicsDriver : public VideoMemoryGraphicsDriver
// Deletes draw list backups
void ClearDrawBackups();
void _render(bool clearDrawListAfterwards);
// Set current backbuffer state, which properties are used when refering to backbuffer
// TODO: find a good way to merge with SetRenderTarget
void SetBackbufferState(BackbufferState *state);
// Sets the scissor (render clip), clip rect is passed in the "native" coordinates.
// Optionally pass surface_size if the rendering is done to texture, in native coords,
// otherwise we assume it is set on a whole screen, scaled to the screen coords.
void SetScissor(const Rect &clip, bool render_on_texture, const Size &surface_size);
// Configures rendering mode for the render target, depending on its properties
void SetRenderTarget(const OGLSpriteBatch *batch, Size &surface_sz, glm::mat4 &projection, bool clear);
void RenderSpriteBatches(const glm::mat4 &projection);
void RenderSpriteBatches();
size_t RenderSpriteBatch(const OGLSpriteBatch &batch, size_t from, const glm::mat4 &projection,
const Size &surface_size);
void _reDrawLastFrame();
Expand Down
5 changes: 5 additions & 0 deletions Engine/gfx/gfxfilter_aad3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const GfxFilterInfo &AAD3DGfxFilter::GetInfo() const
return FilterInfo;
}

int AAD3DGfxFilter::GetSamplerStateForStandardSprite()
{
return D3DTEXF_LINEAR;
}

void AAD3DGfxFilter::SetSamplerStateForStandardSprite(void *direct3ddevice9)
{
IDirect3DDevice9* d3d9 = ((IDirect3DDevice9*)direct3ddevice9);
Expand Down
1 change: 1 addition & 0 deletions Engine/gfx/gfxfilter_aad3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AAD3DGfxFilter : public D3DGfxFilter
public:
const GfxFilterInfo &GetInfo() const override;

int GetSamplerStateForStandardSprite() override;
void SetSamplerStateForStandardSprite(void *direct3ddevice9) override;
bool NeedToColourEdgeLines() override;

Expand Down
6 changes: 6 additions & 0 deletions Engine/gfx/gfxfilter_aaogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ bool AAOGLGfxFilter::UseLinearFiltering() const
return true;
}

void AAOGLGfxFilter::GetFilteringForStandardSprite(int &filter, int &clamp)
{
filter = GL_LINEAR;
clamp = GL_CLAMP_TO_EDGE;
}

void AAOGLGfxFilter::SetFilteringForStandardSprite()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Expand Down
1 change: 1 addition & 0 deletions Engine/gfx/gfxfilter_aaogl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AAOGLGfxFilter : public OGLGfxFilter
const GfxFilterInfo &GetInfo() const override;

bool UseLinearFiltering() const override;
void GetFilteringForStandardSprite(int &filter, int &clamp) override;
void SetFilteringForStandardSprite() override;

static const GfxFilterInfo FilterInfo;
Expand Down
5 changes: 5 additions & 0 deletions Engine/gfx/gfxfilter_d3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const GfxFilterInfo &D3DGfxFilter::GetInfo() const
return FilterInfo;
}

int D3DGfxFilter::GetSamplerStateForStandardSprite()
{
return D3DTEXF_POINT;
}

void D3DGfxFilter::SetSamplerStateForStandardSprite(void *direct3ddevice9)
{
IDirect3DDevice9* d3d9 = ((IDirect3DDevice9*)direct3ddevice9);
Expand Down
1 change: 1 addition & 0 deletions Engine/gfx/gfxfilter_d3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class D3DGfxFilter : public ScalingGfxFilter
public:
const GfxFilterInfo &GetInfo() const override;

virtual int GetSamplerStateForStandardSprite();
virtual void SetSamplerStateForStandardSprite(void *direct3ddevice9);
virtual bool NeedToColourEdgeLines();

Expand Down
6 changes: 6 additions & 0 deletions Engine/gfx/gfxfilter_ogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ bool OGLGfxFilter::UseLinearFiltering() const
return false;
}

void OGLGfxFilter::GetFilteringForStandardSprite(int &filter, int &clamp)
{
filter = GL_NEAREST;
clamp = GL_CLAMP;
}

void OGLGfxFilter::SetFilteringForStandardSprite()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Expand Down
1 change: 1 addition & 0 deletions Engine/gfx/gfxfilter_ogl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OGLGfxFilter : public ScalingGfxFilter
const GfxFilterInfo &GetInfo() const override;

virtual bool UseLinearFiltering() const;
virtual void GetFilteringForStandardSprite(int &filter, int &clamp);
virtual void SetFilteringForStandardSprite();

static const GfxFilterInfo FilterInfo;
Expand Down
Loading

0 comments on commit aa0647d

Please sign in to comment.