Allow negative x/y in bgfx::setViewRect. (#3848)

This commit is contained in:
Branimir Karadžić
2026-07-25 15:04:06 +00:00
committed by GitHub
parent 7551ac61c5
commit ce18bdb6c6
23 changed files with 167 additions and 152 deletions
+6 -6
View File
@@ -4247,25 +4247,25 @@ public static class bgfx
/// </summary>
///
/// <param name="_id">View id.</param>
/// <param name="_x">Position x from the left corner of the window.</param>
/// <param name="_y">Position y from the top corner of the window.</param>
/// <param name="_x">Position x from the left corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_y">Position y from the top corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_width">Width of view port region.</param>
/// <param name="_height">Height of view port region.</param>
///
[LinkName("bgfx_set_view_rect")]
public static extern void set_view_rect(ViewId _id, uint16 _x, uint16 _y, uint16 _width, uint16 _height);
public static extern void set_view_rect(ViewId _id, int16 _x, int16 _y, uint16 _width, uint16 _height);
/// <summary>
/// Set view rectangle. Draw primitive outside view will be clipped.
/// </summary>
///
/// <param name="_id">View id.</param>
/// <param name="_x">Position x from the left corner of the window.</param>
/// <param name="_y">Position y from the top corner of the window.</param>
/// <param name="_x">Position x from the left corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_y">Position y from the top corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_ratio">Width and height will be set in respect to back-buffer size. See: `BackbufferRatio::Enum`.</param>
///
[LinkName("bgfx_set_view_rect_ratio")]
public static extern void set_view_rect_ratio(ViewId _id, uint16 _x, uint16 _y, BackbufferRatio _ratio);
public static extern void set_view_rect_ratio(ViewId _id, int16 _x, int16 _y, BackbufferRatio _ratio);
/// <summary>
/// Set view scissor. Draw primitive outside view will be clipped. When
+6 -6
View File
@@ -3042,18 +3042,18 @@ extern fn void set_view_name(ushort _id, ZString _name, int _len) @cname("bgfx_s
// Set view rectangle. Draw primitive outside view will be clipped.
// _id : `View id.`
// _x : `Position x from the left corner of the window.`
// _y : `Position y from the top corner of the window.`
// _x : `Position x from the left corner of the window. Can be negative to place view origin outside of the window.`
// _y : `Position y from the top corner of the window. Can be negative to place view origin outside of the window.`
// _width : `Width of view port region.`
// _height : `Height of view port region.`
extern fn void set_view_rect(ushort _id, ushort _x, ushort _y, ushort _width, ushort _height) @cname("bgfx_set_view_rect");
extern fn void set_view_rect(ushort _id, short _x, short _y, ushort _width, ushort _height) @cname("bgfx_set_view_rect");
// Set view rectangle. Draw primitive outside view will be clipped.
// _id : `View id.`
// _x : `Position x from the left corner of the window.`
// _y : `Position y from the top corner of the window.`
// _x : `Position x from the left corner of the window. Can be negative to place view origin outside of the window.`
// _y : `Position y from the top corner of the window. Can be negative to place view origin outside of the window.`
// _ratio : `Width and height will be set in respect to back-buffer size. See: `BackbufferRatio::Enum`.`
extern fn void set_view_rect_ratio(ushort _id, ushort _x, ushort _y, BackbufferRatio _ratio) @cname("bgfx_set_view_rect_ratio");
extern fn void set_view_rect_ratio(ushort _id, short _x, short _y, BackbufferRatio _ratio) @cname("bgfx_set_view_rect_ratio");
// Set view scissor. Draw primitive outside view will be clipped. When
// _x, _y, _width and _height are set to 0, scissor will be disabled.
+6 -6
View File
@@ -4197,25 +4197,25 @@ public static partial class bgfx
/// </summary>
///
/// <param name="_id">View id.</param>
/// <param name="_x">Position x from the left corner of the window.</param>
/// <param name="_y">Position y from the top corner of the window.</param>
/// <param name="_x">Position x from the left corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_y">Position y from the top corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_width">Width of view port region.</param>
/// <param name="_height">Height of view port region.</param>
///
[DllImport(DllName, EntryPoint="bgfx_set_view_rect", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void set_view_rect(ushort _id, ushort _x, ushort _y, ushort _width, ushort _height);
public static extern unsafe void set_view_rect(ushort _id, short _x, short _y, ushort _width, ushort _height);
/// <summary>
/// Set view rectangle. Draw primitive outside view will be clipped.
/// </summary>
///
/// <param name="_id">View id.</param>
/// <param name="_x">Position x from the left corner of the window.</param>
/// <param name="_y">Position y from the top corner of the window.</param>
/// <param name="_x">Position x from the left corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_y">Position y from the top corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_ratio">Width and height will be set in respect to back-buffer size. See: `BackbufferRatio::Enum`.</param>
///
[DllImport(DllName, EntryPoint="bgfx_set_view_rect_ratio", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void set_view_rect_ratio(ushort _id, ushort _x, ushort _y, BackbufferRatio _ratio);
public static extern unsafe void set_view_rect_ratio(ushort _id, short _x, short _y, BackbufferRatio _ratio);
/// <summary>
/// Set view scissor. Draw primitive outside view will be clipped. When
+11 -7
View File
@@ -9,7 +9,7 @@ import bindbc.common.types: c_int64, c_uint64, va_list;
import bindbc.bgfx.config;
static import bgfx.impl;
enum uint apiVersion = 151;
enum uint apiVersion = 152;
alias ViewID = ushort;
@@ -3347,23 +3347,27 @@ mixin(joinFnBinds((){
* Set view rectangle. Draw primitive outside view will be clipped.
Params:
id = View id.
x = Position x from the left corner of the window.
y = Position y from the top corner of the window.
x = Position x from the left corner of the window. Can be
negative to place view origin outside of the window.
y = Position y from the top corner of the window. Can be
negative to place view origin outside of the window.
width = Width of view port region.
height = Height of view port region.
*/
{q{void}, q{setViewRect}, q{ViewID id, ushort x, ushort y, ushort width, ushort height}, ext: `C++, "bgfx"`},
{q{void}, q{setViewRect}, q{ViewID id, short x, short y, ushort width, ushort height}, ext: `C++, "bgfx"`},
/**
* Set view rectangle. Draw primitive outside view will be clipped.
Params:
id = View id.
x = Position x from the left corner of the window.
y = Position y from the top corner of the window.
x = Position x from the left corner of the window. Can be
negative to place view origin outside of the window.
y = Position y from the top corner of the window. Can be
negative to place view origin outside of the window.
ratio = Width and height will be set in respect to back-buffer size.
See: `BackbufferRatio::Enum`.
*/
{q{void}, q{setViewRect}, q{ViewID id, ushort x, ushort y, bgfx.impl.BackbufferRatio.Enum ratio}, ext: `C++, "bgfx"`},
{q{void}, q{setViewRect}, q{ViewID id, short x, short y, bgfx.impl.BackbufferRatio.Enum ratio}, ext: `C++, "bgfx"`},
/**
* Set view scissor. Draw primitive outside view will be clipped. When
+8 -8
View File
@@ -3351,24 +3351,24 @@ extern fn bgfx_set_view_name(_id: ViewId, _name: [*c]const u8, _len: i32) void;
/// Set view rectangle. Draw primitive outside view will be clipped.
/// <param name="_id">View id.</param>
/// <param name="_x">Position x from the left corner of the window.</param>
/// <param name="_y">Position y from the top corner of the window.</param>
/// <param name="_x">Position x from the left corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_y">Position y from the top corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_width">Width of view port region.</param>
/// <param name="_height">Height of view port region.</param>
pub inline fn setViewRect(_id: ViewId, _x: u16, _y: u16, _width: u16, _height: u16) void {
pub inline fn setViewRect(_id: ViewId, _x: i16, _y: i16, _width: u16, _height: u16) void {
return bgfx_set_view_rect(_id, _x, _y, _width, _height);
}
extern fn bgfx_set_view_rect(_id: ViewId, _x: u16, _y: u16, _width: u16, _height: u16) void;
extern fn bgfx_set_view_rect(_id: ViewId, _x: i16, _y: i16, _width: u16, _height: u16) void;
/// Set view rectangle. Draw primitive outside view will be clipped.
/// <param name="_id">View id.</param>
/// <param name="_x">Position x from the left corner of the window.</param>
/// <param name="_y">Position y from the top corner of the window.</param>
/// <param name="_x">Position x from the left corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_y">Position y from the top corner of the window. Can be negative to place view origin outside of the window.</param>
/// <param name="_ratio">Width and height will be set in respect to back-buffer size. See: `BackbufferRatio::Enum`.</param>
pub inline fn setViewRectRatio(_id: ViewId, _x: u16, _y: u16, _ratio: BackbufferRatio) void {
pub inline fn setViewRectRatio(_id: ViewId, _x: i16, _y: i16, _ratio: BackbufferRatio) void {
return bgfx_set_view_rect_ratio(_id, _x, _y, _ratio);
}
extern fn bgfx_set_view_rect_ratio(_id: ViewId, _x: u16, _y: u16, _ratio: BackbufferRatio) void;
extern fn bgfx_set_view_rect_ratio(_id: ViewId, _x: i16, _y: i16, _ratio: BackbufferRatio) void;
/// Set view scissor. Draw primitive outside view will be clipped. When
/// _x, _y, _width and _height are set to 0, scissor will be disabled.
+2 -2
View File
@@ -252,8 +252,8 @@ A View's state is preserved between frames.
:members:
.. doxygenfunction:: bgfx::setViewName
.. doxygenfunction:: bgfx::setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
.. doxygenfunction:: bgfx::setViewRect(ViewId _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio)
.. doxygenfunction:: bgfx::setViewRect(ViewId _id, int16_t _x, int16_t _y, uint16_t _width, uint16_t _height)
.. doxygenfunction:: bgfx::setViewRect(ViewId _id, int16_t _x, int16_t _y, BackbufferRatio::Enum _ratio)
.. doxygenfunction:: bgfx::setViewScissor
.. doxygenfunction:: bgfx::setViewClear(ViewId _id, uint16_t _flags, uint32_t _rgba = 0x000000ff, float _depth = 1.0f, uint8_t _stencil = 0)
.. doxygenfunction:: bgfx::setViewClear(ViewId _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _c0 = UINT8_MAX, uint8_t _c1 = UINT8_MAX, uint8_t _c2 = UINT8_MAX, uint8_t _c3 = UINT8_MAX, uint8_t _c4 = UINT8_MAX, uint8_t _c5 = UINT8_MAX, uint8_t _c6 = UINT8_MAX, uint8_t _c7 = UINT8_MAX)
+12 -8
View File
@@ -3743,8 +3743,10 @@ namespace bgfx
/// Set view rectangle. Draw primitive outside view will be clipped.
///
/// @param[in] _id View id.
/// @param[in] _x Position x from the left corner of the window.
/// @param[in] _y Position y from the top corner of the window.
/// @param[in] _x Position x from the left corner of the window. Can be
/// negative to place view origin outside of the window.
/// @param[in] _y Position y from the top corner of the window. Can be
/// negative to place view origin outside of the window.
/// @param[in] _width Width of view port region.
/// @param[in] _height Height of view port region.
///
@@ -3752,8 +3754,8 @@ namespace bgfx
///
void setViewRect(
ViewId _id
, uint16_t _x
, uint16_t _y
, int16_t _x
, int16_t _y
, uint16_t _width
, uint16_t _height
);
@@ -3761,8 +3763,10 @@ namespace bgfx
/// Set view rectangle. Draw primitive outside view will be clipped.
///
/// @param[in] _id View id.
/// @param[in] _x Position x from the left corner of the window.
/// @param[in] _y Position y from the top corner of the window.
/// @param[in] _x Position x from the left corner of the window. Can be
/// negative to place view origin outside of the window.
/// @param[in] _y Position y from the top corner of the window. Can be
/// negative to place view origin outside of the window.
/// @param[in] _ratio Width and height will be set in respect to back-buffer size.
/// See: `BackbufferRatio::Enum`.
///
@@ -3770,8 +3774,8 @@ namespace bgfx
///
void setViewRect(
ViewId _id
, uint16_t _x
, uint16_t _y
, int16_t _x
, int16_t _y
, BackbufferRatio::Enum _ratio
);
+12 -8
View File
@@ -2570,25 +2570,29 @@ BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name, int32_
* Set view rectangle. Draw primitive outside view will be clipped.
*
* @param[in] _id View id.
* @param[in] _x Position x from the left corner of the window.
* @param[in] _y Position y from the top corner of the window.
* @param[in] _x Position x from the left corner of the window. Can be
* negative to place view origin outside of the window.
* @param[in] _y Position y from the top corner of the window. Can be
* negative to place view origin outside of the window.
* @param[in] _width Width of view port region.
* @param[in] _height Height of view port region.
*
*/
BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, int16_t _x, int16_t _y, uint16_t _width, uint16_t _height);
/**
* Set view rectangle. Draw primitive outside view will be clipped.
*
* @param[in] _id View id.
* @param[in] _x Position x from the left corner of the window.
* @param[in] _y Position y from the top corner of the window.
* @param[in] _x Position x from the left corner of the window. Can be
* negative to place view origin outside of the window.
* @param[in] _y Position y from the top corner of the window. Can be
* negative to place view origin outside of the window.
* @param[in] _ratio Width and height will be set in respect to back-buffer size.
* See: `BackbufferRatio::Enum`.
*
*/
BGFX_C_API void bgfx_set_view_rect_ratio(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio);
BGFX_C_API void bgfx_set_view_rect_ratio(bgfx_view_id_t _id, int16_t _x, int16_t _y, bgfx_backbuffer_ratio_t _ratio);
/**
* Set view scissor. Draw primitive outside view will be clipped. When
@@ -4314,8 +4318,8 @@ struct bgfx_interface_vtbl
void (*set_palette_color_rgba32f)(uint8_t _index, float _r, float _g, float _b, float _a);
void (*set_palette_color_rgba8)(uint8_t _index, uint32_t _rgba);
void (*set_view_name)(bgfx_view_id_t _id, const char* _name, int32_t _len);
void (*set_view_rect)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_rect_ratio)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio);
void (*set_view_rect)(bgfx_view_id_t _id, int16_t _x, int16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_rect_ratio)(bgfx_view_id_t _id, int16_t _x, int16_t _y, bgfx_backbuffer_ratio_t _ratio);
void (*set_view_scissor)(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height);
void (*set_view_clear)(bgfx_view_id_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil);
void (*set_view_clear_mrt)(bgfx_view_id_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _c0, uint8_t _c1, uint8_t _c2, uint8_t _c3, uint8_t _c4, uint8_t _c5, uint8_t _c6, uint8_t _c7);
+1 -1
View File
@@ -15,7 +15,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(151)
#define BGFX_API_VERSION UINT32_C(152)
/**
* Color RGB/alpha/depth write. When it's not specified write will be disabled.
+10 -5
View File
@@ -1,12 +1,13 @@
-- vim: syntax=lua
-- bgfx interface
version(151)
version(152)
typedef "bool"
typedef "char"
typedef "float"
typedef "int8_t"
typedef "int16_t"
typedef "int32_t"
typedef "int64_t"
typedef "uint8_t"
@@ -2303,8 +2304,10 @@ func.setViewName { section = "Views" }
func.setViewRect { section = "Views" }
"void"
.id "ViewId" --- View id.
.x "uint16_t" --- Position x from the left corner of the window.
.y "uint16_t" --- Position y from the top corner of the window.
.x "int16_t" --- Position x from the left corner of the window. Can be
--- negative to place view origin outside of the window.
.y "int16_t" --- Position y from the top corner of the window. Can be
--- negative to place view origin outside of the window.
.width "uint16_t" --- Width of view port region.
.height "uint16_t" --- Height of view port region.
@@ -2312,8 +2315,10 @@ func.setViewRect { section = "Views" }
func.setViewRect { cname = "set_view_rect_ratio", section = "Views" }
"void"
.id "ViewId" --- View id.
.x "uint16_t" --- Position x from the left corner of the window.
.y "uint16_t" --- Position y from the top corner of the window.
.x "int16_t" --- Position x from the left corner of the window. Can be
--- negative to place view origin outside of the window.
.y "int16_t" --- Position y from the top corner of the window. Can be
--- negative to place view origin outside of the window.
.ratio "BackbufferRatio::Enum" --- Width and height will be set in respect to back-buffer size.
--- See: `BackbufferRatio::Enum`.
+2
View File
@@ -58,6 +58,8 @@ local function convert_type_0(arg)
return arg.ctype:gsub("int32_t", "int32")
elseif hasPrefix(arg.ctype, "uint16_t") then
return arg.ctype:gsub("uint16_t", "uint16")
elseif hasPrefix(arg.ctype, "int16_t") then
return arg.ctype:gsub("int16_t", "int16")
elseif hasPrefix(arg.ctype, "uint8_t") then
return arg.ctype:gsub("uint8_t", "uint8")
elseif hasPrefix(arg.ctype, "uintptr_t") then
+2
View File
@@ -38,6 +38,8 @@ local function convert_type_0(arg)
return arg.ctype:gsub("int32_t", "int")
elseif hasPrefix(arg.ctype, "uint16_t") then
return arg.ctype:gsub("uint16_t", "ushort")
elseif hasPrefix(arg.ctype, "int16_t") then
return arg.ctype:gsub("int16_t", "short")
elseif hasPrefix(arg.ctype, "bgfx_view_id_t") then
return arg.ctype:gsub("bgfx_view_id_t", "ushort")
elseif hasPrefix(arg.ctype, "uint8_t") then
+2
View File
@@ -76,6 +76,8 @@ local function convert_type_0(arg)
return arg.ctype:gsub("int32_t", "int")
elseif hasPrefix(arg.ctype, "uint16_t") then
return arg.ctype:gsub("uint16_t", "ushort")
elseif hasPrefix(arg.ctype, "int16_t") then
return arg.ctype:gsub("int16_t", "short")
elseif hasPrefix(arg.ctype, "bgfx_view_id_t") then
return arg.ctype:gsub("bgfx_view_id_t", "ushort")
elseif hasPrefix(arg.ctype, "uint8_t") then
+2
View File
@@ -65,6 +65,8 @@ local function convert_type_0(arg)
return arg.ctype:gsub("int32_t", "i32")
elseif hasPrefix(arg.ctype, "uint16_t") then
return arg.ctype:gsub("uint16_t", "u16")
elseif hasPrefix(arg.ctype, "int16_t") then
return arg.ctype:gsub("int16_t", "i16")
elseif hasPrefix(arg.ctype, "uint8_t") then
return arg.ctype:gsub("uint8_t", "u8")
elseif hasPrefix(arg.ctype, "uintptr_t") then
+4 -3
View File
@@ -1716,7 +1716,8 @@ namespace bgfx
}
}
view.m_rect.intersect(rect);
view.m_clippedRect = view.m_rect;
view.m_clippedRect.intersect(rect);
if (!view.m_scissor.isZero() )
{
@@ -6072,13 +6073,13 @@ namespace bgfx
s_ctx->setViewName(_id, bx::StringView(_name, _len) );
}
void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
void setViewRect(ViewId _id, int16_t _x, int16_t _y, uint16_t _width, uint16_t _height)
{
BX_ASSERT(checkView(_id), "Invalid view id: %d", _id);
s_ctx->setViewRect(_id, _x, _y, _width, _height);
}
void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio)
void setViewRect(ViewId _id, int16_t _x, int16_t _y, BackbufferRatio::Enum _ratio)
{
BX_ASSERT(checkView(_id), "Invalid view id: %d", _id);
+2 -2
View File
@@ -667,12 +667,12 @@ BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name, int32_
bgfx::setViewName((bgfx::ViewId)_id, _name, _len);
}
BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, int16_t _x, int16_t _y, uint16_t _width, uint16_t _height)
{
bgfx::setViewRect((bgfx::ViewId)_id, _x, _y, _width, _height);
}
BGFX_C_API void bgfx_set_view_rect_ratio(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio)
BGFX_C_API void bgfx_set_view_rect_ratio(bgfx_view_id_t _id, int16_t _x, int16_t _y, bgfx_backbuffer_ratio_t _ratio)
{
bgfx::setViewRect((bgfx::ViewId)_id, _x, _y, (bgfx::BackbufferRatio::Enum)_ratio);
}
+25 -20
View File
@@ -515,7 +515,7 @@ namespace bgfx
{
}
Rect(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
Rect(int16_t _x, int16_t _y, uint16_t _width, uint16_t _height)
: m_x(_x)
, m_y(_y)
, m_width(_width)
@@ -557,7 +557,7 @@ namespace bgfx
;
}
void set(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
void set(int16_t _x, int16_t _y, uint16_t _width, uint16_t _height)
{
m_x = _x;
m_y = _y;
@@ -567,14 +567,14 @@ namespace bgfx
void setIntersect(const Rect& _a, const Rect& _b)
{
const uint16_t sx = bx::max<uint16_t>(_a.m_x, _b.m_x);
const uint16_t sy = bx::max<uint16_t>(_a.m_y, _b.m_y);
const uint16_t ex = bx::min<uint16_t>(_a.m_x + _a.m_width, _b.m_x + _b.m_width );
const uint16_t ey = bx::min<uint16_t>(_a.m_y + _a.m_height, _b.m_y + _b.m_height);
m_x = sx;
m_y = sy;
m_width = (uint16_t)bx::satSub<uint32_t>(ex, sx);
m_height = (uint16_t)bx::satSub<uint32_t>(ey, sy);
const int32_t sx = bx::max<int32_t>(_a.m_x, _b.m_x);
const int32_t sy = bx::max<int32_t>(_a.m_y, _b.m_y);
const int32_t ex = bx::min<int32_t>(_a.m_x + _a.m_width, _b.m_x + _b.m_width );
const int32_t ey = bx::min<int32_t>(_a.m_y + _a.m_height, _b.m_y + _b.m_height);
m_x = int16_t(sx);
m_y = int16_t(sy);
m_width = uint16_t(bx::max<int32_t>(ex - sx, 0) );
m_height = uint16_t(bx::max<int32_t>(ey - sy, 0) );
}
void intersect(const Rect& _a)
@@ -582,8 +582,8 @@ namespace bgfx
setIntersect(*this, _a);
}
uint16_t m_x;
uint16_t m_y;
int16_t m_x;
int16_t m_y;
uint16_t m_width;
uint16_t m_height;
};
@@ -1725,8 +1725,8 @@ namespace bgfx
Rect& rect = m_cache[first];
rect.m_x = _x;
rect.m_y = _y;
rect.m_x = bx::narrowCast<int16_t>(_x);
rect.m_y = bx::narrowCast<int16_t>(_y);
rect.m_width = _width;
rect.m_height = _height;
@@ -2443,12 +2443,16 @@ namespace bgfx
setTransform(NULL, NULL);
}
void setRect(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
void setRect(int16_t _x, int16_t _y, uint16_t _width, uint16_t _height)
{
m_rect.m_x = uint16_t(bx::max<int16_t>(int16_t(_x), 0) );
m_rect.m_y = uint16_t(bx::max<int16_t>(int16_t(_y), 0) );
m_rect.m_x = _x;
m_rect.m_y = _y;
m_rect.m_width = bx::max<uint16_t>(_width, 1);
m_rect.m_height = bx::max<uint16_t>(_height, 1);
// Frame::sort clips this against the render target. Default to
// unclipped, so it's never stale when sort didn't run.
m_clippedRect = m_rect;
}
void setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
@@ -2512,6 +2516,7 @@ namespace bgfx
Clear m_clear;
Rect m_rect;
Rect m_clippedRect;
Rect m_scissor;
Matrix4 m_view;
Matrix4 m_proj;
@@ -5886,8 +5891,8 @@ namespace bgfx
cmdbuf.write(_side);
cmdbuf.write(_mip);
Rect rect;
rect.m_x = _x;
rect.m_y = _y;
rect.m_x = bx::narrowCast<int16_t>(_x);
rect.m_y = bx::narrowCast<int16_t>(_y);
rect.m_width = _width;
rect.m_height = _height;
cmdbuf.write(rect);
@@ -6278,7 +6283,7 @@ namespace bgfx
cmdbuf.write(_name);
}
BGFX_API_FUNC(void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) )
BGFX_API_FUNC(void setViewRect(ViewId _id, int16_t _x, int16_t _y, uint16_t _width, uint16_t _height) )
{
m_view[_id].setRect(_x, _y, _width, _height);
}
+3 -2
View File
@@ -6156,10 +6156,11 @@ namespace bgfx { namespace d3d11
}
viewState.m_rect = _render->m_view[view].m_rect;
const Rect& clippedRect = _render->m_view[view].m_clippedRect;
const Rect& scissorRect = _render->m_view[view].m_scissor;
viewHasScissor = !scissorRect.isZero();
viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect;
viewScissorRect = viewHasScissor ? scissorRect : clippedRect;
D3D11_VIEWPORT vp;
vp.TopLeftX = viewState.m_rect.m_x;
@@ -6173,7 +6174,7 @@ namespace bgfx { namespace d3d11
if (BGFX_CLEAR_NONE != (clr.m_flags & BGFX_CLEAR_MASK) )
{
clearQuad(_clearQuad, viewState.m_rect, clr, _render->m_colorPalette);
clearQuad(_clearQuad, clippedRect, clr, _render->m_colorPalette);
prim = s_primInfo[Topology::Count]; // Force primitive type update after clear quad.
}
+4 -3
View File
@@ -7983,9 +7983,10 @@ namespace bgfx { namespace d3d12
viewState.m_rect = renderView.m_rect;
const Rect& rect = renderView.m_rect;
const Rect& clippedRect = renderView.m_clippedRect;
const Rect& scissorRect = renderView.m_scissor;
viewHasScissor = !scissorRect.isZero();
viewScissorRect = viewHasScissor ? scissorRect : rect;
viewScissorRect = viewHasScissor ? scissorRect : clippedRect;
D3D12_VIEWPORT vp;
vp.TopLeftX = rect.m_x;
@@ -8008,8 +8009,8 @@ namespace bgfx { namespace d3d12
if (BGFX_CLEAR_NONE != clr.m_flags)
{
Rect clearRect = rect;
clearRect.setIntersect(rect, viewScissorRect);
Rect clearRect;
clearRect.setIntersect(clippedRect, viewScissorRect);
clearQuad(clearRect, clr, _render->m_colorPalette);
}
+3 -2
View File
@@ -7922,10 +7922,11 @@ namespace bgfx { namespace gl
profiler.begin(view);
viewState.m_rect = _render->m_view[view].m_rect;
const Rect& clippedRect = _render->m_view[view].m_clippedRect;
const Rect& scissorRect = _render->m_view[view].m_scissor;
viewHasScissor = !scissorRect.isZero();
viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect;
viewScissorRect = viewHasScissor ? scissorRect : clippedRect;
GL_CHECK(glViewport(viewState.m_rect.m_x
, resolutionHeight-viewState.m_rect.m_height-viewState.m_rect.m_y
@@ -7938,7 +7939,7 @@ namespace bgfx { namespace gl
if (BGFX_CLEAR_NONE != (clear.m_flags & BGFX_CLEAR_MASK) )
{
clearQuad(_clearQuad, viewState.m_rect, clear, resolutionHeight, _render->m_colorPalette);
clearQuad(_clearQuad, clippedRect, clear, resolutionHeight, _render->m_colorPalette);
}
GL_CHECK(glDisable(GL_STENCIL_TEST) );
+16 -24
View File
@@ -5334,9 +5334,10 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
if (!isCompute)
{
const Rect& clippedRect = _render->m_view[view].m_clippedRect;
const Rect& scissorRect = _render->m_view[view].m_scissor;
viewHasScissor = !scissorRect.isZero();
viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect;
viewScissorRect = viewHasScissor ? scissorRect : clippedRect;
Clear& clr = _render->m_view[view].m_clear;
const Rect viewRect = viewState.m_rect;
@@ -5525,10 +5526,10 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
rce->setViewport(vp);
MTL::ScissorRect sciRect = {
viewState.m_rect.m_x,
viewState.m_rect.m_y,
viewState.m_rect.m_width,
viewState.m_rect.m_height
NS::UInteger(clippedRect.m_x),
NS::UInteger(clippedRect.m_y),
NS::UInteger(clippedRect.m_width),
NS::UInteger(clippedRect.m_height)
};
rce->setScissorRect(sciRect);
}
@@ -5536,7 +5537,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
if (BGFX_CLEAR_NONE != (clr.m_flags & BGFX_CLEAR_MASK)
&& !clearWithRenderPass)
{
clearQuad(_clearQuad, viewState.m_rect, clr, _render->m_colorPalette);
clearQuad(_clearQuad, clippedRect, clr, _render->m_colorPalette);
}
}
}
@@ -5764,30 +5765,21 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
MTL::ScissorRect rc;
if (UINT16_MAX == scissor)
{
if (viewHasScissor)
{
rc.x = viewScissorRect.m_x;
rc.y = viewScissorRect.m_y;
rc.width = viewScissorRect.m_width;
rc.height = viewScissorRect.m_height;
}
else
{ // can't disable: set to view rect
rc.x = viewState.m_rect.m_x;
rc.y = viewState.m_rect.m_y;
rc.width = viewState.m_rect.m_width;
rc.height = viewState.m_rect.m_height;
}
// Can't disable scissor, so it's set to view scissor rect.
rc.x = NS::UInteger(viewScissorRect.m_x);
rc.y = NS::UInteger(viewScissorRect.m_y);
rc.width = NS::UInteger(viewScissorRect.m_width);
rc.height = NS::UInteger(viewScissorRect.m_height);
}
else
{
Rect scissorRect;
scissorRect.setIntersect(viewScissorRect, _render->m_frameCache.m_rectCache.m_cache[scissor]);
rc.x = scissorRect.m_x;
rc.y = scissorRect.m_y;
rc.width = scissorRect.m_width;
rc.height = scissorRect.m_height;
rc.x = NS::UInteger(scissorRect.m_x);
rc.y = NS::UInteger(scissorRect.m_y);
rc.width = NS::UInteger(scissorRect.m_width);
rc.height = NS::UInteger(scissorRect.m_height);
}
rce->setScissorRect(rc);
+15 -26
View File
@@ -4619,11 +4619,13 @@ VK_IMPORT_DEVICE
void clearQuad(const Rect& _rect, const Clear& _clear, const float _palette[][4])
{
const Rect clearRect = _rect;
VkClearRect rect[1];
rect[0].rect.offset.x = _rect.m_x;
rect[0].rect.offset.y = _rect.m_y;
rect[0].rect.extent.width = _rect.m_width;
rect[0].rect.extent.height = _rect.m_height;
rect[0].rect.offset.x = clearRect.m_x;
rect[0].rect.offset.y = clearRect.m_y;
rect[0].rect.extent.width = clearRect.m_width;
rect[0].rect.extent.height = clearRect.m_height;
rect[0].baseArrayLayer = 0;
rect[0].layerCount = 1;
@@ -9719,32 +9721,19 @@ VK_DESTROY
VkRenderPass renderPass = fb.getRenderPass(_render->m_view[view].m_clear.m_flags);
viewState.m_rect = _render->m_view[view].m_rect;
Rect rect = _render->m_view[view].m_rect;
const Rect& rect = _render->m_view[view].m_rect;
const Rect& renderArea = _render->m_view[view].m_clippedRect;
Rect scissorRect = _render->m_view[view].m_scissor;
viewHasScissor = !scissorRect.isZero();
viewScissorRect = viewHasScissor ? scissorRect : rect;
viewScissorRect = viewHasScissor ? scissorRect : renderArea;
restoreScissor = false;
// Clamp the rect to what's valid according to Vulkan.
rect.m_width = bx::min(rect.m_width, bx::narrowCast<uint16_t>(fb.m_width) - rect.m_x);
rect.m_height = bx::min(rect.m_height, bx::narrowCast<uint16_t>(fb.m_height) - rect.m_y);
if (_render->m_view[view].m_rect.m_width != rect.m_width
|| _render->m_view[view].m_rect.m_height != rect.m_height)
{
BX_TRACE("Clamp render pass from %dx%d to %dx%d"
, _render->m_view[view].m_rect.m_width
, _render->m_view[view].m_rect.m_height
, rect.m_width
, rect.m_height
);
}
rpbi.framebuffer = fb.m_currentFramebuffer;
rpbi.renderPass = renderPass;
rpbi.renderArea.offset.x = rect.m_x;
rpbi.renderArea.offset.y = rect.m_y;
rpbi.renderArea.extent.width = rect.m_width;
rpbi.renderArea.extent.height = rect.m_height;
rpbi.renderArea.offset.x = renderArea.m_x;
rpbi.renderArea.offset.y = renderArea.m_y;
rpbi.renderArea.extent.width = renderArea.m_width;
rpbi.renderArea.extent.height = renderArea.m_height;
VkViewport vp;
vp.x = float(rect.m_x);
@@ -9861,8 +9850,8 @@ VK_DESTROY
const Clear& clr = _render->m_view[view].m_clear;
if (BGFX_CLEAR_NONE != clr.m_flags)
{
Rect clearRect = rect;
clearRect.setIntersect(rect, viewScissorRect);
Rect clearRect;
clearRect.setIntersect(renderArea, viewScissorRect);
clearQuad(clearRect, clr, _render->m_colorPalette);
}
+13 -13
View File
@@ -4317,8 +4317,8 @@ WGPU_IMPORT
.mipLevel = _mip,
.origin =
{
.x = _rect.m_x,
.y = _rect.m_y,
.x = uint32_t(_rect.m_x),
.y = uint32_t(_rect.m_y),
.z = originZ,
},
.aspect = WGPUTextureAspect_All,
@@ -5949,21 +5949,21 @@ m_resolution.formatColor = TextureFormat::BGRA8;
;
viewState.m_rect = _render->m_view[view].m_rect;
Rect viewRect = _render->m_view[view].m_rect;
const Rect& viewRect = _render->m_view[view].m_rect;
const Rect& clippedRect = _render->m_view[view].m_clippedRect;
Rect scissorRect = _render->m_view[view].m_scissor;
const Rect fbRect(0, 0, bx::narrowCast<uint16_t>(fb.m_width), bx::narrowCast<uint16_t>(fb.m_height) );
viewRect.intersect(fbRect);
scissorRect.intersect(fbRect);
viewHasScissor = !scissorRect.isZero();
viewScissorRect = viewHasScissor ? scissorRect : viewRect;
viewScissorRect = viewHasScissor ? scissorRect : clippedRect;
restoreScissor = false;
const Clear& clr = _render->m_view[view].m_clear;
const bool needClear = BGFX_CLEAR_NONE != ( (BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH|BGFX_CLEAR_STENCIL) & clr.m_flags);
const bool clearWhole = viewRect.isEqual(fbRect);
const bool clearWhole = clippedRect.isEqual(fbRect);
WGPURenderPassColorAttachment colorAttachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS];
@@ -6083,13 +6083,13 @@ m_resolution.formatColor = TextureFormat::BGRA8;
if (!clearWhole && needClear)
{
clearQuad(renderPassEncoder, fbh, msaaCount, _clearQuad, viewRect, clr, _render->m_colorPalette);
clearQuad(renderPassEncoder, fbh, msaaCount, _clearQuad, clippedRect, clr, _render->m_colorPalette);
}
wgpuRenderPassEncoderSetScissorRect(
renderPassEncoder
, viewScissorRect.m_x
, viewScissorRect.m_y
, uint32_t(viewScissorRect.m_x)
, uint32_t(viewScissorRect.m_y)
, viewScissorRect.m_width
, viewScissorRect.m_height
);
@@ -6440,8 +6440,8 @@ m_resolution.formatColor = TextureFormat::BGRA8;
wgpuRenderPassEncoderSetScissorRect(
renderPassEncoder
, viewScissorRect.m_x
, viewScissorRect.m_y
, uint32_t(viewScissorRect.m_x)
, uint32_t(viewScissorRect.m_y)
, viewScissorRect.m_width
, viewScissorRect.m_height
);
@@ -6459,8 +6459,8 @@ m_resolution.formatColor = TextureFormat::BGRA8;
wgpuRenderPassEncoderSetScissorRect(
renderPassEncoder
, scissorRect.m_x
, scissorRect.m_y
, uint32_t(scissorRect.m_x)
, uint32_t(scissorRect.m_y)
, scissorRect.m_width
, scissorRect.m_height
);