├── .gitattributes ├── .gitignore ├── README.md ├── log ├── arcintersect.png ├── badrect.png ├── cover.png ├── cover2.png ├── ibw1.png ├── ibw2.png ├── ibw3.png ├── ibw4.png ├── ls.png ├── pcracks.png ├── readme.md ├── reyes_bs.png ├── reyes_first.png ├── uvquad.png ├── v2_patches.png └── v2_shaded.png ├── resources.md └── src └── reyes ├── aajob.hpp ├── backend.hpp ├── bezier16.hpp ├── bmpsampler.hpp ├── camera.hpp ├── color.hpp ├── cpufilm.hpp ├── depthmat.hpp ├── directionalight.hpp ├── disc.hpp ├── displacementmat.hpp ├── film.hpp ├── grid.hpp ├── klein.hpp ├── lambertmat.hpp ├── lena.bmp ├── litmat.hpp ├── main.cpp ├── mat.hpp ├── mem.hpp ├── normalmat.hpp ├── oglfilm.hpp ├── pipeline.hpp ├── plane.hpp ├── pointlight.hpp ├── primitive.hpp ├── renderer.hpp ├── reyes.sln ├── reyes.vcxproj ├── reyes.vcxproj.filters ├── samplermat.hpp ├── scene.hpp ├── settings.hpp ├── shading.hpp ├── shape.hpp ├── shlight.hpp ├── sincossampler.hpp ├── solidcolormat.hpp ├── sphere.hpp ├── stone_albedo.bmp ├── stone_normal.bmp ├── teapot.hpp ├── thirdparty ├── AntTweakBar.dll ├── AntTweakBar.h ├── AntTweakBar.lib ├── AntTweakBar64.dll ├── AntTweakBar64.lib ├── glew.h ├── glew32.dll ├── glew32.lib ├── glew32s.lib ├── glxew.h ├── nvToolsExt.h ├── nvToolsExt32_1.dll ├── nvToolsExt32_1.lib ├── nvToolsExt64_1.dll ├── nvToolsExt64_1.lib └── wglew.h ├── uvmat.hpp └── vecmx.hpp /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # reyes 2 | REYES renderer in C++ 3 | 4 | complementary slides about the algorithm and the implementation: https://www.slideshare.net/DraganOkanovic/reyes-59489937 5 | 6 | | example renderer output | algorithm | 7 | | --- | --- | 8 | | ![cover2](log/cover2.png "cover2") | ![image](https://user-images.githubusercontent.com/1355455/147876291-fdb4e1e2-de13-4790-9c90-6509a8552da1.png) | 9 | 10 | ### file structure 11 | 12 | Source code is divided as following: 13 | 14 | ![ls](log/ls.png "ls") 15 | 16 | - **core/**: responsible for systems independent of the reyes algorithm 17 | - [aajob.hpp](src/reyes/aajob.hpp): multithreading management 18 | - [backend.hpp](src/reyes/backend.hpp): win api and opengl init 19 | - [mem.hpp](src/reyes/mem.hpp): memory management 20 | - **reyes/** 21 | - [settings.hpp](src/reyes/settings.hpp): modifies behavior and data structures 22 | - [pipeline.hpp](src/reyes/pipeline.hpp): main rendering procedure and heart of the system 23 | - [shape.hpp](src/reyes/shape.hpp): main abstraction of the input 24 | - [shading.hpp](src/reyes/shading.hpp): abstraction of a material and shading system 25 | - [grid.hpp](src/reyes/grid.hpp): microgrid abstraction 26 | - [scene.hpp](src/reyes/scene.hpp): convenient data structure 27 | - **camera/** 28 | - [scene.hpp](src/reyes/scene.hpp): abstraction of the virtual camera 29 | - [film.hpp](src/reyes/film.hpp): abstraction of the image's film 30 | - **film/**: different implementations of the film 31 | - **lib/**: different implementations of the core parts of the shading system 32 | - **lights/** 33 | - **materials/** 34 | - **samplers/** 35 | - **shapes/** 36 | - **misc/**: vector math and matrices 37 | 38 | --- 39 | 40 | #### v1.0 41 | 42 | - [x] basic buffer (1 sample per pixel) 43 | - [x] no bucketing 44 | - [x] no splitting and bounding (dice entire primitives, each and every) 45 | - [x] basic pipeline 46 | - [x] basic rasterizer 47 | 48 | #### v2.0 49 | 50 | - [x] transformations (translate, scale) 51 | - [x] dicing 52 | - [x] bounding and splitting 53 | - [x] entire reyes pipeline 54 | - [x] finalize quadrilaterals and triangles 55 | - [x] G-buffer 56 | - [x] improved memory management and speed 57 | - [x] geometry: plane, sphere, disc, cubic bezier patch, Utah teapot 58 | - [x] support for different materials (custom "shaders") 59 | - [x] texture samplers in "shaders" 60 | - [x] support for lights: directional, point 61 | 62 | #### v3.0 63 | 64 | - [x] threaded renderer 65 | - [x] improved memory managment 66 | - [ ] A-buffer 67 | - [ ] *stochastic (multi)sampling* 68 | - [ ] transparency support 69 | - [ ] inject optimizations 70 | - [ ] dof 71 | - [ ] motion blur 72 | - [x] task (job) manager 73 | - [ ] profiling 74 | - [ ] bucketing 75 | - [ ] (progress indicator) 76 | - [ ] (camera; perspective and orthographic) 77 | - [ ] (Klein bottle) 78 | - [ ] (SH light) 79 | 80 | #### v4.0 81 | 82 | - [ ] optimized memory layout 83 | - [ ] (GP)GPU implementation 84 | - [ ] (pseudo) real-time 85 | 86 | #### v5.0 87 | 88 | - [ ] alogirthms for fixing cracks 89 | - [ ] fix elongated micropolygons 90 | - [ ] dice criterium different 91 | - [ ] dynamic dicing 92 | 93 | #### v6.0 94 | 95 | - [ ] shadow mapping 96 | - [ ] additional post-processing effects 97 | - [ ] animations 98 | - [ ] materials (toon, phong, ggxD) 99 | - [ ] additional geometry 100 | - [ ] catmull-clark subdiv 101 | - [ ] more bezier 102 | - [ ] nurbs (b-spline) 103 | - [ ] loop subdiv 104 | - [ ] full Renderman specification 105 | -------------------------------------------------------------------------------- /log/arcintersect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/arcintersect.png -------------------------------------------------------------------------------- /log/badrect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/badrect.png -------------------------------------------------------------------------------- /log/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/cover.png -------------------------------------------------------------------------------- /log/cover2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/cover2.png -------------------------------------------------------------------------------- /log/ibw1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/ibw1.png -------------------------------------------------------------------------------- /log/ibw2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/ibw2.png -------------------------------------------------------------------------------- /log/ibw3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/ibw3.png -------------------------------------------------------------------------------- /log/ibw4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/ibw4.png -------------------------------------------------------------------------------- /log/ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/ls.png -------------------------------------------------------------------------------- /log/pcracks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/pcracks.png -------------------------------------------------------------------------------- /log/reyes_bs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/reyes_bs.png -------------------------------------------------------------------------------- /log/reyes_first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/reyes_first.png -------------------------------------------------------------------------------- /log/uvquad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/uvquad.png -------------------------------------------------------------------------------- /log/v2_patches.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/v2_patches.png -------------------------------------------------------------------------------- /log/v2_shaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/log/v2_shaded.png -------------------------------------------------------------------------------- /resources.md: -------------------------------------------------------------------------------- 1 | ####reyes architecture 2 | 3 | - Reyes architecture, Alexander Boswell (blogposts) 4 | - http://www.steckles.com/reyes1.html 5 | - http://www.steckles.com/reyes2.html 6 | - Reyes architecture and Implementation, Kayvon Fatahalian (slides) 7 | - A real-time micropolygon rendering, Kayvon Fatahalian (slides, SIGGRAPH 2009) 8 | - Parallel micropolygon rendering (slides, http://www.cs.cmu.edu/afs/cs/academic/class/15418-s12/www/lectures/25_micropolygons.pdf) 9 | - Implementing a modern, RenderMan compliant, REYES renderer, Davide Pasca (slides, http://www.slideshare.net/davidepasca/implementing-a-modern-renderman-compliant-reyes-renderer) 10 | - The Reyes Image Rendering Architecture, Cook, Carpenter, Catmull (original paper '87') 11 | - Real-time Reyes-style Adaptive Surface Subdivision, Patney and Owens (slides) 12 | - RenderAnts: Interactive Reyes rendering on GPUs, Kun Zhou et al. (paper) 13 | 14 | ####stochastic sampling, dof and motion blur 15 | 16 | - Micropolygon Raytracing with Defocus and Motion Blur, Quiming Hou et al. (paper) 17 | - Interactive DOF using simulated diffusion on a GPU, Michael Kass et al. (paper, @Pixar) 18 | - Motionblur, Max Liani (blogpost, http://glimpse-rt.blogspot.rs/2012/09/motionblur.html) 19 | - Real-time Stochastic Rasterization on Conventional GPU Architectures, McGuire et al. (paper) 20 | - Toward a Blurry Rasterizer, Jacob Munkberg (slides, SIGGRAPH 2011) 21 | 22 | ####bezier surfaces 23 | 24 | - scratchapixel, http://scratchapixel.com/lessons/advanced-rendering/bezier-curve-rendering-utah-teapot/bezier-surface 25 | - Philip Rideout, http://prideout.net/blog/?p=46#patch 26 | 27 | ####towards raytracing of subdivision surfaces 28 | 29 | - Direct ray tracing of full-featured subdivison surfaces using Bezier clipping, Takahito Tejima et al. (paper, @jcgt) 30 | - Curve intersection using Bezier clipping, Sederberg and Nishita (paper) -------------------------------------------------------------------------------- /src/reyes/aajob.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | inline void globalAssert(bool aCond){ 9 | if (!aCond){ 10 | #if _MSC_VER // VC 11 | #if _M_X64 12 | __debugbreak(); 13 | #else 14 | _asm { int 3 } 15 | #endif 16 | #endif 17 | } 18 | } 19 | #define GLIB_ASSERT(cond) globalAssert(cond) 20 | 21 | #define AAJOB_ENTRY_POINT(_fnName) void _fnName(void* jobDataPtr) 22 | 23 | namespace aajob 24 | { 25 | // ------------------------------------------------------------------------- Event 26 | struct Event 27 | { 28 | Event() 29 | : mHandle(CreateEvent(nullptr, true, false, nullptr)) 30 | {} 31 | ~Event() 32 | { 33 | CloseHandle(mHandle); 34 | } 35 | 36 | void raise() { SetEvent(mHandle); } 37 | void reset() { ResetEvent(mHandle); } 38 | void wait() 39 | { 40 | DWORD res = WaitForSingleObject(mHandle, INFINITE); 41 | GLIB_ASSERT(res == WAIT_OBJECT_0); 42 | } 43 | bool isRaised() 44 | { 45 | DWORD res = WaitForSingleObject(mHandle, 0); 46 | if (res == WAIT_OBJECT_0) return true; 47 | else if (res == WAIT_TIMEOUT) return false; 48 | else GLIB_ASSERT(false); 49 | } 50 | private: 51 | Event(const Event& a); 52 | Event& operator=(const Event&a); 53 | HANDLE mHandle; 54 | }; 55 | 56 | // ------------------------------------------------------------------------- Mutex 57 | struct Mutex 58 | { 59 | Mutex() 60 | { 61 | InitializeCriticalSection(&mCs); 62 | } 63 | ~Mutex() 64 | { 65 | DeleteCriticalSection(&mCs); 66 | } 67 | 68 | class Lock; 69 | friend class Lock; 70 | 71 | struct Lock 72 | { 73 | explicit Lock(Mutex& m) 74 | : mMtx(m) 75 | { 76 | EnterCriticalSection(&mMtx.mCs); 77 | } 78 | ~Lock() 79 | { 80 | LeaveCriticalSection(&mMtx.mCs); 81 | } 82 | private: 83 | Mutex& mMtx; 84 | Lock(Lock const &); 85 | Lock& operator=(Lock const &); 86 | }; 87 | 88 | private: 89 | CRITICAL_SECTION mCs; 90 | Mutex(Mutex const &); 91 | Mutex & operator=(Mutex const &); 92 | }; 93 | 94 | // ------------------------------------------------------------------------- Thread 95 | struct Thread 96 | { 97 | Thread(void(*fn)()) 98 | : mFunc(fn) 99 | { 100 | mHandle = CreateThread(0, 0, &ThreadFunc, this, CREATE_SUSPENDED, &mId); 101 | } 102 | void start() { ResumeThread(mHandle); } 103 | void stop() { SuspendThread(mHandle); } 104 | ~Thread() 105 | { 106 | SuspendThread(mHandle); 107 | CloseHandle(mHandle); 108 | } 109 | static DWORD WINAPI ThreadFunc(void* fn) 110 | { 111 | Thread* pT = (Thread*)fn; 112 | pT->mFunc(); 113 | return 0; 114 | } 115 | void(*mFunc)(); 116 | HANDLE mHandle; 117 | DWORD mId; 118 | 119 | private: 120 | Thread(const Thread& t); 121 | Thread& operator=(const Thread& t); 122 | }; 123 | 124 | // ------------------------------------------------------------------------- JobDecl 125 | typedef void(JobFunc)(void*); 126 | typedef JobFunc* JobFuncPtr; 127 | 128 | struct JobDecl 129 | { 130 | JobFuncPtr fn; 131 | void* data; 132 | 133 | JobDecl(JobFunc fnName = 0, void* dataPtr = 0) 134 | : fn(fnName) 135 | , data(dataPtr) 136 | {} 137 | }; 138 | 139 | // ------------------------------------------------------------------------- JobQueue 140 | struct JobQueue 141 | { 142 | JobQueue() 143 | : mNbWorkingJob(0) 144 | {} 145 | void addJob(const JobDecl& _job) 146 | { 147 | Mutex::Lock lock(mJobMutex); 148 | mAllDone.reset(); 149 | mJobs.push_back(_job); 150 | } 151 | JobDecl retrieveNextJob() 152 | { 153 | Mutex::Lock lock(mJobMutex); 154 | if (mJobs.size()>0){ 155 | JobDecl job = mJobs.front(); 156 | mJobs.pop_front(); 157 | _InterlockedIncrement(&mNbWorkingJob); 158 | return job; 159 | } 160 | else 161 | { 162 | return nullptr; 163 | } 164 | } 165 | // called when a job is done 166 | void markJobDone(JobDecl& _job) 167 | { 168 | Mutex::Lock lock(mJobMutex); 169 | long bbWorking = _InterlockedDecrement(&mNbWorkingJob); 170 | if (bbWorking == 0 && mJobs.size() == 0) 171 | { 172 | mAllDone.raise(); 173 | } 174 | } 175 | // waits until all job are done 176 | void waitForAllDone() 177 | { 178 | mAllDone.wait(); 179 | } 180 | bool hasWorking() 181 | { 182 | Mutex::Lock lock(mJobMutex); 183 | return mNbWorkingJob>0; 184 | } 185 | bool isDone() 186 | { 187 | Mutex::Lock lock(mJobMutex); 188 | return ((mJobs.size() == 0) && (mNbWorkingJob == 0)); 189 | } 190 | private: 191 | JobQueue(const JobQueue&); 192 | JobQueue& operator=(const JobQueue&); 193 | 194 | std::list mJobs; 195 | Mutex mJobMutex; 196 | long mNbWorkingJob; 197 | Event mAllDone; 198 | }; 199 | 200 | static JobQueue g_jobqueue; 201 | 202 | // ------------------------------------------------------------------------- Worker 203 | struct Worker 204 | { 205 | Worker(uint32_t auiId) 206 | : muiId(auiId) 207 | { 208 | mpThread = new Thread(&workerFunc); 209 | mpThread->start(); 210 | } 211 | ~Worker() 212 | { 213 | delete mpThread; 214 | } 215 | static void workerFunc() 216 | { 217 | while (1) 218 | { 219 | JobDecl t = aajob::g_jobqueue.retrieveNextJob(); 220 | if (t.fn) 221 | { 222 | t.fn(t.data); 223 | aajob::g_jobqueue.markJobDone(t); 224 | } 225 | } 226 | } 227 | uint32_t muiId; 228 | Thread* mpThread; 229 | private: 230 | Worker(const Worker& a); 231 | Worker& operator=(const Worker& a); 232 | }; 233 | 234 | // ------------------------------------------------------------------------- System 235 | static uint8_t g_workerCnt; 236 | static Worker** g_workers; 237 | 238 | void RunJob(const JobDecl& _job) 239 | { 240 | if (0 == g_workerCnt) 241 | { 242 | _job.fn(_job.data); 243 | } 244 | else 245 | { 246 | g_jobqueue.addJob(_job); 247 | } 248 | } 249 | 250 | void Flush(void) 251 | { 252 | JobDecl job = g_jobqueue.retrieveNextJob(); 253 | while (job.fn) 254 | { 255 | job.fn(job.data); 256 | g_jobqueue.markJobDone(job); 257 | job = g_jobqueue.retrieveNextJob(); 258 | } 259 | if (g_workerCnt>0 && g_jobqueue.hasWorking()) 260 | g_jobqueue.waitForAllDone(); 261 | } 262 | 263 | void Init(uint8_t workerCnt = 2) 264 | { 265 | g_workerCnt = workerCnt; 266 | if (aajob::g_workerCnt > 0) 267 | { 268 | aajob::g_workers = new aajob::Worker*[aajob::g_workerCnt]; 269 | for (DWORD i = 0; i < aajob::g_workerCnt; ++i) 270 | { 271 | aajob::g_workers[i] = new aajob::Worker(i); 272 | } 273 | } 274 | } 275 | 276 | void Cleanup() 277 | { 278 | if (!g_jobqueue.isDone()) 279 | g_jobqueue.waitForAllDone(); 280 | 281 | if (aajob::g_workerCnt > 0) 282 | { 283 | for (DWORD i = 0; i < aajob::g_workerCnt; ++i) 284 | delete aajob::g_workers[i]; 285 | delete[] aajob::g_workers; 286 | } 287 | } 288 | } 289 | 290 | #undef GLIB_ASSERT -------------------------------------------------------------------------------- /src/reyes/backend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // --------------------------------------------------------------------------- 4 | #define USE_CONSOLE_BACKEND 5 | //#define USE_NVTX_BACKEND 6 | //#define USE_ANTTWBAR_BACKEND 7 | //#define ANIMATE_BACKEND 8 | // -------------------------------------------------------------------------- 9 | 10 | // -------------------------------------------------------------------- 11 | #define INPUT_f_mouseMove(fn) (__mouseMoveF=fn) 12 | #define INPUT_f_mouseDown(fn) (__mouseDownF=fn) 13 | #define INPUT_f_mouseUp(fn) (__mouseUpF=fn) 14 | #define INPUT_f_mouseDouble(fn) (__mouseDoubleF=fn) 15 | #define INPUT_f_keyDown(fn) (__keyDownF=fn) 16 | #define INPUT_f_keyUp(fn) (__keyUpF=fn) 17 | #define INPUT_f_resize(fn) (__resizeF=fn) 18 | 19 | #ifdef ANIMATE_BACKEND 20 | void InitApp(); 21 | void RenderApp(); 22 | void CleanupApp(); 23 | #else 24 | void mainApp(); 25 | #endif 26 | // ------------------------------------------------------------------- 27 | 28 | // commonly used keys 29 | #define INPUT_KEY_ESC 0x1B 30 | #define INPUT_KEY_BACK 0x08 31 | #define INPUT_KEY_TAB 0x09 32 | #define INPUT_KEY_ENTER 0x0D 33 | #define INPUT_KEY_SPACE 0x20 34 | #define INPUT_KEY_PAUSE 0x13 35 | #define INPUT_KEY_CAPS 0x14 36 | #define INPUT_KEY_INSERT 0x2D 37 | #define INPUT_KEY_DELETE 0x2E 38 | // system keys 39 | #define INPUT_KEY_SHIFT 0x10 40 | #define INPUT_KEY_CTRL 0x11 41 | #define INPUT_KEY_ALT 0x12 42 | #define INPUT_KEY_LSHIFT 0xA0 43 | #define INPUT_KEY_RSHIFT 0xA1 44 | #define INPUT_KEY_LCTRL 0xA2 45 | #define INPUT_KEY_RCTRL 0xA3 46 | #define INPUT_KEY_LALT 0xA4 47 | #define INPUT_KEY_RALT 0xA5 48 | // arrow keys 49 | #define INPUT_KEY_LEFT 0x25 50 | #define INPUT_KEY_UP 0x26 51 | #define INPUT_KEY_RIGHT 0x27 52 | #define INPUT_KEY_DOWN 0x28 53 | // number keys 54 | #define INPUT_KEY_0 0x30 55 | #define INPUT_KEY_1 0x31 56 | #define INPUT_KEY_2 0x32 57 | #define INPUT_KEY_3 0x33 58 | #define INPUT_KEY_4 0x34 59 | #define INPUT_KEY_5 0x35 60 | #define INPUT_KEY_6 0x36 61 | #define INPUT_KEY_7 0x37 62 | #define INPUT_KEY_8 0x38 63 | #define INPUT_KEY_9 0x39 64 | // letter keys 65 | #define INPUT_KEY_A 0x41 66 | #define INPUT_KEY_B 0x42 67 | #define INPUT_KEY_C 0x43 68 | #define INPUT_KEY_D 0x44 69 | #define INPUT_KEY_E 0x45 70 | #define INPUT_KEY_F 0x46 71 | #define INPUT_KEY_G 0x47 72 | #define INPUT_KEY_H 0x48 73 | #define INPUT_KEY_I 0x49 74 | #define INPUT_KEY_J 0x4A 75 | #define INPUT_KEY_K 0x4B 76 | #define INPUT_KEY_L 0x4C 77 | #define INPUT_KEY_M 0x4D 78 | #define INPUT_KEY_N 0x4E 79 | #define INPUT_KEY_O 0x4F 80 | #define INPUT_KEY_P 0x50 81 | #define INPUT_KEY_Q 0x51 82 | #define INPUT_KEY_R 0x52 83 | #define INPUT_KEY_S 0x53 84 | #define INPUT_KEY_T 0x54 85 | #define INPUT_KEY_U 0x55 86 | #define INPUT_KEY_V 0x56 87 | #define INPUT_KEY_W 0x57 88 | #define INPUT_KEY_X 0x58 89 | #define INPUT_KEY_Y 0x59 90 | #define INPUT_KEY_Z 0x5A 91 | // function keys 92 | #define INPUT_KEY_F1 0x70 93 | #define INPUT_KEY_F2 0x71 94 | #define INPUT_KEY_F3 0x72 95 | #define INPUT_KEY_F4 0x73 96 | #define INPUT_KEY_F5 0x74 97 | #define INPUT_KEY_F6 0x75 98 | #define INPUT_KEY_F7 0x76 99 | #define INPUT_KEY_F8 0x77 100 | #define INPUT_KEY_F9 0x78 101 | #define INPUT_KEY_F10 0x79 102 | #define INPUT_KEY_F11 0x7A 103 | #define INPUT_KEY_F12 0x7B 104 | // mouse buttons 105 | #define INPUT_MOUSE_LEFT 0x0001 106 | #define INPUT_MOUSE_MIDDLE 0x0010 107 | #define INPUT_MOUSE_RIGHT 0x0002 108 | // input functions 109 | extern void(*__mouseMoveF)(int, int, unsigned int, unsigned int); 110 | extern void(*__mouseDownF)(int); 111 | extern void(*__mouseUpF)(int); 112 | extern void(*__mouseDoubleF)(int); 113 | extern void(*__keyDownF)(unsigned int); 114 | extern void(*__keyUpF)(unsigned int); 115 | extern void(*__resizeF)(unsigned int, unsigned int); 116 | 117 | // loading graphics backend libraries 118 | #include 119 | #include 120 | #include "thirdparty/glew.h" 121 | 122 | // loading perf tracking (nv tools extension) 123 | #ifdef USE_NVTX_BACKEND 124 | # include "thirdparty/nvToolsExt.h" 125 | # define perfMarkerStart(_text) nvtxRangePushA((_text)) 126 | # define perfMarkerEnd(_nil) nvtxRangePop() 127 | # define perfMarkerStartEx(_text,_col) \ 128 | { \ 129 | nvtxEventAttributes_t initAttrib = { 0 }; \ 130 | initAttrib.version = NVTX_VERSION; \ 131 | initAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; \ 132 | initAttrib.color = (_col); \ 133 | initAttrib.colorType = NVTX_COLOR_ARGB; \ 134 | initAttrib.message.ascii = _text; \ 135 | initAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; \ 136 | nvtxRangePushEx(&initAttrib); \ 137 | } 138 | #else 139 | # define perfMarkerStart(_text) 140 | # define perfMarkerEnd(_nil) 141 | # define perfMarkerStartEx(_text,_col) 142 | #endif 143 | struct PerfMarker_t 144 | { 145 | PerfMarker_t(const char* name, unsigned int col=0) 146 | { 147 | if (0 == col) perfMarkerStart(name); 148 | else perfMarkerStartEx(name, col); 149 | } 150 | ~PerfMarker_t() { perfMarkerEnd(); } 151 | }; 152 | #define NVTX_B_COMBINE1(X,Y) X##Y 153 | #define NVTX_B_COMBINE(X,Y) NVTX_B_COMBINE1(X,Y) 154 | #define PerfMarker(markerName,col) PerfMarker_t NVTX_B_COMBINE(marker,__LINE__) (markerName, col) 155 | 156 | 157 | // loading antTweakBar libraries 158 | #ifdef USE_ANTTWBAR_BACKEND 159 | # include "thirdparty/AntTweakBar.h" 160 | #endif 161 | 162 | //-------------------------------------------------------------------------------------- 163 | // Global Variables 164 | //-------------------------------------------------------------------------------------- 165 | HINSTANCE g_hInst = nullptr; 166 | HWND g_hWnd = nullptr; 167 | 168 | void(*__mouseMoveF)(int, int, unsigned int, unsigned int) = NULL; 169 | void(*__mouseDownF)(int) = NULL; 170 | void(*__mouseUpF)(int) = NULL; 171 | void(*__mouseDoubleF)(int) = NULL; 172 | void(*__keyDownF)(unsigned int) = NULL; 173 | void(*__keyUpF)(unsigned int) = NULL; 174 | void(*__resizeF)(unsigned int, unsigned int) = NULL; 175 | 176 | //-------------------------------------------------------------------------------------- 177 | // Forward declarations 178 | //-------------------------------------------------------------------------------------- 179 | HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow); 180 | HRESULT InitBackend(HWND hWnd); 181 | void CleanupWindow(); 182 | void CleanupBackend(HWND hWnd); 183 | LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 184 | void SwapBuffersBackend(); 185 | 186 | //-------------------------------------------------------------------------------------- 187 | // Entry point to the program. Initializes everything and goes into a message processing 188 | // loop. Idle time is used to render the scene. 189 | //-------------------------------------------------------------------------------------- 190 | int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) 191 | { 192 | UNREFERENCED_PARAMETER(hPrevInstance); 193 | UNREFERENCED_PARAMETER(lpCmdLine); 194 | 195 | #ifdef USE_CONSOLE_BACKEND 196 | AllocConsole(); 197 | freopen("CONIN$", "r", stdin); 198 | freopen("CONOUT$", "w", stdout); 199 | freopen("CONOUT$", "w", stderr); 200 | #endif 201 | 202 | // init 203 | if (FAILED(InitWindow(hInstance, nCmdShow))) 204 | return 0; 205 | 206 | if (FAILED(InitBackend(g_hWnd))) 207 | { 208 | CleanupBackend(g_hWnd); 209 | return 0; 210 | } 211 | 212 | ShowWindow(g_hWnd, SW_SHOW); 213 | SetForegroundWindow(g_hWnd); 214 | SetFocus(g_hWnd); 215 | 216 | #ifdef USE_ANTTWBAR_BACKEND 217 | TwInit(TW_OPENGL, NULL); 218 | #endif 219 | 220 | #ifdef ANIMATE_BACKEND 221 | InitApp(); 222 | #else 223 | mainApp(); 224 | #endif 225 | 226 | // main loop 227 | static bool quit = false; 228 | MSG msg = { 0 }; 229 | while (!quit) 230 | { 231 | if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) 232 | { 233 | TranslateMessage(&msg); 234 | DispatchMessage(&msg); 235 | } 236 | if (msg.message == WM_QUIT) 237 | { 238 | quit = true; 239 | } 240 | #ifdef ANIMATE_BACKEND 241 | else 242 | { 243 | RenderApp(); 244 | #ifdef USE_ANTTWBAR_BACKEND 245 | TwDraw(); 246 | #endif 247 | SwapBuffersBackend(); 248 | } 249 | #endif 250 | } 251 | 252 | // cleanup 253 | #ifdef ANIMATE_BACKEND 254 | CleanupApp(); 255 | #endif 256 | #ifdef USE_ANTTWBAR_BACKEND 257 | TwTerminate(); 258 | #endif 259 | CleanupBackend(g_hWnd); 260 | CleanupWindow(); 261 | 262 | return (int)msg.wParam; 263 | } 264 | 265 | //-------------------------------------------------------------------------------------- 266 | // Register class and create window 267 | //-------------------------------------------------------------------------------------- 268 | HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow) 269 | { 270 | // Register class 271 | WNDCLASSEX wcex; 272 | wcex.cbSize = sizeof(WNDCLASSEX); 273 | wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 274 | wcex.lpfnWndProc = WndProc; 275 | wcex.cbClsExtra = 0; 276 | wcex.cbWndExtra = 0; 277 | wcex.hInstance = hInstance; 278 | wcex.hIcon = LoadIcon(NULL, IDI_WINLOGO); 279 | wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); 280 | wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 281 | wcex.lpszMenuName = nullptr; 282 | wcex.lpszClassName = L"FrameWinClass"; 283 | wcex.hIconSm = wcex.hIcon; 284 | if (!RegisterClassEx(&wcex)) 285 | return E_FAIL; 286 | 287 | // Create window 288 | g_hInst = hInstance; 289 | RECT rc = { 0, 0, 800, 800 }; 290 | AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE); 291 | g_hWnd = CreateWindow(L"FrameWinClass", L"Frame", 292 | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 293 | CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, hInstance, 294 | nullptr); 295 | 296 | if (!g_hWnd) 297 | return E_FAIL; 298 | 299 | //ShowWindow(g_hWnd, nCmdShow); 300 | 301 | return S_OK; 302 | } 303 | 304 | //-------------------------------------------------------------------------------------- 305 | // Release resources, destroy window and unregister class 306 | //-------------------------------------------------------------------------------------- 307 | void CleanupWindow() 308 | { 309 | if (g_hWnd && !DestroyWindow(g_hWnd)) 310 | { 311 | MessageBox(NULL, L"Could Not Release hWnd.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); 312 | g_hWnd = NULL; 313 | } 314 | 315 | if (!UnregisterClass(L"FrameWinClass", g_hInst)) 316 | { 317 | MessageBox(NULL, L"Could Not Unregister Class.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); 318 | g_hInst = NULL; 319 | } 320 | } 321 | 322 | // -------------------------------------------------------------------------------------- 323 | // Called every time the application receives a message 324 | //--------------------------------------------------------------------------------------- 325 | LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 326 | { 327 | PAINTSTRUCT ps; 328 | HDC hdc; 329 | 330 | #ifdef USE_ANTTWBAR_BACKEND 331 | TwEventWin(hWnd, message, wParam, lParam); 332 | #endif 333 | 334 | switch (message) 335 | { 336 | case WM_CLOSE: 337 | PostQuitMessage(0); 338 | return 0; 339 | case WM_PAINT: 340 | hdc = BeginPaint(hWnd, &ps); 341 | EndPaint(hWnd, &ps); 342 | break; 343 | case WM_DESTROY: 344 | PostQuitMessage(0); 345 | break; 346 | case WM_KEYDOWN: 347 | if (__keyDownF) 348 | (__keyDownF)(wParam); 349 | return 0; 350 | case WM_KEYUP: 351 | if (__keyUpF) 352 | (*__keyUpF)(wParam); 353 | return 0; 354 | case WM_MOUSEMOVE: 355 | { 356 | if (__mouseMoveF) 357 | (*__mouseMoveF) 358 | ( 359 | wParam, 360 | ((wParam == INPUT_MOUSE_LEFT || wParam == INPUT_MOUSE_MIDDLE || wParam == INPUT_MOUSE_RIGHT) ? 1 : 0), 361 | LOWORD(lParam), 362 | HIWORD(lParam) 363 | ); 364 | return 0; 365 | } 366 | case WM_LBUTTONDOWN: 367 | if (__mouseDownF) 368 | (*__mouseDownF)(INPUT_MOUSE_LEFT); 369 | return 0; 370 | case WM_MBUTTONDOWN: 371 | if (__mouseDownF) 372 | (*__mouseDownF)(INPUT_MOUSE_MIDDLE); 373 | return 0; 374 | case WM_RBUTTONDOWN: 375 | if (__mouseDownF) 376 | (*__mouseDownF)(INPUT_MOUSE_RIGHT); 377 | return 0; 378 | case WM_LBUTTONUP: 379 | if (__mouseUpF) 380 | (*__mouseUpF)(INPUT_MOUSE_LEFT); 381 | return 0; 382 | case WM_MBUTTONUP: 383 | if (__mouseUpF) 384 | (*__mouseUpF)(INPUT_MOUSE_MIDDLE); 385 | return 0; 386 | case WM_RBUTTONUP: 387 | if (__mouseUpF) 388 | (*__mouseUpF)(INPUT_MOUSE_RIGHT); 389 | return 0; 390 | case WM_LBUTTONDBLCLK: 391 | if (__mouseDoubleF) 392 | (*__mouseDoubleF)(INPUT_MOUSE_LEFT); 393 | return 0; 394 | case WM_MBUTTONDBLCLK: 395 | if (__mouseDoubleF) 396 | (*__mouseDoubleF)(INPUT_MOUSE_MIDDLE); 397 | return 0; 398 | case WM_RBUTTONDBLCLK: 399 | if (__mouseDoubleF) 400 | (*__mouseDoubleF)(INPUT_MOUSE_RIGHT); 401 | return 0; 402 | case WM_SIZE: 403 | if(__resizeF) 404 | (*__resizeF)(LOWORD(lParam), HIWORD(lParam)); 405 | return 0; 406 | default: 407 | return DefWindowProc(hWnd, message, wParam, lParam); 408 | } 409 | 410 | return 0; 411 | } 412 | 413 | HGLRC g_hRC = nullptr; 414 | HDC g_hDC = nullptr; 415 | 416 | //-------------------------------------------------------------------------------------- 417 | // Initialize drawing API 418 | //-------------------------------------------------------------------------------------- 419 | HRESULT InitBackend(HWND hWnd) 420 | { 421 | if (!(g_hDC = GetDC(hWnd))) 422 | { 423 | printf("Error: Device fail.\n"); 424 | return E_FAIL; 425 | } 426 | 427 | int format; 428 | static PIXELFORMATDESCRIPTOR pfd = 429 | { 430 | sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 431 | 1, // Version Number 432 | PFD_DRAW_TO_WINDOW | // Format Must Support Window 433 | PFD_SUPPORT_OPENGL | // Format Must Support OpenGL 434 | PFD_DOUBLEBUFFER, // Must Support Double Buffering 435 | PFD_TYPE_RGBA, // Request An RGBA Format 436 | 32, // Select Our Color Depth 437 | 0, 0, 0, 0, 0, 0, // Color Bits Ignored 438 | 0, // No Alpha Buffer 439 | 0, // Shift Bit Ignored 440 | 0, // No Accumulation Buffer 441 | 0, 0, 0, 0, // Accumulation Bits Ignored 442 | 16, // 16Bit Z-Buffer (Depth Buffer) 443 | 0, // No Stencil Buffer 444 | 0, // No Auxiliary Buffer 445 | PFD_MAIN_PLANE, // Main Drawing Layer 446 | 0, // Reserved 447 | 0, 0, 0 448 | }; 449 | 450 | if (!(format = ChoosePixelFormat(g_hDC, &pfd))) 451 | { 452 | printf("Error: PixelFormat fail.\n"); 453 | return E_FAIL; 454 | } 455 | if (!SetPixelFormat(g_hDC, format, &pfd)) 456 | { 457 | printf("Error: PixelFormat not set.\n"); 458 | return E_FAIL; 459 | } 460 | if (!(g_hRC = wglCreateContext(g_hDC))) 461 | { 462 | printf("Error: Context not creted.\n"); 463 | return E_FAIL; 464 | } 465 | if (!wglMakeCurrent(g_hDC, g_hRC)) 466 | { 467 | printf("Error: Context not set.\n"); 468 | return E_FAIL; 469 | } 470 | 471 | // initialize glew 472 | GLenum res = glewInit(); 473 | if (res != GLEW_OK) 474 | { 475 | printf("Error: GLEW fail.\n"); 476 | return E_FAIL; 477 | } 478 | 479 | return S_OK; 480 | } 481 | 482 | //-------------------------------------------------------------------------------------- 483 | // Release drawing API resources 484 | //-------------------------------------------------------------------------------------- 485 | void CleanupBackend(HWND hWnd) 486 | { 487 | if (g_hRC) 488 | { 489 | if (!wglMakeCurrent(NULL, NULL)) 490 | MessageBox(NULL, L"Release Of DC And RC Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); 491 | if (!wglDeleteContext(g_hRC)) 492 | MessageBox(NULL, L"Release Rendering Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); 493 | g_hRC = NULL; 494 | } 495 | 496 | if (g_hDC && !ReleaseDC(hWnd, g_hDC)) 497 | { 498 | MessageBox(NULL, L"Release Device Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); 499 | g_hDC = NULL; 500 | } 501 | } 502 | 503 | //-------------------------------------------------------------------------------------- 504 | // Swap buffers and display 505 | //-------------------------------------------------------------------------------------- 506 | void SwapBuffersBackend() 507 | { 508 | SwapBuffers(g_hDC); 509 | } -------------------------------------------------------------------------------- /src/reyes/bezier16.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shape.hpp" 4 | 5 | namespace reyes { 6 | namespace lib { 7 | struct Bezier16 : public Shape 8 | { 9 | vec3 points[16]; 10 | Bezier16(const vec3* _p=0) 11 | { 12 | if (_p) 13 | { 14 | for (char i = 0; i < 16; i++) 15 | { 16 | points[i].x = _p[i].x; 17 | points[i].y = _p[i].y; 18 | points[i].z = _p[i].z; 19 | } 20 | } 21 | } 22 | 23 | vec3 evalBezierCurve4(const vec3* P, float t) 24 | { 25 | float b0 = (1 - t) * (1 - t) * (1 - t); 26 | float b1 = 3 * t * (1 - t) * (1 - t); 27 | float b2 = 3 * t * t * (1 - t); 28 | float b3 = t * t * t; 29 | return P[0] * b0 + P[1] * b1 + P[2] * b2 + P[3] * b3; 30 | } 31 | 32 | normal EvalN(uv _uv) 33 | { 34 | float epsi = 0.01f; 35 | 36 | vec3 pa = EvalP(_uv); 37 | vec3 pb = EvalP(uv(_uv.x + epsi, _uv.y)); 38 | vec3 pc = EvalP(uv(_uv.x, _uv.y + epsi)); 39 | 40 | vec3 b(pb.x - pa.x, pb.y - pa.y, pb.z - pa.z); 41 | vec3 a(pc.x - pa.x, pc.y - pa.y, pc.z - pa.z); 42 | 43 | vec3 n(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); 44 | /*if ((_uv.x + epsi > 1.0f) || (_uv.y + epsi > 1.0f)) 45 | n = vec3(-n.x, -n.y, -n.z);*/ 46 | return n.normalize(); 47 | } 48 | position EvalP(uv uv) 49 | { 50 | vec3 uCurve[4]; 51 | for (int i = 0; i < 4; ++i) 52 | { 53 | uCurve[i] = evalBezierCurve4(points + 4 * i, uv.x); 54 | } 55 | return evalBezierCurve4(uCurve, uv.y); 56 | } 57 | 58 | void split(Scene& scene, Shape** shapes=0) 59 | { 60 | mem::blk mblks[4]; 61 | for (char i = 0; i < 4; i++) 62 | { 63 | mblks[i] = scene.alloc(sizeof(Bezier16)); 64 | Bezier16* p = ::new(mblks[i].ptr) Bezier16; 65 | for (char i = 0; i < 16; i++) 66 | { 67 | p->points[i].x = points[i].x; 68 | p->points[i].y = points[i].y; 69 | p->points[i].z = points[i].z; 70 | } 71 | Shape::splitData(p, i); 72 | if (shapes) 73 | shapes[i] = p; 74 | } 75 | } 76 | }; 77 | } 78 | } -------------------------------------------------------------------------------- /src/reyes/bmpsampler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct BMPSampler : public Sampler 10 | { 11 | uint16_t width, height; 12 | unsigned char* data; 13 | 14 | BMPSampler(uint16_t w, uint16_t h, const char* filename) 15 | : width(w) 16 | , height(h) 17 | { 18 | unsigned char header[54]; 19 | size_t imageSize; 20 | data = 0; 21 | 22 | // open the file 23 | FILE * file = fopen(filename, "rb"); 24 | if (!file) 25 | return; 26 | if (fread(header, 1, 54, file) != 54) 27 | return; 28 | if (header[0] != 'B' || header[1] != 'M') 29 | return; 30 | 31 | // allocate data 32 | imageSize = this->width * this->height * 3; 33 | data = new unsigned char[imageSize]; 34 | if (!data) 35 | return; 36 | 37 | // read data 38 | fread(data, 1, imageSize, file); 39 | 40 | // close file 41 | fclose(file); 42 | 43 | // invert BGR to RGB 44 | for (size_t i = 0; i < this->width * this->height; i++) 45 | { 46 | unsigned char t = data[3 * i + 0]; 47 | data[3 * i + 0] = data[3 * i + 2]; 48 | data[3 * i + 2] = t; 49 | } 50 | } 51 | 52 | color sample(uv uv) 53 | { 54 | // repeat 55 | //while (uv.x > 1.0f) uv.x -= 1.0f; 56 | //while (uv.y > 1.0f) uv.y -= 1.0f; 57 | 58 | // calc offset 59 | size_t x = (size_t)(uv.x*width); 60 | size_t y = (size_t)((1.0f - uv.y)*height); 61 | size_t offset = y*width + x; 62 | 63 | // sample 64 | unsigned char R = data[3 * offset + 0]; 65 | unsigned char G = data[3 * offset + 1]; 66 | unsigned char B = data[3 * offset + 2]; 67 | return{ R / 255.0f, G / 255.0f, B / 255.0f, 1.0f }; 68 | } 69 | 70 | ~BMPSampler() 71 | { 72 | delete[] data; 73 | } 74 | }; 75 | } 76 | } -------------------------------------------------------------------------------- /src/reyes/camera.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vecmx.hpp" 4 | #include "film.hpp" 5 | 6 | namespace reyes 7 | { 8 | /* Camera interface. */ 9 | struct Camera 10 | { 11 | mx4 view; 12 | mx4 projection; 13 | FilmI* film; 14 | 15 | /* Mark perspective frustum. */ 16 | void perspective(float fov, float aspect, float near, float far) 17 | { 18 | /*float ymax = near * tan(((double)fov * 0.5)*M_PI/180.0); 19 | float ymin = -ymax; 20 | float xmin = ymin * aspect; 21 | float xmax = ymax * aspect; 22 | 23 | projection.frustum(xmin, xmax, ymin, ymax, near, far);*/ 24 | } 25 | 26 | /* Make orthographics frustum. */ 27 | void orthographic(float left, float right, float bottom, float top, float near=0.1f, float far=1000.0f) 28 | { 29 | /*float dx = (right - left) / 2; 30 | float dy = (top - bottom) / 2; 31 | float cx = (right + left) / 2; 32 | float cy = (top + bottom) / 2; 33 | 34 | projection.orthographic(cx - dx, cx + dx, cy + dy, cy - dy, near, far);*/ 35 | } 36 | 37 | /* Orient camera to look at the target position, with selected up vector, from the selected origin. */ 38 | void lookAt(const vec3 eye, vec3 target, const vec3 up = { 0, 1, 0 }) 39 | { 40 | projection.lookAt(eye, target, up); 41 | } 42 | }; 43 | } -------------------------------------------------------------------------------- /src/reyes/color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vecmx.hpp" 4 | #include 5 | 6 | namespace reyes 7 | { 8 | /* RGBA32F color struct. */ 9 | struct color 10 | { 11 | float r, g, b, a; 12 | color(float _r = 0, float _g = 0, float _b = 0, float _a = 1) 13 | : r(_r) 14 | , g(_g) 15 | , b(_b) 16 | , a(_a) 17 | {} 18 | }; 19 | 20 | typedef vec2 uv; 21 | 22 | struct PosNormal 23 | { 24 | position p; 25 | normal n; 26 | PosNormal(position _p, normal _n) 27 | : p(_p) 28 | , n(_n) 29 | {} 30 | }; 31 | struct PosColor 32 | { 33 | position p; 34 | color col; 35 | }; 36 | struct PosNormalColor 37 | { 38 | position p; 39 | normal n; 40 | color col; 41 | }; 42 | struct PosNormalUV 43 | { 44 | position p; 45 | normal n; 46 | uv uv; 47 | }; 48 | 49 | struct Vertex 50 | { 51 | position p; 52 | normal n; 53 | uv uv; 54 | color c; 55 | Vertex() 56 | : p(0,0,0) 57 | , n (0,1,0) 58 | , uv(0,0) 59 | , c(0,0,0,1) 60 | {} 61 | }; 62 | typedef uint16_t Index; 63 | } -------------------------------------------------------------------------------- /src/reyes/cpufilm.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "film.hpp" 4 | 5 | namespace reyes 6 | { 7 | /* Film that rasterizes image on the CPU. */ 8 | struct CPUFilm : public FilmI 9 | { 10 | struct RGBpixel 11 | { 12 | char r, g, b; 13 | } *rgb_data; 14 | struct Apixel 15 | { 16 | float a; 17 | } *a_data; 18 | struct Zpixel 19 | { 20 | float z; 21 | } *z_data; 22 | 23 | CPUFilm(uint16_t _width, uint16_t _height) 24 | : FilmI(_width, _height) 25 | , rgb_data(new RGBpixel[_width*_height]) 26 | , a_data(new Apixel[_width*_height]) 27 | , z_data(new Zpixel[_width*_height]) 28 | { 29 | for (uint16_t x = 0; x < width; x++) 30 | for (uint16_t y = 0; y < height; y++) 31 | { 32 | rgb_data[y*width + x] = { 0, 0, 0 }; 33 | a_data[y*width + x] = { 1.0f }; 34 | z_data[y*width + x] = { -1.0f }; 35 | } 36 | } 37 | 38 | void rasterize(Microgrid& grid) 39 | { 40 | uint16_t p_cnt = grid.primCount(); 41 | float halfpx_x = 1.0f / width; 42 | float halfpx_y = 1.0f / height; 43 | for (uint16_t pidx = 0; pidx < p_cnt; pidx++) 44 | { 45 | primitive::PrimitiveI* prim = grid[pidx]; 46 | // get bounding box 47 | AABB2 bb = prim->aabb(); 48 | uint16_t start_x = 0, end_x = width, start_y = 0, end_y = height; 49 | // calc tight rasterization box 50 | for (start_x = 0; -1.0f + (2 * start_x + 1)*halfpx_x < bb.min.x && start_x < width; start_x++); 51 | for (end_x = start_x; -1.0f + (2 * end_x + 1)*halfpx_x < bb.max.x && end_x bb.max.y && start_y < height; start_y++); 53 | for (end_y = start_y; 1.0f - (2 * end_y + 1)*halfpx_y >= bb.min.y && end_y < height; end_y++); 54 | // rasterize 55 | for (uint16_t x = start_x; x < end_x; x++) 56 | { 57 | for (uint16_t y = start_y; y < end_y; y++) 58 | { 59 | // construct pixel location 60 | float px = -1.0f + (2 * x + 1)*halfpx_x; 61 | float py = 1.0f - (2 * y + 1)*halfpx_y; 62 | vec3 p(px, py, 0); 63 | 64 | // test 65 | if (prim->in(p)) 66 | { 67 | Vertex r = prim->interpolate(p); 68 | Zpixel px_z = z_data[y*width + x]; 69 | 70 | // rasterized pixel should overwrite information 71 | if (r.p.z > px_z.z) 72 | { 73 | // TODO depth test settings 74 | // TODO blending 75 | px_z.z = r.p.z; 76 | RGBpixel px_rgb = { r.c.r*255.0f, r.c.g*255.0f, r.c.b*255.0f }; 77 | rgb_data[y*width + x] = px_rgb; 78 | z_data[y*width + x] = px_z; 79 | } 80 | } 81 | } 82 | } 83 | } 84 | } 85 | 86 | char* getRGB(void) 87 | { 88 | return (char*)rgb_data; 89 | } 90 | 91 | void display() 92 | { 93 | // TODO 94 | } 95 | }; 96 | } -------------------------------------------------------------------------------- /src/reyes/depthmat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | MATERIAL(DepthColor) 10 | { 11 | DISPLACE 12 | { 13 | return vertex.p; 14 | } 15 | 16 | SHADE 17 | { 18 | /*float d = vertex.p.z > 1.0f ? 1.0f : vertex.p.z; 19 | d = vertex.p.z < 0 ? 0 : vertex.p.z;*/ 20 | float d = vertex.p.z*.5f + .5f; 21 | return{ d, d, d, 1 }; 22 | } 23 | }; 24 | } 25 | } -------------------------------------------------------------------------------- /src/reyes/directionalight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct DirectionalLight : public Light 10 | { 11 | vec3 direction; 12 | color col; 13 | DirectionalLight(color c, vec3 d) 14 | : col(c) 15 | , direction(d) 16 | {} 17 | color sample(PosNormal point) 18 | { 19 | vec3 n = point.n; 20 | n.normalize(); 21 | direction.normalize(); 22 | float k = n.x*direction.x + n.y*direction.y + n.z*direction.z; 23 | k = k < 0.0f ? 0.0f : k; 24 | return{ col.r*k, col.g*k, col.b*k, 1.0f }; 25 | } 26 | }; 27 | } 28 | } -------------------------------------------------------------------------------- /src/reyes/disc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shape.hpp" 4 | 5 | namespace reyes { 6 | namespace lib { 7 | 8 | struct Disc : public Shape 9 | { 10 | normal EvalN(uv uv) 11 | { 12 | return vec3(0, 0, 1); 13 | } 14 | position EvalP(uv uv) 15 | { 16 | float angle = 2.0f*M_PI*(1.0f - uv.x); 17 | vec3 v = vec3(cos(angle), -sin(angle), 0).normalize(); 18 | float l = uv.y; 19 | return v*l; 20 | } 21 | void split(Scene& scene, Shape** shapes=0) 22 | { 23 | mem::blk mblks[4]; 24 | for (char i = 0; i < 4; i++) 25 | { 26 | mblks[i] = scene.alloc(sizeof(Disc)); 27 | Disc* p = ::new(mblks[i].ptr) Disc; 28 | Shape::splitData(p, i); 29 | if (shapes) 30 | shapes[i] = p; 31 | } 32 | 33 | } 34 | }; 35 | } 36 | } -------------------------------------------------------------------------------- /src/reyes/displacementmat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | MATERIAL(DisplacementMat) 10 | { 11 | UNIFORM_BEGIN 12 | Sampler* sampler; 13 | float k; 14 | vec3 S; 15 | vec3 T; 16 | Uniform() 17 | : sampler(0) 18 | , k(0.05f) 19 | {} 20 | UNIFORM_END 21 | 22 | DISPLACE 23 | { 24 | color c = uniform.sampler->sample(vertex.uv); 25 | vec3 n = vertex.n.normalize(); 26 | vec3 p = vertex.p * uniform.S + uniform.T; 27 | p.x += n.x * uniform.k * c.r; 28 | p.y += n.y * uniform.k * c.g; 29 | p.z += n.z * uniform.k * c.b; 30 | return p; 31 | } 32 | 33 | SHADE 34 | { 35 | return uniform.sampler->sample(vertex.uv); 36 | } 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /src/reyes/film.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vecmx.hpp" 4 | #include "shape.hpp" 5 | #include "color.hpp" 6 | #include 7 | #include 8 | #include "backend.hpp" 9 | 10 | #define GLSL(version, shader) "#version " #version "\n" #shader 11 | 12 | static const char* fsquad_vs = GLSL(330, 13 | in vec2 iPos; 14 | out vec2 uv; 15 | 16 | void main() 17 | { 18 | gl_Position = vec4(iPos, 0.5, 1.0); 19 | uv = (iPos + vec2(1.0)) * 0.5; 20 | uv.y = 1.0 - uv.y; 21 | } 22 | ); 23 | 24 | static const char* fsquad_fs = GLSL(330, 25 | in vec2 uv; 26 | uniform sampler2D tex; 27 | out vec4 frag; 28 | 29 | void main() 30 | { 31 | frag = texture(tex, uv); 32 | } 33 | ); 34 | 35 | namespace reyes 36 | { 37 | /* Image interface. */ 38 | struct FilmI 39 | { 40 | uint16_t width, height; 41 | GLuint tex, program, quad; 42 | 43 | virtual char* getRGB(void) = 0; 44 | virtual void rasterize(Microgrid& grid) = 0; 45 | virtual void display(GLuint tt=0) 46 | { 47 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 48 | glUseProgram(program); 49 | 50 | if (tt) 51 | { 52 | glBindTexture(GL_TEXTURE_2D, tt); 53 | } 54 | else 55 | { 56 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, getRGB()); 57 | } 58 | glUniform1i(glGetUniformLocation(program, "tex"), 0); 59 | glBindBuffer(GL_ARRAY_BUFFER, quad); 60 | glEnableVertexAttribArray(glGetAttribLocation(program, "iPos")); 61 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); 62 | glDrawArrays(GL_TRIANGLES, 0, 6); 63 | } 64 | 65 | FilmI(uint16_t _width, uint16_t _height) 66 | : width(_width) 67 | , height(_height) 68 | { 69 | // init texture 70 | { 71 | glGenTextures(1, &tex); 72 | glBindTexture(GL_TEXTURE_2D, tex); 73 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 74 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 75 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 76 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 77 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 78 | } 79 | 80 | // init program 81 | { 82 | GLuint vs, fs; 83 | program = glCreateProgram(); 84 | vs = glCreateShader(GL_VERTEX_SHADER); 85 | fs = glCreateShader(GL_FRAGMENT_SHADER); 86 | glShaderSource(vs, 1, &fsquad_vs, NULL); 87 | glShaderSource(fs, 1, &fsquad_fs, NULL); 88 | glCompileShader(vs); 89 | glCompileShader(fs); 90 | glAttachShader(program, vs); 91 | glAttachShader(program, fs); 92 | glLinkProgram(program); 93 | glDeleteShader(vs); 94 | glDeleteShader(fs); 95 | } 96 | 97 | // inti and draw quad 98 | { 99 | GLfloat verts[12] = { -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 }; 100 | glGenBuffers(1, &quad); 101 | glBindBuffer(GL_ARRAY_BUFFER, quad); 102 | glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW); 103 | } 104 | } 105 | 106 | ~FilmI() 107 | { 108 | glUseProgram(0); 109 | glDeleteProgram(program); 110 | glDeleteBuffers(1, &quad); 111 | glDeleteTextures(1, &tex); 112 | } 113 | 114 | /* Writes RGB data to PPM file. */ 115 | void writePPM(const char* filename) 116 | { 117 | FILE* ppm_file = fopen(filename, "wb"); 118 | if (!ppm_file) 119 | return; 120 | 121 | fprintf(ppm_file, "P6\n%d %d\n%d\n", width, height, 255); 122 | size_t size = width * height * 3; 123 | char* rgbdata = getRGB(); 124 | size_t cnt = fwrite(rgbdata, sizeof(char), size, ppm_file); 125 | fclose(ppm_file); 126 | } 127 | 128 | /* Estimate raster size of the vector in NDC space. */ 129 | inline vec2 estimate(vec2 dist) 130 | { 131 | float half_width = width / 2.0f; 132 | float half_height = height / 2.0f;; 133 | return vec2(dist.x*half_width, dist.y*half_height); 134 | } 135 | }; 136 | } 137 | 138 | #undef GLSL -------------------------------------------------------------------------------- /src/reyes/grid.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "color.hpp" 6 | #include "settings.hpp" 7 | #include "mem.hpp" 8 | 9 | namespace reyes 10 | { 11 | struct Microgrid 12 | { 13 | Vertex vertices[GRID_SIZE]; 14 | Index indices[GRID_IDX_SIZE]; 15 | 16 | Microgrid() 17 | { 18 | for (uint16_t v = 0; v < GRID_DIM; v++) 19 | for (uint16_t u = 0; u < GRID_DIM; u++) 20 | { 21 | #if GRID_TYPE==TRIANGLE_GRID 22 | // ADB 23 | indices[v * (GRID_DIM * 6) + u * 6 + 0] = (v * (GRID_DIM + 1)) + (u); 24 | indices[v * (GRID_DIM * 6) + u * 6 + 1] = ((v + 1) * (GRID_DIM + 1)) + (u); 25 | indices[v * (GRID_DIM * 6) + u * 6 + 2] = (v * (GRID_DIM + 1)) + (u + 1); 26 | 27 | // BDC 28 | indices[v * (GRID_DIM * 6) + u * 6 + 3] = (v * (GRID_DIM + 1)) + (u + 1); 29 | indices[v * (GRID_DIM * 6) + u * 6 + 4] = ((v + 1) * (GRID_DIM + 1)) + (u); 30 | indices[v * (GRID_DIM * 6) + u * 6 + 5] = ((v + 1) * (GRID_DIM + 1)) + (u + 1); 31 | #else 32 | indices[v * (GRID_DIM * 4) + u * 4 + 0] = (v * (GRID_DIM + 1)) + (u); 33 | indices[v * (GRID_DIM * 4) + u * 4 + 1] = ((v + 1) * (GRID_DIM + 1)) + (u); 34 | indices[v * (GRID_DIM * 4) + u * 4 + 2] = ((v + 1) * (GRID_DIM + 1)) + (u + 1); 35 | indices[v * (GRID_DIM * 4) + u * 4 + 3] = (v * (GRID_DIM + 1)) + (u + 1); 36 | #endif 37 | } 38 | } 39 | 40 | /* Bounding box for entire grid. */ 41 | AABB2 aabb(void) 42 | { 43 | AABB2 bb; 44 | bb.max = vec2(vertices[0].p.x, vertices[0].p.y); 45 | bb.min = bb.max; 46 | for (uint16_t i = 1; i < GRID_SIZE; i++) 47 | { 48 | vec3 p = vertices[i].p; 49 | bb.min = vec2(fminf(bb.min.x, p.x), fminf(bb.min.y, p.y)); 50 | bb.max = vec2(fmaxf(bb.max.x, p.x), fmaxf(bb.max.y, p.y)); 51 | } 52 | return bb; 53 | } 54 | }; 55 | } -------------------------------------------------------------------------------- /src/reyes/klein.hpp: -------------------------------------------------------------------------------- 1 | //#pragma once 2 | // 3 | //#include "shape.hpp" 4 | // 5 | //namespace reyes 6 | //{ 7 | // namespace lib 8 | // { 9 | // template 10 | // struct Klein : public Shape 11 | // { 12 | // Klein() 13 | // {} 14 | // 15 | // normal EvalN(uv uv) 16 | // { 17 | // return vec3(0, 0, 1); 18 | // } 19 | // position EvalP(uv uv) 20 | // { 21 | // float u = (uv.x *2.0f)*M_PI; 22 | // float v = (uv.y *2.0f) *M_PI; 23 | // 24 | // 25 | // float A = 6.0f, B = 16.0f, C = 4.0f; 26 | // 27 | // float r = C * (1.0f - cos(u) / 2.0f); 28 | // float x, y, z; 29 | // if (u < M_PI) 30 | // { 31 | // x = A * cos(u)*(1 + sin(u)) + r*cos(u)*cos(v); 32 | // y = B * sin(u) + r*sin(u)*cos(v); 33 | // } 34 | // else 35 | // { 36 | // x = A * cos(u)*(1 + sin(u)) + cos(v + M_PI); 37 | // y = B * sin(u); 38 | // } 39 | // z = r*sin(v); 40 | // /*x = cos(u) * (cos(0.5f*u)*(M_SQRT2 + cos(v)) + sin(0.5f*u)*sin(v)*cos(v)); 41 | // y = sin(u) * (cos(0.5f*u)*(M_SQRT2 + cos(v)) + sin(0.5f*u)*sin(v)*cos(v)); 42 | // z = -sin(0.5f*u)*(M_SQRT2 + cos(v)) + cos(0.5f*u)*sin(v)*cos(v);*/ 43 | // position p(x, -y, z); 44 | // return p*0.05f; 45 | // } 46 | // 47 | // void split(SplitDir direction, Scene& scene) 48 | // { 49 | // mem::blk mblks[4]; 50 | // for (char i = 0; i < 4; i++) 51 | // { 52 | // mblks[i] = scene.alloc(sizeof(Klein)); 53 | // Klein* p = ::new(mblks[i].ptr) Klein; 54 | // Shape::splitData(p, i); 55 | // } 56 | // } 57 | // }; 58 | // } 59 | //} -------------------------------------------------------------------------------- /src/reyes/lambertmat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | #include "directionalight.hpp" 5 | 6 | namespace reyes 7 | { 8 | namespace lib 9 | { 10 | // ------------------------------------------- Lambert 11 | MATERIAL(Lambert) 12 | { 13 | UNIFORM_BEGIN 14 | DirectionalLight* light; 15 | Sampler* texture; 16 | vec3 S, T; 17 | UNIFORM_END 18 | 19 | DISPLACE 20 | { 21 | return vertex.p * uniform.S + uniform.T; 22 | } 23 | 24 | SHADE 25 | { 26 | PosNormal pn(vertex.p, vertex.n); 27 | color c = uniform.light->sample(pn); 28 | color a = uniform.texture->sample(vertex.uv); 29 | color total(c.r*a.r, c.g*a.g, c.b*a.b, 1); 30 | total.r = total.r>1.0 ? 1.0f : total.r; 31 | total.g = total.g > 1.0 ? 1.0f : total.g; 32 | total.b = total.b > 1.0 ? 1.0f : total.b; 33 | return total; 34 | } 35 | }; 36 | } 37 | } -------------------------------------------------------------------------------- /src/reyes/lena.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/lena.bmp -------------------------------------------------------------------------------- /src/reyes/litmat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | #include "directionalight.hpp" 5 | 6 | namespace reyes 7 | { 8 | namespace lib 9 | { 10 | MATERIAL(LitMat) 11 | { 12 | UNIFORM_BEGIN 13 | Sampler* albedoMap; 14 | Sampler* normalMap; 15 | DirectionalLight* light; 16 | vec3 rot; 17 | UNIFORM_END 18 | 19 | DISPLACE 20 | { 21 | return vertex.p; 22 | } 23 | 24 | SHADE 25 | { 26 | color _cn = uniform.normalMap->sample(vertex.uv); 27 | float Rx = uniform.rot.x; 28 | float Ry = uniform.rot.y; 29 | float Rz = uniform.rot.z; 30 | normal cn(_cn.r, _cn.g, _cn.b); 31 | cn.y = cn.y*cos(Rx) + sin(Rx)*cn.z; 32 | cn.z = -cn.y*sin(Rx) + cos(Rx)*cn.z; 33 | cn.x = cn.x*cos(Ry) - sin(Ry)*cn.z; 34 | cn.z = cn.x*sin(Ry) + cos(Ry)*cn.z; 35 | cn.x = cn.x*cos(Rz) + sin(Rz)*cn.y; 36 | cn.y = -cn.x*sin(Rz) + cos(Rz)*cn.y; 37 | cn.normalize(); 38 | 39 | normal n(vertex.n.x + cn.x, vertex.n.y + cn.y, vertex.n.z + cn.z); 40 | n.normalize(); 41 | color light = uniform.light->sample(PosNormal(vertex.p, n)); 42 | color albedo = uniform.albedoMap->sample(vertex.uv); 43 | color color; 44 | color.r = albedo.r * light.r; 45 | color.g = albedo.g * light.g; 46 | color.b = albedo.b * light.b; 47 | color.a = 1; 48 | 49 | return color; 50 | } 51 | }; 52 | } 53 | } -------------------------------------------------------------------------------- /src/reyes/main.cpp: -------------------------------------------------------------------------------- 1 | #include "backend.hpp" 2 | #include "pipeline.hpp" 3 | #include "settings.hpp" 4 | #include "renderer.hpp" 5 | 6 | #include "oglfilm.hpp" 7 | // shapes 8 | #include "plane.hpp" 9 | #include "disc.hpp" 10 | #include "sphere.hpp" 11 | #include "bezier16.hpp" 12 | #include "teapot.hpp" 13 | // materials 14 | #include "depthmat.hpp" 15 | #include "lambertmat.hpp" 16 | #include "normalmat.hpp" 17 | #include "solidcolormat.hpp" 18 | #include "uvmat.hpp" 19 | #include "samplermat.hpp" 20 | #include "displacementmat.hpp" 21 | #include "litmat.hpp" 22 | // samplers 23 | #include "sincossampler.hpp" 24 | #include "bmpsampler.hpp" 25 | 26 | using namespace reyes; 27 | 28 | reyes::Renderer ryRenderer; 29 | 30 | #define MAKE_SHAPE(_scene, _shp, _name) _shp* _name = ::new(_scene.alloc(sizeof(_shp)).ptr) _shp 31 | #define MAKE_MSHAPE(_scene, _shptype, _shpname, _shpmat) _shptype* _shpname = ::new(_scene.alloc(sizeof(_shptype)).ptr) _shptype; _shpname->material = &_shpmat; 32 | 33 | void keyUpHandler(unsigned int key) 34 | { 35 | if (key == INPUT_KEY_A) 36 | { 37 | RASTER_THRESHOLD.x /= 2; 38 | RASTER_THRESHOLD.y /= 2; 39 | } 40 | else if (key == INPUT_KEY_S) 41 | { 42 | RASTER_THRESHOLD.x *= 2; 43 | RASTER_THRESHOLD.y *= 2; 44 | } 45 | else if (key == INPUT_KEY_D) 46 | { 47 | mainApp(); 48 | } 49 | } 50 | 51 | #ifndef ANIMATE_BACKEND 52 | void mainApp() 53 | { 54 | // mt test 55 | { 56 | // mt version 57 | //ryRenderer.render(3); 58 | // no-mt version 59 | //for (int i = 0; i < 10000; i++) reyes::Renderer::testJob(&i); 60 | } 61 | 62 | // REYES 63 | srand(time(NULL)); 64 | printf("REYES renderer v" REYES_VERSION "(%.1f %.1f)\n", RASTER_THRESHOLD.x, RASTER_THRESHOLD.y); 65 | INPUT_f_keyUp(keyUpHandler); 66 | 67 | // camera and scene 68 | Scene scene; 69 | Camera camera; 70 | OGLFilm film(800, 800); 71 | camera.film = &film; 72 | // sphere 73 | lib::DisplacementMat sp_mat; 74 | lib::SinCosSampler sc_sampler; 75 | sp_mat.uniform.k = 0.03f; 76 | sp_mat.uniform.sampler = &sc_sampler; 77 | sp_mat.uniform.T = vec3(-0.5f, 0.5f, 0); 78 | sp_mat.uniform.S = vec3(0.3f, 0.3f, 0.3f); 79 | MAKE_MSHAPE(scene, lib::Sphere, sphere, sp_mat); 80 | // plane 81 | lib::SamplerMat sq_mat; 82 | lib::BMPSampler lena_sampler(512, 512, "lena.bmp"); 83 | sq_mat.uniform.sampler = &lena_sampler; 84 | sq_mat.uniform.T = vec3(-0.5f, -0.5f, 0); 85 | sq_mat.uniform.S = vec3(.8f, .8f, .8f); 86 | MAKE_MSHAPE(scene, lib::Plane, square, sq_mat); 87 | // disc 88 | lib::UVColor uv_mat; 89 | uv_mat.uniform.S = vec3(.4f, .4f, .4f); 90 | uv_mat.uniform.T = vec3(0.5f, -0.5f, 0); 91 | MAKE_MSHAPE(scene, lib::Disc, disc, uv_mat); 92 | // teapot 93 | lib::NormalColor n_mat; 94 | n_mat.uniform.S = vec3(0.15f, 0.15f, 0.15f); 95 | n_mat.uniform.T = vec3(0.45f, 0.3f, 0); 96 | for (uint32_t i = 0; i < kTeapotNumPatches; i++) 97 | { 98 | vec3 control_points[16]; 99 | for (uint32_t vi = 0; vi < 16; vi++) 100 | { 101 | control_points[vi].x = teapotVertices[teapotPatches[i][vi] - 1][0]; 102 | control_points[vi].z = teapotVertices[teapotPatches[i][vi] - 1][1]; 103 | control_points[vi].y = teapotVertices[teapotPatches[i][vi] - 1][2]; 104 | } 105 | MAKE_SHAPE(scene, lib::Bezier16, patch) (control_points); 106 | patch->material = &n_mat; 107 | } 108 | 109 | // render 110 | glUseProgram(0); 111 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 112 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 113 | glEnable(GL_DEPTH_TEST); 114 | 115 | reyes::render(scene, camera); 116 | 117 | SwapBuffersBackend(); 118 | } 119 | #else 120 | void InitApp() 121 | { 122 | // init 123 | } 124 | 125 | void RenderApp() 126 | { 127 | PerfMarker("Frame"); 128 | // update & display 129 | } 130 | 131 | void CleanupApp() 132 | { 133 | // cleanup 134 | } 135 | #endif 136 | 137 | /*vec3 control_points[16]; 138 | control_points[0] = vec3(-.75f, .75f, 0); 139 | control_points[1] = vec3(-.25f, .75f, 0); 140 | control_points[2] = vec3(.25f, .75f, 0); 141 | control_points[3] = vec3(.75f, .75f, 0); 142 | 143 | control_points[4] = vec3(-.75f, 0.25f); 144 | control_points[5] = vec3(-.25f, 0.25f, 1); 145 | control_points[6] = vec3(.25f, 0.25f, 1); 146 | control_points[7] = vec3(.75f, 0.25f, 0); 147 | 148 | control_points[8] = vec3(-.75f, -.25f, 0); 149 | control_points[9] = vec3(-.25f, -.25f, 1); 150 | control_points[10] = vec3(.25f, -.25f, 1); 151 | control_points[11] = vec3(.75f, -.25f, 0); 152 | 153 | control_points[12] = vec3(-.75f, -.75f, 0); 154 | control_points[13] = vec3(-.25f, -.75f, 0); 155 | control_points[14] = vec3(.25f, -.75f, 0); 156 | control_points[15] = vec3(.75f, -.75f, 0); 157 | MAKE_SHAPE(patch, scene, lib::Bezier16) (control_points); 158 | patch->transform.R.y = M_PI *0.25f; 159 | patch->transform.T = vec3(0.5f, 0.5f, 0); 160 | patch->transform.S = vec3(.5f, .5f, .5f);*/ -------------------------------------------------------------------------------- /src/reyes/mat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vecmx.hpp" 4 | #include "color.hpp" 5 | 6 | struct VertexDescDefault 7 | { 8 | reyes::color c; 9 | reyes::position p; 10 | }; 11 | 12 | //struct Material 13 | //{ 14 | // virtual void pShdr(VertexDesc& vertex) 15 | // { 16 | // } 17 | // virtual void cShdr(VertexDesc& vertex) 18 | // { 19 | // } 20 | //}; 21 | 22 | #define UNIFORM_BEGIN struct Uniform { 23 | #define UNIFORM_END } uniform; 24 | #define VERTEX_BEGIN struct VertexDesc : public VertexDescDefault { 25 | #define VERTEX_END }; 26 | #define PSHDR_BEGIN void pShdr(VertexDesc& vertex) { 27 | #define PSHDR_END } 28 | #define CSHDR_BEGIN void cShdr(VertexDesc& vertex) { 29 | #define CSHDR_END } 30 | 31 | struct Lambert/* : public Material*/ 32 | { 33 | UNIFORM_BEGIN 34 | reyes::mx4 model; 35 | int a; 36 | UNIFORM_END 37 | 38 | VERTEX_BEGIN 39 | reyes::normal n; 40 | reyes::uv uv; 41 | VERTEX_END 42 | 43 | PSHDR_BEGIN 44 | uniform.a = 1; 45 | PSHDR_END 46 | 47 | CSHDR_BEGIN 48 | CSHDR_END 49 | }; 50 | 51 | struct SolidColor/* : public Material*/ 52 | { 53 | UNIFORM_BEGIN 54 | reyes::color color; 55 | UNIFORM_END 56 | 57 | VERTEX_BEGIN 58 | reyes::uv _uv; 59 | VERTEX_END 60 | 61 | PSHDR_BEGIN 62 | PSHDR_END 63 | 64 | CSHDR_BEGIN 65 | vertex.c = uniform.color; 66 | CSHDR_END 67 | }; 68 | 69 | #define USE_MAT(_name) _name, _name::VertexDesc 70 | 71 | 72 | 73 | struct AbstractShape 74 | { 75 | virtual void dice() = 0; 76 | virtual void shade() = 0; 77 | virtual void split() = 0; 78 | virtual void rasterize(void* c) = 0; 79 | }; 80 | 81 | template 82 | struct Shape : public AbstractShape 83 | { 84 | MatTy* material; 85 | VertexTy grid[(GRID_DIM + 1)*(GRID_DIM + 1)]; 86 | #if GRID_TYPE==0 87 | Index indices[GRID_DIM*GRID_DIM * 6]; 88 | #else 89 | Index indices[GRID_DIM*GRID_DIM * 4]; 90 | #endif 91 | 92 | Shape(MatTy* material = 0) 93 | : material(material) 94 | { 95 | if (!material) 96 | material = new MatTy; 97 | } 98 | 99 | void dice() 100 | { 101 | // popuni vertekse 102 | // popuni indice - mogu se izmestiti u zasebnu klasu/strukturu 103 | for (uint16_t i = 0; i < GRID_SIZE; i++) 104 | { 105 | material->pShdr(grid[i]); 106 | } 107 | } 108 | 109 | void shade() 110 | { 111 | for (uint16_t i = 0; i < GRID_SIZE; i++) 112 | { 113 | material->cShdr(grid[i]); 114 | } 115 | } 116 | 117 | bool requiresSplit() 118 | { 119 | // calc bounding box 120 | for (uint16_t i = 0; i < GRID_SIZE; i++) 121 | { 122 | 123 | } 124 | // compare to threshold 125 | } 126 | 127 | virtual void split() 128 | { 129 | 130 | } 131 | 132 | void rasterize(void* c) 133 | { 134 | // do shit 135 | } 136 | }; 137 | 138 | template 139 | struct ParametricSurface : public Shape 140 | { 141 | float start_u, end_u, start_v, end_v; 142 | ParametricSurface(MatTy* material=0) 143 | : Shape(material) 144 | {} 145 | void split() 146 | { 147 | // napravi cetiri nova 148 | for (unsigned char i = 0; i < 4; i++) 149 | { 150 | ParametricSurface* shp = new ParametricSurface(material); 151 | } 152 | // raspodeli uv 153 | } 154 | }; 155 | 156 | /*ParametricSurface oblik; 157 | ParametricSurface kugla; 158 | oblik.dice(); 159 | oblik.shade(); 160 | AbstractShape* shapes[2]; 161 | shapes[0] = &oblik; 162 | shapes[1] = &kugla; 163 | 164 | for (uint16_t i = 0; i < 2; i++) 165 | { 166 | shapes[i]->dice(); 167 | shapes[i]->split(); 168 | shapes[i]->shade(); 169 | shapes[i]->rasterize(0); 170 | }*/ 171 | 172 | /* 173 | // calculate model-world values 174 | vx.uv = uv(start_u + u*wu, start_v + v*wv); 175 | vx.p = P(_uv); 176 | vx.n = N(_uv); 177 | vx.p = material.pShdr(vx); 178 | 179 | // TODO transformations: model, view, projection 180 | 181 | // transform vertex 182 | // 1. scale 183 | vx.p.x *= transform.S.x; 184 | vx.p.y *= transform.S.y; 185 | vx.p.z *= transform.S.z; 186 | // 2. rotate (XYZ order) 187 | // 1 0 0 188 | // 0 c -s 189 | // 0 s c 190 | float Rx = transform.R.x; 191 | vx.p.y = vx.p.y*cos(Rx) + sin(Rx)*vx.p.z; 192 | vx.p.z = -vx.p.y*sin(Rx) + cos(Rx)*vx.p.z; 193 | // c 0 s 194 | // 0 1 0 195 | // -s 0 c 196 | float Ry = transform.R.y; 197 | vx.p.x = vx.p.x*cos(Ry) - sin(Ry)*vx.p.z; 198 | vx.p.z = vx.p.x*sin(Ry) + cos(Ry)*vx.p.z; 199 | // c -s 0 200 | // s c 0 201 | // 0 0 1 202 | float Rz = transform.R.z; 203 | vx.p.x = vx.p.x*cos(Rz) + sin(Rz)*vx.p.y; 204 | vx.p.y = -vx.p.x*sin(Rz) + cos(Rz)*vx.p.y; 205 | // 3. translate 206 | vx.p.x += transform.T.x; 207 | vx.p.y += transform.T.y; 208 | vx.p.z += transform.T.z; 209 | 210 | // transform normal 211 | vx.n.y = vx.n.y*cos(Rx) + sin(Rx)*vx.n.z; 212 | vx.n.z = -vx.n.y*sin(Rx) + cos(Rx)*vx.n.z; 213 | vx.n.x = vx.n.x*cos(Ry) - sin(Ry)*vx.n.z; 214 | vx.n.z = vx.n.x*sin(Ry) + cos(Ry)*vx.n.z; 215 | vx.n.x = vx.n.x*cos(Rz) + sin(Rz)*vx.n.y; 216 | vx.n.y = -vx.n.x*sin(Rz) + cos(Rz)*vx.n.y; 217 | 218 | vx.n.x *= transform.S.x; 219 | vx.n.y *= transform.S.y; 220 | vx.n.z *= transform.S.z; 221 | 222 | vx.n.normalize(); 223 | 224 | 225 | grid->vertices[idx] = vx; 226 | */ -------------------------------------------------------------------------------- /src/reyes/mem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef __FUNCTION_NAME__ 10 | # ifdef WIN32 //WINDOWS 11 | # define __FUNCTION_NAME__ __FUNCTION__ 12 | # else //*NIX 13 | # define __FUNCTION_NAME__ __func__ 14 | #endif 15 | #endif 16 | 17 | #define RMEM_NEW(_alloc, _type) static_cast<_type*>(_alloc.alloc(sizeof(_type)).ptr) 18 | #define RMEM_MAKE(_type, _name, _alloc) _type _name = *(static_cast<_type*>(_alloc.alloc(sizeof(_type)).ptr)) 19 | #define RMEM_DEL(_name, _alloc) { reyes::mem::blk _blk(static_cast(&_name),sizeof(_name)); _alloc.free(_blk); } 20 | 21 | namespace reyes 22 | { 23 | namespace mem 24 | { 25 | /* Memory block sturcture. */ 26 | struct blk 27 | { 28 | void* ptr; 29 | size_t size; 30 | blk() : ptr(nullptr), size(0) {} 31 | blk(void* p, size_t s = 0) : ptr(p), size(s) {} 32 | 33 | template 34 | ptr_t to() { return static_cast(ptr); } 35 | }; 36 | 37 | /* Allocator interface. */ 38 | class AllocatorI 39 | { 40 | public: 41 | virtual bool owns(blk&) = 0; 42 | virtual blk alloc(size_t size) = 0; // TODO: add align 43 | // virtual blk realloc(blk&, size_t); // TODO: add realloc 44 | virtual void free(blk&) = 0; 45 | }; 46 | 47 | /* Standard malloc/free allocator on heap. */ 48 | class CAllocator : public AllocatorI 49 | { 50 | size_t total; 51 | public: 52 | CAllocator() : total(0) {} 53 | bool owns(blk&) { return true; } 54 | blk alloc(size_t size) 55 | { 56 | blk blk; 57 | blk.ptr = ::malloc(size); 58 | blk.size = size; 59 | total += size; 60 | return blk; 61 | } 62 | void free(blk& mem) 63 | { 64 | total -= mem.size; 65 | ::free(mem.ptr); 66 | mem.ptr = 0; 67 | } 68 | ~CAllocator() 69 | { 70 | assert(total == 0); 71 | } 72 | }; 73 | 74 | /* Standard malloc/free allocator on heap. */ 75 | typedef CAllocator mAllocator; 76 | 77 | /* Null allocator, everything always fails. */ 78 | class NullAllocator : public AllocatorI 79 | { 80 | public: 81 | bool owns(const blk&) { return false; } 82 | blk alloc(size_t size) { return{ nullptr, 0 }; } 83 | void free(blk& mem) { assert(!mem.ptr && !mem.size); } 84 | }; 85 | 86 | template 87 | /* Stack allocator, compile time known size (in bytes). */ 88 | class StackAllocator : public AllocatorI 89 | { 90 | char data[S]; 91 | char* top; 92 | public: 93 | StackAllocator() : top(data) {} 94 | bool owns(blk& mem) 95 | { 96 | return (mem.ptr >= data && mem.ptr data + S - top) return{ nullptr, 0 }; 101 | blk mem = { top, size }; 102 | top += size; 103 | return mem; 104 | } 105 | void free(blk& mem) 106 | { 107 | if (static_cast(mem.ptr) + mem.size == top) 108 | top = static_cast(mem.ptr); 109 | } 110 | ~StackAllocator() 111 | { 112 | assert(data == top); 113 | } 114 | }; 115 | 116 | template 117 | /* Fallback allocator: use Primary first, Fallback otherwise. */ 118 | class FallbackAllocator : private P, private F 119 | { 120 | public: 121 | bool owns(blk& mem) 122 | { 123 | return P::owns(mem) || F::owns(mem); 124 | } 125 | blk alloc(size_t size) 126 | { 127 | blk mem = P::alloc(size); 128 | if (!mem.ptr) mem = F::alloc(size); 129 | return mem; 130 | } 131 | void free(blk& mem) 132 | { 133 | if (P::owns(mem)) 134 | P::free(mem); 135 | else 136 | F::free(mem); 137 | } 138 | }; 139 | 140 | template 141 | /* Uses small allocator for allocs below threshold, otherwise it uses large allocator. */ 142 | class SegregatorAllocator : private SmallAllocator, private LargeAllocator, public AllocatorI 143 | { 144 | public: 145 | blk alloc(size_t size) 146 | { 147 | return (size <= threshold) 148 | ? SmallAllocator::alloc(size) 149 | : LargeAllocator::alloc(size); 150 | } 151 | void free(blk& mem) 152 | { 153 | if (!mem.ptr) return; 154 | if (mem.size <= threshold) return SmallAllocator::free(mem); 155 | return LargeAllocator::free(mem); 156 | } 157 | bool owns(blk& mem) 158 | { 159 | return (mem.size <= threshold) 160 | ? SmallAllocator::owns(mem) 161 | : LargeAllocator::owns(mem); 162 | } 163 | }; 164 | 165 | template 166 | /* Allocator that wraps other allocator and adds prefix (and sufix) information. */ 167 | class AffixAllocator 168 | { 169 | A allocator; 170 | public: 171 | Prefix* getPrefixPtr(const blk& mem) const 172 | { 173 | return static_cast(mem.ptr); 174 | } 175 | Sufix* getSufixPtr(const blk& mem) const 176 | { 177 | return static_cast(static_cast(mem.ptr) + mem.size - sufix_size); 178 | } 179 | void* getDataPtr(const blk& mem) const 180 | { 181 | return static_cast(static_cast(mem.ptr) + sufix_size); 182 | } 183 | blk getInnerblk(const blk& mem) const 184 | { 185 | return{ static_cast(mem.ptr) + prefix_size, mem.size - prefix_size - sufix_size }; 186 | } 187 | blk getOuterblk(const blk& mem) const 188 | { 189 | return{ static_cast(mem.ptr) - prefix_size, mem.size + prefix_size + sufix_size }; 190 | } 191 | bool owns(blk& mem) 192 | { 193 | return allocator::owns(mem); 194 | } 195 | blk alloc(size_t size) 196 | { 197 | blk mem = allocator.alloc(prefix_size + size + sufix_size); 198 | if (mem.ptr) { 199 | if (prefix_size > 0) { 200 | new (static_cast(mem.ptr) - prefix_size) Prefix{}; 201 | } 202 | if (sufix_size > 0) { 203 | new (static_cast(mem.ptr) + prefix_size + size) Sufix{}; 204 | } 205 | getInnerblk(mem); 206 | } 207 | return mem; 208 | } 209 | void free(blk& mem) 210 | { 211 | allocator.free(mem); 212 | } 213 | }; 214 | 215 | // TODO: alignment 216 | template 217 | struct ObjectStack 218 | { 219 | // ....[ Object_n-1 ][ size_n-1 ][ Object_n ][ size_n ] 220 | // ....................................................^ top 221 | 222 | size_t capacity; 223 | char* data; 224 | char* top; 225 | 226 | ObjectStack(size_t cap=1024) 227 | : capacity(cap) 228 | , data(new char[cap]) 229 | , top(data) 230 | {} 231 | void* alloc(size_t size) 232 | { 233 | if (size + sizeof(size_t) > data + capacity - top) 234 | return nullptr; 235 | 236 | void* mem = static_cast(top); 237 | size_t* sz_ptr = (size_t*)(top += size); 238 | *sz_ptr = size; 239 | top += sizeof(size_t); 240 | return mem; 241 | } 242 | ObjTy* pop(void) 243 | { 244 | if (!size()) return 0; 245 | size_t size = *(size_t*)(top -= sizeof(size_t)); 246 | top -= size; 247 | return (ObjTy*)(top); 248 | } 249 | ObjTy* get(char* ptr) 250 | { 251 | if(ptr==data) return 0; 252 | size_t size = *(size_t*)(ptr -= sizeof(size_t)); 253 | ptr -= size; 254 | return (ObjTy*)(ptr); 255 | } 256 | size_t size() const 257 | { 258 | return top - data; 259 | } 260 | operator bool(void) const 261 | { 262 | return size() > 0; 263 | } 264 | ~ObjectStack() 265 | { 266 | assert(data == top); 267 | delete[] data; 268 | } 269 | }; 270 | 271 | struct ObjectArray 272 | { 273 | size_t capacity; 274 | char* data; 275 | char* writePtr; 276 | char* readPtr; 277 | size_t allocCnt; 278 | 279 | ObjectArray(size_t cap) 280 | : capacity(cap) 281 | , data(new char[cap]) 282 | , readPtr(data) 283 | , writePtr(data) 284 | , allocCnt(0) 285 | {} 286 | ~ObjectArray() 287 | { 288 | assert(0 == allocCnt); 289 | delete[] data; 290 | } 291 | 292 | mem::blk alloc(size_t size) 293 | { 294 | assert(size + sizeof(size_t) <= data + capacity - writePtr); 295 | allocCnt++; 296 | 297 | size_t* sz_ptr = (size_t*)(writePtr); 298 | *sz_ptr = size; 299 | writePtr += sizeof(size); 300 | void* mem = (void*)(writePtr); 301 | writePtr += size; 302 | return {mem, size}; 303 | } 304 | 305 | mem::blk getNext(void) 306 | { 307 | assert(allocCnt > 0); 308 | assert(readPtr < writePtr); 309 | allocCnt--; 310 | 311 | size_t* sz_ptr = (size_t*)(readPtr); 312 | readPtr += sizeof(size_t); 313 | void* objptr = (void*)(readPtr); 314 | readPtr += *sz_ptr; 315 | return{objptr,*sz_ptr}; 316 | } 317 | }; 318 | 319 | template 320 | struct Stack 321 | { 322 | ItemTy data[size]; 323 | size_t top; 324 | Stack() : top(0) {} 325 | void push(ItemTy item) 326 | { 327 | data[top] = item; 328 | top++; 329 | assert(top <= size); 330 | } 331 | ItemTy pop() 332 | { 333 | assert(top > 0); 334 | top--; 335 | return data[top]; 336 | } 337 | ~Stack() 338 | { 339 | assert(top == 0); 340 | } 341 | operator bool() 342 | { 343 | return top > 0; 344 | } 345 | }; 346 | 347 | template 348 | struct Pool 349 | { 350 | SlotTy data[slotCount]; 351 | int freeList[slotCount]; // can be optimized to reuse 352 | int freeHead; 353 | int freeCnt; 354 | 355 | Pool() 356 | : freeHead(0) 357 | , freeCnt(slotCount) 358 | { 359 | for (int i = 0; i < slotCount - 1; i++) 360 | freeList[i] = i + 1; 361 | freeList[slotCount-1] = -1; 362 | } 363 | 364 | SlotTy* alloc(void) 365 | { 366 | assert(freeHead>=0 && freeHeadfree(&slot); 384 | } 385 | 386 | ~Pool() 387 | { 388 | assert(slotCount == freeCnt); 389 | } 390 | }; 391 | } 392 | } -------------------------------------------------------------------------------- /src/reyes/normalmat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | #define CLAMP(_a,_min,_max) ((_a)<(_min)?(_min):(((_a)>(_max))?(_max):(_a))) 6 | 7 | namespace reyes 8 | { 9 | namespace lib 10 | { 11 | MATERIAL(NormalColor) 12 | { 13 | struct uniform_tag 14 | { 15 | vec3 S; 16 | vec3 T; 17 | } uniform; 18 | 19 | DISPLACE 20 | { 21 | return vertex.p * uniform.S + uniform.T; 22 | } 23 | 24 | SHADE 25 | { 26 | /*float nx = CLAMP(vertex.n.x, 0, 1); 27 | float ny = CLAMP(vertex.n.y, 0, 1); 28 | float nz = CLAMP(vertex.n.z, 0, 1); 29 | vec3 n(nx, ny, nz); 30 | return{ n.x, n.y, n.z, 1 };*/ 31 | 32 | vec3 n(vertex.n.x*0.5f + 0.5f, vertex.n.y*0.5f + 0.5f, vertex.n.z*0.5f + 0.5f); 33 | return{ n.x, n.y, n.z, 1 }; 34 | } 35 | }; 36 | } 37 | } 38 | 39 | #undef CLAMP -------------------------------------------------------------------------------- /src/reyes/oglfilm.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "film.hpp" 4 | #include "backend.hpp" 5 | #include 6 | 7 | namespace reyes 8 | { 9 | struct OGLFilm : public FilmI 10 | { 11 | GLuint fbo, rb, tex; 12 | char* data; 13 | OGLFilm(uint16_t _width, uint16_t _height) 14 | : FilmI(_width, _height) 15 | , data(0) 16 | { 17 | glGenRenderbuffers(1, &rb); 18 | glBindRenderbuffer(GL_RENDERBUFFER, rb); 19 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); 20 | 21 | glGenTextures(1, &tex); 22 | glBindTexture(GL_TEXTURE_2D, tex); 23 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 24 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 25 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 26 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 27 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); 28 | 29 | glGenFramebuffers(1, &fbo); 30 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); 31 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb); 32 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); 33 | 34 | assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); 35 | } 36 | 37 | char* getRGB(void) 38 | { 39 | data = new char[3 * width*height]; 40 | glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); 41 | return data; 42 | } 43 | void rasterize(Microgrid& grid) 44 | { 45 | #if GRID_TYPE==TRIANGLE_GRID 46 | glBegin(GL_TRIANGLES); 47 | for (uint16_t i = 0; i < GRID_PRIM_SIZE; i++) 48 | { 49 | #ifdef DEBUG_PRIM 50 | color rnd = { rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, 1 }; 51 | #endif 52 | Vertex a = grid.vertices[grid.indices[3 * i + 0]]; 53 | Vertex b = grid.vertices[grid.indices[3 * i + 1]]; 54 | Vertex c = grid.vertices[grid.indices[3 * i + 2]]; 55 | 56 | // one 57 | #ifdef DEBUG_PRIM 58 | glColor3f(rnd.r, rnd.g, rnd.b); 59 | #else 60 | glColor3f(a.c.r, a.c.g, a.c.b); 61 | #endif 62 | glVertex3f(a.p.x, a.p.y, -a.p.z); 63 | 64 | // two 65 | #ifdef DEBUG_PRIM 66 | glColor3f(rnd.r, rnd.g, rnd.b); 67 | #else 68 | glColor3f(b.c.r, b.c.g, b.c.b); 69 | #endif 70 | glVertex3f(b.p.x, b.p.y, -b.p.z); 71 | 72 | // three 73 | #ifdef DEBUG_PRIM 74 | glColor3f(rnd.r, rnd.g, rnd.b); 75 | #else 76 | glColor3f(c.c.r, c.c.g, c.c.b); 77 | #endif 78 | glVertex3f(c.p.x, c.p.y, -c.p.z); 79 | } 80 | glEnd(); 81 | #else 82 | glBegin(GL_QUADS); 83 | for (uint16_t i = 0; i < GRID_PRIM_SIZE; i++) 84 | { 85 | #ifdef DEBUG_PRIM 86 | color rnd = { rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, 1 }; 87 | #endif 88 | Vertex a = grid.vertices[grid.indices[4 * i + 0]]; 89 | Vertex b = grid.vertices[grid.indices[4 * i + 1]]; 90 | Vertex c = grid.vertices[grid.indices[4 * i + 2]]; 91 | Vertex d = grid.vertices[grid.indices[4 * i + 3]]; 92 | #ifdef DEBUG_PRIM 93 | glColor3f(rnd.r, rnd.g, rnd.b); 94 | #else 95 | glColor3f(a.c.r, a.c.g, a.c.b); 96 | #endif 97 | glVertex3f(a.p.x, a.p.y, -a.p.z); 98 | 99 | #ifdef DEBUG_PRIM 100 | glColor3f(rnd.r, rnd.g, rnd.b); 101 | #else 102 | glColor3f(b.c.r, b.c.g, b.c.b); 103 | #endif 104 | glVertex3f(b.p.x, b.p.y, -b.p.z); 105 | 106 | #ifdef DEBUG_PRIM 107 | glColor3f(rnd.r, rnd.g, rnd.b); 108 | #else 109 | glColor3f(c.c.r, c.c.g, c.c.b); 110 | #endif 111 | glVertex3f(c.p.x, c.p.y, -c.p.z); 112 | 113 | #ifdef DEBUG_PRIM 114 | glColor3f(rnd.r, rnd.g, rnd.b); 115 | #else 116 | glColor3f(d.c.r, d.c.g, d.c.b); 117 | #endif 118 | glVertex3f(d.p.x, d.p.y, -d.p.z); 119 | } 120 | glEnd(); 121 | #endif 122 | } 123 | 124 | ~OGLFilm() 125 | { 126 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 127 | glDeleteRenderbuffers(1, &rb); 128 | glDeleteTextures(1, &tex); 129 | glDeleteFramebuffers(1, &fbo); 130 | fbo = 0; 131 | tex = 0; 132 | rb = 0; 133 | delete[] data; 134 | } 135 | 136 | void display(GLuint tt = 0) 137 | { 138 | FilmI::display(tex); 139 | } 140 | }; 141 | } -------------------------------------------------------------------------------- /src/reyes/pipeline.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "mem.hpp" 4 | #include "backend.hpp" 5 | #include "shape.hpp" 6 | #include "grid.hpp" 7 | #include "camera.hpp" 8 | #include "settings.hpp" 9 | 10 | namespace reyes 11 | { 12 | void render(Scene& scene, Camera& camera) 13 | { 14 | Microgrid grid; 15 | 16 | while (scene) 17 | { 18 | Shape* shape = static_cast(scene.pop().ptr); 19 | 20 | shape->dice(grid); // DICE 21 | 22 | AABB2 bb = grid.aabb(); // BOUND 23 | if (!isInFrustum(bb)) // | try to cull 24 | continue; // | 25 | 26 | vec2 rasSz = camera.film->estimate(bb.max - bb.min); // SPLIT - estimate grid's raster size 27 | if (requiresSplit(rasSz, RASTER_THRESHOLD)) // | 28 | { // | 29 | shape->split(scene); // | do split 30 | } // | 31 | else // | don't split, so continue to raster 32 | { 33 | shape->shade(grid); // SHADE 34 | 35 | camera.film->rasterize(grid); // SAMPLE 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/reyes/plane.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shape.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct Plane : public Shape 10 | { 11 | normal EvalN(uv uv) 12 | { 13 | return vec3(0, 0, 1); 14 | } 15 | position EvalP(uv uv) 16 | { 17 | return vec3(-0.5f + uv.x, 0.5f - uv.y, 0); 18 | } 19 | void split(Scene& scene, Shape** shapes=0) 20 | { 21 | mem::blk mblks[4]; 22 | for (char i = 0; i < 4; i++) 23 | { 24 | mblks[i] = scene.alloc(sizeof(Plane)); 25 | Plane* p = ::new(mblks[i].ptr) Plane; 26 | Shape::splitData(p, i); 27 | if (shapes) 28 | shapes[i] = p; 29 | } 30 | } 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /src/reyes/pointlight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct PointLight : public Light 10 | { 11 | color col; 12 | position pos; 13 | color sample(PosNormal point) 14 | { 15 | float dist = (pos - point.p).len(); 16 | float max_dist = 10.0f; 17 | float k = 1.0f - dist / max_dist; 18 | k = (k < 0.0 ? 0.0 : k); 19 | return{ col.r*k, col.g*k, col.b*k, 1.0f }; 20 | } 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /src/reyes/primitive.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "color.hpp" 5 | 6 | #define CROSS(a,b) vec3(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x) 7 | #define DOT(a,b) (a.x*b.x+a.y*b.y+a.z*b.z) 8 | #define edgeFn(a,b,c) ((c.x - a.p.x) * (b.p.y - a.p.y) - (c.y - a.p.y) * (b.p.x - a.p.x)) 9 | 10 | namespace reyes 11 | { 12 | namespace primitive 13 | { 14 | struct PrimitiveI 15 | { 16 | virtual Vertex interpolate(position p) = 0; 17 | virtual AABB2 aabb(void) = 0; 18 | virtual bool in(position p) = 0; 19 | inline bool on_side(vec3 test, vec3 v1, vec3 v2) 20 | { 21 | return ((v2.x - v1.x)*(test.y - v1.y) - (v2.y - v1.y)*(test.x - v1.x)) >= 0.0; 22 | } 23 | }; 24 | struct Triangle : public PrimitiveI 25 | { 26 | Vertex a, b, c; 27 | 28 | Vertex interpolate(position p) 29 | { 30 | Vertex res; 31 | Vertex _a = a; 32 | Vertex _b = b; 33 | Vertex _c = c; 34 | 35 | // adjust attributes 36 | _a.c.r /= a.p.z; 37 | _a.c.g /= a.p.z; 38 | _a.c.b /= a.p.z; 39 | 40 | _b.c.r /= b.p.z; 41 | _b.c.g /= b.p.z; 42 | _b.c.b /= b.p.z; 43 | 44 | _c.c.r /= c.p.z; 45 | _c.c.g /= c.p.z; 46 | _c.c.b /= c.p.z; 47 | 48 | float wa, wb, wc; 49 | float area = edgeFn(_a, _b, _c.p); 50 | wa = edgeFn(_b, _c, p) / area; 51 | wb = edgeFn(_c, _a, p) / area; 52 | wc = edgeFn(_a, _b, p) / area; 53 | res.p = p; 54 | float z = (wa * _a.p.z + wb*_b.p.z + wc*_c.p.z); 55 | res.p.z = z; 56 | 57 | res.c = color( 58 | (_a.c.r*wa + _b.c.r*wb + _c.c.r*wc)*z, 59 | (_a.c.g*wa + _b.c.g*wb + _c.c.g*wc)*z, 60 | (_a.c.b*wa + _b.c.b*wb + _c.c.b*wc)*z, 61 | 1 62 | ); 63 | 64 | 65 | //vec3 _a = { a.p.x, a.p.y, 1.0f }; 66 | //vec3 _b = { b.p.x, b.p.y, 1.0f }; 67 | //vec3 _c = { c.p.x, c.p.y, 1.0f }; 68 | //p.z = 1.0f; 69 | // 70 | //vec3 bxc = CROSS(_b, _c); 71 | //vec3 axb = CROSS(_a, _b); 72 | //vec3 cxa = CROSS(_c, _a); 73 | //float denom = DOT(_a, bxc); 74 | // 75 | //float alpha = DOT(p, bxc) / denom; 76 | //float beta = DOT(p, cxa) / denom; 77 | //float gamma = DOT(p, axb) / denom; 78 | // 79 | //res.c = color( 80 | // a.c.r*alpha + b.c.r*beta + c.c.r*gamma, // R 81 | // a.c.g*alpha + b.c.g*beta + c.c.g*gamma, // G 82 | // a.c.b*alpha + b.c.b*beta + c.c.b*gamma, // B 83 | // a.c.a*alpha + b.c.a*beta + c.c.a*gamma // A 84 | //); 85 | // 86 | //res.p = position( 87 | // a.p.x*alpha + b.p.x*beta + c.p.x*gamma, // X 88 | // a.p.y*alpha + b.p.y*beta + c.p.y*gamma, // Y 89 | // a.p.z*alpha + b.p.z*beta + c.p.z*gamma // Z 90 | //); 91 | 92 | return res; 93 | } 94 | 95 | AABB2 aabb(void) 96 | { 97 | AABB2 bb; 98 | bb.min = vec2(fminf(a.p.x, fminf(b.p.x, c.p.x)), fminf(a.p.y, fminf(b.p.y, c.p.y))); 99 | bb.max = vec2(fmaxf(a.p.x, fmaxf(b.p.x, c.p.x)), fmaxf(a.p.y, fmaxf(b.p.y, c.p.y))); 100 | return bb; 101 | } 102 | 103 | bool in(position p) 104 | { 105 | return on_side(p, a.p, b.p) && on_side(p, b.p, c.p) && on_side(p, c.p, a.p); 106 | } 107 | }; 108 | 109 | struct Quad : public PrimitiveI 110 | { 111 | Vertex a, b, c, d; 112 | 113 | Vertex interpolate(position p) 114 | { 115 | Vertex res; 116 | vec2 uv; 117 | 118 | vec2 _a = { a.p.x, a.p.y }; 119 | vec2 _b = { b.p.x, b.p.y }; 120 | vec2 _c = { c.p.x, c.p.y }; 121 | vec2 _d = { d.p.x, d.p.y }; 122 | 123 | vec2 e = _b - _a; 124 | vec2 f = _d - _a; 125 | vec2 g = _a - _b + _c - _d; 126 | vec2 h = vec2(p.x,p.y) -_a; 127 | 128 | float k2 = g.x*f.y - g.y*f.x; 129 | float k1 = e.x*f.y - e.y*f.x + h.x*g.y - h.y*g.x; 130 | float k0 = h.x*e.y - h.y*e.x; 131 | 132 | // rectangle 133 | if (k2 == 0) 134 | { 135 | uv.x = (p.x - _a.x) / (_b.x - _a.x); 136 | uv.y = (p.y - _a.y) / (_d.y - _a.y); 137 | } 138 | // any other quadrilateral 139 | else 140 | { 141 | float w = k1*k1 - 4.0f*k0*k2; 142 | 143 | if (!(w < 0.0)) 144 | { 145 | w = sqrt(w); 146 | 147 | float v1 = (-k1 - w) / (2.0f*k2); 148 | float v2 = (-k1 + w) / (2.0f*k2); 149 | float u1 = (h.x - f.x*v1) / (e.x + g.x*v1); 150 | float u2 = (h.x - f.x*v2) / (e.x + g.x*v2); 151 | bool b1 = v1>0.0 && v1<1.0 && u1>0.0 && u1<1.0; 152 | bool b2 = v2>0.0 && v2<1.0 && u2>0.0 && u2 < 1.0; 153 | 154 | if (b1 && !b2) uv = vec2(u1, v1); 155 | if (!b1 && b2) uv = vec2(u2, v2); 156 | } 157 | } 158 | 159 | res.p = (a.p*(1.0f - uv.x) + b.p*uv.x)*(1.0f - uv.y) + (d.p*(1.0f - uv.x) + c.p*uv.x)*uv.y; 160 | 161 | // TODO: perspective correction 162 | res.c = color( 163 | (a.c.r*(1.0f - uv.x) + b.c.r*uv.x)*(1.0f - uv.y) + (d.c.r*(1.0f - uv.x) + c.c.r*uv.x)*uv.y, // R 164 | (a.c.g*(1.0f - uv.x) + b.c.g*uv.x)*(1.0f - uv.y) + (d.c.g*(1.0f - uv.x) + c.c.g*uv.x)*uv.y, // G 165 | (a.c.b*(1.0f - uv.x) + b.c.b*uv.x)*(1.0f - uv.y) + (d.c.b*(1.0f - uv.x) + c.c.b*uv.x)*uv.y, // B 166 | (a.c.a*(1.0f - uv.x) + b.c.a*uv.x)*(1.0f - uv.y) + (d.c.a*(1.0f - uv.x) + c.c.a*uv.x)*uv.y // A 167 | ); 168 | 169 | return res; 170 | } 171 | 172 | AABB2 aabb(void) 173 | { 174 | AABB2 bb; 175 | bb.min = vec2(fminf(a.p.x, fminf(b.p.x, fminf(c.p.x, d.p.x))), fminf(a.p.y, fminf(b.p.y, fminf(c.p.y, d.p.y)))); 176 | bb.max = vec2(fmaxf(a.p.x, fmaxf(b.p.x, fmaxf(c.p.x, d.p.x))), fmaxf(a.p.y, fmaxf(b.p.y, fmaxf(c.p.y, d.p.y)))); 177 | return bb; 178 | } 179 | 180 | bool in(position p) 181 | { 182 | bool ab = !on_side(p, a.p, b.p); 183 | bool bc = !on_side(p, b.p, c.p); 184 | bool cd = !on_side(p, c.p, d.p); 185 | bool da = !on_side(p, d.p, a.p); 186 | return ab&&bc&&cd&&da; 187 | } 188 | }; 189 | } 190 | } -------------------------------------------------------------------------------- /src/reyes/renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // core 4 | #include "backend.hpp" 5 | #include "mem.hpp" 6 | #include "settings.hpp" 7 | #include "aajob.hpp" 8 | // reyes 9 | #include "scene.hpp" 10 | #include "camera.hpp" 11 | 12 | namespace reyes 13 | { 14 | struct Renderer 15 | { 16 | Renderer() 17 | { 18 | hRenderThread = CreateThread(0, 0, &renderProc, this, CREATE_SUSPENDED, 0); 19 | } 20 | 21 | void render(DWORD _threadCnt = 1) 22 | { 23 | threadCnt = _threadCnt - 1; 24 | 25 | // kickoff 26 | ResumeThread(hRenderThread); 27 | } 28 | 29 | ~Renderer() 30 | { 31 | SuspendThread(hRenderThread); 32 | CloseHandle(hRenderThread); 33 | } 34 | private: 35 | 36 | HANDLE hRenderThread; 37 | uint8_t threadCnt; 38 | 39 | static DWORD WINAPI renderProc(void* pR) 40 | { 41 | Renderer* _renderer = (Renderer*)pR; 42 | 43 | // init other threads besides main rendering 44 | aajob::Init(_renderer->threadCnt); 45 | 46 | // add jobs 47 | // TODO 48 | 49 | // go! 50 | aajob::Flush(); 51 | 52 | // cleanup 53 | aajob::Cleanup(); 54 | 55 | // notify that render has ended 56 | // TODO 57 | 58 | return 0; 59 | } 60 | 61 | struct _InRenderData 62 | { 63 | Scene* scene; 64 | Shape* shape; 65 | Camera* camera; 66 | }; 67 | static AAJOB_ENTRY_POINT(renderShape) 68 | { 69 | _InRenderData* pRD = static_cast<_InRenderData*>(jobDataPtr); 70 | Scene* scene = pRD->scene; 71 | Shape* shape = pRD->shape; 72 | Camera* camera = pRD->camera; 73 | 74 | Microgrid grid; 75 | 76 | shape->dice(grid); // DICE 77 | 78 | AABB2 bb = grid.aabb(); // BOUND 79 | if (!isInFrustum(bb)) // | try to cull 80 | goto memoryCleanup; // | 81 | 82 | vec2 rasSz = camera->film->estimate(bb.max - bb.min); // SPLIT - estimate grid's raster size 83 | if (requiresSplit(rasSz, RASTER_THRESHOLD)) // | 84 | { // | 85 | Shape* sptrs[4]; // | 86 | shape->split(*scene, sptrs); // | do split 87 | for (uint8_t i = 0; i < 4; i++) 88 | { 89 | _InRenderData& rd = *new _InRenderData; 90 | rd.camera = camera; 91 | rd.scene = scene; 92 | rd.shape = sptrs[i]; 93 | aajob::JobDecl job(renderShape, &rd); //// SH*T! 94 | aajob::RunJob(job); 95 | } 96 | } // | 97 | else // | don't split, so continue to raster 98 | { 99 | shape->shade(grid); // SHADE 100 | 101 | camera->film->rasterize(grid); // SAMPLE 102 | } 103 | memoryCleanup: 104 | delete pRD; 105 | } 106 | }; 107 | } -------------------------------------------------------------------------------- /src/reyes/reyes.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "reyes", "reyes.vcxproj", "{E6061664-6C0A-49AF-B78F-7993D410604B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E6061664-6C0A-49AF-B78F-7993D410604B}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {E6061664-6C0A-49AF-B78F-7993D410604B}.Debug|Win32.Build.0 = Debug|Win32 16 | {E6061664-6C0A-49AF-B78F-7993D410604B}.Release|Win32.ActiveCfg = Release|Win32 17 | {E6061664-6C0A-49AF-B78F-7993D410604B}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /src/reyes/reyes.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {E6061664-6C0A-49AF-B78F-7993D410604B} 15 | Win32Proj 16 | reyes 17 | 18 | 19 | 20 | Application 21 | true 22 | v120 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v120 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | $(VC_IncludePath);$(WindowsSDK_IncludePath);thirdparty; 45 | $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);thirdparty; 46 | $(VC_SourcePath);thirdparty; 47 | 48 | 49 | false 50 | 51 | 52 | 53 | 54 | 55 | Level3 56 | Disabled 57 | WIN32;_DEBUG;_WINDOWS;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 58 | 59 | 60 | Windows 61 | true 62 | thirdparty; 63 | opengl32.lib;glu32.lib;glew32.lib;glew32s.lib;AntTweakBar.lib;AntTweakBar64.lib;nvToolsExt32_1.lib;nvToolsExt64_1.lib;%(AdditionalDependencies) 64 | 65 | 66 | 67 | 68 | Level3 69 | 70 | 71 | MaxSpeed 72 | true 73 | true 74 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 75 | 76 | 77 | Console 78 | true 79 | true 80 | true 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 | -------------------------------------------------------------------------------- /src/reyes/reyes.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {94e09b13-4988-47b9-8eb1-ddbc96d9fa3b} 6 | 7 | 8 | {e89e5ce4-8f0c-44a4-8b04-3c4883905997} 9 | 10 | 11 | {bb2fdb06-1b53-4afb-bf99-bfc9945ed30b} 12 | 13 | 14 | {04280ec0-5dbe-4259-a361-87e8f8025da8} 15 | 16 | 17 | {be965d2c-0552-41c4-a0a8-b9b4c422ee18} 18 | 19 | 20 | {19cb3b84-5472-42af-bb77-10a8c5fbe678} 21 | 22 | 23 | {1946201c-c8d0-4632-b4de-b2379846de82} 24 | 25 | 26 | {d65b093e-4a27-4532-b58b-98826dda6092} 27 | 28 | 29 | {895735d6-3ced-4a54-bf73-f76900fc7fb2} 30 | 31 | 32 | {032365f0-8433-46b5-8697-c6c7c47aaa5a} 33 | 34 | 35 | {2aeec2d6-3dcd-4d02-9483-cdcf7a12c0c6} 36 | 37 | 38 | 39 | 40 | 41 | app\reyes\misc 42 | 43 | 44 | 45 | 46 | app\core 47 | 48 | 49 | app\reyes 50 | 51 | 52 | app\reyes 53 | 54 | 55 | app\reyes 56 | 57 | 58 | app\reyes\camera 59 | 60 | 61 | app\reyes\misc 62 | 63 | 64 | app\core 65 | 66 | 67 | app\reyes 68 | 69 | 70 | app\reyes\lib\shapes 71 | 72 | 73 | app\reyes\lib\shapes 74 | 75 | 76 | app\reyes\lib\shapes 77 | 78 | 79 | app\reyes\camera\films 80 | 81 | 82 | app\reyes\camera 83 | 84 | 85 | app\reyes\camera\films 86 | 87 | 88 | app\reyes\lib\shapes 89 | 90 | 91 | app\reyes 92 | 93 | 94 | app\reyes\lib\lights 95 | 96 | 97 | app\reyes\lib\lights 98 | 99 | 100 | app\reyes\lib\lights 101 | 102 | 103 | app\reyes\lib\materials 104 | 105 | 106 | app\reyes\lib\materials 107 | 108 | 109 | app\reyes\lib\materials 110 | 111 | 112 | app\reyes\lib\materials 113 | 114 | 115 | app\reyes\lib\materials 116 | 117 | 118 | app\reyes\lib\materials 119 | 120 | 121 | app\reyes 122 | 123 | 124 | app\reyes\lib\materials 125 | 126 | 127 | app\reyes\lib\samplers 128 | 129 | 130 | app\reyes\lib\samplers 131 | 132 | 133 | app\reyes\lib\shapes 134 | 135 | 136 | app\reyes\lib\materials 137 | 138 | 139 | app\reyes\lib\shapes 140 | 141 | 142 | app\reyes 143 | 144 | 145 | app\reyes 146 | 147 | 148 | app\reyes 149 | 150 | 151 | app\core 152 | 153 | 154 | -------------------------------------------------------------------------------- /src/reyes/samplermat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | MATERIAL(SamplerMat) 10 | { 11 | struct uniform_tag 12 | { 13 | vec3 S; 14 | vec3 T; 15 | Sampler* sampler; 16 | } uniform; 17 | 18 | DISPLACE 19 | { 20 | return vertex.p * uniform.S + uniform.T; 21 | } 22 | 23 | SHADE 24 | { 25 | return uniform.sampler->sample(vertex.uv); 26 | } 27 | }; 28 | } 29 | } -------------------------------------------------------------------------------- /src/reyes/scene.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "mem.hpp" 4 | #include "aajob.hpp" 5 | 6 | namespace reyes 7 | { 8 | struct Scene 9 | { 10 | aajob::Mutex mJobMutex; 11 | mem::ObjectArray memory; 12 | uint16_t cnt; 13 | 14 | Scene() 15 | : cnt(0) 16 | , memory(SCENEMEM_SIZE) 17 | {} 18 | 19 | ~Scene() 20 | { 21 | assert(0 == cnt); 22 | } 23 | 24 | mem::blk alloc(size_t size) 25 | { 26 | aajob::Mutex::Lock lock(mJobMutex); 27 | mem::blk block = memory.alloc(size); 28 | cnt++; 29 | return block; 30 | } 31 | 32 | mem::blk pop() 33 | { 34 | cnt--; 35 | return memory.getNext(); 36 | } 37 | 38 | operator bool() 39 | { 40 | return cnt > 0; 41 | } 42 | }; 43 | } -------------------------------------------------------------------------------- /src/reyes/settings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "vecmx.hpp" 3 | #define TRIANGLE_GRID 0 4 | #define QUAD_GRID 1 5 | 6 | 7 | // ---- ---------------------------- 8 | 9 | #define REYES_VERSION "2.2" 10 | #define GRID_DIM 8 11 | #define GRID_TYPE QUAD_GRID 12 | namespace reyes { static vec2 RASTER_THRESHOLD = { 32, 32 }; } 13 | #define GIRDPOOL_SIZE 20 14 | #define SCENEMEM_SIZE 1<<23 15 | #define DEBUG_GRID 16 | #define DEBUG_PRIM 17 | #ifdef DEBUG_GRID 18 | //#define DEBUG_THREAD 19 | #endif 20 | 21 | // ---- --------------------------- 22 | 23 | #define GRID_SIZE ((GRID_DIM + 1)*(GRID_DIM + 1)) 24 | #if GRID_TYPE==TRIANGLE_GRID 25 | #define GRID_IDX_SIZE GRID_DIM*GRID_DIM * 6 26 | #define GRID_PRIM_SIZE GRID_DIM*GRID_DIM*2 27 | #else 28 | #define GRID_IDX_SIZE GRID_DIM*GRID_DIM * 4 29 | #define GRID_PRIM_SIZE GRID_DIM*GRID_DIM 30 | #endif -------------------------------------------------------------------------------- /src/reyes/shading.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "color.hpp" 4 | 5 | #define MATERIAL(matName) struct matName : public Material 6 | #define UNIFORM_BEGIN struct Uniform { 7 | #define UNIFORM_END } uniform; 8 | #define DISPLACE position pShdr(Vertex vertex) 9 | #define SHADE color cShdr(Vertex vertex) 10 | 11 | namespace reyes 12 | { 13 | /* Material interface and storage. */ 14 | struct Material 15 | { 16 | virtual position pShdr(Vertex a) = 0; 17 | virtual color cShdr(Vertex a) = 0; 18 | }; 19 | 20 | template 21 | /* Resource interface. Base for textures and lights. */ 22 | struct Resource 23 | { 24 | virtual OutputTy sample(InputTy input) = 0; 25 | }; 26 | typedef Resource Sampler; 27 | 28 | /* Light interface. */ 29 | struct Light : public Resource 30 | { 31 | /* Returns RGB color. Alpha serves as a intensity, but colors 32 | should be premultiplied before returning value. */ 33 | virtual color sample(PosNormal point) = 0; 34 | }; 35 | } -------------------------------------------------------------------------------- /src/reyes/shape.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "mem.hpp" 4 | #include "shading.hpp" 5 | #include "grid.hpp" 6 | #include "scene.hpp" 7 | #include 8 | #include 9 | #include "settings.hpp" 10 | 11 | namespace reyes 12 | { 13 | inline bool isInFrustum(AABB2& bb) 14 | { 15 | return !(bb.max.x <= -1.0f || bb.min.x >= 1.0f || bb.min.y >= 1.0f || bb.max.y <= -1.0f); 16 | } 17 | inline bool requiresSplit(vec2 size, vec2 threshold) 18 | { 19 | return (size.x > threshold.x || size.y > threshold.y); 20 | } 21 | 22 | struct Shape 23 | { 24 | float start_u, end_u, start_v, end_v; 25 | Material* material; 26 | 27 | Shape() 28 | : start_u(0) 29 | , end_u(1) 30 | , start_v(0) 31 | , end_v(1) 32 | {} 33 | 34 | void dice(Microgrid& grid) 35 | { 36 | float wu = (end_u - start_u) / (float)(GRID_DIM); 37 | float wv = (end_v - start_v) / (float)(GRID_DIM); 38 | Vertex vx; 39 | uv _uv; 40 | 41 | // vertices 42 | for (uint16_t u = 0; u < GRID_DIM+1; u++) 43 | for (uint16_t v = 0; v < GRID_DIM+1; v++) 44 | { 45 | _uv = vec2(start_u + u*wu, start_v + v*wv); 46 | vx.uv = uv(start_u + u*wu, start_v + v*wv); 47 | vx.p = EvalP(_uv); 48 | vx.n = EvalN(_uv); 49 | vx.p = material->pShdr(vx); 50 | grid.vertices[v * (GRID_DIM + 1) + u] = vx; 51 | } 52 | } 53 | 54 | void splitData(Shape* shp, char i) 55 | { 56 | shp->material = material; 57 | if (0 == i) 58 | { 59 | shp->start_u = start_u; 60 | shp->end_u = (start_u + end_u)*0.5f; 61 | shp->start_v = start_v; 62 | shp->end_v = (start_v + end_v)*0.5f; 63 | } 64 | else if (1 == i) 65 | { 66 | shp->start_u = (start_u + end_u)*0.5f; 67 | shp->end_u = end_u; 68 | shp->start_v = start_v; 69 | shp->end_v = (start_v + end_v)*0.5f; 70 | } 71 | else if (2 == i) 72 | { 73 | shp->start_u = start_u; 74 | shp->end_u = (start_u + end_u)*0.5f; 75 | shp->start_v = (start_v + end_v)*0.5f; 76 | shp->end_v = end_v; 77 | } 78 | else if (3 == i) 79 | { 80 | shp->start_u = (start_u + end_u)*0.5f; 81 | shp->end_u = end_u; 82 | shp->start_v = (start_v + end_v)*0.5f; 83 | shp->end_v = end_v; 84 | } 85 | } 86 | 87 | void shade(Microgrid& grid) 88 | { 89 | #ifdef DEBUG_GRID 90 | #ifdef DEBUG_THREAD 91 | DWORD ctid = GetCurrentThreadId(); 92 | DWORD b = ctid%10; 93 | DWORD g = ((ctid-b)/10)%10; 94 | DWORD r = ((ctid-b-10*g)/100)%100; 95 | color rnd = { (float)r/9.0f, (float)g/9.0f, (float)b/9.0f, 1 }; 96 | #else 97 | color rnd = { rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, 1 }; 98 | #endif 99 | #endif 100 | for (uint16_t i = 0; i < GRID_SIZE; i++) 101 | { 102 | #ifdef DEBUG_GRID 103 | grid.vertices[i].c = rnd; 104 | #else 105 | grid.vertices[i].c = material->cShdr(grid.vertices[i]); 106 | #endif 107 | } 108 | } 109 | 110 | // ----------------------------------------------- 111 | // every parametric shape needs to implement these 112 | virtual void split(Scene& scene, Shape** shapes=0) = 0; 113 | virtual position EvalP(uv _uv) = 0; 114 | virtual normal EvalN(uv _uv) = 0; 115 | // ----------------------------------------------- 116 | }; 117 | } -------------------------------------------------------------------------------- /src/reyes/shlight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct SHLight : public Light 10 | { 11 | float* coefficients; 12 | uint16_t count; 13 | color sample(PosNormal point) 14 | { 15 | // TODO: sample spherical harmonics light probe 16 | // caclulate items and mul with coefficients 17 | return{ 0, 0, 0, 1 }; 18 | } 19 | }; 20 | } 21 | } -------------------------------------------------------------------------------- /src/reyes/sincossampler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct SinCosSampler : public Sampler 10 | { 11 | color sample(uv uv) 12 | { 13 | float k = sin(uv.x * M_PI * 20.0)*cos(uv.y * M_PI* 20.0); 14 | return{ k, k, k, 1 }; 15 | } 16 | }; 17 | } 18 | } -------------------------------------------------------------------------------- /src/reyes/solidcolormat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | MATERIAL(SolidColor) 10 | { 11 | UNIFORM_BEGIN 12 | color col; 13 | Uniform() 14 | : col(1, 0, 0, 1) 15 | {} 16 | UNIFORM_END 17 | DISPLACE 18 | { 19 | return vertex.p; 20 | } 21 | 22 | SHADE 23 | { 24 | return uniform.col; 25 | } 26 | }; 27 | } 28 | } -------------------------------------------------------------------------------- /src/reyes/sphere.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shape.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | struct Sphere : public Shape 10 | { 11 | position EvalP(uv uv) 12 | { 13 | vec3 n = EvalN(uv); 14 | return n; 15 | } 16 | normal EvalN(uv uv) 17 | { 18 | float theta = uv.x*2.0f*M_PI; 19 | float phi = uv.y* M_PI; 20 | 21 | float z = cos(theta) * sin(phi); 22 | float x = sin(theta) * sin(phi); 23 | float y = cos(phi); 24 | 25 | vec3 n(x,y,z); 26 | n.normalize(); 27 | 28 | return n; 29 | } 30 | void split(Scene& scene, Shape** shapes = 0) 31 | { 32 | mem::blk mblks[4]; 33 | for (char i = 0; i < 4; i++) 34 | { 35 | mblks[i] = scene.alloc(sizeof(Sphere)); 36 | Sphere* p = ::new(mblks[i].ptr) Sphere; 37 | Shape::splitData(p, i); 38 | if (shapes) 39 | shapes[i] = p; 40 | } 41 | } 42 | }; 43 | } 44 | } -------------------------------------------------------------------------------- /src/reyes/stone_albedo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/stone_albedo.bmp -------------------------------------------------------------------------------- /src/reyes/stone_normal.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/stone_normal.bmp -------------------------------------------------------------------------------- /src/reyes/teapot.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // http://scratchapixel.com/code.php?id=35&origin=/lessons/advanced-rendering/bezier-curve-rendering-utah-teapot&src=1 6 | 7 | const static uint16_t kTeapotNumPatches = 32; 8 | const static uint16_t kTeapotNumVertices = 306; 9 | uint32_t teapotPatches[kTeapotNumPatches][16] = { 10 | { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, 11 | { 4, 17, 18, 19, 8, 20, 21, 22, 12, 23, 24, 25, 16, 26, 27, 28 }, 12 | { 19, 29, 30, 31, 22, 32, 33, 34, 25, 35, 36, 37, 28, 38, 39, 40 }, 13 | { 31, 41, 42, 1, 34, 43, 44, 5, 37, 45, 46, 9, 40, 47, 48, 13 }, 14 | { 13, 14, 15, 16, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 }, 15 | { 16, 26, 27, 28, 52, 61, 62, 63, 56, 64, 65, 66, 60, 67, 68, 69 }, 16 | { 28, 38, 39, 40, 63, 70, 71, 72, 66, 73, 74, 75, 69, 76, 77, 78 }, 17 | { 40, 47, 48, 13, 72, 79, 80, 49, 75, 81, 82, 53, 78, 83, 84, 57 }, 18 | { 57, 58, 59, 60, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 }, 19 | { 60, 67, 68, 69, 88, 97, 98, 99, 92, 100, 101, 102, 96, 103, 104, 105 }, 20 | { 69, 76, 77, 78, 99, 106, 107, 108, 102, 109, 110, 111, 105, 112, 113, 114 }, 21 | { 78, 83, 84, 57, 108, 115, 116, 85, 111, 117, 118, 89, 114, 119, 120, 93 }, 22 | { 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136 }, 23 | { 124, 137, 138, 121, 128, 139, 140, 125, 132, 141, 142, 129, 136, 143, 144, 133 }, 24 | { 133, 134, 135, 136, 145, 146, 147, 148, 149, 150, 151, 152, 69, 153, 154, 155 }, 25 | { 136, 143, 144, 133, 148, 156, 157, 145, 152, 158, 159, 149, 155, 160, 161, 69 }, 26 | { 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177 }, 27 | { 165, 178, 179, 162, 169, 180, 181, 166, 173, 182, 183, 170, 177, 184, 185, 174 }, 28 | { 174, 175, 176, 177, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197 }, 29 | { 177, 184, 185, 174, 189, 198, 199, 186, 193, 200, 201, 190, 197, 202, 203, 194 }, 30 | { 204, 204, 204, 204, 207, 208, 209, 210, 211, 211, 211, 211, 212, 213, 214, 215 }, 31 | { 204, 204, 204, 204, 210, 217, 218, 219, 211, 211, 211, 211, 215, 220, 221, 222 }, 32 | { 204, 204, 204, 204, 219, 224, 225, 226, 211, 211, 211, 211, 222, 227, 228, 229 }, 33 | { 204, 204, 204, 204, 226, 230, 231, 207, 211, 211, 211, 211, 229, 232, 233, 212 }, 34 | { 212, 213, 214, 215, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245 }, 35 | { 215, 220, 221, 222, 237, 246, 247, 248, 241, 249, 250, 251, 245, 252, 253, 254 }, 36 | { 222, 227, 228, 229, 248, 255, 256, 257, 251, 258, 259, 260, 254, 261, 262, 263 }, 37 | { 229, 232, 233, 212, 257, 264, 265, 234, 260, 266, 267, 238, 263, 268, 269, 242 }, 38 | { 270, 270, 270, 270, 279, 280, 281, 282, 275, 276, 277, 278, 271, 272, 273, 274 }, 39 | { 270, 270, 270, 270, 282, 289, 290, 291, 278, 286, 287, 288, 274, 283, 284, 285 }, 40 | { 270, 270, 270, 270, 291, 298, 299, 300, 288, 295, 296, 297, 285, 292, 293, 294 }, 41 | { 270, 270, 270, 270, 300, 305, 306, 279, 297, 303, 304, 275, 294, 301, 302, 271 } 42 | }; 43 | 44 | float teapotVertices[kTeapotNumVertices][3] = { 45 | { 1.4000, 0.0000, 2.4000 }, 46 | { 1.4000, -0.7840, 2.4000 }, 47 | { 0.7840, -1.4000, 2.4000 }, 48 | { 0.0000, -1.4000, 2.4000 }, 49 | { 1.3375, 0.0000, 2.5312 }, 50 | { 1.3375, -0.7490, 2.5312 }, 51 | { 0.7490, -1.3375, 2.5312 }, 52 | { 0.0000, -1.3375, 2.5312 }, 53 | { 1.4375, 0.0000, 2.5312 }, 54 | { 1.4375, -0.8050, 2.5312 }, 55 | { 0.8050, -1.4375, 2.5312 }, 56 | { 0.0000, -1.4375, 2.5312 }, 57 | { 1.5000, 0.0000, 2.4000 }, 58 | { 1.5000, -0.8400, 2.4000 }, 59 | { 0.8400, -1.5000, 2.4000 }, 60 | { 0.0000, -1.5000, 2.4000 }, 61 | { -0.7840, -1.4000, 2.4000 }, 62 | { -1.4000, -0.7840, 2.4000 }, 63 | { -1.4000, 0.0000, 2.4000 }, 64 | { -0.7490, -1.3375, 2.5312 }, 65 | { -1.3375, -0.7490, 2.5312 }, 66 | { -1.3375, 0.0000, 2.5312 }, 67 | { -0.8050, -1.4375, 2.5312 }, 68 | { -1.4375, -0.8050, 2.5312 }, 69 | { -1.4375, 0.0000, 2.5312 }, 70 | { -0.8400, -1.5000, 2.4000 }, 71 | { -1.5000, -0.8400, 2.4000 }, 72 | { -1.5000, 0.0000, 2.4000 }, 73 | { -1.4000, 0.7840, 2.4000 }, 74 | { -0.7840, 1.4000, 2.4000 }, 75 | { 0.0000, 1.4000, 2.4000 }, 76 | { -1.3375, 0.7490, 2.5312 }, 77 | { -0.7490, 1.3375, 2.5312 }, 78 | { 0.0000, 1.3375, 2.5312 }, 79 | { -1.4375, 0.8050, 2.5312 }, 80 | { -0.8050, 1.4375, 2.5312 }, 81 | { 0.0000, 1.4375, 2.5312 }, 82 | { -1.5000, 0.8400, 2.4000 }, 83 | { -0.8400, 1.5000, 2.4000 }, 84 | { 0.0000, 1.5000, 2.4000 }, 85 | { 0.7840, 1.4000, 2.4000 }, 86 | { 1.4000, 0.7840, 2.4000 }, 87 | { 0.7490, 1.3375, 2.5312 }, 88 | { 1.3375, 0.7490, 2.5312 }, 89 | { 0.8050, 1.4375, 2.5312 }, 90 | { 1.4375, 0.8050, 2.5312 }, 91 | { 0.8400, 1.5000, 2.4000 }, 92 | { 1.5000, 0.8400, 2.4000 }, 93 | { 1.7500, 0.0000, 1.8750 }, 94 | { 1.7500, -0.9800, 1.8750 }, 95 | { 0.9800, -1.7500, 1.8750 }, 96 | { 0.0000, -1.7500, 1.8750 }, 97 | { 2.0000, 0.0000, 1.3500 }, 98 | { 2.0000, -1.1200, 1.3500 }, 99 | { 1.1200, -2.0000, 1.3500 }, 100 | { 0.0000, -2.0000, 1.3500 }, 101 | { 2.0000, 0.0000, 0.9000 }, 102 | { 2.0000, -1.1200, 0.9000 }, 103 | { 1.1200, -2.0000, 0.9000 }, 104 | { 0.0000, -2.0000, 0.9000 }, 105 | { -0.9800, -1.7500, 1.8750 }, 106 | { -1.7500, -0.9800, 1.8750 }, 107 | { -1.7500, 0.0000, 1.8750 }, 108 | { -1.1200, -2.0000, 1.3500 }, 109 | { -2.0000, -1.1200, 1.3500 }, 110 | { -2.0000, 0.0000, 1.3500 }, 111 | { -1.1200, -2.0000, 0.9000 }, 112 | { -2.0000, -1.1200, 0.9000 }, 113 | { -2.0000, 0.0000, 0.9000 }, 114 | { -1.7500, 0.9800, 1.8750 }, 115 | { -0.9800, 1.7500, 1.8750 }, 116 | { 0.0000, 1.7500, 1.8750 }, 117 | { -2.0000, 1.1200, 1.3500 }, 118 | { -1.1200, 2.0000, 1.3500 }, 119 | { 0.0000, 2.0000, 1.3500 }, 120 | { -2.0000, 1.1200, 0.9000 }, 121 | { -1.1200, 2.0000, 0.9000 }, 122 | { 0.0000, 2.0000, 0.9000 }, 123 | { 0.9800, 1.7500, 1.8750 }, 124 | { 1.7500, 0.9800, 1.8750 }, 125 | { 1.1200, 2.0000, 1.3500 }, 126 | { 2.0000, 1.1200, 1.3500 }, 127 | { 1.1200, 2.0000, 0.9000 }, 128 | { 2.0000, 1.1200, 0.9000 }, 129 | { 2.0000, 0.0000, 0.4500 }, 130 | { 2.0000, -1.1200, 0.4500 }, 131 | { 1.1200, -2.0000, 0.4500 }, 132 | { 0.0000, -2.0000, 0.4500 }, 133 | { 1.5000, 0.0000, 0.2250 }, 134 | { 1.5000, -0.8400, 0.2250 }, 135 | { 0.8400, -1.5000, 0.2250 }, 136 | { 0.0000, -1.5000, 0.2250 }, 137 | { 1.5000, 0.0000, 0.1500 }, 138 | { 1.5000, -0.8400, 0.1500 }, 139 | { 0.8400, -1.5000, 0.1500 }, 140 | { 0.0000, -1.5000, 0.1500 }, 141 | { -1.1200, -2.0000, 0.4500 }, 142 | { -2.0000, -1.1200, 0.4500 }, 143 | { -2.0000, 0.0000, 0.4500 }, 144 | { -0.8400, -1.5000, 0.2250 }, 145 | { -1.5000, -0.8400, 0.2250 }, 146 | { -1.5000, 0.0000, 0.2250 }, 147 | { -0.8400, -1.5000, 0.1500 }, 148 | { -1.5000, -0.8400, 0.1500 }, 149 | { -1.5000, 0.0000, 0.1500 }, 150 | { -2.0000, 1.1200, 0.4500 }, 151 | { -1.1200, 2.0000, 0.4500 }, 152 | { 0.0000, 2.0000, 0.4500 }, 153 | { -1.5000, 0.8400, 0.2250 }, 154 | { -0.8400, 1.5000, 0.2250 }, 155 | { 0.0000, 1.5000, 0.2250 }, 156 | { -1.5000, 0.8400, 0.1500 }, 157 | { -0.8400, 1.5000, 0.1500 }, 158 | { 0.0000, 1.5000, 0.1500 }, 159 | { 1.1200, 2.0000, 0.4500 }, 160 | { 2.0000, 1.1200, 0.4500 }, 161 | { 0.8400, 1.5000, 0.2250 }, 162 | { 1.5000, 0.8400, 0.2250 }, 163 | { 0.8400, 1.5000, 0.1500 }, 164 | { 1.5000, 0.8400, 0.1500 }, 165 | { -1.6000, 0.0000, 2.0250 }, 166 | { -1.6000, -0.3000, 2.0250 }, 167 | { -1.5000, -0.3000, 2.2500 }, 168 | { -1.5000, 0.0000, 2.2500 }, 169 | { -2.3000, 0.0000, 2.0250 }, 170 | { -2.3000, -0.3000, 2.0250 }, 171 | { -2.5000, -0.3000, 2.2500 }, 172 | { -2.5000, 0.0000, 2.2500 }, 173 | { -2.7000, 0.0000, 2.0250 }, 174 | { -2.7000, -0.3000, 2.0250 }, 175 | { -3.0000, -0.3000, 2.2500 }, 176 | { -3.0000, 0.0000, 2.2500 }, 177 | { -2.7000, 0.0000, 1.8000 }, 178 | { -2.7000, -0.3000, 1.8000 }, 179 | { -3.0000, -0.3000, 1.8000 }, 180 | { -3.0000, 0.0000, 1.8000 }, 181 | { -1.5000, 0.3000, 2.2500 }, 182 | { -1.6000, 0.3000, 2.0250 }, 183 | { -2.5000, 0.3000, 2.2500 }, 184 | { -2.3000, 0.3000, 2.0250 }, 185 | { -3.0000, 0.3000, 2.2500 }, 186 | { -2.7000, 0.3000, 2.0250 }, 187 | { -3.0000, 0.3000, 1.8000 }, 188 | { -2.7000, 0.3000, 1.8000 }, 189 | { -2.7000, 0.0000, 1.5750 }, 190 | { -2.7000, -0.3000, 1.5750 }, 191 | { -3.0000, -0.3000, 1.3500 }, 192 | { -3.0000, 0.0000, 1.3500 }, 193 | { -2.5000, 0.0000, 1.1250 }, 194 | { -2.5000, -0.3000, 1.1250 }, 195 | { -2.6500, -0.3000, 0.9375 }, 196 | { -2.6500, 0.0000, 0.9375 }, 197 | { -2.0000, -0.3000, 0.9000 }, 198 | { -1.9000, -0.3000, 0.6000 }, 199 | { -1.9000, 0.0000, 0.6000 }, 200 | { -3.0000, 0.3000, 1.3500 }, 201 | { -2.7000, 0.3000, 1.5750 }, 202 | { -2.6500, 0.3000, 0.9375 }, 203 | { -2.5000, 0.3000, 1.1250 }, 204 | { -1.9000, 0.3000, 0.6000 }, 205 | { -2.0000, 0.3000, 0.9000 }, 206 | { 1.7000, 0.0000, 1.4250 }, 207 | { 1.7000, -0.6600, 1.4250 }, 208 | { 1.7000, -0.6600, 0.6000 }, 209 | { 1.7000, 0.0000, 0.6000 }, 210 | { 2.6000, 0.0000, 1.4250 }, 211 | { 2.6000, -0.6600, 1.4250 }, 212 | { 3.1000, -0.6600, 0.8250 }, 213 | { 3.1000, 0.0000, 0.8250 }, 214 | { 2.3000, 0.0000, 2.1000 }, 215 | { 2.3000, -0.2500, 2.1000 }, 216 | { 2.4000, -0.2500, 2.0250 }, 217 | { 2.4000, 0.0000, 2.0250 }, 218 | { 2.7000, 0.0000, 2.4000 }, 219 | { 2.7000, -0.2500, 2.4000 }, 220 | { 3.3000, -0.2500, 2.4000 }, 221 | { 3.3000, 0.0000, 2.4000 }, 222 | { 1.7000, 0.6600, 0.6000 }, 223 | { 1.7000, 0.6600, 1.4250 }, 224 | { 3.1000, 0.6600, 0.8250 }, 225 | { 2.6000, 0.6600, 1.4250 }, 226 | { 2.4000, 0.2500, 2.0250 }, 227 | { 2.3000, 0.2500, 2.1000 }, 228 | { 3.3000, 0.2500, 2.4000 }, 229 | { 2.7000, 0.2500, 2.4000 }, 230 | { 2.8000, 0.0000, 2.4750 }, 231 | { 2.8000, -0.2500, 2.4750 }, 232 | { 3.5250, -0.2500, 2.4938 }, 233 | { 3.5250, 0.0000, 2.4938 }, 234 | { 2.9000, 0.0000, 2.4750 }, 235 | { 2.9000, -0.1500, 2.4750 }, 236 | { 3.4500, -0.1500, 2.5125 }, 237 | { 3.4500, 0.0000, 2.5125 }, 238 | { 2.8000, 0.0000, 2.4000 }, 239 | { 2.8000, -0.1500, 2.4000 }, 240 | { 3.2000, -0.1500, 2.4000 }, 241 | { 3.2000, 0.0000, 2.4000 }, 242 | { 3.5250, 0.2500, 2.4938 }, 243 | { 2.8000, 0.2500, 2.4750 }, 244 | { 3.4500, 0.1500, 2.5125 }, 245 | { 2.9000, 0.1500, 2.4750 }, 246 | { 3.2000, 0.1500, 2.4000 }, 247 | { 2.8000, 0.1500, 2.4000 }, 248 | { 0.0000, 0.0000, 3.1500 }, 249 | { 0.0000, -0.0020, 3.1500 }, 250 | { 0.0020, 0.0000, 3.1500 }, 251 | { 0.8000, 0.0000, 3.1500 }, 252 | { 0.8000, -0.4500, 3.1500 }, 253 | { 0.4500, -0.8000, 3.1500 }, 254 | { 0.0000, -0.8000, 3.1500 }, 255 | { 0.0000, 0.0000, 2.8500 }, 256 | { 0.2000, 0.0000, 2.7000 }, 257 | { 0.2000, -0.1120, 2.7000 }, 258 | { 0.1120, -0.2000, 2.7000 }, 259 | { 0.0000, -0.2000, 2.7000 }, 260 | { -0.0020, 0.0000, 3.1500 }, 261 | { -0.4500, -0.8000, 3.1500 }, 262 | { -0.8000, -0.4500, 3.1500 }, 263 | { -0.8000, 0.0000, 3.1500 }, 264 | { -0.1120, -0.2000, 2.7000 }, 265 | { -0.2000, -0.1120, 2.7000 }, 266 | { -0.2000, 0.0000, 2.7000 }, 267 | { 0.0000, 0.0020, 3.1500 }, 268 | { -0.8000, 0.4500, 3.1500 }, 269 | { -0.4500, 0.8000, 3.1500 }, 270 | { 0.0000, 0.8000, 3.1500 }, 271 | { -0.2000, 0.1120, 2.7000 }, 272 | { -0.1120, 0.2000, 2.7000 }, 273 | { 0.0000, 0.2000, 2.7000 }, 274 | { 0.4500, 0.8000, 3.1500 }, 275 | { 0.8000, 0.4500, 3.1500 }, 276 | { 0.1120, 0.2000, 2.7000 }, 277 | { 0.2000, 0.1120, 2.7000 }, 278 | { 0.4000, 0.0000, 2.5500 }, 279 | { 0.4000, -0.2240, 2.5500 }, 280 | { 0.2240, -0.4000, 2.5500 }, 281 | { 0.0000, -0.4000, 2.5500 }, 282 | { 1.3000, 0.0000, 2.5500 }, 283 | { 1.3000, -0.7280, 2.5500 }, 284 | { 0.7280, -1.3000, 2.5500 }, 285 | { 0.0000, -1.3000, 2.5500 }, 286 | { 1.3000, 0.0000, 2.4000 }, 287 | { 1.3000, -0.7280, 2.4000 }, 288 | { 0.7280, -1.3000, 2.4000 }, 289 | { 0.0000, -1.3000, 2.4000 }, 290 | { -0.2240, -0.4000, 2.5500 }, 291 | { -0.4000, -0.2240, 2.5500 }, 292 | { -0.4000, 0.0000, 2.5500 }, 293 | { -0.7280, -1.3000, 2.5500 }, 294 | { -1.3000, -0.7280, 2.5500 }, 295 | { -1.3000, 0.0000, 2.5500 }, 296 | { -0.7280, -1.3000, 2.4000 }, 297 | { -1.3000, -0.7280, 2.4000 }, 298 | { -1.3000, 0.0000, 2.4000 }, 299 | { -0.4000, 0.2240, 2.5500 }, 300 | { -0.2240, 0.4000, 2.5500 }, 301 | { 0.0000, 0.4000, 2.5500 }, 302 | { -1.3000, 0.7280, 2.5500 }, 303 | { -0.7280, 1.3000, 2.5500 }, 304 | { 0.0000, 1.3000, 2.5500 }, 305 | { -1.3000, 0.7280, 2.4000 }, 306 | { -0.7280, 1.3000, 2.4000 }, 307 | { 0.0000, 1.3000, 2.4000 }, 308 | { 0.2240, 0.4000, 2.5500 }, 309 | { 0.4000, 0.2240, 2.5500 }, 310 | { 0.7280, 1.3000, 2.5500 }, 311 | { 1.3000, 0.7280, 2.5500 }, 312 | { 0.7280, 1.3000, 2.4000 }, 313 | { 1.3000, 0.7280, 2.4000 }, 314 | { 0.0000, 0.0000, 0.0000 }, 315 | { 1.5000, 0.0000, 0.1500 }, 316 | { 1.5000, 0.8400, 0.1500 }, 317 | { 0.8400, 1.5000, 0.1500 }, 318 | { 0.0000, 1.5000, 0.1500 }, 319 | { 1.5000, 0.0000, 0.0750 }, 320 | { 1.5000, 0.8400, 0.0750 }, 321 | { 0.8400, 1.5000, 0.0750 }, 322 | { 0.0000, 1.5000, 0.0750 }, 323 | { 1.4250, 0.0000, 0.0000 }, 324 | { 1.4250, 0.7980, 0.0000 }, 325 | { 0.7980, 1.4250, 0.0000 }, 326 | { 0.0000, 1.4250, 0.0000 }, 327 | { -0.8400, 1.5000, 0.1500 }, 328 | { -1.5000, 0.8400, 0.1500 }, 329 | { -1.5000, 0.0000, 0.1500 }, 330 | { -0.8400, 1.5000, 0.0750 }, 331 | { -1.5000, 0.8400, 0.0750 }, 332 | { -1.5000, 0.0000, 0.0750 }, 333 | { -0.7980, 1.4250, 0.0000 }, 334 | { -1.4250, 0.7980, 0.0000 }, 335 | { -1.4250, 0.0000, 0.0000 }, 336 | { -1.5000, -0.8400, 0.1500 }, 337 | { -0.8400, -1.5000, 0.1500 }, 338 | { 0.0000, -1.5000, 0.1500 }, 339 | { -1.5000, -0.8400, 0.0750 }, 340 | { -0.8400, -1.5000, 0.0750 }, 341 | { 0.0000, -1.5000, 0.0750 }, 342 | { -1.4250, -0.7980, 0.0000 }, 343 | { -0.7980, -1.4250, 0.0000 }, 344 | { 0.0000, -1.4250, 0.0000 }, 345 | { 0.8400, -1.5000, 0.1500 }, 346 | { 1.5000, -0.8400, 0.1500 }, 347 | { 0.8400, -1.5000, 0.0750 }, 348 | { 1.5000, -0.8400, 0.0750 }, 349 | { 0.7980, -1.4250, 0.0000 }, 350 | { 1.4250, -0.7980, 0.0000 } 351 | }; -------------------------------------------------------------------------------- /src/reyes/thirdparty/AntTweakBar.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/AntTweakBar.dll -------------------------------------------------------------------------------- /src/reyes/thirdparty/AntTweakBar.h: -------------------------------------------------------------------------------- 1 | // ---------------------------------------------------------------------------- 2 | // 3 | // @file AntTweakBar.h 4 | // 5 | // @brief AntTweakBar is a light and intuitive graphical user interface 6 | // that can be readily integrated into OpenGL and DirectX 7 | // applications in order to interactively tweak parameters. 8 | // 9 | // @author Philippe Decaudin 10 | // 11 | // @doc http://anttweakbar.sourceforge.net/doc 12 | // 13 | // @license This file is part of the AntTweakBar library. 14 | // AntTweakBar is a free software released under the zlib license. 15 | // For conditions of distribution and use, see License.txt 16 | // 17 | // ---------------------------------------------------------------------------- 18 | 19 | 20 | #if !defined TW_INCLUDED 21 | #define TW_INCLUDED 22 | 23 | #include 24 | 25 | #define TW_VERSION 116 // Version Mmm : M=Major mm=minor (e.g., 102 is version 1.02) 26 | 27 | 28 | #ifdef __cplusplus 29 | # if defined(_MSC_VER) 30 | # pragma warning(push) 31 | # pragma warning(disable: 4995 4530) 32 | # include 33 | # pragma warning(pop) 34 | # else 35 | # include 36 | # endif 37 | extern "C" { 38 | #endif // __cplusplus 39 | 40 | 41 | // ---------------------------------------------------------------------------- 42 | // OS specific definitions 43 | // ---------------------------------------------------------------------------- 44 | 45 | #if (defined(_WIN32) || defined(_WIN64)) && !defined(TW_STATIC) 46 | # define TW_CALL __stdcall 47 | # define TW_CDECL_CALL __cdecl 48 | # define TW_EXPORT_API __declspec(dllexport) 49 | # define TW_IMPORT_API __declspec(dllimport) 50 | #else 51 | # define TW_CALL 52 | # define TW_CDECL_CALL 53 | # define TW_EXPORT_API 54 | # define TW_IMPORT_API 55 | #endif 56 | 57 | #if defined TW_EXPORTS 58 | # define TW_API TW_EXPORT_API 59 | #elif defined TW_STATIC 60 | # define TW_API 61 | # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA) 62 | # ifdef _WIN64 63 | # pragma comment(lib, "AntTweakBarStatic64") 64 | # else 65 | # pragma comment(lib, "AntTweakBarStatic") 66 | # endif 67 | # endif 68 | #else 69 | # define TW_API TW_IMPORT_API 70 | # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA) 71 | # ifdef _WIN64 72 | # pragma comment(lib, "AntTweakBar64") 73 | # else 74 | # pragma comment(lib, "AntTweakBar") 75 | # endif 76 | # endif 77 | #endif 78 | 79 | 80 | // ---------------------------------------------------------------------------- 81 | // Bar functions and definitions 82 | // ---------------------------------------------------------------------------- 83 | 84 | typedef struct CTwBar TwBar; // structure CTwBar is not exposed. 85 | 86 | TW_API TwBar * TW_CALL TwNewBar(const char *barName); 87 | TW_API int TW_CALL TwDeleteBar(TwBar *bar); 88 | TW_API int TW_CALL TwDeleteAllBars(); 89 | TW_API int TW_CALL TwSetTopBar(const TwBar *bar); 90 | TW_API TwBar * TW_CALL TwGetTopBar(); 91 | TW_API int TW_CALL TwSetBottomBar(const TwBar *bar); 92 | TW_API TwBar * TW_CALL TwGetBottomBar(); 93 | TW_API const char * TW_CALL TwGetBarName(const TwBar *bar); 94 | TW_API int TW_CALL TwGetBarCount(); 95 | TW_API TwBar * TW_CALL TwGetBarByIndex(int barIndex); 96 | TW_API TwBar * TW_CALL TwGetBarByName(const char *barName); 97 | TW_API int TW_CALL TwRefreshBar(TwBar *bar); 98 | 99 | // ---------------------------------------------------------------------------- 100 | // Var functions and definitions 101 | // ---------------------------------------------------------------------------- 102 | 103 | typedef enum ETwType 104 | { 105 | TW_TYPE_UNDEF = 0, 106 | #ifdef __cplusplus 107 | TW_TYPE_BOOLCPP = 1, 108 | #endif // __cplusplus 109 | TW_TYPE_BOOL8 = 2, 110 | TW_TYPE_BOOL16, 111 | TW_TYPE_BOOL32, 112 | TW_TYPE_CHAR, 113 | TW_TYPE_INT8, 114 | TW_TYPE_UINT8, 115 | TW_TYPE_INT16, 116 | TW_TYPE_UINT16, 117 | TW_TYPE_INT32, 118 | TW_TYPE_UINT32, 119 | TW_TYPE_FLOAT, 120 | TW_TYPE_DOUBLE, 121 | TW_TYPE_COLOR32, // 32 bits color. Order is RGBA if API is OpenGL or Direct3D10, and inversed if API is Direct3D9 (can be modified by defining 'colorOrder=...', see doc) 122 | TW_TYPE_COLOR3F, // 3 floats color. Order is RGB. 123 | TW_TYPE_COLOR4F, // 4 floats color. Order is RGBA. 124 | TW_TYPE_CDSTRING, // Null-terminated C Dynamic String (pointer to an array of char dynamically allocated with malloc/realloc/strdup) 125 | #ifdef __cplusplus 126 | # if defined(_MSC_VER) && (_MSC_VER == 1600) 127 | TW_TYPE_STDSTRING = (0x2ffe0000+sizeof(std::string)), // VS2010 C++ STL string (std::string) 128 | # else 129 | TW_TYPE_STDSTRING = (0x2fff0000+sizeof(std::string)), // C++ STL string (std::string) 130 | # endif 131 | #endif // __cplusplus 132 | TW_TYPE_QUAT4F = TW_TYPE_CDSTRING+2, // 4 floats encoding a quaternion {qx,qy,qz,qs} 133 | TW_TYPE_QUAT4D, // 4 doubles encoding a quaternion {qx,qy,qz,qs} 134 | TW_TYPE_DIR3F, // direction vector represented by 3 floats 135 | TW_TYPE_DIR3D // direction vector represented by 3 doubles 136 | } TwType; 137 | #define TW_TYPE_CSSTRING(n) ((TwType)(0x30000000+((n)&0xfffffff))) // Null-terminated C Static String of size n (defined as char[n], with n<2^28) 138 | 139 | typedef void (TW_CALL * TwSetVarCallback)(const void *value, void *clientData); 140 | typedef void (TW_CALL * TwGetVarCallback)(void *value, void *clientData); 141 | typedef void (TW_CALL * TwButtonCallback)(void *clientData); 142 | 143 | TW_API int TW_CALL TwAddVarRW(TwBar *bar, const char *name, TwType type, void *var, const char *def); 144 | TW_API int TW_CALL TwAddVarRO(TwBar *bar, const char *name, TwType type, const void *var, const char *def); 145 | TW_API int TW_CALL TwAddVarCB(TwBar *bar, const char *name, TwType type, TwSetVarCallback setCallback, TwGetVarCallback getCallback, void *clientData, const char *def); 146 | TW_API int TW_CALL TwAddButton(TwBar *bar, const char *name, TwButtonCallback callback, void *clientData, const char *def); 147 | TW_API int TW_CALL TwAddSeparator(TwBar *bar, const char *name, const char *def); 148 | TW_API int TW_CALL TwRemoveVar(TwBar *bar, const char *name); 149 | TW_API int TW_CALL TwRemoveAllVars(TwBar *bar); 150 | 151 | typedef struct CTwEnumVal 152 | { 153 | int Value; 154 | const char * Label; 155 | } TwEnumVal; 156 | typedef struct CTwStructMember 157 | { 158 | const char * Name; 159 | TwType Type; 160 | size_t Offset; 161 | const char * DefString; 162 | } TwStructMember; 163 | typedef void (TW_CALL * TwSummaryCallback)(char *summaryString, size_t summaryMaxLength, const void *value, void *clientData); 164 | 165 | TW_API int TW_CALL TwDefine(const char *def); 166 | TW_API TwType TW_CALL TwDefineEnum(const char *name, const TwEnumVal *enumValues, unsigned int nbValues); 167 | TW_API TwType TW_CALL TwDefineEnumFromString(const char *name, const char *enumString); 168 | TW_API TwType TW_CALL TwDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize, TwSummaryCallback summaryCallback, void *summaryClientData); 169 | 170 | typedef void (TW_CALL * TwCopyCDStringToClient)(char **destinationClientStringPtr, const char *sourceString); 171 | TW_API void TW_CALL TwCopyCDStringToClientFunc(TwCopyCDStringToClient copyCDStringFunc); 172 | TW_API void TW_CALL TwCopyCDStringToLibrary(char **destinationLibraryStringPtr, const char *sourceClientString); 173 | #ifdef __cplusplus 174 | typedef void (TW_CALL * TwCopyStdStringToClient)(std::string& destinationClientString, const std::string& sourceString); 175 | TW_API void TW_CALL TwCopyStdStringToClientFunc(TwCopyStdStringToClient copyStdStringToClientFunc); 176 | TW_API void TW_CALL TwCopyStdStringToLibrary(std::string& destinationLibraryString, const std::string& sourceClientString); 177 | #endif // __cplusplus 178 | 179 | typedef enum ETwParamValueType 180 | { 181 | TW_PARAM_INT32, 182 | TW_PARAM_FLOAT, 183 | TW_PARAM_DOUBLE, 184 | TW_PARAM_CSTRING // Null-terminated array of char (ie, c-string) 185 | } TwParamValueType; 186 | TW_API int TW_CALL TwGetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int outValueMaxCount, void *outValues); 187 | TW_API int TW_CALL TwSetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int inValueCount, const void *inValues); 188 | 189 | 190 | // ---------------------------------------------------------------------------- 191 | // Management functions and definitions 192 | // ---------------------------------------------------------------------------- 193 | 194 | typedef enum ETwGraphAPI 195 | { 196 | TW_OPENGL = 1, 197 | TW_DIRECT3D9 = 2, 198 | TW_DIRECT3D10 = 3, 199 | TW_DIRECT3D11 = 4, 200 | TW_OPENGL_CORE = 5 201 | } TwGraphAPI; 202 | 203 | TW_API int TW_CALL TwInit(TwGraphAPI graphAPI, void *device); 204 | TW_API int TW_CALL TwTerminate(); 205 | 206 | TW_API int TW_CALL TwDraw(); 207 | TW_API int TW_CALL TwWindowSize(int width, int height); 208 | 209 | TW_API int TW_CALL TwSetCurrentWindow(int windowID); // multi-windows support 210 | TW_API int TW_CALL TwGetCurrentWindow(); 211 | TW_API int TW_CALL TwWindowExists(int windowID); 212 | 213 | typedef enum ETwKeyModifier 214 | { 215 | TW_KMOD_NONE = 0x0000, // same codes as SDL keysym.mod 216 | TW_KMOD_SHIFT = 0x0003, 217 | TW_KMOD_CTRL = 0x00c0, 218 | TW_KMOD_ALT = 0x0100, 219 | TW_KMOD_META = 0x0c00 220 | } TwKeyModifier; 221 | typedef enum EKeySpecial 222 | { 223 | TW_KEY_BACKSPACE = '\b', 224 | TW_KEY_TAB = '\t', 225 | TW_KEY_CLEAR = 0x0c, 226 | TW_KEY_RETURN = '\r', 227 | TW_KEY_PAUSE = 0x13, 228 | TW_KEY_ESCAPE = 0x1b, 229 | TW_KEY_SPACE = ' ', 230 | TW_KEY_DELETE = 0x7f, 231 | TW_KEY_UP = 273, // same codes and order as SDL 1.2 keysym.sym 232 | TW_KEY_DOWN, 233 | TW_KEY_RIGHT, 234 | TW_KEY_LEFT, 235 | TW_KEY_INSERT, 236 | TW_KEY_HOME, 237 | TW_KEY_END, 238 | TW_KEY_PAGE_UP, 239 | TW_KEY_PAGE_DOWN, 240 | TW_KEY_F1, 241 | TW_KEY_F2, 242 | TW_KEY_F3, 243 | TW_KEY_F4, 244 | TW_KEY_F5, 245 | TW_KEY_F6, 246 | TW_KEY_F7, 247 | TW_KEY_F8, 248 | TW_KEY_F9, 249 | TW_KEY_F10, 250 | TW_KEY_F11, 251 | TW_KEY_F12, 252 | TW_KEY_F13, 253 | TW_KEY_F14, 254 | TW_KEY_F15, 255 | TW_KEY_LAST 256 | } TwKeySpecial; 257 | 258 | TW_API int TW_CALL TwKeyPressed(int key, int modifiers); 259 | TW_API int TW_CALL TwKeyTest(int key, int modifiers); 260 | 261 | typedef enum ETwMouseAction 262 | { 263 | TW_MOUSE_RELEASED, 264 | TW_MOUSE_PRESSED 265 | } TwMouseAction; 266 | typedef enum ETwMouseButtonID 267 | { 268 | TW_MOUSE_LEFT = 1, // same code as SDL_BUTTON_LEFT 269 | TW_MOUSE_MIDDLE = 2, // same code as SDL_BUTTON_MIDDLE 270 | TW_MOUSE_RIGHT = 3 // same code as SDL_BUTTON_RIGHT 271 | } TwMouseButtonID; 272 | 273 | TW_API int TW_CALL TwMouseButton(TwMouseAction action, TwMouseButtonID button); 274 | TW_API int TW_CALL TwMouseMotion(int mouseX, int mouseY); 275 | TW_API int TW_CALL TwMouseWheel(int pos); 276 | 277 | TW_API const char * TW_CALL TwGetLastError(); 278 | typedef void (TW_CALL * TwErrorHandler)(const char *errorMessage); 279 | TW_API void TW_CALL TwHandleErrors(TwErrorHandler errorHandler); 280 | 281 | 282 | // ---------------------------------------------------------------------------- 283 | // Helper functions to translate events from some common window management 284 | // frameworks to AntTweakBar. 285 | // They call TwKeyPressed, TwMouse* and TwWindowSize for you (implemented in 286 | // files TwEventWin.c TwEventSDL*.c TwEventGLFW.c TwEventGLUT.c) 287 | // ---------------------------------------------------------------------------- 288 | 289 | // For Windows message proc 290 | #ifndef _W64 // Microsoft specific (detection of 64 bits portability issues) 291 | # define _W64 292 | #endif // _W64 293 | #ifdef _WIN64 294 | TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned __int64 _W64 wParam, __int64 _W64 lParam); 295 | #else 296 | TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam); 297 | #endif 298 | #define TwEventWin32 TwEventWin // For compatibility with AntTweakBar versions prior to 1.11 299 | 300 | // For libSDL event loop 301 | TW_API int TW_CALL TwEventSDL(const void *sdlEvent, unsigned char sdlMajorVersion, unsigned char sdlMinorVersion); 302 | 303 | // For GLFW event callbacks 304 | // You should define GLFW_CDECL before including AntTweakBar.h if your version of GLFW uses cdecl calling convensions 305 | #ifdef GLFW_CDECL 306 | TW_API int TW_CDECL_CALL TwEventMouseButtonGLFWcdecl(int glfwButton, int glfwAction); 307 | TW_API int TW_CDECL_CALL TwEventKeyGLFWcdecl(int glfwKey, int glfwAction); 308 | TW_API int TW_CDECL_CALL TwEventCharGLFWcdecl(int glfwChar, int glfwAction); 309 | TW_API int TW_CDECL_CALL TwEventMousePosGLFWcdecl(int mouseX, int mouseY); 310 | TW_API int TW_CDECL_CALL TwEventMouseWheelGLFWcdecl(int wheelPos); 311 | # define TwEventMouseButtonGLFW TwEventMouseButtonGLFWcdecl 312 | # define TwEventKeyGLFW TwEventKeyGLFWcdecl 313 | # define TwEventCharGLFW TwEventCharGLFWcdecl 314 | # define TwEventMousePosGLFW TwEventMousePosGLFWcdecl 315 | # define TwEventMouseWheelGLFW TwEventMouseWheelGLFWcdecl 316 | #else 317 | TW_API int TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction); 318 | TW_API int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction); 319 | TW_API int TW_CALL TwEventCharGLFW(int glfwChar, int glfwAction); 320 | # define TwEventMousePosGLFW TwMouseMotion 321 | # define TwEventMouseWheelGLFW TwMouseWheel 322 | #endif 323 | 324 | // For GLUT event callbacks (Windows calling convention for GLUT callbacks is cdecl) 325 | #if defined(_WIN32) || defined(_WIN64) 326 | # define TW_GLUT_CALL TW_CDECL_CALL 327 | #else 328 | # define TW_GLUT_CALL 329 | #endif 330 | TW_API int TW_GLUT_CALL TwEventMouseButtonGLUT(int glutButton, int glutState, int mouseX, int mouseY); 331 | TW_API int TW_GLUT_CALL TwEventMouseMotionGLUT(int mouseX, int mouseY); 332 | TW_API int TW_GLUT_CALL TwEventKeyboardGLUT(unsigned char glutKey, int mouseX, int mouseY); 333 | TW_API int TW_GLUT_CALL TwEventSpecialGLUT(int glutKey, int mouseX, int mouseY); 334 | TW_API int TW_CALL TwGLUTModifiersFunc(int (TW_CALL *glutGetModifiersFunc)(void)); 335 | typedef void (TW_GLUT_CALL *GLUTmousebuttonfun)(int glutButton, int glutState, int mouseX, int mouseY); 336 | typedef void (TW_GLUT_CALL *GLUTmousemotionfun)(int mouseX, int mouseY); 337 | typedef void (TW_GLUT_CALL *GLUTkeyboardfun)(unsigned char glutKey, int mouseX, int mouseY); 338 | typedef void (TW_GLUT_CALL *GLUTspecialfun)(int glutKey, int mouseX, int mouseY); 339 | 340 | // For SFML event loop 341 | TW_API int TW_CALL TwEventSFML(const void *sfmlEvent, unsigned char sfmlMajorVersion, unsigned char sfmlMinorVersion); 342 | 343 | // For X11 event loop 344 | #if defined(_UNIX) 345 | TW_API int TW_CDECL_CALL TwEventX11(void *xevent); 346 | #endif 347 | 348 | // ---------------------------------------------------------------------------- 349 | // Make sure the types have the right sizes 350 | // ---------------------------------------------------------------------------- 351 | 352 | #define TW_COMPILE_TIME_ASSERT(name, x) typedef int TW_DUMMY_ ## name[(x) * 2 - 1] 353 | 354 | TW_COMPILE_TIME_ASSERT(TW_CHAR, sizeof(char) == 1); 355 | TW_COMPILE_TIME_ASSERT(TW_SHORT, sizeof(short) == 2); 356 | TW_COMPILE_TIME_ASSERT(TW_INT, sizeof(int) == 4); 357 | TW_COMPILE_TIME_ASSERT(TW_FLOAT, sizeof(float) == 4); 358 | TW_COMPILE_TIME_ASSERT(TW_DOUBLE, sizeof(double) == 8); 359 | 360 | // Check pointer size on Windows 361 | #if !defined(_WIN64) && defined(_WIN32) 362 | // If the following assert failed, the platform is not 32-bit and _WIN64 is not defined. 363 | // When targetting 64-bit Windows platform, _WIN64 must be defined. 364 | TW_COMPILE_TIME_ASSERT(TW_PTR32, sizeof(void*) == 4); 365 | #elif defined(_WIN64) 366 | // If the following assert failed, _WIN64 is defined but the targeted platform is not 64-bit. 367 | TW_COMPILE_TIME_ASSERT(TW_PTR64, sizeof(void*) == 8); 368 | #endif 369 | 370 | // --------------------------------------------------------------------------- 371 | 372 | 373 | #ifdef __cplusplus 374 | } // extern "C" 375 | #endif // __cplusplus 376 | 377 | 378 | #endif // !defined TW_INCLUDED 379 | -------------------------------------------------------------------------------- /src/reyes/thirdparty/AntTweakBar.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/AntTweakBar.lib -------------------------------------------------------------------------------- /src/reyes/thirdparty/AntTweakBar64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/AntTweakBar64.dll -------------------------------------------------------------------------------- /src/reyes/thirdparty/AntTweakBar64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/AntTweakBar64.lib -------------------------------------------------------------------------------- /src/reyes/thirdparty/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/glew32.dll -------------------------------------------------------------------------------- /src/reyes/thirdparty/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/glew32.lib -------------------------------------------------------------------------------- /src/reyes/thirdparty/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/glew32s.lib -------------------------------------------------------------------------------- /src/reyes/thirdparty/nvToolsExt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009-2012 NVIDIA Corporation. All rights reserved. 3 | * 4 | * NOTICE TO USER: 5 | * 6 | * This source code is subject to NVIDIA ownership rights under U.S. and 7 | * international Copyright laws. 8 | * 9 | * This software and the information contained herein is PROPRIETARY and 10 | * CONFIDENTIAL to NVIDIA and is being provided under the terms and conditions 11 | * of a form of NVIDIA software license agreement. 12 | * 13 | * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE 14 | * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 15 | * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH 16 | * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 17 | * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. 18 | * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, 19 | * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 20 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 21 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 22 | * OR PERFORMANCE OF THIS SOURCE CODE. 23 | * 24 | * U.S. Government End Users. This source code is a "commercial item" as 25 | * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of 26 | * "commercial computer software" and "commercial computer software 27 | * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) 28 | * and is provided to the U.S. Government only as a commercial end item. 29 | * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 30 | * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the 31 | * source code with only those rights set forth herein. 32 | * 33 | * Any use of this source code in individual and commercial software must 34 | * include, in the user documentation and internal comments to the code, 35 | * the above Disclaimer and U.S. Government End Users Notice. 36 | */ 37 | 38 | /** \mainpage 39 | * \section Introduction 40 | * The NVIDIA Tools Extension library is a set of functions that a 41 | * developer can use to provide additional information to tools. 42 | * The additional information is used by the tool to improve 43 | * analysis and visualization of data. 44 | * 45 | * The library introduces close to zero overhead if no tool is 46 | * attached to the application. The overhead when a tool is 47 | * attached is specific to the tool. 48 | */ 49 | 50 | #ifndef NVTOOLSEXT_H_ 51 | #define NVTOOLSEXT_H_ 52 | 53 | #if defined(_MSC_VER) /* Microsoft Visual C++ Compiler */ 54 | #ifdef NVTX_EXPORTS 55 | #define NVTX_DECLSPEC 56 | #else 57 | #define NVTX_DECLSPEC __declspec(dllimport) 58 | #endif /* NVTX_EXPORTS */ 59 | #define NVTX_API __stdcall 60 | #else /* GCC and most other compilers */ 61 | #define NVTX_DECLSPEC 62 | #define NVTX_API 63 | #endif /* Platform */ 64 | 65 | /** 66 | * The nvToolsExt library depends on stdint.h. If the build tool chain in use 67 | * does not include stdint.h then define NVTX_STDINT_TYPES_ALREADY_DEFINED 68 | * and define the following types: 69 | *
    70 | *
  • uint8_t 71 | *
  • int8_t 72 | *
  • uint16_t 73 | *
  • int16_t 74 | *
  • uint32_t 75 | *
  • int32_t 76 | *
  • uint64_t 77 | *
  • int64_t 78 | *
  • uintptr_t 79 | *
  • intptr_t 80 | *
