mirror of
https://github.com/holub/mame
synced 2025-04-17 22:13:04 +03:00
Initial support for BGFX [Dario Manesku, Branimir Karadic, Miodrag Milanovic]
Need optimization and cleanup, note that all shaders can be built only on windows due to usage of DirectX DLLs
This commit is contained in:
parent
5b432512fa
commit
178167b8fe
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,6 +13,7 @@
|
||||
!/samples/
|
||||
!/scripts/
|
||||
!/src/
|
||||
!/shaders/
|
||||
!/tests/
|
||||
!/doxygen/
|
||||
!/web/
|
||||
|
1
3rdparty/bgfx/tools/bin/windows/.gitignore
vendored
1
3rdparty/bgfx/tools/bin/windows/.gitignore
vendored
@ -1 +0,0 @@
|
||||
*
|
BIN
3rdparty/bgfx/tools/bin/windows/geometryc.exe
vendored
Normal file
BIN
3rdparty/bgfx/tools/bin/windows/geometryc.exe
vendored
Normal file
Binary file not shown.
BIN
3rdparty/bgfx/tools/bin/windows/shaderc.exe
vendored
Normal file
BIN
3rdparty/bgfx/tools/bin/windows/shaderc.exe
vendored
Normal file
Binary file not shown.
BIN
3rdparty/bgfx/tools/bin/windows/texturec.exe
vendored
Normal file
BIN
3rdparty/bgfx/tools/bin/windows/texturec.exe
vendored
Normal file
Binary file not shown.
4
makefile
4
makefile
@ -1367,3 +1367,7 @@ cppcheck:
|
||||
@echo Generate CppCheck analysis report
|
||||
cppcheck --enable=all src/ $(CPPCHECK_PARAMS) -j9
|
||||
|
||||
.PHONY: shaders
|
||||
|
||||
shaders:
|
||||
$(SILENT) $(MAKE) -C $(SRC)/osd/modules/render/bgfx rebuild
|
||||
|
BIN
shaders/dx11/fs_line.bin
Normal file
BIN
shaders/dx11/fs_line.bin
Normal file
Binary file not shown.
BIN
shaders/dx11/fs_quad.bin
Normal file
BIN
shaders/dx11/fs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/dx11/fs_quad_texture.bin
Normal file
BIN
shaders/dx11/fs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/dx11/vs_line.bin
Normal file
BIN
shaders/dx11/vs_line.bin
Normal file
Binary file not shown.
BIN
shaders/dx11/vs_quad.bin
Normal file
BIN
shaders/dx11/vs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/dx11/vs_quad_texture.bin
Normal file
BIN
shaders/dx11/vs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/dx9/fs_line.bin
Normal file
BIN
shaders/dx9/fs_line.bin
Normal file
Binary file not shown.
BIN
shaders/dx9/fs_quad.bin
Normal file
BIN
shaders/dx9/fs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/dx9/fs_quad_texture.bin
Normal file
BIN
shaders/dx9/fs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/dx9/vs_line.bin
Normal file
BIN
shaders/dx9/vs_line.bin
Normal file
Binary file not shown.
BIN
shaders/dx9/vs_quad.bin
Normal file
BIN
shaders/dx9/vs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/dx9/vs_quad_texture.bin
Normal file
BIN
shaders/dx9/vs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/gles/fs_line.bin
Normal file
BIN
shaders/gles/fs_line.bin
Normal file
Binary file not shown.
BIN
shaders/gles/fs_quad.bin
Normal file
BIN
shaders/gles/fs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/gles/fs_quad_texture.bin
Normal file
BIN
shaders/gles/fs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/gles/vs_line.bin
Normal file
BIN
shaders/gles/vs_line.bin
Normal file
Binary file not shown.
BIN
shaders/gles/vs_quad.bin
Normal file
BIN
shaders/gles/vs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/gles/vs_quad_texture.bin
Normal file
BIN
shaders/gles/vs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/glsl/fs_line.bin
Normal file
BIN
shaders/glsl/fs_line.bin
Normal file
Binary file not shown.
BIN
shaders/glsl/fs_quad.bin
Normal file
BIN
shaders/glsl/fs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/glsl/fs_quad_texture.bin
Normal file
BIN
shaders/glsl/fs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/glsl/vs_line.bin
Normal file
BIN
shaders/glsl/vs_line.bin
Normal file
Binary file not shown.
BIN
shaders/glsl/vs_quad.bin
Normal file
BIN
shaders/glsl/vs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/glsl/vs_quad_texture.bin
Normal file
BIN
shaders/glsl/vs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/metal/fs_line.bin
Normal file
BIN
shaders/metal/fs_line.bin
Normal file
Binary file not shown.
BIN
shaders/metal/fs_quad.bin
Normal file
BIN
shaders/metal/fs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/metal/fs_quad_texture.bin
Normal file
BIN
shaders/metal/fs_quad_texture.bin
Normal file
Binary file not shown.
BIN
shaders/metal/vs_line.bin
Normal file
BIN
shaders/metal/vs_line.bin
Normal file
Binary file not shown.
BIN
shaders/metal/vs_quad.bin
Normal file
BIN
shaders/metal/vs_quad.bin
Normal file
Binary file not shown.
BIN
shaders/metal/vs_quad_texture.bin
Normal file
BIN
shaders/metal/vs_quad_texture.bin
Normal file
Binary file not shown.
11
src/osd/modules/render/bgfx/fs_line.sc
Normal file
11
src/osd/modules/render/bgfx/fs_line.sc
Normal file
@ -0,0 +1,11 @@
|
||||
$input v_color0
|
||||
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Dario Manesku
|
||||
|
||||
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = v_color0;
|
||||
}
|
11
src/osd/modules/render/bgfx/fs_quad.sc
Normal file
11
src/osd/modules/render/bgfx/fs_quad.sc
Normal file
@ -0,0 +1,11 @@
|
||||
$input v_color0
|
||||
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Dario Manesku
|
||||
|
||||
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = v_color0;
|
||||
}
|
14
src/osd/modules/render/bgfx/fs_quad_texture.sc
Normal file
14
src/osd/modules/render/bgfx/fs_quad_texture.sc
Normal file
@ -0,0 +1,14 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Dario Manesku
|
||||
|
||||
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
|
||||
|
||||
SAMPLER2D(s_tex, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texel = texture2D(s_tex, v_texcoord0);
|
||||
gl_FragColor = texel * v_color0;
|
||||
}
|
13
src/osd/modules/render/bgfx/makefile
Normal file
13
src/osd/modules/render/bgfx/makefile
Normal file
@ -0,0 +1,13 @@
|
||||
BGFX_DIR=../../../../../3rdparty/bgfx
|
||||
RUNTIME_DIR=../../../../..
|
||||
BUILD_DIR=../../../../../build
|
||||
|
||||
include $(BGFX_DIR)/scripts/shader.mk
|
||||
|
||||
rebuild:
|
||||
@make -s --no-print-directory TARGET=0 clean all
|
||||
@make -s --no-print-directory TARGET=1 clean all
|
||||
@make -s --no-print-directory TARGET=2 clean all
|
||||
@make -s --no-print-directory TARGET=3 clean all
|
||||
@make -s --no-print-directory TARGET=4 clean all
|
||||
@make -s --no-print-directory TARGET=5 clean all
|
7
src/osd/modules/render/bgfx/varying.def.sc
Normal file
7
src/osd/modules/render/bgfx/varying.def.sc
Normal file
@ -0,0 +1,7 @@
|
||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||
vec3 v_pos : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
vec3 a_position : POSITION;
|
||||
vec4 a_color0 : COLOR0;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
13
src/osd/modules/render/bgfx/vs_line.sc
Normal file
13
src/osd/modules/render/bgfx/vs_line.sc
Normal file
@ -0,0 +1,13 @@
|
||||
$input a_position, a_color0
|
||||
$output v_color0
|
||||
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Dario Manesku
|
||||
|
||||
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
|
||||
v_color0 = a_color0;
|
||||
}
|
13
src/osd/modules/render/bgfx/vs_quad.sc
Normal file
13
src/osd/modules/render/bgfx/vs_quad.sc
Normal file
@ -0,0 +1,13 @@
|
||||
$input a_position, a_color0
|
||||
$output v_color0
|
||||
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Dario Manesku
|
||||
|
||||
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
|
||||
v_color0 = a_color0;
|
||||
}
|
14
src/osd/modules/render/bgfx/vs_quad_texture.sc
Normal file
14
src/osd/modules/render/bgfx/vs_quad_texture.sc
Normal file
@ -0,0 +1,14 @@
|
||||
$input a_position, a_texcoord0, a_color0
|
||||
$output v_texcoord0, v_color0
|
||||
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Dario Manesku
|
||||
|
||||
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
|
||||
v_texcoord0 = a_texcoord0;
|
||||
v_color0 = a_color0;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Miodrag Milanovic
|
||||
// copyright-holders:Miodrag Milanovic, Dario Manesku, Branimir Karadzic
|
||||
//============================================================
|
||||
//
|
||||
// drawbgfx.c - BGFX drawer
|
||||
@ -30,6 +30,8 @@
|
||||
|
||||
#include <bgfx/bgfxplatform.h>
|
||||
#include <bgfx/bgfx.h>
|
||||
#include <bx/fpumath.h>
|
||||
#include <bx/readerwriter.h>
|
||||
|
||||
//============================================================
|
||||
// DEBUGGING
|
||||
@ -110,6 +112,11 @@ public:
|
||||
INT64 m_last_blit_time;
|
||||
INT64 m_last_blit_pixels;
|
||||
|
||||
bgfx::ProgramHandle m_progQuad;
|
||||
bgfx::ProgramHandle m_progQuadTexture;
|
||||
bgfx::ProgramHandle m_progLine;
|
||||
bgfx::UniformHandle m_s_texColor;
|
||||
|
||||
// Original display_mode
|
||||
};
|
||||
|
||||
@ -155,7 +162,7 @@ static void drawbgfx_exit(void)
|
||||
//============================================================
|
||||
// renderer_bgfx::create
|
||||
//============================================================
|
||||
|
||||
bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName);
|
||||
int renderer_bgfx::create()
|
||||
{
|
||||
// create renderer
|
||||
@ -177,7 +184,12 @@ int renderer_bgfx::create()
|
||||
#endif
|
||||
|
||||
// Enable debug text.
|
||||
bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
|
||||
bgfx::setDebug(BGFX_DEBUG_TEXT); //BGFX_DEBUG_STATS
|
||||
// Create program from shaders.
|
||||
m_progQuad = loadProgram("vs_quad", "fs_quad");
|
||||
m_progQuadTexture = loadProgram("vs_quad_texture", "fs_quad_texture");
|
||||
m_progLine = loadProgram("vs_line", "fs_line");
|
||||
m_s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
|
||||
|
||||
osd_printf_verbose("Leave drawsdl2_window_create\n");
|
||||
return 0;
|
||||
@ -192,6 +204,12 @@ void renderer_bgfx::destroy()
|
||||
// free the memory in the window
|
||||
|
||||
// destroy_all_textures();
|
||||
//
|
||||
bgfx::destroyUniform(m_s_texColor);
|
||||
// Cleanup.
|
||||
bgfx::destroyProgram(m_progQuad);
|
||||
bgfx::destroyProgram(m_progQuadTexture);
|
||||
bgfx::destroyProgram(m_progLine);
|
||||
|
||||
// Shutdown bgfx.
|
||||
bgfx::shutdown();
|
||||
@ -215,39 +233,421 @@ int renderer_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt)
|
||||
}
|
||||
#endif
|
||||
|
||||
static const bgfx::Memory* loadMem(bx::FileReaderI* _reader, const char* _filePath)
|
||||
{
|
||||
if (bx::open(_reader, _filePath))
|
||||
{
|
||||
uint32_t size = (uint32_t)bx::getSize(_reader);
|
||||
const bgfx::Memory* mem = bgfx::alloc(size + 1);
|
||||
bx::read(_reader, mem->data, size);
|
||||
bx::close(_reader);
|
||||
mem->data[mem->size - 1] = '\0';
|
||||
return mem;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static bgfx::ShaderHandle loadShader(bx::FileReaderI* _reader, const char* _name)
|
||||
{
|
||||
char filePath[512];
|
||||
|
||||
const char* shaderPath = "shaders/dx9/";
|
||||
|
||||
switch (bgfx::getRendererType())
|
||||
{
|
||||
case bgfx::RendererType::Direct3D11:
|
||||
case bgfx::RendererType::Direct3D12:
|
||||
shaderPath = "shaders/dx11/";
|
||||
break;
|
||||
|
||||
case bgfx::RendererType::OpenGL:
|
||||
shaderPath = "shaders/glsl/";
|
||||
break;
|
||||
|
||||
case bgfx::RendererType::Metal:
|
||||
shaderPath = "shaders/metal/";
|
||||
break;
|
||||
|
||||
case bgfx::RendererType::OpenGLES:
|
||||
shaderPath = "shaders/gles/";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
strcpy(filePath, shaderPath);
|
||||
strcat(filePath, _name);
|
||||
strcat(filePath, ".bin");
|
||||
|
||||
return bgfx::createShader(loadMem(_reader, filePath));
|
||||
}
|
||||
|
||||
bgfx::ProgramHandle loadProgram(bx::FileReaderI* _reader, const char* _vsName, const char* _fsName)
|
||||
{
|
||||
bgfx::ShaderHandle vsh = loadShader(_reader, _vsName);
|
||||
bgfx::ShaderHandle fsh = BGFX_INVALID_HANDLE;
|
||||
if (NULL != _fsName)
|
||||
{
|
||||
fsh = loadShader(_reader, _fsName);
|
||||
}
|
||||
|
||||
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
|
||||
}
|
||||
static auto s_fileReader = new bx::CrtFileReader;
|
||||
|
||||
bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
|
||||
{
|
||||
|
||||
return loadProgram(s_fileReader, _vsName, _fsName);
|
||||
}
|
||||
//============================================================
|
||||
// drawbgfx_window_draw
|
||||
//============================================================
|
||||
|
||||
struct PosColorTexCoord0Vertex
|
||||
{
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
uint32_t m_rgba;
|
||||
float m_u;
|
||||
float m_v;
|
||||
|
||||
static void init()
|
||||
{
|
||||
ms_decl.begin()
|
||||
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
||||
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
|
||||
.end();
|
||||
}
|
||||
|
||||
static bgfx::VertexDecl ms_decl;
|
||||
};
|
||||
bgfx::VertexDecl PosColorTexCoord0Vertex::ms_decl;
|
||||
|
||||
void screenQuad(float _x1
|
||||
, float _y1
|
||||
, float _x2
|
||||
, float _y2
|
||||
, uint32_t _abgr
|
||||
, render_quad_texuv uv
|
||||
)
|
||||
{
|
||||
if (bgfx::checkAvailTransientVertexBuffer(6, PosColorTexCoord0Vertex::ms_decl))
|
||||
{
|
||||
bgfx::TransientVertexBuffer vb;
|
||||
bgfx::allocTransientVertexBuffer(&vb, 6, PosColorTexCoord0Vertex::ms_decl);
|
||||
PosColorTexCoord0Vertex* vertex = (PosColorTexCoord0Vertex*)vb.data;
|
||||
|
||||
const float minx = _x1;
|
||||
const float miny = _y1;
|
||||
const float maxx = _x2;
|
||||
const float maxy = _y2;
|
||||
const float zz = 0.0f;
|
||||
|
||||
vertex[0].m_x = minx;
|
||||
vertex[0].m_y = miny;
|
||||
vertex[0].m_z = zz;
|
||||
vertex[0].m_rgba = _abgr;
|
||||
vertex[0].m_u = uv.tl.u;
|
||||
vertex[0].m_v = uv.tl.v;
|
||||
|
||||
vertex[1].m_x = maxx;
|
||||
vertex[1].m_y = miny;
|
||||
vertex[1].m_z = zz;
|
||||
vertex[1].m_rgba = _abgr;
|
||||
vertex[1].m_u = uv.tr.u;
|
||||
vertex[1].m_v = uv.tr.v;
|
||||
|
||||
vertex[2].m_x = maxx;
|
||||
vertex[2].m_y = maxy;
|
||||
vertex[2].m_z = zz;
|
||||
vertex[2].m_rgba = _abgr;
|
||||
vertex[2].m_u = uv.br.u;
|
||||
vertex[2].m_v = uv.br.v;
|
||||
|
||||
vertex[3].m_x = maxx;
|
||||
vertex[3].m_y = maxy;
|
||||
vertex[3].m_z = zz;
|
||||
vertex[3].m_rgba = _abgr;
|
||||
vertex[3].m_u = uv.br.u;
|
||||
vertex[3].m_v = uv.br.v;
|
||||
|
||||
vertex[4].m_x = minx;
|
||||
vertex[4].m_y = maxy;
|
||||
vertex[4].m_z = zz;
|
||||
vertex[4].m_rgba = _abgr;
|
||||
vertex[4].m_u = uv.bl.u;
|
||||
vertex[4].m_v = uv.bl.v;
|
||||
|
||||
vertex[5].m_x = minx;
|
||||
vertex[5].m_y = miny;
|
||||
vertex[5].m_z = zz;
|
||||
vertex[5].m_rgba = _abgr;
|
||||
vertex[5].m_u = uv.tl.u;
|
||||
vertex[5].m_v = uv.tl.v;
|
||||
bgfx::setVertexBuffer(&vb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct PosColorVertex
|
||||
{
|
||||
float m_x;
|
||||
float m_y;
|
||||
uint32_t m_abgr;
|
||||
|
||||
static void init()
|
||||
{
|
||||
ms_decl
|
||||
.begin()
|
||||
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
|
||||
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
||||
.end();
|
||||
}
|
||||
|
||||
static bgfx::VertexDecl ms_decl;
|
||||
};
|
||||
bgfx::VertexDecl PosColorVertex::ms_decl;
|
||||
|
||||
#define MAX_TEMP_COORDS 100
|
||||
|
||||
void drawPolygon(const float* _coords, uint32_t _numCoords, float _r, uint32_t _abgr)
|
||||
{
|
||||
float tempCoords[MAX_TEMP_COORDS * 2];
|
||||
float tempNormals[MAX_TEMP_COORDS * 2];
|
||||
|
||||
_numCoords = _numCoords < MAX_TEMP_COORDS ? _numCoords : MAX_TEMP_COORDS;
|
||||
|
||||
for (uint32_t ii = 0, jj = _numCoords - 1; ii < _numCoords; jj = ii++)
|
||||
{
|
||||
const float* v0 = &_coords[jj * 2];
|
||||
const float* v1 = &_coords[ii * 2];
|
||||
float dx = v1[0] - v0[0];
|
||||
float dy = v1[1] - v0[1];
|
||||
float d = sqrtf(dx * dx + dy * dy);
|
||||
if (d > 0)
|
||||
{
|
||||
d = 1.0f / d;
|
||||
dx *= d;
|
||||
dy *= d;
|
||||
}
|
||||
|
||||
tempNormals[jj * 2 + 0] = dy;
|
||||
tempNormals[jj * 2 + 1] = -dx;
|
||||
}
|
||||
|
||||
for (uint32_t ii = 0, jj = _numCoords - 1; ii < _numCoords; jj = ii++)
|
||||
{
|
||||
float dlx0 = tempNormals[jj * 2 + 0];
|
||||
float dly0 = tempNormals[jj * 2 + 1];
|
||||
float dlx1 = tempNormals[ii * 2 + 0];
|
||||
float dly1 = tempNormals[ii * 2 + 1];
|
||||
float dmx = (dlx0 + dlx1) * 0.5f;
|
||||
float dmy = (dly0 + dly1) * 0.5f;
|
||||
float dmr2 = dmx * dmx + dmy * dmy;
|
||||
if (dmr2 > 0.000001f)
|
||||
{
|
||||
float scale = 1.0f / dmr2;
|
||||
if (scale > 10.0f)
|
||||
{
|
||||
scale = 10.0f;
|
||||
}
|
||||
|
||||
dmx *= scale;
|
||||
dmy *= scale;
|
||||
}
|
||||
|
||||
tempCoords[ii * 2 + 0] = _coords[ii * 2 + 0] + dmx * _r;
|
||||
tempCoords[ii * 2 + 1] = _coords[ii * 2 + 1] + dmy * _r;
|
||||
}
|
||||
|
||||
uint32_t numVertices = _numCoords * 6 + (_numCoords - 2) * 3;
|
||||
if (bgfx::checkAvailTransientVertexBuffer(numVertices, PosColorVertex::ms_decl))
|
||||
{
|
||||
bgfx::TransientVertexBuffer tvb;
|
||||
bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosColorVertex::ms_decl);
|
||||
uint32_t trans = _abgr & 0xffffff;
|
||||
|
||||
PosColorVertex* vertex = (PosColorVertex*)tvb.data;
|
||||
for (uint32_t ii = 0, jj = _numCoords - 1; ii < _numCoords; jj = ii++)
|
||||
{
|
||||
vertex->m_x = _coords[ii * 2 + 0];
|
||||
vertex->m_y = _coords[ii * 2 + 1];
|
||||
vertex->m_abgr = _abgr;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = _coords[jj * 2 + 0];
|
||||
vertex->m_y = _coords[jj * 2 + 1];
|
||||
vertex->m_abgr = _abgr;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = tempCoords[jj * 2 + 0];
|
||||
vertex->m_y = tempCoords[jj * 2 + 1];
|
||||
vertex->m_abgr = trans;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = tempCoords[jj * 2 + 0];
|
||||
vertex->m_y = tempCoords[jj * 2 + 1];
|
||||
vertex->m_abgr = trans;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = tempCoords[ii * 2 + 0];
|
||||
vertex->m_y = tempCoords[ii * 2 + 1];
|
||||
vertex->m_abgr = trans;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = _coords[ii * 2 + 0];
|
||||
vertex->m_y = _coords[ii * 2 + 1];
|
||||
vertex->m_abgr = _abgr;
|
||||
++vertex;
|
||||
}
|
||||
|
||||
for (uint32_t ii = 2; ii < _numCoords; ++ii)
|
||||
{
|
||||
vertex->m_x = _coords[0];
|
||||
vertex->m_y = _coords[1];
|
||||
vertex->m_abgr = _abgr;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = _coords[(ii - 1) * 2 + 0];
|
||||
vertex->m_y = _coords[(ii - 1) * 2 + 1];
|
||||
vertex->m_abgr = _abgr;
|
||||
++vertex;
|
||||
|
||||
vertex->m_x = _coords[ii * 2 + 0];
|
||||
vertex->m_y = _coords[ii * 2 + 1];
|
||||
vertex->m_abgr = _abgr;
|
||||
++vertex;
|
||||
}
|
||||
|
||||
bgfx::setVertexBuffer(&tvb);
|
||||
}
|
||||
}
|
||||
|
||||
void drawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _abgr, float _fth = 1.0f)
|
||||
{
|
||||
float dx = _x1 - _x0;
|
||||
float dy = _y1 - _y0;
|
||||
float d = sqrtf(dx * dx + dy * dy);
|
||||
if (d > 0.0001f)
|
||||
{
|
||||
d = 1.0f / d;
|
||||
dx *= d;
|
||||
dy *= d;
|
||||
}
|
||||
|
||||
float nx = dy;
|
||||
float ny = -dx;
|
||||
float verts[4 * 2];
|
||||
_r -= _fth;
|
||||
_r *= 0.5f;
|
||||
if (_r < 0.01f)
|
||||
{
|
||||
_r = 0.01f;
|
||||
}
|
||||
|
||||
dx *= _r;
|
||||
dy *= _r;
|
||||
nx *= _r;
|
||||
ny *= _r;
|
||||
|
||||
verts[0] = _x0 - dx - nx;
|
||||
verts[1] = _y0 - dy - ny;
|
||||
|
||||
verts[2] = _x0 - dx + nx;
|
||||
verts[3] = _y0 - dy + ny;
|
||||
|
||||
verts[4] = _x1 + dx + nx;
|
||||
verts[5] = _y1 + dy + ny;
|
||||
|
||||
verts[6] = _x1 + dx - nx;
|
||||
verts[7] = _y1 + dy - ny;
|
||||
|
||||
drawPolygon(verts, 4, _fth, _abgr);
|
||||
}
|
||||
|
||||
void initVertexDecls()
|
||||
{
|
||||
PosColorTexCoord0Vertex::init();
|
||||
PosColorVertex::init();
|
||||
}
|
||||
|
||||
static inline
|
||||
uint32_t u32Color(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
|
||||
{
|
||||
return 0
|
||||
| (uint32_t(_r) << 0)
|
||||
| (uint32_t(_g) << 8)
|
||||
| (uint32_t(_b) << 16)
|
||||
| (uint32_t(_a) << 24)
|
||||
;
|
||||
}
|
||||
|
||||
int renderer_bgfx::draw(int update)
|
||||
{
|
||||
//if (has_flags(FI_CHANGED) || (window().width() != m_last_width) || (window().height() != m_last_height))
|
||||
// do something
|
||||
//clear_flags(FI_CHANGED);
|
||||
initVertexDecls();
|
||||
|
||||
// Set view 0 default viewport.
|
||||
int width, height;
|
||||
#ifdef OSD_WINDOWS
|
||||
RECT client;
|
||||
GetClientRect(window().m_hwnd, &client);
|
||||
width = rect_width(&client);
|
||||
height = rect_height(&client);
|
||||
#else
|
||||
width = m_blit_dim.width();
|
||||
height = m_blit_dim.height();
|
||||
#endif
|
||||
bgfx::setViewRect(0, 0, 0, width, height);
|
||||
bgfx::reset(width, height, BGFX_RESET_VSYNC);
|
||||
// Setup view transform.
|
||||
{
|
||||
float view[16];
|
||||
bx::mtxIdentity(view);
|
||||
|
||||
float left = 0.0f;
|
||||
float top = 0.0f;
|
||||
float right = width;
|
||||
float bottom = height;
|
||||
float proj[16];
|
||||
bx::mtxOrtho(proj, left, right, bottom, top, 0.0f, 100.0f);
|
||||
bgfx::setViewTransform(0, view, proj);
|
||||
}
|
||||
bgfx::setViewClear(0
|
||||
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
|
||||
, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
|
||||
, 0x000000ff
|
||||
, 1.0f
|
||||
, 0
|
||||
);
|
||||
// Set view 0 default viewport.
|
||||
#ifdef OSD_WINDOWS
|
||||
RECT client;
|
||||
GetClientRect(window().m_hwnd, &client);
|
||||
bgfx::setViewRect(0, 0, 0, rect_width(&client), rect_height(&client));
|
||||
#else
|
||||
bgfx::setViewRect(0, 0, 0, m_blit_dim.width(), m_blit_dim.height());
|
||||
#endif
|
||||
|
||||
// This dummy draw call is here to make sure that view 0 is cleared
|
||||
// if no other draw calls are submitted to view 0.
|
||||
bgfx::touch(0);
|
||||
|
||||
window().m_primlist->acquire_lock();
|
||||
|
||||
// Draw quad.
|
||||
// now draw
|
||||
for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
|
||||
{
|
||||
uint64_t flags = BGFX_STATE_RGB_WRITE;
|
||||
switch (prim->flags & PRIMFLAG_BLENDMODE_MASK)
|
||||
{
|
||||
case PRIMFLAG_BLENDMODE(BLENDMODE_NONE):
|
||||
break;
|
||||
case PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA):
|
||||
flags |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
|
||||
break;
|
||||
case PRIMFLAG_BLENDMODE(BLENDMODE_RGB_MULTIPLY):
|
||||
flags |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_DST_COLOR, BGFX_STATE_BLEND_ZERO);
|
||||
break;
|
||||
case PRIMFLAG_BLENDMODE(BLENDMODE_ADD):
|
||||
flags |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_ONE);
|
||||
}
|
||||
|
||||
switch (prim->type)
|
||||
{
|
||||
/**
|
||||
@ -255,72 +655,98 @@ int renderer_bgfx::draw(int update)
|
||||
* since entering and leaving one is most expensive..
|
||||
*/
|
||||
case render_primitive::LINE:
|
||||
// check if it's really a point
|
||||
/*
|
||||
if (((prim->bounds.x1 - prim->bounds.x0) == 0) && ((prim->bounds.y1 - prim->bounds.y0) == 0))
|
||||
{
|
||||
curPrimitive=GL_POINTS;
|
||||
} else {
|
||||
curPrimitive=GL_LINES;
|
||||
}
|
||||
|
||||
if(pendingPrimitive!=GL_NO_PRIMITIVE && pendingPrimitive!=curPrimitive)
|
||||
{
|
||||
glEnd();
|
||||
pendingPrimitive=GL_NO_PRIMITIVE;
|
||||
}
|
||||
|
||||
if ( pendingPrimitive==GL_NO_PRIMITIVE )
|
||||
{
|
||||
set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags));
|
||||
}
|
||||
|
||||
glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a);
|
||||
|
||||
if(pendingPrimitive!=curPrimitive)
|
||||
{
|
||||
glBegin(curPrimitive);
|
||||
pendingPrimitive=curPrimitive;
|
||||
}
|
||||
|
||||
// check if it's really a point
|
||||
if (curPrimitive==GL_POINTS)
|
||||
{
|
||||
glVertex2f(prim->bounds.x0+hofs, prim->bounds.y0+vofs);
|
||||
}
|
||||
else
|
||||
{
|
||||
glVertex2f(prim->bounds.x0+hofs, prim->bounds.y0+vofs);
|
||||
glVertex2f(prim->bounds.x1+hofs, prim->bounds.y1+vofs);
|
||||
}*/
|
||||
|
||||
drawLine(prim->bounds.x0, prim->bounds.y0, prim->bounds.x1, prim->bounds.y1,
|
||||
1.0f,
|
||||
u32Color(prim->color.r * 255, prim->color.g * 255, prim->color.b * 255, prim->color.a * 255),
|
||||
1.0f);
|
||||
bgfx::setState(flags);
|
||||
bgfx::submit(0, m_progLine);
|
||||
break;
|
||||
|
||||
case render_primitive::QUAD:
|
||||
/*
|
||||
if(pendingPrimitive!=GL_NO_PRIMITIVE)
|
||||
{
|
||||
glEnd();
|
||||
pendingPrimitive=GL_NO_PRIMITIVE;
|
||||
}
|
||||
if (prim->texture.base == nullptr) {
|
||||
render_quad_texuv uv;
|
||||
uv.tl.u = uv.tl.v = uv.tr.u = uv.tr.v = 0;
|
||||
uv.bl.u = uv.bl.v = uv.br.u = uv.br.v = 0;
|
||||
screenQuad(prim->bounds.x0, prim->bounds.y0,prim->bounds.x1, prim->bounds.y1,
|
||||
u32Color(prim->color.r * 255, prim->color.g * 255, prim->color.b * 255, prim->color.a * 255),uv);
|
||||
bgfx::setState(flags);
|
||||
bgfx::submit(0, m_progQuad);
|
||||
} else {
|
||||
screenQuad(prim->bounds.x0, prim->bounds.y0, prim->bounds.x1, prim->bounds.y1,
|
||||
0xFFFFFFFF,prim->texcoords);
|
||||
bgfx::TextureHandle m_texture;
|
||||
// render based on the texture coordinates
|
||||
switch (prim->flags & PRIMFLAG_TEXFORMAT_MASK)
|
||||
{
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTEA16):
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16):
|
||||
{
|
||||
auto mem = bgfx::alloc(prim->texture.width*prim->texture.height * 4);
|
||||
|
||||
int y, x;
|
||||
|
||||
glColor4f(prim->color.r, prim->color.g, prim->color.b, prim->color.a);
|
||||
for (y = 0; y < prim->texture.height; y++)
|
||||
{
|
||||
unsigned char *pARGB32 = (unsigned char *)prim->texture.base + y*prim->texture.rowpixels*2;
|
||||
unsigned char *pRGBA8 = (unsigned char *)mem->data + y*prim->texture.width * 4;
|
||||
for (x = 0; x < prim->texture.width*2; x+=2)
|
||||
{
|
||||
pRGBA8[x*2 + 0] = prim->texture.palette[pARGB32[x + 0] + pARGB32[x + 1] * 256].r();
|
||||
pRGBA8[x*2 + 1] = prim->texture.palette[pARGB32[x + 0] + pARGB32[x + 1] * 256].g();
|
||||
pRGBA8[x*2 + 2] = prim->texture.palette[pARGB32[x + 0] + pARGB32[x + 1] * 256].b();
|
||||
pRGBA8[x*2 + 3] = prim->texture.palette[pARGB32[x + 0] + pARGB32[x + 1] * 256].a();
|
||||
}
|
||||
}
|
||||
m_texture = bgfx::createTexture2D((uint16_t)prim->texture.width
|
||||
, (uint16_t)prim->texture.height
|
||||
, 1
|
||||
, bgfx::TextureFormat::RGBA8
|
||||
, 0
|
||||
, mem
|
||||
);
|
||||
}
|
||||
break;
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16):
|
||||
break;
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32):
|
||||
case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32):
|
||||
{
|
||||
|
||||
auto mem = bgfx::alloc(prim->texture.width*prim->texture.height * 4);
|
||||
int y, x;
|
||||
|
||||
set_blendmode(sdl, PRIMFLAG_GET_BLENDMODE(prim->flags));
|
||||
for (y = 0; y < prim->texture.height; y++)
|
||||
{
|
||||
unsigned char *pARGB32 = (unsigned char *)prim->texture.base + y*prim->texture.rowpixels*4;
|
||||
unsigned char *pRGBA8 = (unsigned char *)mem->data + y*prim->texture.width *4;
|
||||
for (x = 0; x < prim->texture.width *4; x+=4 )
|
||||
{
|
||||
pRGBA8[x] = pARGB32[x+2];
|
||||
pRGBA8[x+1] = pARGB32[x+1];
|
||||
pRGBA8[x+2] = pARGB32[x+0];
|
||||
pRGBA8[x + 3] = pARGB32[x + 3];
|
||||
}
|
||||
}
|
||||
m_texture = bgfx::createTexture2D((uint16_t)prim->texture.width
|
||||
, (uint16_t)prim->texture.height
|
||||
, 1
|
||||
, bgfx::TextureFormat::RGBA8
|
||||
, 0
|
||||
, mem
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
texture = texture_update(window, prim, 0);
|
||||
|
||||
|
||||
sdl->texVerticex[0]=prim->bounds.x0 + hofs;
|
||||
sdl->texVerticex[1]=prim->bounds.y0 + vofs;
|
||||
sdl->texVerticex[2]=prim->bounds.x1 + hofs;
|
||||
sdl->texVerticex[3]=prim->bounds.y0 + vofs;
|
||||
sdl->texVerticex[4]=prim->bounds.x1 + hofs;
|
||||
sdl->texVerticex[5]=prim->bounds.y1 + vofs;
|
||||
sdl->texVerticex[6]=prim->bounds.x0 + hofs;
|
||||
sdl->texVerticex[7]=prim->bounds.y1 + vofs;
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bgfx::setTexture(0, m_s_texColor, m_texture);
|
||||
bgfx::setState(flags);
|
||||
bgfx::submit(0, m_progQuadTexture);
|
||||
bgfx::destroyTexture(m_texture);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user