Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering system overhaul #6693

Merged
merged 27 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
581c6e6
video: Add functions for immediate rendering of surfaces and textures.
mesilliac May 1, 2022
eb60753
Overhaul drawing to use CVideo API in stead of blitting to a surface.
mesilliac May 1, 2022
fca99c9
CVideo: mark location arguments of blit_texture as const.
mesilliac May 3, 2022
5877371
CVideo: add functions to read pixels back from the render target.
mesilliac May 3, 2022
d45440f
Read title_screen screenshots from the high-res render target.
mesilliac May 3, 2022
2d22120
sdl/texture: Add wrapper for setting an alpha modifier.
mesilliac May 3, 2022
c0ea33e
Reenable floating labels.
mesilliac May 3, 2022
3a3342f
sdl/texture: Allow creating an empty texture from am empty surface.
mesilliac May 3, 2022
f85f1da
gui/window: cache restorer as a texture and from the render target.
mesilliac May 3, 2022
27758e4
gui/canvas: Reenable blur.
mesilliac May 3, 2022
12260a7
Buggy but forward-compatible halo rendering.
mesilliac May 3, 2022
3089477
Add a low-res pixel retrieval function and use it for reports.
mesilliac May 3, 2022
c627c96
sdl/surface: use low-res pixel retrieval for surface_restorer.
mesilliac May 3, 2022
1ac5b42
video: Ensure render viewport is an integer multiple of logical size.
mesilliac May 3, 2022
01cf583
Fix halo background rendering.
mesilliac May 3, 2022
cba8b9d
CVideo: Fix read_pixels behaviour in a certain edge case.
mesilliac May 3, 2022
11c78c9
CVideo: Add a helper for setting the clip area.
mesilliac May 3, 2022
19f3037
Use new CVideo clipping interface.
mesilliac May 3, 2022
29c862b
Fix blur.
mesilliac May 3, 2022
5cf876a
CVideo: Ensure correct transfer of alpha when blitting surfaces.
mesilliac May 3, 2022
0bb74bd
Remove all remaining direct usage of the drawing surface.
mesilliac May 3, 2022
00bf4a2
CVideo: Clean up error handling.
mesilliac May 4, 2022
98b2f50
Remove vsync compatibility check.
mesilliac May 7, 2022
36ece6b
Clean up high-dpi todos and comments.
mesilliac May 8, 2022
e681ef3
Update Xcode project
CelticMinstrel May 8, 2022
603006f
Minor code clarification.
mesilliac May 8, 2022
197dfae
Merge remote-tracking branch 'wesnoth/master' into rendering_system_o…
mesilliac May 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@
91A215E31CAD9B9000927AEA /* libpangocairo-1.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = EC5C242F18EF07B4001FA499 /* libpangocairo-1.0.0.dylib */; };
91A41F901CA22A98008B10D5 /* libreadline.8.1.dylib in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = ECA9E7461CA20AA800A947D6 /* libreadline.8.1.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
91AF556D281101C4007A7652 /* input.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91AF556C281101C3007A7652 /* input.cpp */; };
91AF55B02827588B007A7652 /* texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91AF55AF2827588B007A7652 /* texture.cpp */; };
91B621A21B76A3CC00B00E0F /* build_info.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B621A11B76A3CC00B00E0F /* build_info.cpp */; };
91B621BA1B76B2C900B00E0F /* version.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B621B91B76B2C900B00E0F /* version.cpp */; };
91B6220A1B76C0A600B00E0F /* libcairo.2.dylib in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = B513B2270ED36BFB0006E551 /* libcairo.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
Expand Down Expand Up @@ -1605,7 +1606,7 @@
46E2D98D25022BF5003D99F3 /* lua_widget_attributes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_widget_attributes.cpp; sourceTree = "<group>"; };
46E2D98E25022BF5003D99F3 /* lua_widget_methods.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_widget_methods.cpp; sourceTree = "<group>"; };
46E2D99525022D46003D99F3 /* lua_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = lua_ptr.hpp; sourceTree = "<group>"; };
46EB545F27DD2FAD00D5CDE8 /* libwebp.7.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libwebp.7.dylib; path = "lib/libwebp.7.dylib"; sourceTree = "<group>"; };
46EB545F27DD2FAD00D5CDE8 /* libwebp.7.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libwebp.7.dylib; path = lib/libwebp.7.dylib; sourceTree = "<group>"; };
46EEFB742087434200E1E75A /* chat_log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chat_log.cpp; sourceTree = "<group>"; };
46EEFB752087434200E1E75A /* chat_log.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = chat_log.hpp; sourceTree = "<group>"; };
46F302EC220327FD0028938F /* container-migration.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "container-migration.plist"; path = "Resources/container-migration.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2135,6 +2136,8 @@
91A214E41CAD618700927AEA /* gettext.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = gettext.hpp; sourceTree = "<group>"; };
91AF556B281101C3007A7652 /* input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = input.hpp; sourceTree = "<group>"; };
91AF556C281101C3007A7652 /* input.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = input.cpp; sourceTree = "<group>"; };
91AF55AE2827588B007A7652 /* texture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = texture.hpp; sourceTree = "<group>"; };
91AF55AF2827588B007A7652 /* texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = texture.cpp; sourceTree = "<group>"; };
91B621801B766ED500B00E0F /* buffered_istream.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = buffered_istream.hpp; sourceTree = "<group>"; };
91B621811B766F1900B00E0F /* carryover.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = carryover.hpp; sourceTree = "<group>"; };
91B621821B766FD200B00E0F /* display_context.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = display_context.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4172,6 +4175,8 @@
91AF556B281101C3007A7652 /* input.hpp */,
EC669C251DFC95AF00172EED /* surface.cpp */,
467D9DF5205EC3DA00FA2FC4 /* surface.hpp */,
91AF55AF2827588B007A7652 /* texture.cpp */,
91AF55AE2827588B007A7652 /* texture.hpp */,
467D9DF0205EC3D200FA2FC4 /* userevent.hpp */,
EC28C58D19423426003B0F5E /* utils.cpp */,
EC28C58E19423426003B0F5E /* utils.hpp */,
Expand Down Expand Up @@ -5604,6 +5609,7 @@
91FBBAD81CB6BC3F00470BFE /* filesystem_sdl.cpp in Sources */,
46F92DB12174F6A300602C1C /* wml_message.cpp in Sources */,
46F92E832174F6A400602C1C /* grid.cpp in Sources */,
91AF55B02827588B007A7652 /* texture.cpp in Sources */,
91FBBADB1CB6D1B700470BFE /* markov_generator.cpp in Sources */,
91C55DA41CC078820040012E /* context_free_grammar_generator.cpp in Sources */,
46F92D912174F6A300602C1C /* gui_definition.cpp in Sources */,
Expand Down
1 change: 1 addition & 0 deletions source_lists/wesnoth
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ scripting/plugins/context.cpp
scripting/plugins/manager.cpp
sdl/point.cpp
sdl/input.cpp
sdl/texture.cpp
map_settings.cpp
side_filter.cpp
statistics.cpp
Expand Down
73 changes: 29 additions & 44 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ display::display(const display_context* dc,

read(level.child_or_empty("display"));

if(screen_.non_interactive()
&& (screen_.getDrawingSurface() != nullptr
&& screen_.faked())) {
if (screen_.non_interactive()
&& screen_.surface_initialized()
&& screen_.faked())
{
screen_.lock_updates(true);
}

Expand Down Expand Up @@ -779,7 +780,7 @@ map_location display::minimap_location_on(int x, int y)
surface display::screenshot(bool map_screenshot)
{
if (!map_screenshot) {
return screen_.getDrawingSurface().clone();
return screen_.read_pixels();
} else {
if (get_map().empty()) {
ERR_DP << "No map loaded, cannot create a map screenshot.\n";
Expand Down Expand Up @@ -1266,8 +1267,7 @@ void display::drawing_buffer_commit()
drawing_buffer_.sort();

SDL_Rect clip_rect = map_area();
surface& screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
auto clipper = screen_.set_clip(clip_rect);

/*
* Info regarding the rendering algorithm.
Expand All @@ -1284,14 +1284,9 @@ void display::drawing_buffer_commit()

for(const blit_helper& blit : drawing_buffer_) {
for(const surface& surf : blit.surf()) {
// Note that dstrect can be changed by sdl_blit
// and so a new instance should be initialized
// to pass to each call to sdl_blit.
SDL_Rect dstrect{blit.x(), blit.y(), 0, 0};
SDL_Rect srcrect = blit.clip();
SDL_Rect* srcrectArg = (srcrect.x | srcrect.y | srcrect.w | srcrect.h) ? &srcrect : nullptr;
sdl_blit(surf, srcrectArg, screen, &dstrect);
// NOTE: the screen part should already be marked as 'to update'
screen_.blit_surface(blit.x(), blit.y(), surf, srcrectArg, nullptr);
}
}
drawing_buffer_clear();
Expand All @@ -1318,15 +1313,13 @@ void display::flip()
return;
}

surface& drawingSurface = video().getDrawingSurface();

font::draw_floating_labels(drawingSurface);
font::draw_floating_labels();
events::raise_volatile_draw_event();

video().render_screen();

events::raise_volatile_undraw_event();
font::undraw_floating_labels(drawingSurface);
font::undraw_floating_labels();
}

// frametime is in milliseconds
Expand Down Expand Up @@ -1419,7 +1412,7 @@ static void draw_panel(CVideo &video, const theme::panel& panel, std::vector<std
}
}

static void draw_label(CVideo& video, surface target, const theme::label& label)
static void draw_label(CVideo& video, const theme::label& label)
{
//log_scope("draw label");

Expand All @@ -1435,7 +1428,7 @@ static void draw_label(CVideo& video, surface target, const theme::label& label)
surf = scale_surface(surf,loc.w,loc.h);
}

sdl_blit(surf,nullptr,target,&loc);
video.blit_surface(surf, &loc);
}

if(text.empty() == false) {
Expand All @@ -1448,8 +1441,6 @@ static void draw_label(CVideo& video, surface target, const theme::label& label)

void display::draw_all_panels()
{
surface& screen(screen_.getDrawingSurface());

/*
* The minimap is also a panel, force it to update its contents.
* This is required when the size of the minimap has been modified.
Expand All @@ -1461,13 +1452,13 @@ void display::draw_all_panels()
}

for(const auto& label : theme_.labels()) {
draw_label(video(), screen, label);
draw_label(video(), label);
}

render_buttons();
}

static void draw_background(surface screen, const SDL_Rect& area, const std::string& image)
static void draw_background(CVideo& screen_, const SDL_Rect& area, const std::string& image)
{
// No background image, just fill in black.
if(image.empty()) {
Expand All @@ -1486,10 +1477,10 @@ static void draw_background(surface screen, const SDL_Rect& area, const std::str
const unsigned int w_count = static_cast<int>(std::ceil(static_cast<double>(area.w) / static_cast<double>(width)));
const unsigned int h_count = static_cast<int>(std::ceil(static_cast<double>(area.h) / static_cast<double>(height)));

auto clipper = screen_.set_clip(area);
for(unsigned int w = 0, w_off = area.x; w < w_count; ++w, w_off += width) {
for(unsigned int h = 0, h_off = area.y; h < h_count; ++h, h_off += height) {
SDL_Rect clip = sdl::create_rect(w_off, h_off, 0, 0);
sdl_blit(background, nullptr, screen, &clip);
screen_.blit_surface(w_off, h_off, background);
}
}
}
Expand Down Expand Up @@ -1640,10 +1631,8 @@ void display::draw_init()
if(redraw_background_) {
// Full redraw of the background
const SDL_Rect clip_rect = map_outside_area();
const surface& screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
SDL_FillRect(screen, &clip_rect, 0x00000000);
draw_background(screen, clip_rect, theme_.border().background_image);
screen_.fill(clip_rect, 0, 0, 0, 0);
draw_background(screen_, clip_rect, theme_.border().background_image);
redraw_background_ = false;

// Force a full map redraw
Expand Down Expand Up @@ -1764,11 +1753,10 @@ void display::draw_minimap()
}
}

const surface& screen(screen_.getDrawingSurface());
clip_rect_setter clip_setter(screen, &area);
auto clipper = screen_.set_clip(area);

color_t back_color {31,31,23,SDL_ALPHA_OPAQUE};
draw_centered_on_background(minimap_, area, back_color, screen);
draw_centered_on_background(minimap_, area, back_color, screen_);

//update the minimap location for mouse and units functions
minimap_location_.x = area.x + (area.w - minimap_->w) / 2;
Expand Down Expand Up @@ -1821,7 +1809,7 @@ void display::draw_minimap()
};

for(const auto& r : outline_parts) {
SDL_FillRect(screen_.getDrawingSurface(), &r, 0x00FFFFFF);
screen_.fill(r, 255, 255, 255, 0);
}
}

Expand Down Expand Up @@ -1873,7 +1861,7 @@ void display::draw_minimap_units()
// no render clipping rectangle set operaton was queued,
// so let's not use the render API to draw the rectangle.

SDL_FillRect(screen_.getDrawingSurface(), &r, col.to_argb_bytes());
screen_.fill(r, col.r, col.g, col.b, col.a);
}
}

Expand Down Expand Up @@ -1923,8 +1911,6 @@ bool display::scroll(int xmove, int ymove, bool force)
//

if(!screen_.update_locked()) {
surface& screen(screen_.getDrawingSurface());

SDL_Rect dstrect = map_area();
dstrect.x += diff_x;
dstrect.y += diff_y;
Expand All @@ -1934,9 +1920,9 @@ bool display::scroll(int xmove, int ymove, bool force)
srcrect.x -= diff_x;
srcrect.y -= diff_y;

SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_NONE);
SDL_BlitSurface(screen, &srcrect, screen, &dstrect);
SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_BLEND);
// TODO: highdpi - This is gross and should be replaced
texture t = screen_.read_texture(&srcrect);
screen_.blit_texture(t, &dstrect);
}

if(diff_y != 0) {
Expand Down Expand Up @@ -2497,8 +2483,7 @@ const SDL_Rect& display::get_clip_rect()
void display::draw_invalidated() {
// log_scope("display::draw_invalidated");
SDL_Rect clip_rect = get_clip_rect();
surface& screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
auto clipper = screen_.set_clip(clip_rect);
for (const map_location& loc : invalidated_) {
int xpos = get_location_x(loc);
int ypos = get_location_y(loc);
Expand Down Expand Up @@ -2734,13 +2719,13 @@ void display::draw_image_for_report(surface& img, SDL_Rect& rect)
target.h = visible_area.h;
}

sdl_blit(img, &visible_area, screen_.getDrawingSurface(), &target);
screen_.blit_surface(target.x, target.y, img, &visible_area, nullptr);
} else {
if(img->w != rect.w || img->h != rect.h) {
img = scale_surface(img,rect.w,rect.h);
}

sdl_blit(img, nullptr, screen_.getDrawingSurface(), &target);
screen_.blit_surface(img, &target);
}
}

Expand Down Expand Up @@ -2785,7 +2770,7 @@ void display::refresh_report(const std::string& report_name, const config * new_
report = *new_cfg;

if (surf) {
sdl_blit(surf, nullptr, screen_.getDrawingSurface(), &rect);
screen_.blit_surface(surf, &rect);
}

// If the rectangle has just changed, assign the surface to it
Expand All @@ -2799,7 +2784,7 @@ void display::refresh_report(const std::string& report_name, const config * new_
// (Images generally won't need backing up,
// unless they are transparent, but that is done later).
if (rect.w > 0 && rect.h > 0) {
surf = get_surface_portion(screen_.getDrawingSurface(), rect);
surf = screen_.read_pixels_low_res(&rect);
if (reportSurfaces_[report_name] == nullptr) {
ERR_DP << "Could not backup background for report!" << std::endl;
}
Expand Down
3 changes: 0 additions & 3 deletions src/display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ class display : public video2::draw_layering
/** Gets the underlying screen object. */
CVideo& video() { return screen_; }

/** return the screen surface or the surface used for map_screenshot. */
surface& get_screen_surface() { return map_screenshot_ ? map_screenshot_surf_ : screen_.getDrawingSurface();}

virtual bool in_game() const { return false; }
virtual bool in_editor() const { return false; }

Expand Down