Restored black bars and custom images instead of black bars, closes #1571

This commit is contained in:
Juan Linietsky 2017-08-07 18:06:57 -03:00
parent 5f48c3cc07
commit 539fbad919
8 changed files with 105 additions and 31 deletions

View File

@ -941,6 +941,8 @@ void RasterizerGLES2::_canvas_item_setup_shader_params(ShaderMaterial *material,
void RasterizerCanvasGLES3::_copy_texscreen(const Rect2 &p_rect) {
glDisable(GL_BLEND);
state.canvas_texscreen_used = true;
//blur diffuse into effect mipmaps using separatable convolution
//storage->shaders.copy.set_conditional(CopyShaderGLES3::GAUSSIAN_HORIZONTAL,true);
@ -1003,12 +1005,16 @@ void RasterizerCanvasGLES3::_copy_texscreen(const Rect2 &p_rect) {
glBindFramebuffer(GL_FRAMEBUFFER, storage->frame.current_rt->fbo); //back to front
glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
state.canvas_shader.bind(); //back to canvas
_bind_canvas_texture(state.current_tex, state.current_normal);
if (state.using_texture_rect) {
state.using_texture_rect = false;
_set_texture_rect_mode(state.using_texture_rect, state.using_ninepatch);
}
glEnable(GL_BLEND);
}
void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light) {
@ -1595,6 +1601,67 @@ void RasterizerCanvasGLES3::draw_generic_textured_rect(const Rect2 &p_rect, cons
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
void RasterizerCanvasGLES3::draw_window_margins(int *black_margin, RID *black_image) {
Vector2 window_size = OS::get_singleton()->get_window_size();
int window_h = window_size.height;
int window_w = window_size.width;
glBindFramebuffer(GL_FRAMEBUFFER, storage->system_fbo);
glViewport(0, 0, window_size.width, window_size.height);
canvas_begin();
if (black_image[MARGIN_LEFT].is_valid()) {
_bind_canvas_texture(black_image[MARGIN_LEFT], RID());
Size2 sz(storage->texture_get_width(black_image[MARGIN_LEFT]), storage->texture_get_height(black_image[MARGIN_LEFT]));
draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h), Rect2(0, 0, sz.x, sz.y));
} else if (black_margin[MARGIN_LEFT]) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
draw_generic_textured_rect(Rect2(0, 0, black_margin[MARGIN_LEFT], window_h), Rect2(0, 0, 1, 1));
}
if (black_image[MARGIN_RIGHT].is_valid()) {
_bind_canvas_texture(black_image[MARGIN_RIGHT], RID());
Size2 sz(storage->texture_get_width(black_image[MARGIN_RIGHT]), storage->texture_get_height(black_image[MARGIN_RIGHT]));
draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h), Rect2(0, 0, sz.x, sz.y));
} else if (black_margin[MARGIN_RIGHT]) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
draw_generic_textured_rect(Rect2(window_w - black_margin[MARGIN_RIGHT], 0, black_margin[MARGIN_RIGHT], window_h), Rect2(0, 0, 1, 1));
}
if (black_image[MARGIN_TOP].is_valid()) {
_bind_canvas_texture(black_image[MARGIN_TOP], RID());
Size2 sz(storage->texture_get_width(black_image[MARGIN_TOP]), storage->texture_get_height(black_image[MARGIN_TOP]));
draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]), Rect2(0, 0, sz.x, sz.y));
} else if (black_margin[MARGIN_TOP]) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
draw_generic_textured_rect(Rect2(0, 0, window_w, black_margin[MARGIN_TOP]), Rect2(0, 0, 1, 1));
}
if (black_image[MARGIN_BOTTOM].is_valid()) {
_bind_canvas_texture(black_image[MARGIN_BOTTOM], RID());
Size2 sz(storage->texture_get_width(black_image[MARGIN_BOTTOM]), storage->texture_get_height(black_image[MARGIN_BOTTOM]));
draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]), Rect2(0, 0, sz.x, sz.y));
} else if (black_margin[MARGIN_BOTTOM]) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, storage->resources.black_tex);
draw_generic_textured_rect(Rect2(0, window_h - black_margin[MARGIN_BOTTOM], window_w, black_margin[MARGIN_BOTTOM]), Rect2(0, 0, 1, 1));
}
}
void RasterizerCanvasGLES3::initialize() {
{

View File

@ -138,6 +138,8 @@ public:
void initialize();
void finalize();
virtual void draw_window_margins(int *black_margin, RID *black_image);
RasterizerCanvasGLES3();
};

View File

@ -453,7 +453,8 @@ void InputDefault::set_mouse_position(const Point2 &p_posf) {
mouse_speed_track.update(p_posf - mouse_pos);
mouse_pos = p_posf;
if (custom_cursor.is_valid()) {
VisualServer::get_singleton()->cursor_set_pos(get_mouse_position());
//removed, please insist that we implement hardware cursors
// VisualServer::get_singleton()->cursor_set_pos(get_mouse_position());
}
}
@ -538,6 +539,7 @@ bool InputDefault::is_emulating_touchscreen() const {
}
void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p_hotspot) {
/* no longer supported, leaving this for reference to anyone who might want to implement hardware cursors
if (custom_cursor == p_cursor)
return;
@ -545,7 +547,8 @@ void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p
if (p_cursor.is_null()) {
set_mouse_mode(MOUSE_MODE_VISIBLE);
VisualServer::get_singleton()->cursor_set_visible(false);
//removed, please insist us to implement hardare cursors
//VisualServer::get_singleton()->cursor_set_visible(false);
} else {
Ref<AtlasTexture> atex = custom_cursor;
Rect2 region = atex.is_valid() ? atex->get_region() : Rect2();
@ -554,10 +557,11 @@ void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p
VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(), p_hotspot, 0, region);
VisualServer::get_singleton()->cursor_set_pos(get_mouse_position());
}
*/
}
void InputDefault::set_mouse_in_window(bool p_in_window) {
/* no longer supported, leaving this for reference to anyone who might want to implement hardware cursors
if (custom_cursor.is_valid()) {
if (p_in_window) {
@ -568,6 +572,7 @@ void InputDefault::set_mouse_in_window(bool p_in_window) {
VisualServer::get_singleton()->cursor_set_visible(false);
}
}
*/
}
// from github.com/gabomdq/SDL_GameControllerDB

