Skip to content

Instantly share code, notes, and snippets.

/*
The MIT License (MIT)
Copyright (c) 2016 Andre Leiradella
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@rmitton
rmitton / toolbar.cpp
Created March 13, 2019 06:20
How to do a toolbar in Dear ImGui.
// How to do a toolbar in Dear ImGui.
const float toolbarSize = 50;
void DockSpaceUI()
{
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos + ImVec2(0, toolbarSize));
ImGui::SetNextWindowSize(viewport->Size - ImVec2(0, toolbarSize));
ImGui::SetNextWindowViewport(viewport->ID);
// --- Library --------------------------------------------------------------------------
#include <string.h>
#include <assert.h>
struct ui_box {int x,y,w,h;};
typedef unsigned long long ui_id;
struct ui_node {
int parent;
int lst, end, nxt;
int siz[2];
@zeux
zeux / murmur.h
Last active March 20, 2021 23:05
MurMurHash finalizers as 32-bit integer/pointer hashers
uint32_t murmur2(uint32_t h)
{
h ^= h >> 13;
h *= 0x5bd1e995;
h ^= h >> 15;
return h;
}
uint32_t murmur3(uint32_t h)
#pragma once
/*
// Example use on Windows with links opening in a browser
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "Shellapi.h"
inline void LinkCallback( const char* link_, uint32_t linkLength_ )
@sphaero
sphaero / Nodes.cpp
Created December 12, 2018 15:07 — forked from ChemistAion/nodes.cpp
Second prototype of standalone node graph editor for ImGui
#include "Nodes.h"
namespace ImGui
{
template<int n>
struct BezierWeights
{
constexpr BezierWeights() : x_(), y_(), z_(), w_()
{
for (int i = 1; i <= n; ++i)
@ChemistAion
ChemistAion / nodes.cpp
Last active January 12, 2024 20:37
Second prototype of standalone node graph editor for ImGui
#include "nodes.h"
namespace ImGui
{
void ImGuiNodes::UpdateCanvasGeometry(ImDrawList* draw_list)
{
const ImGuiIO& io = ImGui::GetIO();
mouse_ = ImGui::GetMousePos();
@floooh
floooh / imgui_buffer_update.md
Last active February 9, 2022 12:26
How I update vertex/index buffers for Dear Imgui

My Dear Imgui render loop looks a bit unusual because I want to reduce calls to WebGL as much as possible, especially buffer update calls.

This means:

  • only one buffer each for all per-frame vertex- and index-data
  • only one update call each per frame for vertex- and index-data (with my own double-buffering, since buffer-orphaning doesn't work on WebGL, and with this I'm also independent from any 'under-the-hood' magic a GL driver might or might not perform)
@JSandusky
JSandusky / imgui_bitfield.cpp
Created March 26, 2018 05:56
ImGui Bitfield Checkbox Matrix
bool BitField(const char* label, unsigned* bits, unsigned* hoverIndex)
{
unsigned val = *bits;
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
unsigned oldFlags = window->Flags;
ImGuiContext* g = ImGui::GetCurrentContext();
I want to show how you can optimize the rendering functions without going into changes on the upper level (like removing round
stuff and so on), but I want to teach also the ideas behind the optimizations I'm proposing. I have no esp32 board to test my
changes, to I will try to teach the ideas and let others test the optimizations. And I don't want to write an fast software
texture mapper (again) without explaining why it's much faster than the current source code.
1.) optimizing color conversion
this should be done automatically by your compiler (hopefully, has to be checked at assembly level!), but some background:
multiplications and divides can be optimized if they're a power of 2 by bit-shifts, means divison by 255 can also be done with
bitshit of 8 bits to the right. so looking at the first color conversion routine: