forked from LAK132/ImDuino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
169 lines (136 loc) · 5.13 KB
/
main.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifdef __x86_64
/*
* @brief this file is for test the code on the PC
*/
#include "imgui.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
#include <iterator>
#include <vector>
texture_alpha8_t fontAtlas;
namespace {
#define FRAME_X 210
#define FRAME_Y 240
#define SCREENX FRAME_X
#define SCREENY FRAME_Y
std::array<uint16_t, FRAME_X * FRAME_Y> pixels;
texture_color16_t screen;
void drawLineCallback(texture_color16_t &screen, int y, const color16_t *Line) {
const auto *lineData = reinterpret_cast<const uint16_t *>(Line);
std::copy(lineData, lineData + FRAME_X, &(pixels[y * FRAME_X]));
}
ImplSoftRaster implRaster(screen);
void screen_init() {
screen.lineWritedCb = drawLineCallback;
screen.init(SCREENX, SCREENY, nullptr);
}
} // namespace
unsigned long drawTime;
unsigned long renderTime;
unsigned long rasterTime;
void setup() {
auto context = ImGui::CreateContext();
implRaster.ImGui_ImplSoftraster_Init(&screen);
ImGuiStyle &style = ImGui::GetStyle();
style.AntiAliasedLines = false;
style.AntiAliasedFill = false;
style.WindowRounding = 0.0f;
ImGuiIO &io = ImGui::GetIO();
io.Fonts->Flags |=
ImFontAtlasFlags_NoPowerOfTwoHeight | ImFontAtlasFlags_NoMouseCursors;
uint8_t *pixels;
int width, height;
io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height);
fontAtlas.init(width, height, (alpha8_t *)pixels);
io.Fonts->TexID = &fontAtlas;
screen_init();
}
float f = 0.0f;
unsigned long t = 0;
void loop() {
ImGuiIO &io = ImGui::GetIO();
io.DeltaTime = 1.0f / 60.0f;
// io.MousePos = mouse_pos;
// io.MouseDown[0] = mouse_button_0;
// io.MouseDown[1] = mouse_button_1;
/* [0.0f - 1.0f] */
io.NavInputs[ImGuiNavInput_Activate] =
0.0f; // activate / open / toggle / tweak value // e.g. Circle
// (PS4), A (Xbox), B (Switch), Space (Keyboard)
io.NavInputs[ImGuiNavInput_Cancel] =
0.0f; // cancel / close / exit // e.g. Cross
// (PS4), B (Xbox), A (Switch), Escape (Keyboard)
io.NavInputs[ImGuiNavInput_Input] =
0.0f; // text input / on-screen keyboard // e.g.
// Triang.(PS4), Y (Xbox), X (Switch), Return (Keyboard)
io.NavInputs[ImGuiNavInput_Menu] =
0.0f; // tap: toggle menu / hold: focus, move, resize // e.g. Square
// (PS4), X (Xbox), Y (Switch), Alt (Keyboard)
io.NavInputs[ImGuiNavInput_DpadLeft] =
0.0f; // move / tweak / resize window (w/ PadMenu) // e.g. D-pad
// Left/Right/Up/Down (Gamepads), Arrow keys (Keyboard)
io.NavInputs[ImGuiNavInput_DpadRight] = 0.0f;
io.NavInputs[ImGuiNavInput_DpadUp] = 0.0f;
io.NavInputs[ImGuiNavInput_DpadDown] = 0.0f;
io.NavInputs[ImGuiNavInput_TweakSlow] =
0.0f; // slower tweaks // e.g. L1 or L2
// (PS4), LB or LT (Xbox), L or ZL (Switch)
io.NavInputs[ImGuiNavInput_TweakFast] =
0.0f; // faster tweaks // e.g. R1 or R2
// (PS4), RB or RT (Xbox), R or ZL (Switch)
implRaster.ImGui_ImplSoftraster_NewFrame();
ImGui::NewFrame();
ImGui::SetWindowPos(ImVec2(0.0, 0.0));
ImGui::SetWindowSize(ImVec2(SCREENX, SCREENY));
f = 0.0f;
ImGui::Text("Hardware write time %d ms", 10000);
ImGui::Text("Render time %d ms", 10000);
ImGui::Text("Raster time %d ms", 10000);
ImGui::Text("Remaining time %d ms", 10000);
ImGui::SliderFloat("SliderFloat", &f, 0.0f, 1.0f);
ImGui::Render();
// tft.startWrite();
auto now = std::chrono::high_resolution_clock::now();
implRaster.ImGui_ImplSoftraster_RenderDrawData(ImGui::GetDrawData());
auto end = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(
(end - now))
.count()
<< std::endl;
// tft.endWrite();
}
int main() {
setup();
loop();
std::ifstream comparison(std::filesystem::path(MAINSRCDIR) / "tests" /
"compare.data",
std::ios::binary | std::ios::in);
comparison >> std::noskipws;
assert(comparison.is_open());
std::istreambuf_iterator itIn(comparison);
std::vector<uint16_t> data;
{
std::vector<char> datatmp(itIn, {});
data.assign(reinterpret_cast<uint16_t *>(datatmp.data()),
reinterpret_cast<uint16_t *>(datatmp.data()) +
datatmp.size() / sizeof(uint16_t));
}
// std::copy(itIn, {}, outtest);
std::cout << "data size " << data.size() << " pixels size " << pixels.size()
<< std::endl;
std::fstream dump("dump.data",
std::ios::out | std::ios::trunc | std::ios::binary);
dump.write(reinterpret_cast<const char *>(pixels.data()),
screen.size * screen.h * screen.w);
assert(data.size() == pixels.size());
assert(std::equal(data.begin(), data.end(), pixels.begin()));
}
#endif