Benchmark of the drawing primitives with double buffering (flicker-free full screen animation) at 320x200, 64 colors.
Three tests run one after the other in an endless loop. Each test adds a new object every 5 frames until its maximum is reached, then moves to the next test. The yellow label at the top shows the number of objects, the test name and the measured frames per second:
| Test | Content |
| Balls | Up to 300 filled circles bouncing around |
| Polygons | Rotating filled polygons with random shape and color |
| Sprites | Moving sprites |
The demo runs on its own: there are no controls.
What it demonstrates
- VGAController::setResolution(..., doubleBuffered = true) and Canvas::swapBuffers()
- Full-screen redraw at every frame with Canvas::clear(), fillEllipse(), fillPath() and sprites
- Measuring the drawing throughput (FPS) as the scene gets heavier
Set DOUBLEBUFFERING to 0 in DoubleBuffer.cpp to see the same scene without double buffering (the flickering becomes visible).
Hardware
- VGA output (default pins)
Build
See Building the examples.
Source code
Main file of the example, main/DoubleBuffer.cpp. The complete project is in the examples/VGA/DoubleBuffer folder.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "esp_random.h"
29
30
31
32static inline int randomInt(int max) { return max > 0 ? (int) (esp_random() % (uint32_t) max) : 0; }
33
34static inline int randomInt(int min, int max) { return max > min ? min + (int) (esp_random() % (uint32_t) (max - min)) : min; }
35
36
37
38
41
42
43
44#define DOUBLEBUFFERING 1
45
46
47struct Test {
48 virtual ~Test() { };
49 virtual void update() = 0;
50 virtual bool nextState() = 0;
51 virtual int testState() = 0;
52 virtual char const * name() = 0;
53};
54
55
56#include "ballstest.h"
57#include "polygonstest.h"
58#include "spritestest.h"
59
60
61
62void setup()
63{
64 DisplayController.
begin();
66
67
68
69 canvas.selectFont(&fabgl::FONT_8x8);
70
71 canvas.setGlyphOptions(
GlyphOptions().FillBackground(
true));
72}
73
74
75void loop()
76{
77 static int64_t stime = esp_timer_get_time();
78 static int FPS = 0;
79 static int FPSCounter = 0;
80 static int testIndex = 0;
81 static Test * test = new BallsTest;
82
83 if (test->nextState() == false) {
84 delete test;
85 ++testIndex;
86 switch (testIndex) {
87 case 1:
88 test = new PolygonsTest;
89 break;
90 case 2:
91 test = new SpritesTest;
92 break;
93 default:
94 testIndex = 0;
95 test = new BallsTest;
96 break;
97 }
98 }
99
100 if (esp_timer_get_time() - stime > 1000000) {
101
102 FPS = FPSCounter;
103 stime = esp_timer_get_time();
104 FPSCounter = 0;
105 }
106 ++FPSCounter;
107
108 test->update();
109
110
111 canvas.setPenColor(Color::Blue);
112 canvas.setBrushColor(Color::Yellow);
113 canvas.drawTextFmt(80, 5, " %d %s at %d FPS ", test->testState(), test->name(), FPS);
114
115 if (DOUBLEBUFFERING)
116 canvas.swapBuffers();
117}
118
119
120extern "C" void app_main()
121{
122 setup();
123 while (true)
124 loop();
125}
Provides a set of drawing methods.
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
Initializer for 8 colors (5 GPIOs).
VGA bitmapped display controller (64 colors).
Single include file of the FabGL library.
Specifies glyph painting options.