mirror of
https://github.com/godotengine/godot.git
synced 2025-04-01 00:41:35 +08:00
rendering: compositor has is_opengl
API; minor optimisations
This commit is contained in:
parent
c2ba0a8646
commit
5e1fe8040a
@ -104,6 +104,7 @@ public:
|
||||
|
||||
void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount);
|
||||
|
||||
bool is_opengl() { return true; }
|
||||
void gl_end_frame(bool p_swap_buffers);
|
||||
void end_frame(bool p_swap_buffers);
|
||||
|
||||
|
@ -87,6 +87,7 @@ public:
|
||||
|
||||
void blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount) override {}
|
||||
|
||||
bool is_opengl() override { return false; }
|
||||
void gl_end_frame(bool p_swap_buffers) override {}
|
||||
|
||||
void end_frame(bool p_present) override {
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
|
||||
virtual void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) = 0;
|
||||
|
||||
virtual bool is_opengl() = 0;
|
||||
virtual void gl_end_frame(bool p_swap_buffers) = 0;
|
||||
virtual void end_frame(bool p_present) = 0;
|
||||
virtual void finalize() = 0;
|
||||
|
@ -50,7 +50,8 @@ void RendererCompositorRD::blit_render_targets_to_screen(DisplayServer::WindowID
|
||||
RID rd_texture = texture_storage->render_target_get_rd_texture(p_render_targets[i].render_target);
|
||||
ERR_CONTINUE(rd_texture.is_null());
|
||||
|
||||
if (!render_target_descriptors.has(rd_texture) || !RD::get_singleton()->uniform_set_is_valid(render_target_descriptors[rd_texture])) {
|
||||
HashMap<RID, RID>::Iterator it = render_target_descriptors.find(rd_texture);
|
||||
if (it == render_target_descriptors.end() || !RD::get_singleton()->uniform_set_is_valid(it->value)) {
|
||||
Vector<RD::Uniform> uniforms;
|
||||
RD::Uniform u;
|
||||
u.uniform_type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE;
|
||||
@ -60,14 +61,14 @@ void RendererCompositorRD::blit_render_targets_to_screen(DisplayServer::WindowID
|
||||
uniforms.push_back(u);
|
||||
RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, blit.shader.version_get_shader(blit.shader_version, BLIT_MODE_NORMAL), 0);
|
||||
|
||||
render_target_descriptors[rd_texture] = uniform_set;
|
||||
it = render_target_descriptors.insert(rd_texture, uniform_set);
|
||||
}
|
||||
|
||||
Size2 screen_size(RD::get_singleton()->screen_get_width(p_screen), RD::get_singleton()->screen_get_height(p_screen));
|
||||
BlitMode mode = p_render_targets[i].lens_distortion.apply ? BLIT_MODE_LENS : (p_render_targets[i].multi_view.use_layer ? BLIT_MODE_USE_LAYER : BLIT_MODE_NORMAL);
|
||||
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blit.pipelines[mode]);
|
||||
RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array);
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, render_target_descriptors[rd_texture], 0);
|
||||
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, it->value, 0);
|
||||
|
||||
// We need to invert the phone rotation.
|
||||
const int screen_rotation_degrees = -RD::get_singleton()->screen_get_pre_rotation_degrees(p_screen);
|
||||
|
@ -124,6 +124,7 @@ public:
|
||||
void begin_frame(double frame_step);
|
||||
void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount);
|
||||
|
||||
bool is_opengl() { return false; }
|
||||
void gl_end_frame(bool p_swap_buffers) {}
|
||||
void end_frame(bool p_present);
|
||||
void finalize();
|
||||
|
@ -841,9 +841,9 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
|
||||
RSG::texture_storage->render_target_set_velocity_target_size(vp->render_target, xr_interface->get_velocity_target_size());
|
||||
|
||||
if (xr_interface->get_velocity_texture().is_valid()) {
|
||||
viewport_set_force_motion_vectors(vp->self, true);
|
||||
_viewport_set_force_motion_vectors(vp, true);
|
||||
} else {
|
||||
viewport_set_force_motion_vectors(vp->self, false);
|
||||
_viewport_set_force_motion_vectors(vp, false);
|
||||
}
|
||||
|
||||
RSG::texture_storage->render_target_set_render_region(vp->render_target, xr_interface->get_render_region());
|
||||
@ -857,7 +857,7 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
|
||||
// commit our eyes
|
||||
Vector<BlitToScreen> blits = xr_interface->post_draw_viewport(vp->render_target, vp->viewport_to_screen_rect);
|
||||
if (vp->viewport_to_screen != DisplayServer::INVALID_WINDOW_ID) {
|
||||
if (OS::get_singleton()->get_current_rendering_driver_name().begins_with("opengl3")) {
|
||||
if (RSG::rasterizer->is_opengl()) {
|
||||
if (blits.size() > 0) {
|
||||
RSG::rasterizer->blit_render_targets_to_screen(vp->viewport_to_screen, blits.ptr(), blits.size());
|
||||
RSG::rasterizer->gl_end_frame(p_swap_buffers);
|
||||
@ -892,10 +892,8 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
|
||||
blit.dst_rect.size = vp->size;
|
||||
}
|
||||
|
||||
if (OS::get_singleton()->get_current_rendering_driver_name().begins_with("opengl3")) {
|
||||
Vector<BlitToScreen> blit_to_screen_vec;
|
||||
blit_to_screen_vec.push_back(blit);
|
||||
RSG::rasterizer->blit_render_targets_to_screen(vp->viewport_to_screen, blit_to_screen_vec.ptr(), 1);
|
||||
if (RSG::rasterizer->is_opengl()) {
|
||||
RSG::rasterizer->blit_render_targets_to_screen(vp->viewport_to_screen, &blit, 1);
|
||||
RSG::rasterizer->gl_end_frame(p_swap_buffers);
|
||||
} else {
|
||||
Vector<BlitToScreen> *blits = blit_to_screen_list.getptr(vp->viewport_to_screen);
|
||||
@ -1408,19 +1406,23 @@ void RendererViewport::viewport_set_force_motion_vectors(RID p_viewport, bool p_
|
||||
Viewport *viewport = viewport_owner.get_or_null(p_viewport);
|
||||
ERR_FAIL_NULL(viewport);
|
||||
|
||||
if (viewport->force_motion_vectors == p_force_motion_vectors) {
|
||||
_viewport_set_force_motion_vectors(viewport, p_force_motion_vectors);
|
||||
}
|
||||
|
||||
void RendererViewport::_viewport_set_force_motion_vectors(RendererViewport::Viewport *p_viewport, bool p_force_motion_vectors) {
|
||||
if (p_viewport->force_motion_vectors == p_force_motion_vectors) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool motion_vectors_before = _viewport_requires_motion_vectors(viewport);
|
||||
viewport->force_motion_vectors = p_force_motion_vectors;
|
||||
bool motion_vectors_before = _viewport_requires_motion_vectors(p_viewport);
|
||||
p_viewport->force_motion_vectors = p_force_motion_vectors;
|
||||
|
||||
bool motion_vectors_after = _viewport_requires_motion_vectors(viewport);
|
||||
bool motion_vectors_after = _viewport_requires_motion_vectors(p_viewport);
|
||||
if (motion_vectors_before != motion_vectors_after) {
|
||||
num_viewports_with_motion_vectors += motion_vectors_after ? 1 : -1;
|
||||
}
|
||||
|
||||
_configure_3d_render_buffers(viewport);
|
||||
_configure_3d_render_buffers(p_viewport);
|
||||
}
|
||||
|
||||
void RendererViewport::viewport_set_use_occlusion_culling(RID p_viewport, bool p_use_occlusion_culling) {
|
||||
|
@ -203,6 +203,7 @@ private:
|
||||
Vector<Viewport *> _sort_active_viewports();
|
||||
void _viewport_set_size(Viewport *p_viewport, int p_width, int p_height, uint32_t p_view_count);
|
||||
bool _viewport_requires_motion_vectors(Viewport *p_viewport);
|
||||
void _viewport_set_force_motion_vectors(Viewport *p_viewport, bool p_force_motion_vectors);
|
||||
void _configure_3d_render_buffers(Viewport *p_viewport);
|
||||
void _draw_3d(Viewport *p_viewport);
|
||||
void _draw_viewport(Viewport *p_viewport);
|
||||
|
Loading…
x
Reference in New Issue
Block a user