View File

@ -1014,6 +1014,8 @@ public:
virtual void reset_canvas() = 0;
virtual void draw_window_margins(int *p_margins, RID *p_margin_textures) = 0;
virtual ~RasterizerCanvas() {}
};

View File

@ -41,23 +41,29 @@
int VisualServerRaster::changes = 0;
/* CURSOR */
void VisualServerRaster::cursor_set_rotation(float p_rotation, int p_cursor) {
}
void VisualServerRaster::cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor, const Rect2 &p_region) {
}
void VisualServerRaster::cursor_set_visible(bool p_visible, int p_cursor) {
}
void VisualServerRaster::cursor_set_pos(const Point2 &p_pos, int p_cursor) {
}
/* BLACK BARS */
void VisualServerRaster::black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) {
black_margin[MARGIN_LEFT] = p_left;
black_margin[MARGIN_TOP] = p_top;
black_margin[MARGIN_RIGHT] = p_right;
black_margin[MARGIN_BOTTOM] = p_bottom;
}
void VisualServerRaster::black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom) {
black_image[MARGIN_LEFT] = p_left;
black_image[MARGIN_TOP] = p_top;
black_image[MARGIN_RIGHT] = p_right;
black_image[MARGIN_BOTTOM] = p_bottom;
}
void VisualServerRaster::_draw_margins() {
VSG::canvas_render->draw_window_margins(black_margin, black_image);
};
/* FREE */
void VisualServerRaster::free(RID p_rid) {
@ -121,6 +127,8 @@ void VisualServerRaster::draw() {
frame_drawn_callbacks.pop_front();
}
_draw_margins();
}
void VisualServerRaster::sync() {
}
@ -189,6 +197,9 @@ VisualServerRaster::VisualServerRaster() {
VSG::storage = VSG::rasterizer->get_storage();
VSG::canvas_render = VSG::rasterizer->get_canvas();
VSG::scene_render = VSG::rasterizer->get_scene();
for (int i = 0; i < 4; i++)
black_margin[i] = 0;
}
VisualServerRaster::~VisualServerRaster() {

View File

@ -61,6 +61,9 @@ class VisualServerRaster : public VisualServer {
bool draw_extra_frame;
RID test_cube;
int black_margin[4];
RID black_image[4];
struct FrameDrawnCallbacks {
ObjectID object;
@ -584,6 +587,8 @@ class VisualServerRaster : public VisualServer {
#endif
void _draw_margins();
public:
_FORCE_INLINE_ static void redraw_request() { changes++; }
@ -1110,12 +1115,6 @@ public:
BIND2(canvas_occluder_polygon_set_cull_mode, RID, CanvasOccluderPolygonCullMode)
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0); // radians
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor = 0, const Rect2 &p_region = Rect2());
virtual void cursor_set_visible(bool p_visible, int p_cursor = 0);
virtual void cursor_set_pos(const Point2 &p_pos, int p_cursor = 0);
/* BLACK BARS */
virtual void black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom);

View File

@ -538,12 +538,6 @@ public:
FUNC2(canvas_occluder_polygon_set_cull_mode, RID, CanvasOccluderPolygonCullMode)
/* CURSOR */
FUNC2(cursor_set_rotation, float, int) // radians
FUNC4(cursor_set_texture, RID, const Point2 &, int, const Rect2 &)
FUNC2(cursor_set_visible, bool, int)
FUNC2(cursor_set_pos, const Point2 &, int)
/* BLACK BARS */
FUNC4(black_bars_set_margins, int, int, int, int)

View File

@ -875,12 +875,6 @@ public:
};
virtual void canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon, CanvasOccluderPolygonCullMode p_mode) = 0;
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0) = 0; // radians
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor = 0, const Rect2 &p_region = Rect2()) = 0;
virtual void cursor_set_visible(bool p_visible, int p_cursor = 0) = 0;
virtual void cursor_set_pos(const Point2 &p_pos, int p_cursor = 0) = 0;
/* BLACK BARS */
virtual void black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) = 0;