Skip to content

Commit

Permalink
Make supervisor_export_image use FBO instead of screen framebuffer. (#…
Browse files Browse the repository at this point in the history
…6622)

* Make supervisor_export_image use FBO instead of screen framebuffer.

This makes the supervisor_export_image test pass under Wayland and has the added benefit of making that test (and the billboard test) work with "--no-rendering --minimize". As a result those tests are moved into the api group and the with_rendering group is removed.

* Add changelog entry.
  • Loading branch information
brettle committed Aug 15, 2024
1 parent 0bcfb17 commit 0ee2580
Show file tree
Hide file tree
Showing 22 changed files with 16 additions and 92 deletions.
1 change: 1 addition & 0 deletions docs/reference/changelog-r2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Released on December **th, 2023.
- Fixed the bug that when the language is Python, getTargets() cannot correctly obtain the multi-target data detected by the radar ([#6606](https://github.com/cyberbotics/webots/pull/6606))
- Fixed incomplete loading while minimized under some windowing systems ([#6617](https://github.com/cyberbotics/webots/pull/6617)).
- Fixed unitialized sliding friction when using asymmetric rolling friction ([#6618](https://github.com/cyberbotics/webots/pull/6618)).
- Made `supervisor_export_image` work even if using the `--minimize --no-rendering` options ([#6622](https://github.com/cyberbotics/webots/pull/6622)).
3 changes: 1 addition & 2 deletions include/wren/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ void wr_scene_enable_depth_reset(WrScene *scene, bool enable);
void wr_scene_add_frame_listener(WrScene *scene, void (*listener)());
void wr_scene_remove_frame_listener(WrScene *scene, void (*listener)());

void wr_scene_get_main_buffer(WrScene *scene, int width, int height, unsigned int format, unsigned int data_type,
unsigned int buffer_type, void *buffer);
void wr_scene_get_main_buffer(int width, int height, unsigned int format, unsigned int data_type, void *buffer);

void wr_scene_init_frame_capture(WrScene *scene, int pixel_buffer_count, unsigned int *pixel_buffer_ids, int frame_size);
void wr_scene_bind_pixel_buffer(WrScene *scene, int buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/webots/gui/WbView3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void WbView3D::refresh() {
const WbSimulationState *const sim = WbSimulationState::instance();
mPhysicsRefresh = true;
if (mScreenshotRequested)
renderNow();
renderNow(true, true);
else if (sim->isPaused())
renderLater();
else if (WbVideoRecorder::instance()->isRecording()) {
Expand Down
12 changes: 1 addition & 11 deletions src/webots/gui/WbWrenWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,5 @@ void WbWrenWindow::feedMultimediaStreamer() {
}

void WbWrenWindow::readPixels(int width, int height, unsigned int format, void *buffer) {
#ifdef __linux__
if (WbSysInfo::isVirtualMachine()) {
// Reading the front buffer is not supported by all OpenGL implementations (especially on Linux running in a VM).
// In that case, to read the front buffer, we need to swap the buffers, read the back buffer and swap the buffers again.
// However, doing this may cause flickering on platforms where reading the front buffer is supported (including macOS).
WbWrenOpenGlContext::instance()->swapBuffers(this);
wr_scene_get_main_buffer(wr_scene_get_instance(), width, height, format, GL_UNSIGNED_BYTE, GL_BACK, buffer);
WbWrenOpenGlContext::instance()->swapBuffers(this);
} else
#endif
wr_scene_get_main_buffer(wr_scene_get_instance(), width, height, format, GL_UNSIGNED_BYTE, GL_FRONT, buffer);
wr_scene_get_main_buffer(width, height, format, GL_UNSIGNED_BYTE, buffer);
}
14 changes: 6 additions & 8 deletions src/wren/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ namespace wren {
assert(!Texture2d::cachedItemCount());
}

void Scene::getMainBuffer(int width, int height, unsigned int format, unsigned int data_type, unsigned int buffer_type,
void *buffer) {
assert(buffer_type == GL_FRONT || buffer_type == GL_BACK);
glstate::bindFrameBuffer(0);
glReadBuffer(buffer_type);
void Scene::getMainBuffer(int width, int height, unsigned int format, unsigned int data_type, void *buffer) {
glstate::bindFrameBuffer(instance()->mMainViewport->frameBuffer()->glName());
glReadBuffer(GL_COLOR_ATTACHMENT0);
glFinish();
glReadPixels(0, 0, width, height, format, data_type, buffer);
}

Expand Down Expand Up @@ -884,9 +883,8 @@ void wr_scene_apply_pending_updates(WrScene *scene) {
reinterpret_cast<wren::Scene *>(scene)->applyPendingUpdates();
}

void wr_scene_get_main_buffer(WrScene *scene, int width, int height, unsigned int format, unsigned int data_type,
unsigned int buffer_type, void *buffer) {
reinterpret_cast<wren::Scene *>(scene)->getMainBuffer(width, height, format, data_type, buffer_type, buffer);
void wr_scene_get_main_buffer(int width, int height, unsigned int format, unsigned int data_type, void *buffer) {
wren::Scene::getMainBuffer(width, height, format, data_type, buffer);
}

void wr_scene_init_frame_capture(WrScene *scene, int pixel_buffer_count, unsigned int *pixel_buffer_ids, int frame_size) {
Expand Down
3 changes: 1 addition & 2 deletions src/wren/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ namespace wren {
void reset();
static void applyPendingUpdates();

static void getMainBuffer(int width, int height, unsigned int format, unsigned int data_type, unsigned int buffer_type,
void *buffer);
static void getMainBuffer(int width, int height, unsigned int format, unsigned int data_type, void *buffer);
void initFrameCapture(int pixelBufferCount, unsigned int *pixelBufferIds, int frameSize);
static void bindPixelBuffer(int buffer);
void *mapPixelBuffer(unsigned int accessMode);
Expand Down
7 changes: 2 additions & 5 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: api cache other_api parser physics protos rendering with_rendering
.PHONY: api cache other_api parser physics protos rendering

release debug profile: api cache other_api parser physics protos rendering with_rendering
release debug profile: api cache other_api parser physics protos rendering

clean: api cache parser physics protos rendering
@-rm -rf *.txt \
Expand Down Expand Up @@ -56,6 +56,3 @@ protos:

rendering:
+@make -s -C rendering $(MAKECMDGOALS)

with_rendering:
+@make -s -C with_rendering $(MAKECMDGOALS)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
parser.add_argument('--nomake', dest='nomake', default=False, action='store_true', help='The controllers are not re-compiled.')
parser.add_argument('--no-ansi-escape', dest='ansi_escape', default=True, action='store_false', help='Disables ansi escape.')
parser.add_argument('--group', '-g', type=str, dest='group', default=[], help='Specifies which group of tests should be run.',
choices=['api', 'cache', 'other_api', 'physics', 'protos', 'parser', 'rendering', 'with_rendering'])
choices=['api', 'cache', 'other_api', 'physics', 'protos', 'parser', 'rendering'])
parser.add_argument('--performance-log', '-p', type=str, dest='performance_log', default="",
help='The name of the performance log file to use if you want to log performance.')
parser.add_argument('worlds', nargs='*', default=[])
Expand Down Expand Up @@ -236,11 +236,9 @@ def runGroupTest(groupName, firstSimulation, worldsCount, failures):
# command.run(silent = False)

webotsArguments = [webotsFullPath, firstSimulation]
webotsArguments += ['--mode=fast', '--stdout', '--stderr', '--batch']
webotsArguments += ['--mode=fast', '--stdout', '--stderr', '--batch', '--no-rendering', '--minimize']
if args.performance_log:
webotsArguments += [f'--log-performance={args.performance_log}']
if groupName != 'with_rendering':
webotsArguments += ['--no-rendering', '--minimize']
if groupName == 'cache':
webotsArguments += ['--clear-cache']
command = Command(webotsArguments)
Expand Down Expand Up @@ -332,7 +330,7 @@ def runGroupTest(groupName, firstSimulation, worldsCount, failures):
if args.group:
testGroups = [str(args.group)]
else:
testGroups = ['api', 'cache', 'other_api', 'physics', 'protos', 'parser', 'rendering', 'with_rendering']
testGroups = ['api', 'cache', 'other_api', 'physics', 'protos', 'parser', 'rendering']

if sys.platform == 'win32' and 'parser' in testGroups:
testGroups.remove('parser') # this one doesn't work on Windows
Expand Down
2 changes: 0 additions & 2 deletions tests/with_rendering/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions tests/with_rendering/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions tests/with_rendering/controllers/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions tests/with_rendering/controllers/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions tests/with_rendering/worlds/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions tests/with_rendering/worlds/.supervisor_export_image.wbproj

This file was deleted.

0 comments on commit 0ee2580

Please sign in to comment.