81 | #define NVTX_STDINT_TYPES_ALREADY_DEFINED if you are using your own header file. 82 | */ 83 | #ifndef NVTX_STDINT_TYPES_ALREADY_DEFINED 84 | #include 85 | #endif 86 | 87 | #ifdef __cplusplus 88 | extern "C" { 89 | #endif /* __cplusplus */ 90 | 91 | /** 92 | * Tools Extension API version 93 | */ 94 | #define NVTX_VERSION 1 95 | 96 | /** 97 | * Size of the nvtxEventAttributes_t structure. 98 | */ 99 | #define NVTX_EVENT_ATTRIB_STRUCT_SIZE ( (uint16_t)( sizeof(nvtxEventAttributes_v1) ) ) 100 | 101 | #define NVTX_NO_PUSH_POP_TRACKING ((int)-2) 102 | 103 | typedef uint64_t nvtxRangeId_t; 104 | 105 | /** \page EVENT_ATTRIBUTES Event Attributes 106 | * 107 | * \ref MARKER_AND_RANGES can be annotated with various attributes to provide 108 | * additional information for an event or to guide the tool's visualization of 109 | * the data. Each of the attributes is optional and if left unused the 110 | * attributes fall back to a default value. 111 | * 112 | * To specify any attribute other than the text message, the \ref 113 | * EVENT_ATTRIBUTE_STRUCTURE "Event Attribute Structure" must be used. 114 | */ 115 | 116 | /** --------------------------------------------------------------------------- 117 | * Color Types 118 | * ------------------------------------------------------------------------- */ 119 | typedef enum nvtxColorType_t 120 | { 121 | NVTX_COLOR_UNKNOWN = 0, /**< Color attribute is unused. */ 122 | NVTX_COLOR_ARGB = 1 /**< An ARGB color is provided. */ 123 | } nvtxColorType_t; 124 | 125 | /** --------------------------------------------------------------------------- 126 | * Payload Types 127 | * ------------------------------------------------------------------------- */ 128 | typedef enum nvtxPayloadType_t 129 | { 130 | NVTX_PAYLOAD_UNKNOWN = 0, /**< Color payload is unused. */ 131 | NVTX_PAYLOAD_TYPE_UNSIGNED_INT64 = 1, /**< A unsigned integer value is used as payload. */ 132 | NVTX_PAYLOAD_TYPE_INT64 = 2, /**< A signed integer value is used as payload. */ 133 | NVTX_PAYLOAD_TYPE_DOUBLE = 3 /**< A floating point value is used as payload. */ 134 | } nvtxPayloadType_t; 135 | 136 | /** --------------------------------------------------------------------------- 137 | * Message Types 138 | * ------------------------------------------------------------------------- */ 139 | typedef enum nvtxMessageType_t 140 | { 141 | NVTX_MESSAGE_UNKNOWN = 0, /**< Message payload is unused. */ 142 | NVTX_MESSAGE_TYPE_ASCII = 1, /**< A character sequence is used as payload. */ 143 | NVTX_MESSAGE_TYPE_UNICODE = 2 /**< A wide character sequence is used as payload. */ 144 | } nvtxMessageType_t; 145 | 146 | /** \brief Event Attribute Structure. 147 | * \anchor EVENT_ATTRIBUTE_STRUCTURE 148 | * 149 | * This structure is used to describe the attributes of an event. The layout of 150 | * the structure is defined by a specific version of the tools extension 151 | * library and can change between different versions of the Tools Extension 152 | * library. 153 | * 154 | * \par Initializing the Attributes 155 | * 156 | * The caller should always perform the following three tasks when using 157 | * attributes: 158 | *
    159 | *
  • Zero the structure 160 | *
  • Set the version field 161 | *
  • Set the size field 162 | *
