Fission FSN
Loading...
Searching...
No Matches
fsCBgfx2d.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: fsCBgfx2d.h
4*
5* Purpose: Shared 2d drawing context for the bgfx backend.
6*
7* bgfx has no immediate-mode 2d drawing, so this owns the
8* one shader program (the embedded imgui pos/uv/colour
9* shaders that ship precompiled for every bgfx renderer),
10* the vertex layout and a white fallback texture, and
11* submits textured quads through transient buffers.
12*
13* Vertices are supplied in sprite-local space and
14* transformed on the CPU by the sprite's render matrix -
15* the embedded shader only applies u_viewProj, which the
16* renderer sets to a top-left-origin ortho each frame.
17*
18*********************************************************************/
19
20#ifndef fsCBgfx2dhdr
21#define fsCBgfx2dhdr
22
23#include <vector>
24
25#include <bgfx/bgfx.h>
26
27#include <fsCore/fsBaseTypes.h>
28#include <fsCore/fsVec2d.h>
29
30namespace fsNBgfx2d
31{
32 static const bgfx::ViewId mViewId2d = 0;
33
42
43 void initialise();
44 void uninitialise();
45
46 // Vsync is OFF by default: it paces to whatever display the window sits
47 // on (a 4K/5K screen over HDMI may be 30Hz, capping the game at 30fps).
48 // FSBGFX_VSYNC=1 opts back in. When off, the renderer paces the loop to
49 // targetFpsGet() (default 60, FSBGFX_FPS overrides, 0 = uncapped).
52
53 bgfx::TextureHandle whiteTextureGet();
54
55 fsU32 abgrGet(fsU8 pR, fsU8 pG, fsU8 pB, fsU8 pA);
56
57 void quadSubmit(const fsF32* pModelMtx, bgfx::TextureHandle pTexture, fsU32 pSamplerFlags,
58 fsF32 pX, fsF32 pY, fsF32 pW, fsF32 pH,
59 fsF32 pU0, fsF32 pV0, fsF32 pU1, fsF32 pV1,
60 fsU32 pColourAbgr);
61
62 void lineStripSubmit(const fsF32* pModelMtx, const std::vector<fsVec2d>& pVerts, fsU32 pColourAbgr);
63
64 // Batched path - the preferred way to draw. Quads are transformed by their
65 // sprite's matrix immediately and accumulate while consecutive draws share
66 // the same texture/sampler, going to the GPU as one draw call per run.
67 // Per-quad submits (sprites, particles, glyphs) otherwise dominate frame
68 // time on busy scenes. Draw order is preserved: the batch flushes itself
69 // whenever the texture changes, and must be flushed explicitly before any
70 // non-batched draw (lines) and at frame end.
71 void batchQuad(const fsF32* pModelMtx, bgfx::TextureHandle pTexture, fsU32 pSamplerFlags,
72 fsF32 pX, fsF32 pY, fsF32 pW, fsF32 pH,
73 fsF32 pU0, fsF32 pV0, fsF32 pU1, fsF32 pV1,
74 fsU32 pColourAbgr);
75
76 void batchFlush();
77}
78
79#endif
unsigned int fsU32
Definition fsBaseTypes.h:21
unsigned char fsU8
Definition fsBaseTypes.h:15
int fsS32
Definition fsBaseTypes.h:20
float fsF32
Definition fsBaseTypes.h:28
Definition fsCBgfx2d.cpp:52
void batchQuad(const fsF32 *const pModelMtx, bgfx::TextureHandle pTexture, fsU32 pSamplerFlags, fsF32 pX, fsF32 pY, fsF32 pW, fsF32 pH, fsF32 pU0, fsF32 pV0, fsF32 pU1, fsF32 pV1, fsU32 pColourAbgr)
Definition fsCBgfx2d.cpp:180
fsU32 abgrGet(fsU8 pR, fsU8 pG, fsU8 pB, fsU8 pA)
Definition fsCBgfx2d.cpp:120
void lineStripSubmit(const fsF32 *const pModelMtx, const std::vector< fsVec2d > &pVerts, fsU32 pColourAbgr)
Definition fsCBgfx2d.cpp:265
fsU32 resetFlagsGet()
Definition fsCBgfx2d.cpp:53
fsS32 targetFpsGet()
Definition fsCBgfx2d.cpp:58
bgfx::TextureHandle whiteTextureGet()
Definition fsCBgfx2d.cpp:114
void batchFlush()
Definition fsCBgfx2d.cpp:217
void initialise()
Definition fsCBgfx2d.cpp:71
void quadSubmit(const fsF32 *const pModelMtx, bgfx::TextureHandle pTexture, fsU32 pSamplerFlags, fsF32 pX, fsF32 pY, fsF32 pW, fsF32 pH, fsF32 pU0, fsF32 pV0, fsF32 pU1, fsF32 pV1, fsU32 pColourAbgr)
Definition fsCBgfx2d.cpp:128
void uninitialise()
Definition fsCBgfx2d.cpp:98
Definition fsCBgfx2d.h:35
fsF32 mU
Definition fsCBgfx2d.h:38
fsU32 mAbgr
Definition fsCBgfx2d.h:40
fsF32 mV
Definition fsCBgfx2d.h:39
fsF32 mY
Definition fsCBgfx2d.h:37
fsF32 mX
Definition fsCBgfx2d.h:36