Skip to content

Commit

Permalink
useless one pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
yekm committed Jun 20, 2023
1 parent eb4d56d commit 1726865
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion art.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Art {
int tex_w, tex_h;
private:
virtual void resize(int _w, int _h) {default_resize(_w, _h);};
virtual bool render_gui() = 0;
virtual bool render_gui() {return false;}
virtual bool render(uint32_t *p) = 0;

void render_pixel_buffer(uint32_t *screen) {
Expand Down
2 changes: 2 additions & 0 deletions artfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "vermiculate.h"
#include "discrete.h"
#include "thornbird.h"
#include "onepixel.h"


ArtFactory::ArtFactory() {
Expand All @@ -15,6 +16,7 @@ ArtFactory::ArtFactory() {
add_art<Vermiculate>("Vermiculate");
add_art<Discrete>("Discrete");
add_art<Thornbird>("Thornbird");
add_art<OnePixel>("OnePixel");

vc = VectorCombo("Art", art_items);
vc.set_index(1);
Expand Down
51 changes: 29 additions & 22 deletions imgui_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,42 +145,49 @@ bool ScrollableSliderUInt(const char* label, unsigned* v, unsigned v_min, unsign
#include <sys/resource.h>
#include "timer.h"

char * cpu_load_text()
int cpu_load_text_now(char * text)
{
static int c = 0;
static double up = 0, sp = 0;
static common::Timer old_t;
static struct rusage old_usage;
static double outt = 0, ostt = 0;
static double ru_maxrss = 0;
static char text[1024*4];

if (c % 120 == 0) {
common::Timer t;
common::Timer t;

struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
double utt = usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6;
double stt = usage.ru_stime.tv_sec + usage.ru_stime.tv_usec / 1e6;
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
double utt = usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6;
double stt = usage.ru_stime.tv_sec + usage.ru_stime.tv_usec / 1e6;

double dt = (t - old_t).seconds();
up = 100.0 * (utt - outt) / dt;
sp = 100.0 * (stt - ostt) / dt;
double dt = (t - old_t).seconds();
up = 100.0 * (utt - outt) / dt;
sp = 100.0 * (stt - ostt) / dt;

//printf("%.3f %.3f %.3f %.3f %.3f %.3f %.3f\n", dt,
// up, sp, utt, stt, outt, ostt);
//printf("%.3f %.3f %.3f %.3f %.3f %.3f %.3f\n", dt,
// up, sp, utt, stt, outt, ostt);

old_t = t;
outt = utt;
ostt = stt;
old_t = t;
outt = utt;
ostt = stt;

ru_maxrss = usage.ru_maxrss / 1024;
}
c++;
ru_maxrss = usage.ru_maxrss / 1024;

snprintf(text, sizeof(text),
"Usr + Sys = %.2f + %.2f = %.2f. maxrss %.2f MB",
return sprintf(text,
"Usr + Sys = %.2f + %.2f = %.2f\nmaxrss %.2f MB",
up, sp, up+sp, ru_maxrss);
}

char * cpu_load_text()
{
static char text[1024*4];
static int c = 0;
char *t;

if (c % 120 == 0) {
cpu_load_text_now(text);
}
c++;

return text;
}
Expand Down
1 change: 1 addition & 0 deletions imgui_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ bool ScrollableSliderFloat(const char* label, float* v, float v_min, float v_max
bool ScrollableSliderInt(const char* label, int* v, int v_min, int v_max, const char* format, float scrollFactor);
bool ScrollableSliderUInt(const char* label, unsigned* v, unsigned v_min, unsigned v_max, const char* format, float scrollFactor);

int cpu_load_text_now(char * text);
char *cpu_load_text();
void cpu_load_gui();
23 changes: 18 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ static void glfw_error_callback(int error, const char* description)
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}

char info[1024*4];

int main(int argc, char *argv[])
{
unsigned frate = 0;

int opt;
int vsync = 1;

Expand Down Expand Up @@ -168,6 +171,7 @@ int main(int argc, char *argv[])

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();

ImGui::NewFrame();


Expand All @@ -190,11 +194,16 @@ int main(int argc, char *argv[])

bool resize_pbo = art->gui();

ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
1000.0f / ImGui::GetIO().Framerate,
ImGui::GetIO().Framerate);
if (art->frame_number % 120 == 0)
{
char *ti = info;
ti += cpu_load_text_now(info);
ti += sprintf(ti, "\n%.3f ms/frame (%.1f FPS)",
1000.0f / ImGui::GetIO().Framerate,
ImGui::GetIO().Framerate);

cpu_load_gui();
}
ImGui::Text(info);

ImGui::End();

Expand All @@ -204,12 +213,15 @@ int main(int argc, char *argv[])
make_pbos();
}


int nexti = pbo_index;
pbo_index = pbo_index ? 0 : 1;
glBindTexture(GL_TEXTURE_2D, image_texture);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[pbo_index]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
art->tex_w, art->tex_h, GL_RGBA, GL_UNSIGNED_BYTE, 0);
//glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);


glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[nexti]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, texture_size,
Expand All @@ -220,13 +232,14 @@ int main(int argc, char *argv[])
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);


ImGui::GetBackgroundDrawList()->AddImage((void*)(intptr_t)image_texture,
ImVec2(0, 0), ImVec2(sw, sh),
ImVec2(0, 0), ImVec2((float)sw/art->tex_w, (float)sh/art->tex_h));

ImGui::Render();
glViewport(0, 0, sw, sh);

glViewport(0, 0, sw, sh);
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
Expand Down
16 changes: 16 additions & 0 deletions onepixel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "art.hpp"
#include "imgui.h"
#include <vector>

class OnePixel : public Art {
public:
OnePixel()
: Art("One pixel benchmark") {}
private:
//virtual bool render_gui() override {};
//virtual void resize(int _w, int _h) override;
virtual bool render(uint32_t *p) override {
drawdot(p, w/2, h/2, 0x00ffffff);
return true;
}
};

0 comments on commit 1726865

Please sign in to comment.