163 | * 164 | * Zeroing the structure sets all the event attributes types and values 165 | * to the default value. 166 | * 167 | * The version and size field are used by the Tools Extension 168 | * implementation to handle multiple versions of the attributes structure. 169 | * 170 | * It is recommended that the caller use one of the following to methods 171 | * to initialize the event attributes structure: 172 | * 173 | * \par Method 1: Initializing nvtxEventAttributes for future compatibility 174 | * \code 175 | * nvtxEventAttributes_t eventAttrib = {0}; 176 | * eventAttrib.version = NVTX_VERSION; 177 | * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; 178 | * \endcode 179 | * 180 | * \par Method 2: Initializing nvtxEventAttributes for a specific version 181 | * \code 182 | * nvtxEventAttributes_t eventAttrib = {0}; 183 | * eventAttrib.version = 1; 184 | * eventAttrib.size = (uint16_t)(sizeof(nvtxEventAttributes_v1)); 185 | * \endcode 186 | * 187 | * If the caller uses Method 1 it is critical that the entire binary 188 | * layout of the structure be configured to 0 so that all fields 189 | * are initialized to the default value. 190 | * 191 | * The caller should either use both NVTX_VERSION and 192 | * NVTX_EVENT_ATTRIB_STRUCT_SIZE (Method 1) or use explicit values 193 | * and a versioned type (Method 2). Using a mix of the two methods 194 | * will likely cause either source level incompatibility or binary 195 | * incompatibility in the future. 196 | * 197 | * \par Settings Attribute Types and Values 198 | * 199 | * 200 | * \par Example: 201 | * \code 202 | * // Initialize 203 | * nvtxEventAttributes_t eventAttrib = {0}; 204 | * eventAttrib.version = NVTX_VERSION; 205 | * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; 206 | * 207 | * // Configure the Attributes 208 | * eventAttrib.colorType = NVTX_COLOR_ARGB; 209 | * eventAttrib.color = 0xFF880000; 210 | * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; 211 | * eventAttrib.message.ascii = "Example"; 212 | * \endcode 213 | * 214 | * In the example the caller does not have to set the value of 215 | * \ref ::nvtxEventAttributes_v1::category or 216 | * \ref ::nvtxEventAttributes_v1::payload as these fields were set to 217 | * the default value by {0}. 218 | * \sa 219 | * ::nvtxMarkEx 220 | * ::nvtxRangeStartEx 221 | * ::nvtxRangePushEx 222 | */ 223 | typedef struct nvtxEventAttributes_v1 224 | { 225 | /** 226 | * \brief Version flag of the structure. 227 | * 228 | * Needs to be set to NVTX_VERSION to indicate the version of NVTX APIs 229 | * supported in this header file. This can optionally be overridden to 230 | * another version of the tools extension library. 231 | */ 232 | uint16_t version; 233 | 234 | /** 235 | * \brief Size of the structure. 236 | * 237 | * Needs to be set to the size in bytes of the event attribute 238 | * structure used to specify the event. 239 | */ 240 | uint16_t size; 241 | 242 | /** 243 | * \brief ID of the category the event is assigned to. 244 | * 245 | * A category is a user-controlled ID that can be used to group 246 | * events. The tool may use category IDs to improve filtering or 247 | * enable grouping of events in the same category. The functions 248 | * \ref ::nvtxNameCategoryA or \ref ::nvtxNameCategoryW can be used 249 | * to name a category. 250 | * 251 | * Default Value is 0 252 | */ 253 | uint32_t category; 254 | 255 | /** \brief Color type specified in this attribute structure. 256 | * 257 | * Defines the color format of the attribute structure's \ref COLOR_FIELD 258 | * "color" field. 259 | * 260 | * Default Value is NVTX_COLOR_UNKNOWN 261 | */ 262 | int32_t colorType; /* nvtxColorType_t */ 263 | 264 | /** \brief Color assigned to this event. \anchor COLOR_FIELD 265 | * 266 | * The color that the tool should use to visualize the event. 267 | */ 268 | uint32_t color; 269 | 270 | /** 271 | * \brief Payload type specified in this attribute structure. 272 | * 273 | * Defines the payload format of the attribute structure's \ref PAYLOAD_FIELD 274 | * "payload" field. 275 | * 276 | * Default Value is NVTX_PAYLOAD_UNKNOWN 277 | */ 278 | int32_t payloadType; /* nvtxPayloadType_t */ 279 | 280 | int32_t reserved0; 281 | 282 | /** 283 | * \brief Payload assigned to this event. \anchor PAYLOAD_FIELD 284 | * 285 | * A numerical value that can be used to annotate an event. The tool could 286 | * use the payload data to reconstruct graphs and diagrams. 287 | */ 288 | union payload_t 289 | { 290 | uint64_t ullValue; 291 | int64_t llValue; 292 | double dValue; 293 | } payload; 294 | 295 | /** \brief Message type specified in this attribute structure. 296 | * 297 | * Defines the message format of the attribute structure's \ref MESSAGE_FIELD 298 | * "message" field. 299 | * 300 | * Default Value is NVTX_MESSAGE_UNKNOWN 301 | */ 302 | int32_t messageType; /* nvtxMessageType_t */ 303 | 304 | /** \brief Message assigned to this attribute structure. \anchor MESSAGE_FIELD 305 | * 306 | * The text message that is attached to an event. 307 | */ 308 | union message_t 309 | { 310 | const char* ascii; 311 | const wchar_t* unicode; 312 | } message; 313 | 314 | } nvtxEventAttributes_v1; 315 | 316 | typedef struct nvtxEventAttributes_v1 nvtxEventAttributes_t; 317 | 318 | /* ========================================================================= */ 319 | /** \defgroup MARKER_AND_RANGES Marker and Ranges 320 | * 321 | * Markers and ranges are used to describe events at a specific time (markers) 322 | * or over a time span (ranges) during the execution of the application 323 | * respectively. The additional information is presented alongside all other 324 | * captured data and facilitates understanding of the collected information. 325 | */ 326 | 327 | /* ========================================================================= */ 328 | /** \name Markers 329 | */ 330 | /** \name Markers 331 | */ 332 | /** \addtogroup MARKER_AND_RANGES 333 | * \section MARKER Marker 334 | * 335 | * A marker describes a single point in time. A marker event has no side effect 336 | * on other events. 337 | * 338 | * @{ 339 | */ 340 | 341 | /* ------------------------------------------------------------------------- */ 342 | /** \brief Marks an instantaneous event in the application. 343 | * 344 | * A marker can contain a text message or specify additional information 345 | * using the event attributes structure. These attributes include a text 346 | * message, color, category, and a payload. Each of the attributes is optional 347 | * and can only be sent out using the \ref nvtxMarkEx function. 348 | * If \ref nvtxMarkA or \ref nvtxMarkW are used to specify the the marker 349 | * or if an attribute is unspecified then a default value will be used. 350 | * 351 | * \param eventAttrib - The event attribute structure defining the marker's 352 | * attribute types and attribute values. 353 | * 354 | * \par Example: 355 | * \code 356 | * // zero the structure 357 | * nvtxEventAttributes_t eventAttrib = {0}; 358 | * // set the version and the size information 359 | * eventAttrib.version = NVTX_VERSION; 360 | * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; 361 | * // configure the attributes. 0 is the default for all attributes. 362 | * eventAttrib.colorType = NVTX_COLOR_ARGB; 363 | * eventAttrib.color = 0xFF880000; 364 | * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; 365 | * eventAttrib.message.ascii = "Example nvtxMarkEx"; 366 | * nvtxMarkEx(&eventAttrib); 367 | * \endcode 368 | * 369 | * \version \NVTX_VERSION_1 370 | * @{ */ 371 | NVTX_DECLSPEC void NVTX_API nvtxMarkEx(const nvtxEventAttributes_t* eventAttrib); 372 | /** @} */ 373 | 374 | /* ------------------------------------------------------------------------- */ 375 | /** \brief Marks an instantaneous event in the application. 376 | * 377 | * A marker created using \ref nvtxMarkA or \ref nvtxMarkW contains only a 378 | * text message. 379 | * 380 | * \param message - The message associated to this marker event. 381 | * 382 | * \par Example: 383 | * \code 384 | * nvtxMarkA("Example nvtxMarkA"); 385 | * nvtxMarkW(L"Example nvtxMarkW"); 386 | * \endcode 387 | * 388 | * \version \NVTX_VERSION_0 389 | * @{ */ 390 | NVTX_DECLSPEC void NVTX_API nvtxMarkA(const char* message); 391 | NVTX_DECLSPEC void NVTX_API nvtxMarkW(const wchar_t* message); 392 | /** @} */ 393 | 394 | /** @} */ /* END MARKER_AND_RANGES */ 395 | 396 | /* ========================================================================= */ 397 | /** \name Start/Stop Ranges 398 | */ 399 | /** \addtogroup MARKER_AND_RANGES 400 | * \section INDEPENDENT_RANGES Start/Stop Ranges 401 | * 402 | * Start/Stop ranges denote a time span that can expose arbitrary concurrency - 403 | * opposed to Push/Pop ranges that only support nesting. In addition the start 404 | * of a range can happen on a different thread than the end. For the 405 | * correlation of a start/end pair an unique correlation ID is used that is 406 | * returned from the start API call and needs to be passed into the end API 407 | * call. 408 | * 409 | * @{ 410 | */ 411 | 412 | /* ------------------------------------------------------------------------- */ 413 | /** \brief Marks the start of a range. 414 | * 415 | * \param eventAttrib - The event attribute structure defining the range's 416 | * attribute types and attribute values. 417 | * 418 | * \return The unique ID used to correlate a pair of Start and End events. 419 | * 420 | * \remarks Ranges defined by Start/End can overlap. 421 | * 422 | * \par Example: 423 | * \code 424 | * nvtxEventAttributes_t eventAttrib = {0}; 425 | * eventAttrib.version = NVTX_VERSION; 426 | * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; 427 | * eventAttrib.category = 3; 428 | * eventAttrib.colorType = NVTX_COLOR_ARGB; 429 | * eventAttrib.color = 0xFF0088FF; 430 | * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; 431 | * eventAttrib.message.ascii = "Example RangeStartEnd"; 432 | * nvtxRangeId_t rangeId = nvtxRangeStartEx(&eventAttrib); 433 | * // ... 434 | * nvtxRangeEnd(rangeId); 435 | * \endcode 436 | * 437 | * \sa 438 | * ::nvtxRangeEnd 439 | * 440 | * \version \NVTX_VERSION_1 441 | * @{ */ 442 | NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxRangeStartEx(const nvtxEventAttributes_t* eventAttrib); 443 | /** @} */ 444 | 445 | /* ------------------------------------------------------------------------- */ 446 | /** \brief Marks the start of a range. 447 | * 448 | * \param message - The event message associated to this range event. 449 | * 450 | * \return The unique ID used to correlate a pair of Start and End events. 451 | * 452 | * \remarks Ranges defined by Start/End can overlap. 453 | * 454 | * \par Example: 455 | * \code 456 | * nvtxRangeId_t r1 = nvtxRangeStartA("Range 1"); 457 | * nvtxRangeId_t r2 = nvtxRangeStartW(L"Range 2"); 458 | * nvtxRangeEnd(r1); 459 | * nvtxRangeEnd(r2); 460 | * \endcode 461 | * \sa 462 | * ::nvtxRangeEnd 463 | * 464 | * \version \NVTX_VERSION_0 465 | * @{ */ 466 | NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxRangeStartA(const char* message); 467 | NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxRangeStartW(const wchar_t* message); 468 | /** @} */ 469 | 470 | /* ------------------------------------------------------------------------- */ 471 | /** \brief Marks the end of a range. 472 | * 473 | * \param id - The correlation ID returned from a nvtxRangeStart call. 474 | * 475 | * \sa 476 | * ::nvtxRangeStartEx 477 | * ::nvtxRangeStartA 478 | * ::nvtxRangeStartW 479 | * 480 | * \version \NVTX_VERSION_0 481 | * @{ */ 482 | NVTX_DECLSPEC void NVTX_API nvtxRangeEnd(nvtxRangeId_t id); 483 | /** @} */ 484 | 485 | /** @} */ 486 | 487 | 488 | /* ========================================================================= */ 489 | /** \name Push/Pop Ranges 490 | */ 491 | /** \addtogroup MARKER_AND_RANGES 492 | * \section PUSH_POP_RANGES Push/Pop Ranges 493 | * 494 | * Push/Pop ranges denote nested time ranges. Nesting is maintained per thread 495 | * and does not require any additional correlation mechanism. The duration of a 496 | * push/pop range is defined by the corresponding pair of Push/Pop API calls. 497 | * 498 | * @{ 499 | */ 500 | 501 | /* ------------------------------------------------------------------------- */ 502 | /** \brief Marks the start of a nested range 503 | * 504 | * \param eventAttrib - The event attribute structure defining the range's 505 | * attribute types and attribute values. 506 | * 507 | * \return The 0 based level of range being started. If an error occurs a 508 | * negative value is returned. 509 | * 510 | * \par Example: 511 | * \code 512 | * nvtxEventAttributes_t eventAttrib = {0}; 513 | * eventAttrib.version = NVTX_VERSION; 514 | * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; 515 | * eventAttrib.colorType = NVTX_COLOR_ARGB; 516 | * eventAttrib.color = 0xFFFF0000; 517 | * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; 518 | * eventAttrib.message.ascii = "Level 0"; 519 | * nvtxRangePushEx(&eventAttrib); 520 | * 521 | * // Re-use eventAttrib 522 | * eventAttrib.messageType = NVTX_MESSAGE_TYPE_UNICODE; 523 | * eventAttrib.message.unicode = L"Level 1"; 524 | * nvtxRangePushEx(&eventAttrib); 525 | * 526 | * nvtxRangePop(); 527 | * nvtxRangePop(); 528 | * \endcode 529 | * 530 | * \sa 531 | * ::nvtxRangePop 532 | * 533 | * \version \NVTX_VERSION_1 534 | * @{ */ 535 | NVTX_DECLSPEC int NVTX_API nvtxRangePushEx(const nvtxEventAttributes_t* eventAttrib); 536 | /** @} */ 537 | 538 | /* ------------------------------------------------------------------------- */ 539 | /** \brief Marks the start of a nested range 540 | * 541 | * \param message - The event message associated to this range event. 542 | * 543 | * \return The 0 based level of range being started. If an error occurs a 544 | * negative value is returned. 545 | * 546 | * \par Example: 547 | * \code 548 | * nvtxRangePushA("Level 0"); 549 | * nvtxRangePushW(L"Level 1"); 550 | * nvtxRangePop(); 551 | * nvtxRangePop(); 552 | * \endcode 553 | * 554 | * \sa 555 | * ::nvtxRangePop 556 | * 557 | * \version \NVTX_VERSION_0 558 | * @{ */ 559 | NVTX_DECLSPEC int NVTX_API nvtxRangePushA(const char* message); 560 | NVTX_DECLSPEC int NVTX_API nvtxRangePushW(const wchar_t* message); 561 | /** @} */ 562 | 563 | /* ------------------------------------------------------------------------- */ 564 | /** \brief Marks the end of a nested range 565 | * 566 | * \return The level of the range being ended. If an error occurs a negative 567 | * value is returned on the current thread. 568 | * 569 | * \sa 570 | * ::nvtxRangePushEx 571 | * ::nvtxRangePushA 572 | * ::nvtxRangePushW 573 | * 574 | * \version \NVTX_VERSION_0 575 | * @{ */ 576 | NVTX_DECLSPEC int NVTX_API nvtxRangePop(void); 577 | /** @} */ 578 | 579 | /** @} */ 580 | 581 | /* ========================================================================= */ 582 | /** \defgroup RESOURCE_NAMING Resource Naming 583 | * 584 | * This section covers calls that allow to annotate objects with user-provided 585 | * names in order to allow for a better analysis of complex trace data. All of 586 | * the functions take the handle or the ID of the object to name and the name. 587 | * The functions can be called multiple times during the execution of an 588 | * application, however, in that case it is implementation dependent which 589 | * name will be reported by the tool. 590 | * 591 | * \section RESOURCE_NAMING_NVTX NVTX Resource Naming 592 | * The NVIDIA Tools Extension library allows to attribute events with additional 593 | * information such as category IDs. These category IDs can be annotated with 594 | * user-provided names using the respective resource naming functions. 595 | * 596 | * \section RESOURCE_NAMING_OS OS Resource Naming 597 | * In order to enable a tool to report system threads not just by their thread 598 | * identifier, the NVIDIA Tools Extension library allows to provide user-given 599 | * names to these OS resources. 600 | * @{ 601 | */ 602 | 603 | /* ------------------------------------------------------------------------- */ 604 | /** \name Functions for NVTX Resource Naming 605 | */ 606 | /** @{ 607 | * \brief Annotate an NVTX category. 608 | * 609 | * Categories are used to group sets of events. Each category is identified 610 | * through a unique ID and that ID is passed into any of the marker/range 611 | * events to assign that event to a specific category. The nvtxNameCategory 612 | * function calls allow the user to assign a name to a category ID. 613 | * 614 | * \param category - The category ID to name. 615 | * \param name - The name of the category. 616 | * 617 | * \remarks The category names are tracked per process. 618 | * 619 | * \par Example: 620 | * \code 621 | * nvtxNameCategory(1, "Memory Allocation"); 622 | * nvtxNameCategory(2, "Memory Transfer"); 623 | * nvtxNameCategory(3, "Memory Object Lifetime"); 624 | * \endcode 625 | * 626 | * \version \NVTX_VERSION_1 627 | */ 628 | NVTX_DECLSPEC void NVTX_API nvtxNameCategoryA(uint32_t category, const char* name); 629 | NVTX_DECLSPEC void NVTX_API nvtxNameCategoryW(uint32_t category, const wchar_t* name); 630 | /** @} */ 631 | 632 | /* ------------------------------------------------------------------------- */ 633 | /** \name Functions for OS Resource Naming 634 | */ 635 | /** @{ 636 | * \brief Annotate an OS thread. 637 | * 638 | * Allows the user to name an active thread of the current process. If an 639 | * invalid thread ID is provided or a thread ID from a different process is 640 | * used the behavior of the tool is implementation dependent. 641 | * 642 | * \param threadId - The ID of the thread to name. 643 | * \param name - The name of the thread. 644 | * 645 | * \par Example: 646 | * \code 647 | * nvtxNameOsThread(GetCurrentThreadId(), "MAIN_THREAD"); 648 | * \endcode 649 | * 650 | * \version \NVTX_VERSION_1 651 | */ 652 | NVTX_DECLSPEC void NVTX_API nvtxNameOsThreadA(uint32_t threadId, const char* name); 653 | NVTX_DECLSPEC void NVTX_API nvtxNameOsThreadW(uint32_t threadId, const wchar_t* name); 654 | /** @} */ 655 | 656 | /** @} */ /* END RESOURCE_NAMING */ 657 | 658 | /* ========================================================================= */ 659 | 660 | #ifdef UNICODE 661 | #define nvtxMark nvtxMarkW 662 | #define nvtxRangeStart nvtxRangeStartW 663 | #define nvtxRangePush nvtxRangePushW 664 | #define nvtxNameCategory nvtxNameCategoryW 665 | #define nvtxNameOsThread nvtxNameOsThreadW 666 | #else 667 | #define nvtxMark nvtxMarkA 668 | #define nvtxRangeStart nvtxRangeStartA 669 | #define nvtxRangePush nvtxRangePushA 670 | #define nvtxNameCategory nvtxNameCategoryA 671 | #define nvtxNameOsThread nvtxNameOsThreadA 672 | #endif 673 | 674 | #ifdef __cplusplus 675 | } 676 | #endif /* __cplusplus */ 677 | 678 | #endif /* NVTOOLSEXT_H_ */ 679 | -------------------------------------------------------------------------------- /src/reyes/thirdparty/nvToolsExt32_1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/nvToolsExt32_1.dll -------------------------------------------------------------------------------- /src/reyes/thirdparty/nvToolsExt32_1.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/nvToolsExt32_1.lib -------------------------------------------------------------------------------- /src/reyes/thirdparty/nvToolsExt64_1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/nvToolsExt64_1.dll -------------------------------------------------------------------------------- /src/reyes/thirdparty/nvToolsExt64_1.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abstractalgo/reyes/19959ec9e51b39a518dabc2a4d44077671f94c98/src/reyes/thirdparty/nvToolsExt64_1.lib -------------------------------------------------------------------------------- /src/reyes/uvmat.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "shading.hpp" 4 | 5 | namespace reyes 6 | { 7 | namespace lib 8 | { 9 | MATERIAL(UVColor) 10 | { 11 | struct uniform_tag 12 | { 13 | vec3 S; 14 | vec3 T; 15 | } uniform; 16 | DISPLACE 17 | { 18 | return vertex.p * uniform.S + uniform.T; 19 | } 20 | 21 | SHADE 22 | { 23 | return{ vertex.uv.x, vertex.uv.y, 0, 1 }; 24 | } 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /src/reyes/vecmx.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define M_E 2.71828182845904523536 7 | #define M_LOG2E 1.44269504088896340736 8 | #define M_LOG10E 0.434294481903251827651 9 | #define M_LN2 0.693147180559945309417 10 | #define M_LN10 2.30258509299404568402 11 | #define M_PI 3.14159265358979323846 12 | #define M_PI_2 1.57079632679489661923 13 | #define M_PI_4 0.785398163397448309616 14 | #define M_1_PI 0.318309886183790671538 15 | #define M_2_PI 0.636619772367581343076 16 | #define M_1_SQRTPI 0.564189583547756286948 17 | #define M_2_SQRTPI 1.12837916709551257390 18 | #define M_SQRT2 1.41421356237309504880 19 | #define M_SQRT_2 0.707106781186547524401 20 | 21 | namespace reyes 22 | { 23 | 24 | 25 | struct vec2 26 | { 27 | float x, y; 28 | 29 | vec2(float _x = 0.0, float _y = 0.0) 30 | : x(_x) 31 | , y(_y) 32 | {} 33 | 34 | float len() 35 | { 36 | return sqrt(x*x + y*y); 37 | } 38 | vec2& normalize() 39 | { 40 | float l = len(); 41 | if (l > 0.00001) 42 | *this /= l; 43 | return *this; 44 | } 45 | vec2& operator=(vec2& v) 46 | { 47 | x = v.x; 48 | y = v.y; 49 | return *this; 50 | } 51 | vec2 operator-(vec2& v) 52 | { 53 | return vec2(x - v.x, y - v.y); 54 | } 55 | vec2& operator-=(vec2& v) 56 | { 57 | return *this = *this - v; 58 | } 59 | vec2 operator+(vec2& v) 60 | { 61 | return vec2(x + v.x, y + v.y); 62 | } 63 | vec2& operator+=(vec2& v) 64 | { 65 | return *this = *this + v; 66 | } 67 | vec2 operator/(float s) 68 | { 69 | return vec2(x / s, y / s); 70 | } 71 | vec2& operator/=(float s) 72 | { 73 | return *this = *this / s; 74 | } 75 | vec2 operator*(float s) 76 | { 77 | return vec2(x * s, y * s); 78 | } 79 | vec2& operator*=(float s) 80 | { 81 | return *this = *this * s; 82 | } 83 | float operator*(vec2& v) 84 | { 85 | return x*v.y - y*v.x; 86 | } 87 | }; 88 | 89 | struct vec3 90 | { 91 | float x, y, z; 92 | 93 | vec3(float _x = 0.0, float _y = 0.0, float _z = 0.0) 94 | : x(_x) 95 | , y(_y) 96 | , z(_z) 97 | {} 98 | 99 | float len() 100 | { 101 | return sqrt(x*x + y*y + z*z); 102 | } 103 | vec3& normalize() 104 | { 105 | float l = len(); 106 | if (l > 0.00001) 107 | *this /= l; 108 | return *this; 109 | } 110 | vec3& operator=(vec3& v) 111 | { 112 | x = v.x; 113 | y = v.y; 114 | z = v.z; 115 | return *this; 116 | } 117 | vec3 operator-(vec3& v) 118 | { 119 | return vec3(x - v.x, y - v.y, z - v.z); 120 | } 121 | vec3& operator-=(vec3& v) 122 | { 123 | return *this = *this - v; 124 | } 125 | friend vec3 operator-(const vec3& a, const vec3& b) 126 | { 127 | return {a.x-b.x, a.y-b.y, a.z-b.z}; 128 | } 129 | vec3 operator+(vec3& v) 130 | { 131 | return vec3(x + v.x, y + v.y, z + v.z); 132 | } 133 | vec3& operator+=(vec3& v) 134 | { 135 | return *this = *this + v; 136 | } 137 | friend vec3 operator+(const vec3& a, const vec3& b) 138 | { 139 | return{ a.x + b.x, a.y + b.y, a.z + b.z }; 140 | } 141 | vec3 operator/(float s) 142 | { 143 | float is = 1.0f / s; 144 | return *this*is; 145 | } 146 | vec3& operator/=(float s) 147 | { 148 | return *this = *this / s; 149 | } 150 | friend vec3 operator/(const vec3& a, const float s) 151 | { 152 | return{ a.x / s, a.y / s, a.z / s }; 153 | } 154 | vec3 operator*(float s) 155 | { 156 | return vec3(x * s, y * s, z*s); 157 | } 158 | vec3& operator*=(float s) 159 | { 160 | return *this = *this * s; 161 | } 162 | vec3 operator*(vec3& v) 163 | { 164 | return vec3(x*v.x, y*v.y, z*v.z); 165 | } 166 | friend vec3 operator*(const vec3& a, const vec3& b) 167 | { 168 | return vec3(a.x*b.x, a.y*b.y, a.z*b.z); 169 | } 170 | friend vec3 operator*(const vec3& a, const float s) 171 | { 172 | return vec3(a.x*s, a.y*s, a.z*s); 173 | } 174 | float operator[](int i) 175 | { 176 | if (0 == i) return x; 177 | else if (1 == i) return y; 178 | else if (2 == i) return z; 179 | return 0; 180 | } 181 | friend vec3 cross(const vec3& a, const vec3& b) 182 | { 183 | float ax = a.x, ay = a.y, az = a.z; 184 | float bx = b.x, by = b.y, bz = b.z; 185 | 186 | vec3 c; 187 | c.x = ay * bz - az * by; 188 | c.y = az * bx - ax * bz; 189 | c.z = ax * by - ay * bx; 190 | return c; 191 | } 192 | }; 193 | 194 | struct vec4 195 | { 196 | float x, y, z, w; 197 | 198 | vec4(float _x = 0.0, float _y = 0.0, float _z = 0.0, float _w = 0.0) 199 | : x(_x) 200 | , y(_y) 201 | , z(_z) 202 | , w(_w) 203 | {} 204 | 205 | float len() 206 | { 207 | return sqrt(x*x + y*y + z*z + w*w); 208 | } 209 | vec4& normalize() 210 | { 211 | float l = len(); 212 | if (l > 0.00001) 213 | *this /= l; 214 | return *this; 215 | } 216 | vec4& operator=(vec4& v) 217 | { 218 | x = v.x; 219 | y = v.y; 220 | z = v.z; 221 | w = v.w; 222 | return *this; 223 | } 224 | vec4 operator-(vec4& v) 225 | { 226 | return vec4(x - v.x, y - v.y, z - v.z, w - v.w); 227 | } 228 | vec4& operator-=(vec4& v) 229 | { 230 | return *this = *this - v; 231 | } 232 | vec4 operator+(vec4& v) 233 | { 234 | return vec4(x + v.x, y + v.y, z + v.z, w + v.w); 235 | } 236 | vec4& operator+=(vec4& v) 237 | { 238 | return *this = *this + v; 239 | } 240 | vec4 operator/(float s) 241 | { 242 | float is = 1.0f / s; 243 | return *this*is; 244 | } 245 | vec4& operator/=(float s) 246 | { 247 | return *this = *this / s; 248 | } 249 | vec4 operator*(float s) 250 | { 251 | return vec4(x * s, y * s, z*s, w*s); 252 | } 253 | vec4& operator*=(float s) 254 | { 255 | return *this = *this * s; 256 | } 257 | float operator*(vec4& v) 258 | { 259 | return x*v.x + y*v.y + z*v.z + w*v.w; 260 | } 261 | 262 | float operator[](int i) 263 | { 264 | if (0 == i) return x; 265 | else if (1 == i) return y; 266 | else if (2 == i) return z; 267 | else if (3 == i) return w; 268 | return 0; 269 | } 270 | }; 271 | 272 | struct mx3 273 | { 274 | float e[9]; 275 | mx3() 276 | { 277 | for (char i = 0; i < 9; i++) 278 | e[i] = (0 == i % 4 ? 1.0f : 0.0f); 279 | } 280 | }; 281 | 282 | struct mx4 283 | { 284 | float e[16]; 285 | mx4() 286 | { 287 | for (char i = 0; i < 16; i++) 288 | e[i] = (0 == i % 5 ? 1.0f : 0.0f); 289 | } 290 | 291 | void transpose(void) 292 | { 293 | float tmp; 294 | tmp = e[1]; e[1] = e[4]; e[4] = tmp; 295 | tmp = e[2]; e[2] = e[8]; e[8] = tmp; 296 | tmp = e[6]; e[6] = e[9]; e[9] = tmp; 297 | 298 | tmp = e[3]; e[3] = e[12]; e[12] = tmp; 299 | tmp = e[7]; e[7] = e[13]; e[13] = tmp; 300 | tmp = e[11]; e[11] = e[14]; e[14] = tmp; 301 | } 302 | 303 | void orthographic(float left, float right, float bottom, float top, float near, float far) 304 | { 305 | /*float w = right - left; 306 | float h = top - bottom; 307 | float p = far - near; 308 | 309 | float x = (right + left) / w; 310 | float y = (top + bottom) / h; 311 | float z = (far + near) / p; 312 | 313 | e[0] = 2 / w; e[4] = 0; e[8] = 0; e[12] = 0; 314 | e[1] = 0; e[5] = 2 / h; e[9] = 0; e[13] = 0; 315 | e[2] = 0; e[6] = 0; e[10] = -2 / p; e[14] = 0; 316 | e[3] = -x; e[7] = -y; e[11] = -z; e[15] = 1;*/ 317 | } 318 | 319 | void frustum(float left, float right, float bottom, float top, float near, float far) 320 | { 321 | /*float x = 2 * near / (right - left); 322 | float y = 2 * near / (top - bottom); 323 | 324 | float a = (right + left) / (right - left); 325 | float b = (top + bottom) / (top - bottom); 326 | float c = -(far + near) / (far - near); 327 | float d = -2 * far * near / (far - near); 328 | 329 | e[0] = x; e[4] = 0; e[8] = a; e[12] = 0; 330 | e[1] = 0; e[5] = y; e[9] = b; e[13] = 0; 331 | e[2] = 0; e[6] = 0; e[10] = c; e[14] = d; 332 | e[3] = 0; e[7] = 0; e[11] = -1; e[15] = 0; 333 | 334 | transpose();*/ 335 | } 336 | 337 | void lookAt(const vec3 eye, const vec3 target, const vec3 up) 338 | { 339 | vec3 z = (eye-target).normalize(); 340 | 341 | if (z.len() ==0 ) 342 | z.z = 1; 343 | 344 | vec3 x = cross(up, z).normalize(); 345 | 346 | if (x.len() == 0) { 347 | z.x += 0.0001f; 348 | x = cross(up, z).normalize(); 349 | } 350 | 351 | vec3 y = cross(z, x); 352 | 353 | 354 | e[0] = x.x; e[4] = y.x; e[8] = z.x; 355 | e[1] = x.y; e[5] = y.y; e[9] = z.y; 356 | e[2] = x.z; e[6] = y.z; e[10] = z.z; 357 | } 358 | 359 | vec4 operator*(vec4& v) 360 | { 361 | float x = v.x; 362 | float y = v.y; 363 | float z = v.z; 364 | float w = v.w; 365 | 366 | vec4 res; 367 | 368 | res.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w; 369 | res.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w; 370 | res.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w; 371 | res.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w; 372 | 373 | transpose(); 374 | 375 | return res; 376 | } 377 | 378 | vec4 operator*(vec3& v) 379 | { 380 | return (*this)*vec4({ v.x, v.y, v.z, 1.0f }); 381 | } 382 | }; 383 | 384 | /* Axis-algined boundig box (2D). */ 385 | struct AABB2 386 | { 387 | vec2 min, max; 388 | }; 389 | 390 | /* Axis-aligned bounding box (3D). */ 391 | struct AABB3 392 | { 393 | vec3 min, max; 394 | }; 395 | 396 | typedef vec3 position; 397 | typedef vec3 normal; 398 | } --------------------------------------------------------------------------------