Removed old drawing program cache
This commit is contained in:
parent
19f8c99b66
commit
9845d14a83
7 changed files with 8 additions and 68 deletions
|
|
@ -36,10 +36,6 @@ DrawingProgram::DrawingProgram(World& initWorld):
|
||||||
{
|
{
|
||||||
drawTool = DrawingProgramToolBase::allocate_tool_type(*this, DrawingProgramToolType::BRUSH);
|
drawTool = DrawingProgramToolBase::allocate_tool_type(*this, DrawingProgramToolType::BRUSH);
|
||||||
|
|
||||||
components.updateCallback = [&]() {
|
|
||||||
if(&world == world.main.world.get())
|
|
||||||
world.main.drawProgCache.refresh = true;
|
|
||||||
};
|
|
||||||
components.clientInsertCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
components.clientInsertCallback = [&](const CollabListType::ObjectInfoPtr& c) {
|
||||||
if(addToCompCacheOnInsert)
|
if(addToCompCacheOnInsert)
|
||||||
compCache.add_component(c);
|
compCache.add_component(c);
|
||||||
|
|
@ -579,27 +575,16 @@ void DrawingProgram::draw(SkCanvas* canvas, const DrawData& drawData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(world.main.drawProgCache.disableDrawCache) {
|
canvas->saveLayer(nullptr, nullptr);
|
||||||
parallel_loop_all_components([&](auto& c) {
|
canvas->clear(SkColor4f{0.0f, 0.0f, 0.0f, 0.0f});
|
||||||
c->obj->calculate_draw_transform(drawData);
|
|
||||||
});
|
|
||||||
for(auto& c : components.client_list()) {
|
|
||||||
c->obj->draw(canvas, drawData);
|
|
||||||
c->obj->drawSetupData.shouldDraw = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SkCanvas* drawProgCacheCanvas = world.main.drawProgCache.surface->getCanvas();
|
|
||||||
drawProgCacheCanvas->clear(SkColor4f{0.0f, 0.0f, 0.0f, 0.0f});
|
|
||||||
compCache.refresh_all_draw_cache(drawData);
|
compCache.refresh_all_draw_cache(drawData);
|
||||||
compCache.draw_components_to_canvas(drawProgCacheCanvas, drawData);
|
compCache.draw_components_to_canvas(canvas, drawData);
|
||||||
drawProgCacheCanvas->saveLayerAlphaf(nullptr, 1.0f);
|
canvas->saveLayer(nullptr, nullptr);
|
||||||
selection.draw_components(drawProgCacheCanvas, drawData);
|
selection.draw_components(canvas, drawData);
|
||||||
drawProgCacheCanvas->restore();
|
canvas->restore();
|
||||||
canvas->drawImage(world.main.drawProgCache.surface->makeTemporaryImage(), 0, 0);
|
canvas->restore();
|
||||||
selection.draw_gui(canvas, drawData);
|
selection.draw_gui(canvas, drawData);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
drawTool->draw(canvas, drawData);
|
drawTool->draw(canvas, drawData);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,6 @@ void DrawingProgramCache::refresh_draw_cache(const std::shared_ptr<DrawingProgra
|
||||||
if(drawCache.invalidBounds) {
|
if(drawCache.invalidBounds) {
|
||||||
auto& iBounds = drawCache.invalidBounds.value();
|
auto& iBounds = drawCache.invalidBounds.value();
|
||||||
WorldVec bDim = bvhNode->bounds.dim();
|
WorldVec bDim = bvhNode->bounds.dim();
|
||||||
//std::cout << "\niMin: " << iBounds.min.x() << " " << iBounds.min.y() << "\niMax: " << iBounds.max.x() << " " << iBounds.max.y() << "\nbMin: " << bvhNode->bounds.min.x() << " " << bvhNode->bounds.min.y() << "\nbMax: " << bvhNode->bounds.max.x() << " " << bvhNode->bounds.max.y() << "\nbDim: " << bDim.x() << " " << bDim.y();
|
|
||||||
|
|
||||||
Vector2f clipBoundMin{static_cast<float>((iBounds.min.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(),
|
Vector2f clipBoundMin{static_cast<float>((iBounds.min.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(),
|
||||||
static_cast<float>((iBounds.min.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()};
|
static_cast<float>((iBounds.min.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()};
|
||||||
|
|
@ -352,7 +351,6 @@ void DrawingProgramCache::refresh_draw_cache(const std::shared_ptr<DrawingProgra
|
||||||
bvhNode->coords.from_space(clipRectBoundAABB.max)
|
bvhNode->coords.from_space(clipRectBoundAABB.max)
|
||||||
};
|
};
|
||||||
|
|
||||||
//std::cout << "\ncMin: " << clipBoundMin.x() << " " << clipBoundMin.y() << "\ncMax: " << clipBoundMax.x() << " " << clipBoundMax.y() << std::endl;
|
|
||||||
cacheCanvas->save();
|
cacheCanvas->save();
|
||||||
cacheCanvas->clipIRect(clipRect);
|
cacheCanvas->clipIRect(clipRect);
|
||||||
cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
||||||
|
|
|
||||||
|
|
@ -63,28 +63,6 @@ MainProgram::MainProgram():
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainProgram::init_draw_program_cache() {
|
|
||||||
if(window.size.x() < 0 || window.size.y() < 0)
|
|
||||||
return;
|
|
||||||
SkImageInfo imgInfo = SkImageInfo::MakeN32Premul(window.size.x(), window.size.y());
|
|
||||||
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
|
||||||
drawProgCache.surface = SkSurfaces::RenderTarget(window.recorder(), imgInfo, skgpu::Mipmapped::kNo, window.defaultMSAASurfaceProps);
|
|
||||||
#elif USE_SKIA_BACKEND_GANESH
|
|
||||||
drawProgCache.surface = SkSurfaces::RenderTarget(window.ctx.get(), skgpu::Budgeted::kNo, imgInfo, window.defaultMSAASampleCount, &window.defaultMSAASurfaceProps);
|
|
||||||
#endif
|
|
||||||
if(!drawProgCache.surface)
|
|
||||||
throw std::runtime_error("[MainProgram::init_draw_program_cache] Could not make surface");
|
|
||||||
drawProgCache.canvas = drawProgCache.surface->getCanvas();
|
|
||||||
|
|
||||||
if(!drawProgCache.canvas)
|
|
||||||
throw std::runtime_error("[MainProgram::init_draw_program_cache] Could not create canvas");
|
|
||||||
|
|
||||||
drawProgCache.canvas->clear(SkColor4f{0, 0, 0, 0});
|
|
||||||
|
|
||||||
drawProgCache.refresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainProgram::update() {
|
void MainProgram::update() {
|
||||||
while(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / fpsLimit);
|
while(std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / fpsLimit);
|
||||||
lastFrameTime = std::chrono::steady_clock::now();
|
lastFrameTime = std::chrono::steady_clock::now();
|
||||||
|
|
@ -117,8 +95,6 @@ void MainProgram::update() {
|
||||||
|
|
||||||
std::shared_ptr<World> oldWorld = world;
|
std::shared_ptr<World> oldWorld = world;
|
||||||
world = worlds[worldIndex];
|
world = worlds[worldIndex];
|
||||||
if(oldWorld != world)
|
|
||||||
drawProgCache.refresh = true;
|
|
||||||
|
|
||||||
deltaTime.update_time_since();
|
deltaTime.update_time_since();
|
||||||
deltaTime.update_time_point();
|
deltaTime.update_time_point();
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,6 @@ class MainProgram {
|
||||||
|
|
||||||
Vector3f userColor;
|
Vector3f userColor;
|
||||||
|
|
||||||
struct DrawingProgramImageCache {
|
|
||||||
bool refresh = true;
|
|
||||||
sk_sp<SkSurface> surface;
|
|
||||||
std::shared_ptr<DrawComponent> firstCompUpdate = nullptr;
|
|
||||||
SkCanvas* canvas;
|
|
||||||
bool disableDrawCache = false;
|
|
||||||
} drawProgCache;
|
|
||||||
|
|
||||||
struct Window {
|
struct Window {
|
||||||
Vector2i size = {-1, -1};
|
Vector2i size = {-1, -1};
|
||||||
Vector2i pos = {-1, -1};
|
Vector2i pos = {-1, -1};
|
||||||
|
|
@ -86,8 +78,6 @@ class MainProgram {
|
||||||
void update();
|
void update();
|
||||||
void draw(SkCanvas* canvas);
|
void draw(SkCanvas* canvas);
|
||||||
|
|
||||||
void init_draw_program_cache();
|
|
||||||
|
|
||||||
bool setToQuit = false;
|
bool setToQuit = false;
|
||||||
|
|
||||||
void early_destroy();
|
void early_destroy();
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,6 @@ nlohmann::json Toolbar::get_config_json() {
|
||||||
toRet["themeInUse"] = themeData.themeCurrentlyLoaded;
|
toRet["themeInUse"] = themeData.themeCurrentlyLoaded;
|
||||||
toRet["velocityAffectsBrushWidth"] = velocityAffectsBrushWidth;
|
toRet["velocityAffectsBrushWidth"] = velocityAffectsBrushWidth;
|
||||||
toRet["jumpTransitionEasing"] = jumpTransitionEasing;
|
toRet["jumpTransitionEasing"] = jumpTransitionEasing;
|
||||||
toRet["disableDrawCache"] = main.drawProgCache.disableDrawCache;
|
|
||||||
toRet["defaultCanvasBackgroundColor"] = main.defaultCanvasBackgroundColor;
|
toRet["defaultCanvasBackgroundColor"] = main.defaultCanvasBackgroundColor;
|
||||||
|
|
||||||
json tablet;
|
json tablet;
|
||||||
|
|
@ -273,7 +272,6 @@ void Toolbar::set_config_json(const nlohmann::json& j) {
|
||||||
j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);
|
j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);
|
||||||
j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth);
|
j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth);
|
||||||
j.at("jumpTransitionEasing").get_to(jumpTransitionEasing);
|
j.at("jumpTransitionEasing").get_to(jumpTransitionEasing);
|
||||||
j.at("disableDrawCache").get_to(main.drawProgCache.disableDrawCache);
|
|
||||||
j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor);
|
j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor);
|
||||||
|
|
||||||
j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth);
|
j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth);
|
||||||
|
|
@ -1321,7 +1319,6 @@ void Toolbar::options_menu() {
|
||||||
gui.text_label("Note: Requires restart to take effect. May cause bugs on Intel Graphics");
|
gui.text_label("Note: Requires restart to take effect. May cause bugs on Intel Graphics");
|
||||||
gui.input_scalar_field("fps cap slider", "FPS cap", &main.fpsLimit, 3.0f, 10000.0f);
|
gui.input_scalar_field("fps cap slider", "FPS cap", &main.fpsLimit, 3.0f, 10000.0f);
|
||||||
#endif
|
#endif
|
||||||
gui.checkbox_field("Disable Draw Cache", "Disable BVH Draw Cache", &main.drawProgCache.disableDrawCache);
|
|
||||||
gui.pop_id();
|
gui.pop_id();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,6 @@ World::World(MainProgram& initMain, OpenWorldInfo& worldInfo):
|
||||||
|
|
||||||
netSource = worldInfo.netSource;
|
netSource = worldInfo.netSource;
|
||||||
|
|
||||||
drawData.cam.changed = [&]() {
|
|
||||||
main.drawProgCache.refresh = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
if(worldInfo.conType == CONNECTIONTYPE_CLIENT || worldInfo.conType == CONNECTIONTYPE_SERVER)
|
if(worldInfo.conType == CONNECTIONTYPE_CLIENT || worldInfo.conType == CONNECTIONTYPE_SERVER)
|
||||||
NetLibrary::init();
|
NetLibrary::init();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,8 +286,6 @@ void resize_window(MainStruct& mS) {
|
||||||
throw std::runtime_error("[resize_window] No canvas made");
|
throw std::runtime_error("[resize_window] No canvas made");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mS.m->init_draw_program_cache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue