├── .gitignore ├── CHANGES.md ├── LICENSE.md ├── README.md ├── build.bat ├── example-platformer-tiled.c ├── example-platformer.c ├── example-platformer.rc ├── example-tiled.c ├── example-tiled.rc ├── lib ├── gifw.h ├── json.h ├── mingw │ ├── _mingw_unicode.h │ ├── d3d10.h │ ├── d3d10_1.h │ ├── d3d10_1shader.h │ ├── d3d10effect.h │ ├── d3d10misc.h │ ├── d3d10shader.h │ ├── d3d11.h │ ├── d3d11sdklayers.h │ ├── d3dcommon.h │ ├── dsound.h │ ├── dxgi.h │ ├── dxgiformat.h │ └── dxgitype.h ├── punity-sdl.c ├── punity-tiled.h ├── stb_image.h └── stb_vorbis.c ├── main.c ├── main.rc ├── punity.h └── res ├── example-platformer ├── hit.ogg ├── jump.ogg ├── land.ogg ├── map1.json ├── map_test.json ├── music.ogg ├── src │ ├── tileset-minimal.psd │ └── tileset.psd ├── tileset.json └── tileset.png ├── font-4x10.png ├── font-4x7.png └── icon.ico /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | tutorial 3 | lib/punity-file-watcher.c 4 | lib/SDL 5 | lib/GL 6 | lib/lua51 7 | lib/luajit 8 | lib/punity-directx 9 | .idea 10 | .vs 11 | main.aps 12 | NOTES.md 13 | Punity.sublime-project 14 | Punity.sublime-workspace 15 | import.lua 16 | lunity 17 | tools -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Version 2.3 2 | 3 | - Update `example-platformer` to use Tiled maps. 4 | - Fixed bug in `panic_` (used by ASSERT and ASSERT_MESSAGE). 5 | - Fixed bug in `scene_entity_add` caused by misedits in Sublime. GAH! 6 | 7 | # Version 2.2 8 | 9 | - Added tiled format support (still experimental; see example-tiled). 10 | - Added `Tile` and `TileMap` structs to join Tiled format and collision detection in scene. 11 | - Removed tilemap from scene. 12 | - OpenGL canvas now centers canvas correctly in fullscreen. 13 | - Getting system keys now works (Alt+F4 is still reserved for system). 14 | - Fixed MinGW/GCC support. 15 | - Added `sound_stop` to stop all instances of playing sound. 16 | - Changed signature of `tile_draw` (index is now second argument). 17 | - Added support for Visual Studio 2013 (build with 64-bit version of compiler). 18 | 19 | # Version 2.1 20 | 21 | - Major cleanup of stuff not essential, or rarely used, or just plain stupid. 22 | - Removed `file_*` functions. 23 | - Removed `string_*` functions. 24 | - Removed `V2f` and `V2`, as those are not essential. 25 | - Removed `perf_from()`, `perf_to()`, `perf_delta()` 26 | - Removed `Font` struct (superseded by Bitmap as it now stores tile_width and tile_height). 27 | 28 | # Version 2.0 29 | 30 | - Switched to single file `punity.h`. 31 | - Removed the need for `config.h`. 32 | - Added GIF recording. 33 | - Depends on `lib/gifw.h`. 34 | - Forced to 30fps. (even if Punity runs on 60fps) 35 | - Call `record_begin()` to start recording. 36 | - Call `record_end()` to end recording and save the recording to `record.gif`. 37 | - Saving the `gif` might take longer time so the frame in which the record_end() is called 38 | will take longer than 30 or 60fps (depending on your settings). 39 | - Added SDL runtime. (still work-in-progress) 40 | - Depends on `lib/punity-sdl.c`. 41 | - `SDL2.dll` has to be distributed with the executable. 42 | - Build with `build sdl` 43 | - Reorganized `main()`, better platform code separation. 44 | - Added entity and collision system. 45 | - Customizable `SceneEntity` struct with `PUN_SCENE_ENTITY_CUSTOM`. 46 | - Uses `SpatialHash` for entities. 47 | - Uses fixed tile map for static colliders. 48 | - Much faster than adding each tile to `SpatialHash`. 49 | - Integer-only without need to fiddle with float epsilons. 50 | - Uses `Deque` to store "unlimited amount" of entities. 51 | - Use `entity_add` / `entity_remove` to add or remove entities. 52 | - Use `entity_move_x`, `entity_move_y` to move your entities. 53 | - Reworked `build.bat`. 54 | - Now able to build different targets than `main.c` (i.e. build examples/example-platformer) 55 | - Arguments can be in any order. 56 | - Added PUNITY_OPENGL_30FPS to disable forcing framerate to 30fps. 57 | - Removed DirectX support (moved to a separate module that will be optional in the future). 58 | - This change has been made to keep the runtime layer in `punity.h` file as simple as possible. 59 | - Changed `init` signature to return `int` to be able to exit in case of error. 60 | - Changed `Bank` now reserves given capacity and commits when needed. 61 | - Changed `file_read` now takes optional `bank` pointer to store the file, if it's 0 then it'll use malloc() 62 | - Changed COLOR_CHANNELS to PUNITY_COLOR_CHANNELS 63 | - Added `configure` callback now added to do runtime configuration for some options (see CoreConfig) 64 | - Added `window_title(title)` to set the title of the window dynamically. 65 | - Added `window_fullscreen_toggle()` to maximize the window to fullscreen and back. 66 | - Added `Deque` for dynamic allocations. 67 | - Added `pixel_draw` 68 | - Added `line_draw` 69 | - Added `color_set` to set color at given index in the palette. 70 | - Added `frame_draw` to draw rectangle outlines. 71 | - Added `CORE->time`. 72 | - Moved `color_lerp` is now in header file. 73 | - Added `CORE->key_text` and `CORE->key_text_length` to be able to work with text input. 74 | - Fixed bug with drawing bitmaps higher than the screen. 75 | - Removed `PUN_COLOR_BLACK` and `PUN_COLOR_WHITE`. 76 | 77 | # Version 1.6 78 | 79 | - Version actually used for Ludum Dare and Low-Rez jams. 80 | - "Cherchez" has been made with this version: https://martincohen.itch.io/cherchez 81 | - All the configuration macros are now prefixed with PUN_ 82 | - Fixed bug in sound mixing. 83 | - All rendering properties are now stored in dedicated `Canvas` struct. 84 | - Added simple randomization functions (see the documentation). 85 | - Added `file_write` function to accompany `file_read`. 86 | - Added basic `V2f` struct and functions. 87 | - Added vertical flipping for `bitmap_draw` function. 88 | - Reworked `bitmap_draw` function. 89 | - Added drawing list support (see the documentation). 90 | - Added `*_push` functions for pushing draw operations to draw list (see the documentation) 91 | 92 | # Version 1.5 93 | 94 | - Renamed configuration macros to use PUN_* prefix 95 | - PUN_MAIN can now be used to not define the main entry function. 96 | - Forced PUN_COLOR_BLACK to 1 and PUN_COLOR_WHITE to 2. 97 | - Changed bitmap_draw signature to have Bitmap* at the beginning. 98 | - Changed text_draw signature to have const char* at the beginning. 99 | - Translation direction changed in bitmap_draw() and text_draw(). 100 | 101 | # Version 1.4 102 | 103 | - Fixed audio clipping problems by providing a soft-clip. 104 | - Added master and per-sound volume controls. 105 | 106 | # Version 1.3 107 | 108 | - Fixed RGB in bitmap loader on Windows. 109 | 110 | # Version 1.2 111 | 112 | - Replaced usage of `_` prefixes with `PUNP_` prefixes to not violate reserved identifiers. 113 | 114 | # Version 1.1 115 | 116 | - Fixed timing issues and frame counting. 117 | - Fixed KEY_* constants being not correct for Windows platform. 118 | - Added draw_rect(). 119 | 120 | # Version 1.0 121 | 122 | - Initial release 123 | 124 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Martin Cohen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Punity 2 | 3 | A tiny game engine with zero dependencies in C that I made for myself to make tiny games. It's great for game jams. It is also my kōhai course in simplicity and a tribute to my senpai and friend [rxi](https://twitter.com/x_rxi). 4 | 5 | - Single file: `punity.h` all ready for you to start working. (maybe also grab `build.bat` when you're at it) 6 | - Approx. 6000 lines of C code. 7 | - No dependencies. 8 | - Produces a single executable with all resources baked to it. 9 | - Images in PNG, JPG, PSD, TGA, GIF, BMP, HDR, PIC, PNM when used with `stb_image`. (see **Integration** below) 10 | - Sounds in OGG when used with `stb_vorbis`. (see **Integration** below) 11 | - Drawing bitmaps, texts and standard primitives all in software, this is *feature*, shut up! 12 | - Deferred drawing through draw lists. 13 | - Sounds, fonts and bitmap API available. 14 | - Built in GIF recorder (outputs `record.gif` file). 15 | - Example included (see `example-platformer.c`). 16 | - Experimental integration with SDL2 (build with `build sdl`, see `lib/punity-sdl.c`). 17 | 18 | ## Speed 19 | 20 | On an average machine, a game [33 grams](https://martincohen.itch.io/33-grams) utilizing previous version of Punity runs in 240x240 at ~20μs per frame (equivalent of ~50000 FPS). On [GCW Zero](http://www.gcw-zero.com/specifications), the same game in 320x240 runs between 0.7ms to 2ms per frame (equivalent of ~500-1500 FPS). 21 | 22 | ## Limitations 23 | 24 | - Perfect for use with 320x240 resolution. No one will ever need more, anyway. 25 | - Perfect for simple pixel art with only 255 colors (0 reserved for transparency)! 26 | - No need to worry about 8 bits of transparency, because you just get one! 27 | - Optionaly limited to 30 frames per second that gives you them retro feels! 28 | - Windows is supported directly, other platforms (*nix, Mac OS X, Android, Dingus, etc.) via SDL-2 (see [lib/punity-sdl.c](./lib/punity-sdl.c)) 29 | 30 | ## Goals 31 | 32 | - **Ready-to-go instant package.** No tedious external dependencies or fussing around with linkers: download, code and build from a single package. 33 | - **Simplicity and minimalism.** Rather go for limitations than complexities. 34 | - **Portability** Only get absolute minimum from the platform (window, input and drawing/audio buffers). 35 | - **Optional additional features.** Plug & play addons for additional asset file formats, platforms or even scripting. 36 | - **No arbitrary limitations.** All the limitations in the system have their reasons (performance, API simplicity). You might be writing a retro game, but the devices today have a lot of memory and computational power to use. 37 | - **One file.** Even though it's supposed to be a ready-to-go package, the essence is in a single file that you can grab and use. 38 | 39 | One of the most important parts of Punity is that it's made to be changed and edited as you need. That way the code can be really simple only giving you basic features and doesn't need to worry about customizations and abstractions. 40 | 41 | # Documentation 42 | 43 | Please, see the [documentation in Wiki](https://github.com/martincohen/Punity/wiki). 44 | 45 | ## Files 46 | 47 | - `lib/stb_image.h` - Optional library to load images. 48 | - `lib/stb_vorbis.c` - Optional library to load ogg audio files. 49 | - `lib/gifw.h` - Optional library to record and save GIFs. 50 | - `build.bat` - MSVC and MinGW build batch file. 51 | - `main.c` - Minimal template for jump-start game development. 52 | - `main.rc` - Part of the template. 53 | - `punity.h` - Punity's header/implementation file. 54 | 55 | In case you use MinGW, then you'll also need these: 56 | 57 | - `mingw/_mingw_unicode.h` & `mingw/dsound.h` - Provided for your convenience to be able to build with default MinGW installation. This file is taken from MinGW-W64 project. 58 | 59 | 60 | # Contributors 61 | 62 | - [@d7samurai](https://twitter.com/d7samurai) 63 | - [@x_rxi](https://twitter.com/x_rxi) 64 | 65 | # Thank you 66 | 67 | To everyone who gives Punity it a try, plus these awesome guys: 68 | 69 | - [@j_vanrijn](https://twitter.com/J_vanRijn) for his tall support 24/7. 70 | - [@cmuratori](https://twitter.com/cmuratori) for handmadehero.org 71 | - [@nothings](https://twitter.com/nothings) for [stb](https://github.com/nothings/stb). 72 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableextensions enabledelayedexpansion 3 | 4 | set target=main 5 | set target_c=%target% 6 | set target_rc=%target% 7 | set target_exe=%target% 8 | set target_flag=PUN_TARGET_MAIN 9 | set compiler=cl 10 | set configuration=debug 11 | set runtime=PUN_RUNTIME_WINDOWS 12 | set platform=PUN_PLATFORM_WINDOWS 13 | set luajit=0 14 | 15 | if not exist bin mkdir bin 16 | if not exist bin\examples mkdir bin\examples 17 | if not exist bin\lunity mkdir bin\lunity 18 | 19 | if exist import.bat ( 20 | call "import" 21 | ) 22 | 23 | for %%a in (%*) do ( 24 | if "%%a"=="gcc" ( 25 | set compiler=gcc 26 | ) else if "%%a"=="cl" ( 27 | set compiler=cl 28 | ) else if "%%a"=="debug" ( 29 | set configuration=debug 30 | ) else if "%%a"=="release" ( 31 | set configuration=release 32 | ) else if "%%a"=="sdl" ( 33 | set runtime=sdl 34 | ) else if "%%a"=="luajit" ( 35 | set luajit=1 36 | ) else if "%%a"=="lunity" ( 37 | set target_flag=PUN_TARGET_LUNITY 38 | set target=lunity/lunity 39 | set target_rc=lunity/lunity 40 | ) else ( 41 | set target=%%a 42 | set target_rc=%%a 43 | ) 44 | ) 45 | 46 | if not exist "%target_rc%.rc" ( 47 | echo - WARNING: Set target resource file to `main.rc` as `%target_rc%.rc` was not found. 48 | set target_rc=main 49 | ) 50 | 51 | set target_c=%target%.c 52 | set target_rc=%target% 53 | 54 | echo ------------------------------------------------- 55 | echo - Compiler: %compiler% 56 | echo - Configuration: %configuration% 57 | echo - Runtime: %runtime% 58 | echo - Target C: %target% 59 | echo - Target RC: %target_rc%.rc 60 | echo - Output: bin\%target%.exe 61 | if "%luajit%"=="1" ( 62 | echo + LuaJIT 63 | ) 64 | echo ------------------------------------------------- 65 | 66 | if "%compiler%"=="cl" ( 67 | rem MT for statically linked CRT, MD for dynamically linked CRT 68 | set win_runtime_lib=MD 69 | set common_c=..\!target_c! /Fe!target!.exe -nologo -D_WIN32_WINNT=0x0501 -D!runtime!=1 -D!platform!=1 -D!target_flag!=1 -TC -FC -EHa- -I..\ -I..\lib 70 | set common_l=/OPT:REF user32.lib gdi32.lib winmm.lib !target!.res 71 | 72 | if "%target%"=="lunity/lunity" ( 73 | if "%luajit%"=="1" ( 74 | set common_c=..\lib\stb_vorbis.c !common_c! -I..\lib\luajit\src 75 | set common_l=!common_l! -LIBPATH:..\lib\luajit\src lua51.lib 76 | if not exist bin\lunity\lua51.dll copy lib\luajit\src\lua51.dll bin\lunity\ 77 | ) else ( 78 | set common_c=..\lib\stb_vorbis.c ..\lib\lua51\*.c !common_c! -I..\lib\lua51 79 | ) 80 | ) 81 | 82 | if "%runtime%"=="sdl" ( 83 | set common_c=!common_c! -DPUN_RUNTIME_SDL=1 -I..\lib\SDL\include 84 | set common_l=/SUBSYSTEM:WINDOWS /INCREMENTAL:NO !common_l! -LIBPATH:..\lib\SDL\lib\x86 SDL2main.lib SDL2.lib opengl32.lib 85 | if not exist bin\SDL2.dll copy lib\SDL\lib\x86\SDL2.dll bin\ 86 | ) else ( 87 | set common_c=!common_c! -DPUN_RUNTIME_WINDOWS=1 88 | ) 89 | 90 | rem if "%configuration%"=="release" ( 91 | rem echo. 92 | rem echo Building release shaders... 93 | rem fxc /nologo /T ps_4_0 /Fo res/default.cso res/default.hlsl 94 | rem ) else ( 95 | rem echo. 96 | rem echo Building debug shaders... 97 | rem fxc /nologo /Od /Zi /T ps_4_0 /Fo res/default.cso res/default.hlsl 98 | rem ) 99 | 100 | echo. 101 | echo Building resources... 102 | rc /nologo /fo bin\!target!.res !target_rc!.rc 103 | 104 | echo. 105 | echo Compiling... 106 | pushd bin 107 | if "%configuration%"=="release" ( 108 | echo Release... 109 | if "!win_runtime_lib!"=="MD" ( 110 | echo Applying special compiler and linker options... 111 | ) 112 | cl !common_c! -!win_runtime_lib! -O2 -DPUN_RELEASE_BUILD=1 -Gy -Oy /link !common_l! 113 | strip !target!.exe 114 | ) else if "%configuration%"=="release_debug" ( 115 | cl !common_c! -!win_runtime_lib! -O2 -DPUN_RELEASE_BUILD=1 -Gy -Oy -Z7 /link !common_l! 116 | ) else ( 117 | cl !common_c! -!win_runtime_lib!d -Od -Z7 /link !common_l! 118 | ) 119 | popd 120 | 121 | ) else if "%compiler%"=="gcc" ( 122 | 123 | set common_c=!target_c! -std=gnu99 -mssse3 -o ./bin/!target!.exe ./bin/!target_rc!.o -D!runtime!=1 -D!platform!=1 -D!target_flag!=1 -D_WIN32_WINNT=0x0501 -I./lib -I./lib/mingw -I. 124 | set common_l=-luser32 -lgdi32 -lwinmm -lopengl32 125 | if "%target%"=="lunity/lunity" ( 126 | if "%luajit%"=="1" ( 127 | set common_c=./lib/stb_vorbis.c ./lib/luajit/src/luajit.o !common_c! -I./lib/luajit/src 128 | set common_l=-L./lib/luajit/src -llua51 !common_l! 129 | if not exist ./bin/lunity/lua51.dll copy ./lib/luajit/src/lua51.dll ./bin/lunity/ 130 | ) else ( 131 | set common_c=./lib/stb_vorbis.c ./lib/lua51/*.c !common_c! -I./lib/lua51 132 | ) 133 | ) 134 | 135 | rem TODO: SDL 136 | 137 | echo. 138 | echo Building resources... 139 | windres -i !target_rc!.rc -o bin/!target_rc!.o 140 | 141 | echo. 142 | echo Compiling... 143 | if "%configuration%"=="release" ( 144 | gcc !common_c! -O2 -DPUN_RELEASE_BUILD=1 -mwindows !common_l! 145 | echo Stripping... 146 | strip ./bin/!target!.exe 147 | ) else ( 148 | echo Building debug... 149 | gcc -g !common_c! !common_l! 150 | ) 151 | 152 | ) else ( 153 | echo Invalid compiler specified. 154 | ) 155 | 156 | goto :end 157 | 158 | :failed 159 | echo. 160 | echo Build failed. 161 | 162 | :end -------------------------------------------------------------------------------- /example-platformer-tiled.c: -------------------------------------------------------------------------------- 1 | // Build with: build example-platformer 2 | 3 | // TODO: Player sprite and animation (walk, jump) 4 | // TODO: Death condition. 5 | // TODO: Camera. 6 | // TODO: Parallax. 7 | 8 | #define PUNITY_IMPLEMENTATION 9 | #include "punity.h" 10 | 11 | #define TILED_IMPLEMENTATION 12 | #include "punity-tiled.h" 13 | 14 | typedef struct 15 | { 16 | SceneEntity *E; 17 | int jump; 18 | int fall; 19 | int grounded; 20 | } 21 | Player; 22 | 23 | typedef struct Game_ 24 | { 25 | Bitmap font; 26 | Scene scene; 27 | TiledScene scene1; 28 | Bitmap tileset; 29 | Sound sound_jump; 30 | Sound sound_land; 31 | 32 | Player player1; 33 | Player player2; 34 | } 35 | Game; 36 | 37 | static Game *GAME = 0; 38 | 39 | enum { 40 | SceneLayer_Ground = 1 << 0, 41 | SceneLayer_Player = 1 << 1, 42 | }; 43 | 44 | // 45 | // Player 46 | // 47 | 48 | void 49 | player_init(Player *P, TiledItem *item) 50 | { 51 | P->E = scene_entity_add(&GAME->scene, 52 | item->rect, 53 | SceneLayer_Player, 54 | SceneLayer_Player | SceneLayer_Ground); 55 | P->jump = 0; 56 | P->fall = 1; 57 | } 58 | 59 | void 60 | player_step(Player *P, int key_left, int key_right, int key_jump) 61 | { 62 | Collision C = {0}; 63 | 64 | // Left & right. 65 | 66 | int dx = 0; 67 | if (key_right) { dx = +1; } 68 | if (key_left) { dx = -1; } 69 | scene_entity_move_x(&GAME->scene, P->E, dx * 2, &C); 70 | 71 | // Jump & fall. 72 | 73 | static int PLAYER_JUMP[] = { 5, 4, 3, 2, 2, 1, 1, 1 }; 74 | 75 | if (key_jump && P->grounded) { 76 | P->jump = 1; 77 | sound_play(&GAME->sound_jump); 78 | } 79 | 80 | if (!P->jump) { 81 | P->fall = minimum(P->fall + 1, 16); 82 | if (!scene_entity_move_y(&GAME->scene, P->E, P->fall, &C)) { 83 | if (!P->grounded) { 84 | sound_play(&GAME->sound_land); 85 | P->grounded = 1; 86 | } 87 | P->fall = 2; 88 | } else { 89 | P->grounded = 0; 90 | } 91 | } else { 92 | P->grounded = 0; 93 | P->jump++; 94 | if (P->jump >= array_count(PLAYER_JUMP) || 95 | scene_entity_move_y(&GAME->scene, P->E, -(PLAYER_JUMP[P->jump - 1] * 2), &C) == false) 96 | { 97 | P->jump = 0; 98 | } 99 | } 100 | 101 | // Draw the player. 102 | rect_draw_push(P->E->box, 2, 10); 103 | } 104 | 105 | // 106 | // Scene 107 | // 108 | 109 | int 110 | scene_setup(TiledScene *tiled_scene) 111 | { 112 | // EXAMPLE FOR QUICK SETUP: 113 | // Set this tilemap as base for collision detection. 114 | // GAME->scene.tilemap = &tiledscene_find(tiled_scene, "base", 0)->tilemap; 115 | // Set player from `player` rectangle object. 116 | // player_init(&GAME->player1, tiledscene_find(tiled_scene, "player", 0)->item); 117 | 118 | // MORE ADVANCED SETUP: 119 | // Initialize entities. 120 | for (TiledItem *item = tiled_scene->items; 121 | item != tiled_scene->items_end; 122 | item = tileditem_next(item)) 123 | { 124 | switch (item->type) 125 | { 126 | case TiledType_TileMap: 127 | if (strcmp(item->name, "base")) { 128 | GAME->scene.tilemap = &item->tilemap; 129 | } 130 | break; 131 | case TiledType_Rectangle: 132 | if (strcmp(item->name, "player") == 0) { 133 | player_init(&GAME->player1, item); 134 | } 135 | break; 136 | case TiledType_Image: 137 | break; 138 | } 139 | } 140 | 141 | return 1; 142 | } 143 | 144 | // 145 | // Game 146 | // 147 | 148 | int 149 | init() 150 | { 151 | CORE->window.width = 16 * 8; 152 | CORE->window.height = 16 * 8; 153 | CORE->window.scale = 5; 154 | 155 | GAME = bank_push_t(CORE->storage, Game, 1); 156 | 157 | sound_load_resource(&GAME->sound_jump, "jump.ogg"); 158 | sound_load_resource(&GAME->sound_land, "land.ogg"); 159 | 160 | font_load_resource(&GAME->font, "font.png", 4, 7); 161 | CORE->canvas.font = &GAME->font; 162 | 163 | bitmap_load_resource(&GAME->tileset, "tileset.png", 0); 164 | GAME->tileset.tile_width = 8; 165 | GAME->tileset.tile_height = 8; 166 | 167 | // Load scenes. 168 | Tiled tiled; 169 | tiled_init(&tiled); 170 | tiledscene_load_resource(&tiled, &GAME->scene1, "map1.json", 0, 0); 171 | tiled_free(&tiled); 172 | 173 | // Initialize game scene. 174 | scene_init(&GAME->scene, 16); 175 | 176 | // Start at first scene. 177 | scene_setup(&GAME->scene1); 178 | 179 | return 1; 180 | } 181 | 182 | void 183 | step() 184 | { 185 | canvas_clear(1); 186 | 187 | if (key_down(KEY_ESCAPE)) { 188 | CORE->running = 0; 189 | } 190 | 191 | if (key_pressed(KEY_RETURN)) { 192 | window_fullscreen_toggle(); 193 | } 194 | 195 | player_step(&GAME->player1, 196 | key_down(KEY_LEFT), key_down(KEY_RIGHT), key_pressed(KEY_UP)); 197 | 198 | player_step(&GAME->player2, 199 | key_down(KEY_A), key_down(KEY_D), key_pressed(KEY_W)); 200 | 201 | tilemap_draw(GAME->scene.tilemap); 202 | // // Draw tilemap. 203 | // int *t = tiles; 204 | // for (int y = 0; y != 16; ++y) { 205 | // for (int x = 0; x != 16; ++x, ++t) { 206 | // switch (*t) { 207 | // case 0: case 88: case 89: break; 208 | // default: 209 | // tile_draw_push(&GAME->tileset, x * 8, y * 8, *t, 4); 210 | // } 211 | // } 212 | // } 213 | 214 | char buf[256]; 215 | sprintf(buf, "%.3fms %.3f", CORE->perf_step * 1e3, CORE->time_delta); 216 | text_draw(buf, 0, 0, 2); 217 | } -------------------------------------------------------------------------------- /example-platformer.c: -------------------------------------------------------------------------------- 1 | // Build with: build example-platformer 2 | 3 | // TODO: Player sprite and animation (walk, jump) 4 | // TODO: Death condition. 5 | // TODO: Camera. 6 | // TODO: Parallax. 7 | 8 | #define PUNITY_IMPLEMENTATION 9 | #include "punity.h" 10 | 11 | enum { 12 | SceneLayer_Ground = 1 << 0, 13 | SceneLayer_Player = 1 << 1, 14 | }; 15 | 16 | #define TILEDTILE_DEFAULT_LAYER SceneLayer_Ground 17 | 18 | #define TILED_IMPLEMENTATION 19 | #include "punity-tiled.h" 20 | 21 | typedef struct 22 | { 23 | SceneEntity *E; 24 | int jump; 25 | int fall; 26 | int grounded; 27 | } 28 | Player; 29 | 30 | typedef struct Game_ 31 | { 32 | Bitmap font; 33 | Scene scene; 34 | TiledScene scene1; 35 | Bitmap tileset; 36 | Sound sound_jump; 37 | Sound sound_land; 38 | 39 | Player player; 40 | } 41 | Game; 42 | 43 | static Game *GAME = 0; 44 | 45 | // 46 | // Player 47 | // 48 | 49 | void 50 | player_init(Player *P, TiledItem *item) 51 | { 52 | P->E = scene_entity_add(&GAME->scene, 53 | item->rect, 54 | SceneLayer_Player, 55 | SceneLayer_Player | SceneLayer_Ground); 56 | P->jump = 0; 57 | P->fall = 1; 58 | } 59 | 60 | void 61 | player_step(Player *P, int key_left, int key_right, int key_jump) 62 | { 63 | Collision C = {0}; 64 | 65 | // Left & right. 66 | 67 | int dx = 0; 68 | if (key_right) { dx = +1; } 69 | if (key_left) { dx = -1; } 70 | scene_entity_move_x(&GAME->scene, P->E, dx * 2, &C); 71 | 72 | // Jump & fall. 73 | 74 | static int PLAYER_JUMP[] = { 5, 4, 3, 2, 2, 1, 1, 1 }; 75 | 76 | if (key_jump && P->grounded) { 77 | P->jump = 1; 78 | sound_play(&GAME->sound_jump); 79 | } 80 | 81 | if (!P->jump) { 82 | P->fall = minimum(P->fall + 1, 16); 83 | if (!scene_entity_move_y(&GAME->scene, P->E, P->fall, &C)) { 84 | if (!P->grounded) { 85 | sound_play(&GAME->sound_land); 86 | P->grounded = 1; 87 | } 88 | P->fall = 2; 89 | } else { 90 | P->grounded = 0; 91 | } 92 | } else { 93 | P->grounded = 0; 94 | P->jump++; 95 | if (P->jump >= array_count(PLAYER_JUMP) || 96 | scene_entity_move_y(&GAME->scene, P->E, -(PLAYER_JUMP[P->jump - 1] * 2), &C) == false) 97 | { 98 | P->jump = 0; 99 | } 100 | } 101 | 102 | // Draw the player. 103 | rect_draw_push(P->E->box, 2, 10); 104 | } 105 | 106 | // 107 | // Scene 108 | // 109 | 110 | int 111 | scene_setup(TiledScene *tiled_scene) 112 | { 113 | // EXAMPLE FOR QUICK SETUP: 114 | // Set this tilemap as base for collision detection. 115 | // GAME->scene.tilemap = &tiledscene_find(tiled_scene, "base", 0)->tilemap; 116 | // Set player from `player` rectangle object. 117 | // player_init(&GAME->player, tiledscene_find(tiled_scene, "player", 0)->item); 118 | 119 | // MORE ADVANCED SETUP: 120 | // Initialize entities. 121 | for (TiledItem *item = tiled_scene->items; 122 | item != tiled_scene->items_end; 123 | item = tileditem_next(item)) 124 | { 125 | switch (item->type) 126 | { 127 | case TiledType_TileMap: 128 | if (strcmp(item->name, "base") == 0) { 129 | GAME->scene.tilemap = &item->tilemap; 130 | } 131 | break; 132 | case TiledType_Rectangle: 133 | if (strcmp(item->name, "player") == 0) { 134 | player_init(&GAME->player, item); 135 | } 136 | break; 137 | case TiledType_Image: 138 | break; 139 | } 140 | } 141 | 142 | return 1; 143 | } 144 | 145 | // 146 | // Game 147 | // 148 | 149 | int 150 | init() 151 | { 152 | CORE->window.width = 16 * 8; 153 | CORE->window.height = 16 * 8; 154 | CORE->window.scale = 5; 155 | 156 | GAME = bank_push_t(CORE->storage, Game, 1); 157 | 158 | sound_load_resource(&GAME->sound_jump, "jump.ogg"); 159 | sound_load_resource(&GAME->sound_land, "land.ogg"); 160 | 161 | font_load_resource(&GAME->font, "font.png", 4, 7); 162 | CORE->canvas.font = &GAME->font; 163 | 164 | bitmap_load_resource(&GAME->tileset, "tileset.png", 0); 165 | GAME->tileset.tile_width = 8; 166 | GAME->tileset.tile_height = 8; 167 | 168 | // Load scenes. 169 | Tiled tiled; 170 | tiled_init(&tiled); 171 | tiledscene_load_resource(&tiled, &GAME->scene1, "map1.json", 0, 0); 172 | tiled_free(&tiled); 173 | 174 | // Initialize game scene. 175 | scene_init(&GAME->scene, 16); 176 | 177 | // Start at first scene. 178 | scene_setup(&GAME->scene1); 179 | 180 | return 1; 181 | } 182 | 183 | void 184 | step() 185 | { 186 | canvas_clear(1); 187 | 188 | if (key_down(KEY_ESCAPE)) { 189 | CORE->running = 0; 190 | } 191 | 192 | if (key_pressed(KEY_RETURN)) { 193 | window_fullscreen_toggle(); 194 | } 195 | 196 | player_step(&GAME->player, 197 | key_down(KEY_LEFT), key_down(KEY_RIGHT), key_pressed(KEY_UP)); 198 | 199 | tilemap_draw(GAME->scene.tilemap); 200 | 201 | char buf[256]; 202 | sprintf(buf, "%.3fms %.3f", CORE->perf_step * 1e3, CORE->time_delta); 203 | text_draw(buf, 0, 0, 2); 204 | } -------------------------------------------------------------------------------- /example-platformer.rc: -------------------------------------------------------------------------------- 1 | icon.ico ICON "res\\icon.ico" 2 | font.png RESOURCE "res\\font-4x7.png" 3 | 4 | tileset.png RESOURCE "res\\example-platformer\\tileset.png" 5 | jump.ogg RESOURCE "res\\example-platformer\\jump.ogg" 6 | land.ogg RESOURCE "res\\example-platformer\\land.ogg" 7 | map1.json RESOURCE "res\\example-platformer\\map1.json" -------------------------------------------------------------------------------- /example-tiled.c: -------------------------------------------------------------------------------- 1 | // Build with: build example-tiled 2 | 3 | #define PUNITY_IMPLEMENTATION 4 | #include "punity.h" 5 | 6 | #define TILED_IMPLEMENTATION 7 | #include "punity-tiled.h" 8 | 9 | 10 | typedef struct Game_ 11 | { 12 | Bitmap font; 13 | Bitmap tileset; 14 | TiledScene tiled; 15 | } 16 | Game; 17 | 18 | static Game *GAME = 0; 19 | 20 | TILED_CALLBACK(tiled_callback) 21 | { 22 | for (int i = 0; i != properties_count; ++i) { 23 | switch (properties[i].value->type) 24 | { 25 | case json_string: 26 | LOG("%s = %s\n", properties[i].name, properties[i].value->string.ptr); 27 | break; 28 | } 29 | } 30 | } 31 | 32 | int 33 | init() 34 | { 35 | CORE->window.width = 16 * 8; 36 | CORE->window.height = 16 * 8; 37 | CORE->window.scale = 5; 38 | 39 | GAME = bank_push_t(CORE->storage, Game, 1); 40 | font_load_resource(&GAME->font, "font.png", 4, 7); 41 | CORE->canvas.font = &GAME->font; 42 | 43 | f64 p = perf_get(); 44 | Tiled tiled; 45 | tiled_init(&tiled); 46 | tiledscene_load_resource(&tiled, &GAME->tiled, "map_test.json", tiled_callback, 0); 47 | tiled_free(&tiled); 48 | LOG("tiledscene_load_resource %fms\n", (perf_get() - p) * 1e3); 49 | 50 | TiledItem *item = tiledscene_find(&GAME->tiled, "Tile Layer 1", 0); 51 | ASSERT(item); 52 | ASSERT(item->type == TiledType_TileMap); 53 | 54 | return 1; 55 | } 56 | 57 | void 58 | step() 59 | { 60 | if (key_pressed(KEY_F10)) { 61 | window_fullscreen_toggle(); 62 | } 63 | 64 | canvas_clear(1); 65 | 66 | for (TiledItem *item = GAME->tiled.items; 67 | item != GAME->tiled.items_end; 68 | item = tileditem_next(item)) 69 | { 70 | switch (item->type) 71 | { 72 | case TiledType_TileMap: 73 | tilemap_draw(&item->tilemap); 74 | break; 75 | case TiledType_Rectangle: 76 | rect_draw(item->rect, 2); 77 | break; 78 | case TiledType_Image: 79 | bitmap_draw(item->tile.tileset, item->rect.min_x, item->rect.min_y, 0, 0, 0); 80 | break; 81 | } 82 | } 83 | 84 | char buf[256]; 85 | sprintf(buf, "%.3fms %.3f", CORE->perf_step * 1e3, CORE->time_delta); 86 | text_draw(buf, 0, 0, 2); 87 | } -------------------------------------------------------------------------------- /example-tiled.rc: -------------------------------------------------------------------------------- 1 | icon.ico ICON "res\\icon.ico" 2 | font.png RESOURCE "res\\font-4x7.png" 3 | 4 | tileset.png RESOURCE "res\\example-platformer\\tileset.png" 5 | map_test.json RESOURCE "res\\example-platformer\\map_test.json" 6 | tileset.json RESOURCE "res\\example-platformer\\tileset.json" -------------------------------------------------------------------------------- /lib/gifw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2016 Martin Cohen 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* 26 | 27 | Library to write animated GIF supporting all GIF features. It's made to not do 28 | any fancy stuff outside of raw GIF writing, so don't expect any palette 29 | quantizations or dithering (those might appear later as separate libraries). 30 | 31 | I made the library to have fast GIF recording in my tiny game engine Punity, 32 | as other choices were really slow because of extra features I didn't actually 33 | need. 34 | 35 | The library takes frame data (raw pixels, palette, frame properties) and does 36 | a buffered stream output through a callback function. The buffer size is 8k by default, 37 | but you can change it with: 38 | 39 | #define GIFW_WRITE_BUFFER_SIZE (...) 40 | 41 | Usage: 42 | 43 | // header only 44 | #include "gifw.h" 45 | 46 | // header+implementation 47 | #define GIFW_IMPLEMENTATION 48 | #include "gifw.h" 49 | 50 | */ 51 | 52 | #ifndef GIFW_H 53 | #define GIFW_H 54 | 55 | #ifndef GIFW_WRITE_BUFFER_SIZE 56 | #define GIFW_WRITE_BUFFER_SIZE (8192) 57 | #endif 58 | 59 | #include 60 | 61 | typedef struct GIFW_ GIFW; 62 | 63 | typedef struct GIFWColor_ 64 | { 65 | uint8_t r, g, b; 66 | } 67 | GIFWColor; 68 | 69 | typedef struct GIFWColorTable_ 70 | { 71 | GIFWColor colors[256]; 72 | int count; 73 | } 74 | GIFWColorTable; 75 | 76 | #define GIF_LZW_HASH_SIZE 5003 77 | 78 | typedef struct GIFWLZWState_ 79 | { 80 | // LZW dictionary. 81 | int16_t entries[GIF_LZW_HASH_SIZE]; 82 | // LZW dictionary cache. 83 | int32_t hash[GIF_LZW_HASH_SIZE]; 84 | 85 | uint8_t buffer[256]; 86 | uint8_t buffer_size; 87 | 88 | // Bits are being added here. 89 | uint32_t bits; 90 | // Number of bits in `bits`. 91 | uint32_t bits_count; 92 | // Current size of code being stored. 93 | uint32_t bits_size; 94 | } 95 | GIFWLZWState; 96 | 97 | #define GIFW_WRITE_CALLBACK(name) int name(GIFW *gif, uint8_t *begin, uint8_t *end, void *user) 98 | typedef GIFW_WRITE_CALLBACK(GIFWWriteCallbackF); 99 | 100 | // GIFW storage. 101 | typedef struct GIFW_ 102 | { 103 | int width; 104 | int height; 105 | int repeat; 106 | 107 | int frames_count; 108 | GIFWLZWState state; 109 | 110 | uint8_t buffer[GIFW_WRITE_BUFFER_SIZE]; 111 | int buffer_size; 112 | GIFWWriteCallbackF *callback; 113 | void *callback_user; 114 | } 115 | GIFW; 116 | 117 | enum { 118 | // No disposal specified. The decoder is 119 | // not required to take any action. 120 | // Use this as default. 121 | GIFWFrameDispose_NotSpecified = 0, 122 | 123 | // The graphic is to be left in place. 124 | GIFWFrameDispose_DoNotDispose = 1, 125 | 126 | // Restore to background color. The area used by the 127 | // graphic must be restored to the background color. 128 | GIFWFrameDispose_RestoreBackground = 2, 129 | 130 | // Restore to previous. The decoder is required to 131 | // restore the area overwritten by the graphic with 132 | // what was there prior to rendering the graphic. 133 | GIFWFrameDispose_RestorePrevious = 3, 134 | }; 135 | 136 | // Writes GIF header. 137 | // 138 | void gifw_begin 139 | ( 140 | GIFW *G, 141 | 142 | // Dimensions of the GIF. 143 | int width, int height, 144 | 145 | // Number of repeats 146 | // 0 - repeat forever 147 | // 1 - repeat once 148 | // 2 - repeat twice 149 | // ... 150 | int repeat, 151 | 152 | // Optional global color table 153 | // If set to 0, then you must provide a color_table 154 | // for each frame (see gifw_frame). 155 | GIFWColorTable *color_table, 156 | 157 | // Index to color_table for a background color. 158 | uint8_t background_color_index, 159 | 160 | // Stream writing callback and optional user data passed to the callback. 161 | GIFWWriteCallbackF *callback, void *callback_user); 162 | 163 | // Compresses and stores the frame passed. 164 | // 165 | void gifw_frame 166 | ( 167 | GIFW *G, 168 | 169 | // Pixels for the frame. 170 | uint8_t *pixels, 171 | 172 | // Optional frame color table. 173 | // If set to 0, then you must provide global color table via gifw_begin. 174 | GIFWColorTable *color_table, 175 | 176 | // Subframe position and dimensions. 177 | // This is useful if you only want to store portions that have 178 | // changed since previous frame. If that's what you're looking for, 179 | // then you also must set the dispose correctly (see enum above). 180 | uint16_t left, uint16_t top, 181 | uint16_t width, uint16_t height, 182 | 183 | // Delay is set in centiseconds. 184 | // 1 = 10 ms 185 | uint16_t delay, 186 | 187 | // Disposal method, see GIFWFrameDispose_* constants in enum above. 188 | uint8_t dispose, 189 | 190 | // Set to 1 if you want to provide a transparent color index, 191 | int transparent_color_index_flag, 192 | 193 | // Index of a color in color_table that is treated as transparent. 194 | // Note that `transparent_color_index_flag` has to be set to 1. 195 | uint8_t transparent_color_index 196 | ); 197 | 198 | 199 | // Finalizes saving the GIF image and flushes the buffer. 200 | // 201 | void gifw_end(GIFW *G); 202 | 203 | 204 | #endif 205 | 206 | 207 | // 208 | // 209 | // 210 | #ifdef GIFW_IMPLEMENTATION 211 | #undef GIFW_IMPLEMENTATION 212 | // 213 | // 214 | // 215 | 216 | #include 217 | 218 | static unsigned int 219 | gifw_log2_(unsigned int v) 220 | { 221 | register unsigned int r; 222 | register unsigned int shift; 223 | 224 | r = (v > 0xFFFF) << 4; v >>= r; 225 | shift = (v > 0xFF ) << 3; v >>= shift; r |= shift; 226 | shift = (v > 0xF ) << 2; v >>= shift; r |= shift; 227 | shift = (v > 0x3 ) << 1; v >>= shift; r |= shift; 228 | r |= (v >> 1); 229 | 230 | return r; 231 | } 232 | 233 | static void 234 | gifw_flush_(GIFW *gif) 235 | { 236 | if (gif->buffer_size != 0) { 237 | gif->callback(gif, gif->buffer, gif->buffer + gif->buffer_size, gif->callback_user); 238 | gif->buffer_size = 0; 239 | } 240 | } 241 | 242 | static void 243 | gifw_write_(GIFW *gif, void *data, int size) 244 | { 245 | int remaining, i; 246 | while (size) 247 | { 248 | remaining = GIFW_WRITE_BUFFER_SIZE - gif->buffer_size; 249 | if (!remaining) { 250 | gifw_flush_(gif); 251 | remaining = GIFW_WRITE_BUFFER_SIZE; 252 | } 253 | 254 | remaining = remaining > size ? size : remaining; 255 | memmove(gif->buffer + gif->buffer_size, data, remaining); 256 | 257 | gif->buffer_size += remaining; 258 | size -= remaining; 259 | data = ((uint8_t*)data) + remaining; 260 | if (size == 0) { 261 | break; 262 | } 263 | } 264 | } 265 | 266 | static void 267 | gifw_write_string_(GIFW *gif, const char *string, int length) 268 | { 269 | gifw_write_(gif, (void*)string, length); 270 | } 271 | 272 | #define GIFW_WRITE_(Name, Type) \ 273 | static inline void gifw_write_##Name##_(GIFW *G, Type v) \ 274 | { gifw_write_(G, &v, sizeof(Type)); } 275 | 276 | GIFW_WRITE_(u8, uint8_t); 277 | GIFW_WRITE_(i8, int8_t); 278 | GIFW_WRITE_(i16, int16_t); 279 | GIFW_WRITE_(u16, uint16_t); 280 | GIFW_WRITE_(i32, int32_t); 281 | GIFW_WRITE_(u32, uint32_t); 282 | 283 | uint32_t 284 | gifw_next_pow2_(uint32_t n) 285 | { 286 | // NOTE: Returns 0 for n == 0. 287 | n--; 288 | n |= n >> 1; // Divide by 2^k for consecutive doublings of k up to 32, 289 | n |= n >> 2; // and then or the results. 290 | n |= n >> 4; 291 | n |= n >> 8; 292 | n |= n >> 16; 293 | n++; 294 | return n; 295 | } 296 | 297 | void 298 | gifw_begin(GIFW *G, int width, int height, int repeat, 299 | GIFWColorTable *color_table, 300 | uint8_t background_color_index, 301 | GIFWWriteCallbackF *callback, void *callback_user) 302 | { 303 | memset(G, 0, sizeof(GIFW)); 304 | 305 | G->frames_count = 0; 306 | G->width = width; 307 | G->height = height; 308 | G->repeat = repeat; 309 | G->callback = callback; 310 | G->callback_user = callback_user; 311 | 312 | gifw_write_string_(G, "GIF89a", 6); 313 | 314 | gifw_write_u16_(G, G->width); 315 | gifw_write_u16_(G, G->height); 316 | 317 | // uint8_t color_table_present : 1; 318 | // uint8_t color_resolution : 3; 319 | // uint8_t sort_flag : 1; 320 | // uint8_t color_table_size : 3; 321 | uint8_t packed = 0; 322 | 323 | // Color resolution. 324 | // 8 bits per channel minus one. 325 | packed |= (8-1) << 4; 326 | 327 | // Color table size. 328 | // Calculated from this value with: 2^(1+n). 329 | uint32_t colors_count = 0; 330 | if (color_table) 331 | { 332 | colors_count = color_table->count; 333 | if (colors_count < 2) { 334 | colors_count = 2; 335 | } else if (colors_count > 256) { 336 | colors_count = 256; 337 | } 338 | colors_count = gifw_next_pow2_(colors_count); 339 | 340 | // Color table present. 341 | packed |= (uint32_t)1 << 7; 342 | // Color table size. 343 | packed |= ((uint32_t)gifw_log2_(colors_count) - 1) & 0x7; 344 | } 345 | 346 | gifw_write_u8_(G, packed); 347 | 348 | // Background color index. 349 | // This is only meaningful if global color table is present. 350 | gifw_write_u8_(G, background_color_index); 351 | // Pixel aspect ratio 352 | // Set to 0 for no aspect information is given. 353 | // See "viii) Pixel Aspect Ratio" in https://www.w3.org/Graphics/GIFW/spec-gif89a.txt. 354 | gifw_write_u8_(G, 0); 355 | 356 | // Global color table. 357 | if (color_table) { 358 | gifw_write_(G, color_table->colors, colors_count * 3); 359 | } 360 | 361 | // Application extension to store repeat value. 362 | if (G->repeat >= 0) { 363 | gifw_write_string_(G, "\x21\xff\x0bNETSCAPE2.0\x03\x01", 16); 364 | gifw_write_u16_(G, G->repeat); 365 | gifw_write_u8_(G, 0); 366 | } 367 | } 368 | 369 | void 370 | gifw_bits_flush_(GIFW *G) 371 | { 372 | if (G->state.buffer_size != 0) 373 | { 374 | // Write count of bytes in the block. 375 | gifw_write_u8_(G, G->state.buffer_size); 376 | // Write bytes in the block. 377 | gifw_write_(G, G->state.buffer, G->state.buffer_size); 378 | 379 | G->state.buffer_size = 0; 380 | } 381 | } 382 | 383 | void 384 | gifw_bits_push_(GIFW *G, uint32_t bits) 385 | { 386 | GIFWLZWState *state = &G->state; 387 | state->bits |= bits << state->bits_count; 388 | state->bits_count += state->bits_size; 389 | while (state->bits_count >= 8) 390 | { 391 | state->buffer[state->buffer_size++] = state->bits & 0xFF; 392 | state->bits >>= 8; 393 | state->bits_count -= 8; 394 | if (state->buffer_size == 0xFF) { 395 | gifw_bits_flush_(G); 396 | } 397 | } 398 | } 399 | 400 | void 401 | gifw_write_frame_raster_(GIFW *G, uint8_t *pixels, int width, int height) 402 | { 403 | GIFWLZWState *state = &G->state; 404 | memset(state, 0, sizeof(GIFWLZWState)); 405 | memset(state->hash, 0xFF, sizeof(state->hash)); 406 | 407 | // LZW Minimum Code Size 408 | gifw_write_u8_(G, 8); 409 | state->bits_size = 9; 410 | 411 | // Clear. 412 | gifw_bits_push_(G, 0x100); 413 | 414 | uint8_t *it = pixels; 415 | uint8_t *end = pixels + (width * height); 416 | 417 | uint32_t entry_max = 511; 418 | uint32_t entry_count = 0x102; 419 | int32_t hash_value, hash_key; 420 | 421 | uint32_t entry = *it++; 422 | uint32_t entry_next; 423 | 424 | repeat: 425 | while (it != end) 426 | { 427 | entry_next = *it++; 428 | // We store hash value as a pair of 2 entries (entry and entry_next). 429 | // Each entry can be of maximum 12-bits. 430 | hash_value = ((entry_next << 12) + entry); 431 | hash_key = ((entry_next << 4) ^ entry) % GIF_LZW_HASH_SIZE; 432 | while (state->hash[hash_key] >= 0) { 433 | if (state->hash[hash_key] == hash_value) { 434 | entry = state->entries[hash_key]; 435 | goto repeat; 436 | } 437 | hash_key = (hash_key + 1) % GIF_LZW_HASH_SIZE; 438 | } 439 | 440 | gifw_bits_push_(G, entry); 441 | entry = entry_next; 442 | 443 | if (entry_count < 4096) 444 | { 445 | if (entry_count > entry_max) { 446 | // Increase the code size. 447 | ++state->bits_size; 448 | if (state->bits_size == 12) { 449 | entry_max = 4096; 450 | } else { 451 | entry_max = (1 << state->bits_size) - 1; 452 | } 453 | } 454 | 455 | // Write entry index to entries. 456 | state->entries[hash_key] = entry_count++; 457 | // Write the pair of entry and entry_next to the hash. 458 | // under the same key. 459 | state->hash[hash_key] = hash_value; 460 | } 461 | else 462 | { 463 | // Clear if we reached max size of dictionary. 464 | memset(state->hash, 0xFF, sizeof(state->hash)); 465 | gifw_bits_push_(G, 0x100); 466 | state->bits_size = 9; 467 | entry_count = 0x102; 468 | entry_max = 511; 469 | } 470 | } 471 | // Push last entry. 472 | gifw_bits_push_(G, entry); 473 | // Push STOP. 474 | gifw_bits_push_(G, 0x101); 475 | gifw_bits_push_(G, 0); 476 | 477 | // Flush remaining bits. 478 | gifw_bits_flush_(G); 479 | } 480 | 481 | void 482 | gifw_frame(GIFW *G, 483 | uint8_t *pixels, 484 | GIFWColorTable *color_table, 485 | uint16_t left, uint16_t top, 486 | uint16_t width, uint16_t height, 487 | uint16_t delay, uint8_t dispose, 488 | int transparent_color_index_flag, 489 | uint8_t transparent_color_index) 490 | { 491 | G->frames_count++; 492 | 493 | uint8_t packed = 0; 494 | 495 | // GCE Introducer. 496 | gifw_write_u8_(G, 0x21); 497 | // GCE Label 498 | gifw_write_u8_(G, 0xF9); 499 | // GCE Block size. 500 | gifw_write_u8_(G, 0x04); 501 | 502 | // GCE Packed 503 | // uint8_t gce_reserved : 3; 504 | // uint8_t gce_disposal_method : 3; 505 | // uint8_t gce_user_input_flag : 1; 506 | // uint8_t gce_transparent_color_flag : 1; 507 | // header.gce_disposal_method = GIFDisposal_None; 508 | 509 | // Disposal method 510 | packed |= (dispose & 0x7) << 2; 511 | // Transparent color flag 512 | packed |= transparent_color_index_flag & 1; 513 | 514 | gifw_write_u8_(G, packed); 515 | 516 | // GCE Delay time. 517 | gifw_write_u16_(G, delay); 518 | // GCE Transparent color index. 519 | gifw_write_u8_(G, transparent_color_index); 520 | // GCE Block terminator 521 | gifw_write_u8_(G, 0); 522 | 523 | // Image separator 524 | gifw_write_u8_(G, 0x2C); 525 | // Left 526 | gifw_write_u16_(G, left); 527 | // Right 528 | gifw_write_u16_(G, top); 529 | // Width 530 | gifw_write_u16_(G, width); 531 | // Height 532 | gifw_write_u16_(G, height); 533 | 534 | // uint8_t color_table_present : 1; 535 | // uint8_t interlace_flag : 1; 536 | // uint8_t sort_flag : 1; 537 | // uint8_t reserved : 2; 538 | // uint8_t color_table_size : 3; 539 | 540 | packed = 0; 541 | 542 | uint32_t colors_count = 0; 543 | if (color_table) 544 | { 545 | colors_count = color_table->count; 546 | if (colors_count < 2) { 547 | colors_count = 2; 548 | } else if (colors_count > 256) { 549 | colors_count = 256; 550 | } 551 | colors_count = gifw_next_pow2_(colors_count); 552 | 553 | // Color table present. 554 | packed |= (uint32_t)1 << 7; 555 | // Color table size. 556 | packed |= ((uint32_t)gifw_log2_(colors_count) - 1) & 0x7; 557 | } 558 | 559 | gifw_write_u8_(G, packed); 560 | 561 | if (color_table) { 562 | gifw_write_(G, color_table->colors, colors_count * 3); 563 | } 564 | 565 | gifw_write_frame_raster_(G, pixels, width, height); 566 | 567 | // Frame terminator. 568 | gifw_write_u8_(G, 0); 569 | } 570 | 571 | void 572 | gifw_end(GIFW *G) 573 | { 574 | gifw_write_u8_(G, 0x3B); 575 | gifw_flush_(G); 576 | } 577 | 578 | #endif -------------------------------------------------------------------------------- /lib/json.h: -------------------------------------------------------------------------------- 1 | 2 | /* vim: set et ts=3 sw=3 sts=3 ft=c: 3 | * 4 | * Copyright (C) 2012, 2013, 2014 James McLaughlin et al. All rights reserved. 5 | * https://github.com/udp/json-parser 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 | * SUCH DAMAGE. 29 | */ 30 | 31 | // Changes made to use more C99 features and to clear stuff out done by Martin Cohen (@martin_cohen). 32 | // - Converted to a single-file lib. 33 | // - Removed `u` requirement for `json_value` union. 34 | // - Removed all C++ specific stuff. 35 | 36 | #ifndef _JSON_H 37 | #define _JSON_H 38 | 39 | #ifndef json_char 40 | #define json_char char 41 | #endif 42 | 43 | #ifndef json_int_t 44 | #ifndef _MSC_VER 45 | #include 46 | #define json_int_t int64_t 47 | #else 48 | #define json_int_t __int64 49 | #endif 50 | #endif 51 | 52 | #include 53 | 54 | typedef struct 55 | { 56 | unsigned long max_memory; 57 | int settings; 58 | // Custom allocator support (leave null to use malloc/free) 59 | void * (* mem_alloc) (size_t, int zero, void * user_data); 60 | void (* mem_free) (void *, void * user_data); 61 | void * user_data; /* will be passed to mem_alloc and mem_free */ 62 | size_t value_extra; /* how much extra space to allocate for values? */ 63 | } json_settings; 64 | 65 | #define json_enable_comments 0x01 66 | 67 | typedef enum 68 | { 69 | json_none, 70 | json_object, 71 | json_array, 72 | json_integer, 73 | json_double, 74 | json_string, 75 | json_boolean, 76 | json_null 77 | 78 | } json_type; 79 | 80 | extern const struct json_value_ json_value_none; 81 | 82 | typedef struct 83 | { 84 | json_char * name; 85 | unsigned int name_length; 86 | struct json_value_ * value; 87 | } 88 | json_object_entry; 89 | 90 | typedef struct json_value_ 91 | { 92 | struct json_value_ * parent; 93 | json_type type; 94 | 95 | union 96 | { 97 | int boolean; 98 | json_int_t integer; 99 | double dbl; 100 | 101 | struct { 102 | unsigned int length; 103 | json_char * ptr; /* null terminated */ 104 | } string; 105 | 106 | struct { 107 | unsigned int length; 108 | json_object_entry * values; 109 | } object; 110 | 111 | struct { 112 | unsigned int length; 113 | struct json_value_ ** values; 114 | } array; 115 | }; 116 | 117 | union { 118 | struct json_value_ * next_alloc; 119 | void * object_mem; 120 | } reserved_; 121 | } 122 | json_value; 123 | 124 | json_value * json_parse (const json_char * json, 125 | size_t length); 126 | 127 | #define json_error_max 128 128 | json_value * json_parse_ex (json_settings * settings, 129 | const json_char * json, 130 | size_t length, 131 | char * error); 132 | 133 | void json_value_free (json_value *); 134 | 135 | 136 | /* Not usually necessary, unless you used a custom mem_alloc and now want to 137 | * use a custom mem_free. 138 | */ 139 | void json_value_free_ex (json_settings * settings, 140 | json_value *); 141 | 142 | 143 | #endif 144 | 145 | 146 | #ifdef JSON_IMPLEMENTATION 147 | #undef JSON_IMPLEMENTATION 148 | 149 | #ifdef _MSC_VER 150 | #ifndef _CRT_SECURE_NO_WARNINGS 151 | #define _CRT_SECURE_NO_WARNINGS 152 | #endif 153 | #endif 154 | 155 | const struct json_value_ json_value_none; 156 | 157 | #include 158 | #include 159 | #include 160 | #include 161 | 162 | typedef unsigned int json_uchar; 163 | 164 | static unsigned char hex_value (json_char c) 165 | { 166 | if (isdigit(c)) 167 | return c - '0'; 168 | 169 | switch (c) { 170 | case 'a': case 'A': return 0x0A; 171 | case 'b': case 'B': return 0x0B; 172 | case 'c': case 'C': return 0x0C; 173 | case 'd': case 'D': return 0x0D; 174 | case 'e': case 'E': return 0x0E; 175 | case 'f': case 'F': return 0x0F; 176 | default: return 0xFF; 177 | } 178 | } 179 | 180 | typedef struct 181 | { 182 | unsigned long used_memory; 183 | 184 | unsigned int uint_max; 185 | unsigned long ulong_max; 186 | 187 | json_settings settings; 188 | int first_pass; 189 | 190 | const json_char * ptr; 191 | unsigned int cur_line, cur_col; 192 | 193 | } json_state; 194 | 195 | static void * default_alloc (size_t size, int zero, void * user_data) 196 | { 197 | return zero ? calloc (1, size) : malloc (size); 198 | } 199 | 200 | static void default_free (void * ptr, void * user_data) 201 | { 202 | free (ptr); 203 | } 204 | 205 | static void * json_alloc (json_state * state, unsigned long size, int zero) 206 | { 207 | if ((state->ulong_max - state->used_memory) < size) 208 | return 0; 209 | 210 | if (state->settings.max_memory 211 | && (state->used_memory += size) > state->settings.max_memory) 212 | { 213 | return 0; 214 | } 215 | 216 | return state->settings.mem_alloc (size, zero, state->settings.user_data); 217 | } 218 | 219 | static int new_value (json_state * state, 220 | json_value ** top, json_value ** root, json_value ** alloc, 221 | json_type type) 222 | { 223 | json_value * value; 224 | int values_size; 225 | 226 | if (!state->first_pass) 227 | { 228 | value = *top = *alloc; 229 | *alloc = (*alloc)->reserved_.next_alloc; 230 | 231 | if (!*root) 232 | *root = value; 233 | 234 | switch (value->type) 235 | { 236 | case json_array: 237 | 238 | if (value->array.length == 0) 239 | break; 240 | 241 | if (! (value->array.values = (json_value **) json_alloc 242 | (state, value->array.length * sizeof (json_value *), 0)) ) 243 | { 244 | return 0; 245 | } 246 | 247 | value->array.length = 0; 248 | break; 249 | 250 | case json_object: 251 | 252 | if (value->object.length == 0) 253 | break; 254 | 255 | values_size = sizeof (*value->object.values) * value->object.length; 256 | 257 | if (! (value->object.values = (json_object_entry *) json_alloc 258 | (state, values_size + ((unsigned long) value->object.values), 0)) ) 259 | { 260 | return 0; 261 | } 262 | 263 | value->reserved_.object_mem = (*(char **) &value->object.values) + values_size; 264 | 265 | value->object.length = 0; 266 | break; 267 | 268 | case json_string: 269 | 270 | if (! (value->string.ptr = (json_char *) json_alloc 271 | (state, (value->string.length + 1) * sizeof (json_char), 0)) ) 272 | { 273 | return 0; 274 | } 275 | 276 | value->string.length = 0; 277 | break; 278 | 279 | default: 280 | break; 281 | }; 282 | 283 | return 1; 284 | } 285 | 286 | if (! (value = (json_value *) json_alloc 287 | (state, sizeof (json_value) + state->settings.value_extra, 1))) 288 | { 289 | return 0; 290 | } 291 | 292 | if (!*root) 293 | *root = value; 294 | 295 | value->type = type; 296 | value->parent = *top; 297 | 298 | 299 | if (*alloc) 300 | (*alloc)->reserved_.next_alloc = value; 301 | 302 | *alloc = *top = value; 303 | 304 | return 1; 305 | } 306 | 307 | #define whitespace \ 308 | case '\n': ++ state.cur_line; state.cur_col = 0; \ 309 | case ' ': case '\t': case '\r' 310 | 311 | #define string_add(b) \ 312 | do { if (!state.first_pass) string [string_length] = b; ++ string_length; } while (0); 313 | 314 | #define line_and_col \ 315 | state.cur_line, state.cur_col 316 | 317 | static const long 318 | flag_next = 1 << 0, 319 | flag_reproc = 1 << 1, 320 | flag_need_comma = 1 << 2, 321 | flag_seek_value = 1 << 3, 322 | flag_escaped = 1 << 4, 323 | flag_string = 1 << 5, 324 | flag_need_colon = 1 << 6, 325 | flag_done = 1 << 7, 326 | flag_num_negative = 1 << 8, 327 | flag_num_zero = 1 << 9, 328 | flag_num_e = 1 << 10, 329 | flag_num_e_got_sign = 1 << 11, 330 | flag_num_e_negative = 1 << 12, 331 | flag_line_comment = 1 << 13, 332 | flag_block_comment = 1 << 14; 333 | 334 | json_value * json_parse_ex (json_settings * settings, 335 | const json_char * json, 336 | size_t length, 337 | char * error_buf) 338 | { 339 | json_char error [json_error_max]; 340 | const json_char * end; 341 | json_value * top, * root, * alloc = 0; 342 | json_state state = { 0 }; 343 | long flags; 344 | long num_digits = 0, num_e = 0; 345 | json_int_t num_fraction = 0; 346 | 347 | /* Skip UTF-8 BOM 348 | */ 349 | if (length >= 3 && ((unsigned char) json [0]) == 0xEF 350 | && ((unsigned char) json [1]) == 0xBB 351 | && ((unsigned char) json [2]) == 0xBF) 352 | { 353 | json += 3; 354 | length -= 3; 355 | } 356 | 357 | error[0] = '\0'; 358 | end = (json + length); 359 | 360 | memcpy (&state.settings, settings, sizeof (json_settings)); 361 | 362 | if (!state.settings.mem_alloc) 363 | state.settings.mem_alloc = default_alloc; 364 | 365 | if (!state.settings.mem_free) 366 | state.settings.mem_free = default_free; 367 | 368 | memset (&state.uint_max, 0xFF, sizeof (state.uint_max)); 369 | memset (&state.ulong_max, 0xFF, sizeof (state.ulong_max)); 370 | 371 | state.uint_max -= 8; /* limit of how much can be added before next check */ 372 | state.ulong_max -= 8; 373 | 374 | for (state.first_pass = 1; state.first_pass >= 0; -- state.first_pass) 375 | { 376 | json_uchar uchar; 377 | unsigned char uc_b1, uc_b2, uc_b3, uc_b4; 378 | json_char * string = 0; 379 | unsigned int string_length = 0; 380 | 381 | top = root = 0; 382 | flags = flag_seek_value; 383 | 384 | state.cur_line = 1; 385 | 386 | for (state.ptr = json ;; ++ state.ptr) 387 | { 388 | json_char b = (state.ptr == end ? 0 : *state.ptr); 389 | 390 | if (flags & flag_string) 391 | { 392 | if (!b) 393 | { sprintf (error, "Unexpected EOF in string (at %d:%d)", line_and_col); 394 | goto e_failed; 395 | } 396 | 397 | if (string_length > state.uint_max) 398 | goto e_overflow; 399 | 400 | if (flags & flag_escaped) 401 | { 402 | flags &= ~ flag_escaped; 403 | 404 | switch (b) 405 | { 406 | case 'b': string_add ('\b'); break; 407 | case 'f': string_add ('\f'); break; 408 | case 'n': string_add ('\n'); break; 409 | case 'r': string_add ('\r'); break; 410 | case 't': string_add ('\t'); break; 411 | case 'u': 412 | 413 | if (end - state.ptr < 4 || 414 | (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || 415 | (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || 416 | (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || 417 | (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) 418 | { 419 | sprintf (error, "Invalid character value `%c` (at %d:%d)", b, line_and_col); 420 | goto e_failed; 421 | } 422 | 423 | uc_b1 = (uc_b1 << 4) | uc_b2; 424 | uc_b2 = (uc_b3 << 4) | uc_b4; 425 | uchar = (uc_b1 << 8) | uc_b2; 426 | 427 | if ((uchar & 0xF800) == 0xD800) { 428 | json_uchar uchar2; 429 | 430 | if (end - state.ptr < 6 || (*++ state.ptr) != '\\' || (*++ state.ptr) != 'u' || 431 | (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || 432 | (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || 433 | (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || 434 | (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) 435 | { 436 | sprintf (error, "Invalid character value `%c` (at %d:%d)", b, line_and_col); 437 | goto e_failed; 438 | } 439 | 440 | uc_b1 = (uc_b1 << 4) | uc_b2; 441 | uc_b2 = (uc_b3 << 4) | uc_b4; 442 | uchar2 = (uc_b1 << 8) | uc_b2; 443 | 444 | uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); 445 | } 446 | 447 | if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F)) 448 | { 449 | string_add ((json_char) uchar); 450 | break; 451 | } 452 | 453 | if (uchar <= 0x7FF) 454 | { 455 | if (state.first_pass) 456 | string_length += 2; 457 | else 458 | { string [string_length ++] = 0xC0 | (uchar >> 6); 459 | string [string_length ++] = 0x80 | (uchar & 0x3F); 460 | } 461 | 462 | break; 463 | } 464 | 465 | if (uchar <= 0xFFFF) { 466 | if (state.first_pass) 467 | string_length += 3; 468 | else 469 | { string [string_length ++] = 0xE0 | (uchar >> 12); 470 | string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); 471 | string [string_length ++] = 0x80 | (uchar & 0x3F); 472 | } 473 | 474 | break; 475 | } 476 | 477 | if (state.first_pass) 478 | string_length += 4; 479 | else 480 | { string [string_length ++] = 0xF0 | (uchar >> 18); 481 | string [string_length ++] = 0x80 | ((uchar >> 12) & 0x3F); 482 | string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); 483 | string [string_length ++] = 0x80 | (uchar & 0x3F); 484 | } 485 | 486 | break; 487 | 488 | default: 489 | string_add (b); 490 | }; 491 | 492 | continue; 493 | } 494 | 495 | if (b == '\\') 496 | { 497 | flags |= flag_escaped; 498 | continue; 499 | } 500 | 501 | if (b == '"') 502 | { 503 | if (!state.first_pass) 504 | string [string_length] = 0; 505 | 506 | flags &= ~ flag_string; 507 | string = 0; 508 | 509 | switch (top->type) 510 | { 511 | case json_string: 512 | 513 | top->string.length = string_length; 514 | flags |= flag_next; 515 | 516 | break; 517 | 518 | case json_object: 519 | 520 | if (state.first_pass) 521 | (*(json_char **) &top->object.values) += string_length + 1; 522 | else 523 | { 524 | top->object.values [top->object.length].name 525 | = (json_char *) top->reserved_.object_mem; 526 | 527 | top->object.values [top->object.length].name_length 528 | = string_length; 529 | 530 | (*(json_char **) &top->reserved_.object_mem) += string_length + 1; 531 | } 532 | 533 | flags |= flag_seek_value | flag_need_colon; 534 | continue; 535 | 536 | default: 537 | break; 538 | }; 539 | } 540 | else 541 | { 542 | string_add (b); 543 | continue; 544 | } 545 | } 546 | 547 | if (state.settings.settings & json_enable_comments) 548 | { 549 | if (flags & (flag_line_comment | flag_block_comment)) 550 | { 551 | if (flags & flag_line_comment) 552 | { 553 | if (b == '\r' || b == '\n' || !b) 554 | { 555 | flags &= ~ flag_line_comment; 556 | -- state.ptr; /* so null can be reproc'd */ 557 | } 558 | 559 | continue; 560 | } 561 | 562 | if (flags & flag_block_comment) 563 | { 564 | if (!b) 565 | { sprintf (error, "%d:%d: Unexpected EOF in block comment", line_and_col); 566 | goto e_failed; 567 | } 568 | 569 | if (b == '*' && state.ptr < (end - 1) && state.ptr [1] == '/') 570 | { 571 | flags &= ~ flag_block_comment; 572 | ++ state.ptr; /* skip closing sequence */ 573 | } 574 | 575 | continue; 576 | } 577 | } 578 | else if (b == '/') 579 | { 580 | if (! (flags & (flag_seek_value | flag_done)) && top->type != json_object) 581 | { sprintf (error, "%d:%d: Comment not allowed here", line_and_col); 582 | goto e_failed; 583 | } 584 | 585 | if (++ state.ptr == end) 586 | { sprintf (error, "%d:%d: EOF unexpected", line_and_col); 587 | goto e_failed; 588 | } 589 | 590 | switch (b = *state.ptr) 591 | { 592 | case '/': 593 | flags |= flag_line_comment; 594 | continue; 595 | 596 | case '*': 597 | flags |= flag_block_comment; 598 | continue; 599 | 600 | default: 601 | sprintf (error, "%d:%d: Unexpected `%c` in comment opening sequence", line_and_col, b); 602 | goto e_failed; 603 | }; 604 | } 605 | } 606 | 607 | if (flags & flag_done) 608 | { 609 | if (!b) 610 | break; 611 | 612 | switch (b) 613 | { 614 | whitespace: 615 | continue; 616 | 617 | default: 618 | 619 | sprintf (error, "%d:%d: Trailing garbage: `%c`", 620 | state.cur_line, state.cur_col, b); 621 | 622 | goto e_failed; 623 | }; 624 | } 625 | 626 | if (flags & flag_seek_value) 627 | { 628 | switch (b) 629 | { 630 | whitespace: 631 | continue; 632 | 633 | case ']': 634 | 635 | if (top && top->type == json_array) 636 | flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; 637 | else 638 | { sprintf (error, "%d:%d: Unexpected ]", line_and_col); 639 | goto e_failed; 640 | } 641 | 642 | break; 643 | 644 | default: 645 | 646 | if (flags & flag_need_comma) 647 | { 648 | if (b == ',') 649 | { flags &= ~ flag_need_comma; 650 | continue; 651 | } 652 | else 653 | { 654 | sprintf (error, "%d:%d: Expected , before %c", 655 | state.cur_line, state.cur_col, b); 656 | 657 | goto e_failed; 658 | } 659 | } 660 | 661 | if (flags & flag_need_colon) 662 | { 663 | if (b == ':') 664 | { flags &= ~ flag_need_colon; 665 | continue; 666 | } 667 | else 668 | { 669 | sprintf (error, "%d:%d: Expected : before %c", 670 | state.cur_line, state.cur_col, b); 671 | 672 | goto e_failed; 673 | } 674 | } 675 | 676 | flags &= ~ flag_seek_value; 677 | 678 | switch (b) 679 | { 680 | case '{': 681 | 682 | if (!new_value (&state, &top, &root, &alloc, json_object)) 683 | goto e_alloc_failure; 684 | 685 | continue; 686 | 687 | case '[': 688 | 689 | if (!new_value (&state, &top, &root, &alloc, json_array)) 690 | goto e_alloc_failure; 691 | 692 | flags |= flag_seek_value; 693 | continue; 694 | 695 | case '"': 696 | 697 | if (!new_value (&state, &top, &root, &alloc, json_string)) 698 | goto e_alloc_failure; 699 | 700 | flags |= flag_string; 701 | 702 | string = top->string.ptr; 703 | string_length = 0; 704 | 705 | continue; 706 | 707 | case 't': 708 | 709 | if ((end - state.ptr) < 3 || *(++ state.ptr) != 'r' || 710 | *(++ state.ptr) != 'u' || *(++ state.ptr) != 'e') 711 | { 712 | goto e_unknown_value; 713 | } 714 | 715 | if (!new_value (&state, &top, &root, &alloc, json_boolean)) 716 | goto e_alloc_failure; 717 | 718 | top->boolean = 1; 719 | 720 | flags |= flag_next; 721 | break; 722 | 723 | case 'f': 724 | 725 | if ((end - state.ptr) < 4 || *(++ state.ptr) != 'a' || 726 | *(++ state.ptr) != 'l' || *(++ state.ptr) != 's' || 727 | *(++ state.ptr) != 'e') 728 | { 729 | goto e_unknown_value; 730 | } 731 | 732 | if (!new_value (&state, &top, &root, &alloc, json_boolean)) 733 | goto e_alloc_failure; 734 | 735 | flags |= flag_next; 736 | break; 737 | 738 | case 'n': 739 | 740 | if ((end - state.ptr) < 3 || *(++ state.ptr) != 'u' || 741 | *(++ state.ptr) != 'l' || *(++ state.ptr) != 'l') 742 | { 743 | goto e_unknown_value; 744 | } 745 | 746 | if (!new_value (&state, &top, &root, &alloc, json_null)) 747 | goto e_alloc_failure; 748 | 749 | flags |= flag_next; 750 | break; 751 | 752 | default: 753 | 754 | if (isdigit (b) || b == '-') 755 | { 756 | if (!new_value (&state, &top, &root, &alloc, json_integer)) 757 | goto e_alloc_failure; 758 | 759 | if (!state.first_pass) 760 | { 761 | while (isdigit (b) || b == '+' || b == '-' 762 | || b == 'e' || b == 'E' || b == '.') 763 | { 764 | if ( (++ state.ptr) == end) 765 | { 766 | b = 0; 767 | break; 768 | } 769 | 770 | b = *state.ptr; 771 | } 772 | 773 | flags |= flag_next | flag_reproc; 774 | break; 775 | } 776 | 777 | flags &= ~ (flag_num_negative | flag_num_e | 778 | flag_num_e_got_sign | flag_num_e_negative | 779 | flag_num_zero); 780 | 781 | num_digits = 0; 782 | num_fraction = 0; 783 | num_e = 0; 784 | 785 | if (b != '-') 786 | { 787 | flags |= flag_reproc; 788 | break; 789 | } 790 | 791 | flags |= flag_num_negative; 792 | continue; 793 | } 794 | else 795 | { sprintf (error, "%d:%d: Unexpected %c when seeking value", line_and_col, b); 796 | goto e_failed; 797 | } 798 | }; 799 | }; 800 | } 801 | else 802 | { 803 | switch (top->type) 804 | { 805 | case json_object: 806 | 807 | switch (b) 808 | { 809 | whitespace: 810 | continue; 811 | 812 | case '"': 813 | 814 | if (flags & flag_need_comma) 815 | { sprintf (error, "%d:%d: Expected , before \"", line_and_col); 816 | goto e_failed; 817 | } 818 | 819 | flags |= flag_string; 820 | 821 | string = (json_char *) top->reserved_.object_mem; 822 | string_length = 0; 823 | 824 | break; 825 | 826 | case '}': 827 | 828 | flags = (flags & ~ flag_need_comma) | flag_next; 829 | break; 830 | 831 | case ',': 832 | 833 | if (flags & flag_need_comma) 834 | { 835 | flags &= ~ flag_need_comma; 836 | break; 837 | } 838 | 839 | default: 840 | sprintf (error, "%d:%d: Unexpected `%c` in object", line_and_col, b); 841 | goto e_failed; 842 | }; 843 | 844 | break; 845 | 846 | case json_integer: 847 | case json_double: 848 | 849 | if (isdigit (b)) 850 | { 851 | ++ num_digits; 852 | 853 | if (top->type == json_integer || flags & flag_num_e) 854 | { 855 | if (! (flags & flag_num_e)) 856 | { 857 | if (flags & flag_num_zero) 858 | { sprintf (error, "%d:%d: Unexpected `0` before `%c`", line_and_col, b); 859 | goto e_failed; 860 | } 861 | 862 | if (num_digits == 1 && b == '0') 863 | flags |= flag_num_zero; 864 | } 865 | else 866 | { 867 | flags |= flag_num_e_got_sign; 868 | num_e = (num_e * 10) + (b - '0'); 869 | continue; 870 | } 871 | 872 | top->integer = (top->integer * 10) + (b - '0'); 873 | continue; 874 | } 875 | 876 | num_fraction = (num_fraction * 10) + (b - '0'); 877 | continue; 878 | } 879 | 880 | if (b == '+' || b == '-') 881 | { 882 | if ( (flags & flag_num_e) && !(flags & flag_num_e_got_sign)) 883 | { 884 | flags |= flag_num_e_got_sign; 885 | 886 | if (b == '-') 887 | flags |= flag_num_e_negative; 888 | 889 | continue; 890 | } 891 | } 892 | else if (b == '.' && top->type == json_integer) 893 | { 894 | if (!num_digits) 895 | { sprintf (error, "%d:%d: Expected digit before `.`", line_and_col); 896 | goto e_failed; 897 | } 898 | 899 | top->type = json_double; 900 | top->dbl = (double) top->integer; 901 | 902 | num_digits = 0; 903 | continue; 904 | } 905 | 906 | if (! (flags & flag_num_e)) 907 | { 908 | if (top->type == json_double) 909 | { 910 | if (!num_digits) 911 | { sprintf (error, "%d:%d: Expected digit after `.`", line_and_col); 912 | goto e_failed; 913 | } 914 | 915 | top->dbl += ((double) num_fraction) / (pow (10.0, (double) num_digits)); 916 | } 917 | 918 | if (b == 'e' || b == 'E') 919 | { 920 | flags |= flag_num_e; 921 | 922 | if (top->type == json_integer) 923 | { 924 | top->type = json_double; 925 | top->dbl = (double) top->integer; 926 | } 927 | 928 | num_digits = 0; 929 | flags &= ~ flag_num_zero; 930 | 931 | continue; 932 | } 933 | } 934 | else 935 | { 936 | if (!num_digits) 937 | { sprintf (error, "%d:%d: Expected digit after `e`", line_and_col); 938 | goto e_failed; 939 | } 940 | 941 | top->dbl *= pow (10.0, (double) 942 | (flags & flag_num_e_negative ? - num_e : num_e)); 943 | } 944 | 945 | if (flags & flag_num_negative) 946 | { 947 | if (top->type == json_integer) 948 | top->integer = - top->integer; 949 | else 950 | top->dbl = - top->dbl; 951 | } 952 | 953 | flags |= flag_next | flag_reproc; 954 | break; 955 | 956 | default: 957 | break; 958 | }; 959 | } 960 | 961 | if (flags & flag_reproc) 962 | { 963 | flags &= ~ flag_reproc; 964 | -- state.ptr; 965 | } 966 | 967 | if (flags & flag_next) 968 | { 969 | flags = (flags & ~ flag_next) | flag_need_comma; 970 | 971 | if (!top->parent) 972 | { 973 | /* root value done */ 974 | 975 | flags |= flag_done; 976 | continue; 977 | } 978 | 979 | if (top->parent->type == json_array) 980 | flags |= flag_seek_value; 981 | 982 | if (!state.first_pass) 983 | { 984 | json_value * parent = top->parent; 985 | 986 | switch (parent->type) 987 | { 988 | case json_object: 989 | 990 | parent->object.values 991 | [parent->object.length].value = top; 992 | 993 | break; 994 | 995 | case json_array: 996 | 997 | parent->array.values 998 | [parent->array.length] = top; 999 | 1000 | break; 1001 | 1002 | default: 1003 | break; 1004 | }; 1005 | } 1006 | 1007 | if ( (++ top->parent->array.length) > state.uint_max) 1008 | goto e_overflow; 1009 | 1010 | top = top->parent; 1011 | 1012 | continue; 1013 | } 1014 | } 1015 | 1016 | alloc = root; 1017 | } 1018 | 1019 | return root; 1020 | 1021 | e_unknown_value: 1022 | 1023 | sprintf (error, "%d:%d: Unknown value", line_and_col); 1024 | goto e_failed; 1025 | 1026 | e_alloc_failure: 1027 | 1028 | strcpy (error, "Memory allocation failure"); 1029 | goto e_failed; 1030 | 1031 | e_overflow: 1032 | 1033 | sprintf (error, "%d:%d: Too long (caught overflow)", line_and_col); 1034 | goto e_failed; 1035 | 1036 | e_failed: 1037 | 1038 | if (error_buf) 1039 | { 1040 | if (*error) 1041 | strcpy (error_buf, error); 1042 | else 1043 | strcpy (error_buf, "Unknown error"); 1044 | } 1045 | 1046 | if (state.first_pass) 1047 | alloc = root; 1048 | 1049 | while (alloc) 1050 | { 1051 | top = alloc->reserved_.next_alloc; 1052 | state.settings.mem_free (alloc, state.settings.user_data); 1053 | alloc = top; 1054 | } 1055 | 1056 | if (!state.first_pass) 1057 | json_value_free_ex (&state.settings, root); 1058 | 1059 | return 0; 1060 | } 1061 | 1062 | json_value * json_parse (const json_char * json, size_t length) 1063 | { 1064 | json_settings settings = { 0 }; 1065 | return json_parse_ex (&settings, json, length, 0); 1066 | } 1067 | 1068 | void json_value_free_ex (json_settings * settings, json_value * value) 1069 | { 1070 | json_value * cur_value; 1071 | 1072 | if (!value) 1073 | return; 1074 | 1075 | value->parent = 0; 1076 | 1077 | while (value) 1078 | { 1079 | switch (value->type) 1080 | { 1081 | case json_array: 1082 | 1083 | if (!value->array.length) 1084 | { 1085 | settings->mem_free (value->array.values, settings->user_data); 1086 | break; 1087 | } 1088 | 1089 | value = value->array.values [-- value->array.length]; 1090 | continue; 1091 | 1092 | case json_object: 1093 | 1094 | if (!value->object.length) 1095 | { 1096 | settings->mem_free (value->object.values, settings->user_data); 1097 | break; 1098 | } 1099 | 1100 | value = value->object.values [-- value->object.length].value; 1101 | continue; 1102 | 1103 | case json_string: 1104 | 1105 | settings->mem_free (value->string.ptr, settings->user_data); 1106 | break; 1107 | 1108 | default: 1109 | break; 1110 | }; 1111 | 1112 | cur_value = value; 1113 | value = value->parent; 1114 | settings->mem_free (cur_value, settings->user_data); 1115 | } 1116 | } 1117 | 1118 | void json_value_free (json_value * value) 1119 | { 1120 | json_settings settings = { 0 }; 1121 | settings.mem_free = default_free; 1122 | json_value_free_ex (&settings, value); 1123 | } 1124 | 1125 | #endif // JSON_IMPLEMENTATION -------------------------------------------------------------------------------- /lib/mingw/_mingw_unicode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has no copyright assigned and is placed in the Public Domain. 3 | * This file is part of the mingw-w64 runtime package. 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. 5 | */ 6 | 7 | #if !defined(_INC_CRT_UNICODE_MACROS) 8 | /* _INC_CRT_UNICODE_MACROS defined based on UNICODE flag */ 9 | 10 | #if defined(UNICODE) 11 | # define _INC_CRT_UNICODE_MACROS 1 12 | # define __MINGW_NAME_AW(func) func##W 13 | # define __MINGW_NAME_AW_EXT(func,ext) func##W##ext 14 | # define __MINGW_NAME_UAW(func) func##_W 15 | # define __MINGW_NAME_UAW_EXT(func,ext) func##_W_##ext 16 | # define __MINGW_STRING_AW(str) L##str /* same as TEXT() from winnt.h */ 17 | # define __MINGW_PROCNAMEEXT_AW "W" 18 | #else 19 | # define _INC_CRT_UNICODE_MACROS 2 20 | # define __MINGW_NAME_AW(func) func##A 21 | # define __MINGW_NAME_AW_EXT(func,ext) func##A##ext 22 | # define __MINGW_NAME_UAW(func) func##_A 23 | # define __MINGW_NAME_UAW_EXT(func,ext) func##_A_##ext 24 | # define __MINGW_STRING_AW(str) str /* same as TEXT() from winnt.h */ 25 | # define __MINGW_PROCNAMEEXT_AW "A" 26 | #endif 27 | 28 | #define __MINGW_TYPEDEF_AW(type) \ 29 | typedef __MINGW_NAME_AW(type) type; 30 | #define __MINGW_TYPEDEF_UAW(type) \ 31 | typedef __MINGW_NAME_UAW(type) type; 32 | 33 | #endif /* !defined(_INC_CRT_UNICODE_MACROS) */ 34 | -------------------------------------------------------------------------------- /lib/mingw/d3d10_1shader.h: -------------------------------------------------------------------------------- 1 | #undef INTERFACE 2 | /* 3 | * Copyright 2010 Rico Schüller 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 | */ 19 | 20 | #ifndef __D3D10_1SHADER_H__ 21 | #define __D3D10_1SHADER_H__ 22 | 23 | #include "d3d10shader.h" 24 | 25 | DEFINE_GUID(IID_ID3D10ShaderReflection1, 0xc3457783, 0xa846, 0x47ce, 0x95, 0x20, 0xce, 0xa6, 0xf6, 0x6e, 0x74, 0x47); 26 | 27 | #define INTERFACE ID3D10ShaderReflection1 28 | DECLARE_INTERFACE_(ID3D10ShaderReflection1, IUnknown) 29 | { 30 | /* IUnknown methods */ 31 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **out) PURE; 32 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 33 | STDMETHOD_(ULONG, Release)(THIS) PURE; 34 | /* ID3D10ShaderReflection1 methods */ 35 | STDMETHOD(GetDesc)(THIS_ D3D10_SHADER_DESC *desc) PURE; 36 | STDMETHOD_(struct ID3D10ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ UINT index) PURE; 37 | STDMETHOD_(struct ID3D10ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ const char *name) PURE; 38 | STDMETHOD(GetResourceBindingDesc)(THIS_ UINT index, D3D10_SHADER_INPUT_BIND_DESC *desc) PURE; 39 | STDMETHOD(GetInputParameterDesc)(THIS_ UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc) PURE; 40 | STDMETHOD(GetOutputParameterDesc)(THIS_ UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc) PURE; 41 | STDMETHOD_(struct ID3D10ShaderReflectionVariable *, GetVariableByName)(THIS_ const char *name) PURE; 42 | STDMETHOD(GetResourceBindingDescByName)(THIS_ const char *name, D3D10_SHADER_INPUT_BIND_DESC *desc) PURE; 43 | STDMETHOD(GetMovInstructionCount)(THIS_ UINT *count) PURE; 44 | STDMETHOD(GetMovcInstructionCount)(THIS_ UINT *count) PURE; 45 | STDMETHOD(GetConversionInstructionCount)(THIS_ UINT *count) PURE; 46 | STDMETHOD(GetBitwiseInstructionCount)(THIS_ UINT *count) PURE; 47 | STDMETHOD(GetGSInputPrimitive)(THIS_ D3D10_PRIMITIVE *prim) PURE; 48 | STDMETHOD(IsLevel9Shader)(THIS_ WINBOOL *level9shader) PURE; 49 | STDMETHOD(IsSampleFrequencyShader)(THIS_ WINBOOL *samplefrequency) PURE; 50 | }; 51 | #undef INTERFACE 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lib/mingw/d3d10misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Henri Verbeet for CodeWeavers 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | #ifndef __D3D10MISC_H__ 20 | #define __D3D10MISC_H__ 21 | 22 | #include "d3d10.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef enum D3D10_DRIVER_TYPE { 29 | D3D10_DRIVER_TYPE_HARDWARE = 0, 30 | D3D10_DRIVER_TYPE_REFERENCE = 1, 31 | D3D10_DRIVER_TYPE_NULL = 2, 32 | D3D10_DRIVER_TYPE_SOFTWARE = 3, 33 | D3D10_DRIVER_TYPE_WARP = 5, 34 | } D3D10_DRIVER_TYPE; 35 | 36 | HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, 37 | HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device); 38 | 39 | HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, 40 | HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc, 41 | IDXGISwapChain **swapchain, ID3D10Device **device); 42 | 43 | HRESULT WINAPI D3D10CreateBlob(SIZE_T data_size, ID3D10Blob **blob); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* __D3D10MISC_H__ */ 50 | -------------------------------------------------------------------------------- /lib/mingw/d3d10shader.h: -------------------------------------------------------------------------------- 1 | #undef INTERFACE 2 | /* 3 | * Copyright 2009 Henri Verbeet for CodeWeavers 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 | * 19 | */ 20 | 21 | #ifndef __WINE_D3D10SHADER_H 22 | #define __WINE_D3D10SHADER_H 23 | 24 | #include "d3d10.h" 25 | 26 | #define D3D10_SHADER_DEBUG 0x0001 27 | #define D3D10_SHADER_SKIP_VALIDATION 0x0002 28 | #define D3D10_SHADER_SKIP_OPTIMIZATION 0x0004 29 | #define D3D10_SHADER_PACK_MATRIX_ROW_MAJOR 0x0008 30 | #define D3D10_SHADER_PACK_MATRIX_COLUMN_MAJOR 0x0010 31 | #define D3D10_SHADER_PARTIAL_PRECISION 0x0020 32 | #define D3D10_SHADER_FORCE_VS_SOFTWARE_NO_OPT 0x0040 33 | #define D3D10_SHADER_FORCE_PS_SOFTWARE_NO_OPT 0x0080 34 | #define D3D10_SHADER_NO_PRESHADER 0x0100 35 | #define D3D10_SHADER_AVOID_FLOW_CONTROL 0x0200 36 | #define D3D10_SHADER_PREFER_FLOW_CONTROL 0x0400 37 | #define D3D10_SHADER_ENABLE_STRICTNESS 0x0800 38 | #define D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY 0x1000 39 | #define D3D10_SHADER_IEEE_STRICTNESS 0x2000 40 | #define D3D10_SHADER_WARNINGS_ARE_ERRORS 0x40000 41 | 42 | #define D3D10_SHADER_OPTIMIZATION_LEVEL0 0x4000 43 | #define D3D10_SHADER_OPTIMIZATION_LEVEL1 0x0000 44 | #define D3D10_SHADER_OPTIMIZATION_LEVEL2 0xC000 45 | #define D3D10_SHADER_OPTIMIZATION_LEVEL3 0x8000 46 | 47 | /* These are defined as version-neutral in d3dcommon.h */ 48 | typedef D3D_SHADER_MACRO D3D10_SHADER_MACRO; 49 | typedef D3D_SHADER_MACRO *LPD3D10_SHADER_MACRO; 50 | 51 | typedef D3D_SHADER_VARIABLE_CLASS D3D10_SHADER_VARIABLE_CLASS; 52 | typedef D3D_SHADER_VARIABLE_CLASS *LPD3D10_SHADER_VARIABLE_CLASS; 53 | 54 | typedef D3D_CBUFFER_TYPE D3D10_CBUFFER_TYPE; 55 | typedef D3D_CBUFFER_TYPE *LPD3D10_CBUFFER_TYPE; 56 | 57 | typedef D3D_REGISTER_COMPONENT_TYPE D3D10_REGISTER_COMPONENT_TYPE; 58 | 59 | typedef D3D_RESOURCE_RETURN_TYPE D3D10_RESOURCE_RETURN_TYPE; 60 | 61 | typedef D3D_NAME D3D10_NAME; 62 | 63 | typedef D3D_SHADER_INPUT_TYPE D3D10_SHADER_INPUT_TYPE; 64 | typedef D3D_SHADER_INPUT_TYPE *LPD3D10_SHADER_INPUT_TYPE; 65 | 66 | typedef D3D_SHADER_VARIABLE_TYPE D3D10_SHADER_VARIABLE_TYPE; 67 | typedef D3D_SHADER_VARIABLE_TYPE *LPD3D10_SHADER_VARIABLE_TYPE; 68 | 69 | typedef D3D_INCLUDE_TYPE D3D10_INCLUDE_TYPE; 70 | typedef ID3DInclude ID3D10Include; 71 | typedef ID3DInclude *LPD3D10INCLUDE; 72 | #define IID_ID3D10Include IID_ID3DInclude 73 | 74 | typedef struct _D3D10_SHADER_INPUT_BIND_DESC 75 | { 76 | const char *Name; 77 | D3D10_SHADER_INPUT_TYPE Type; 78 | UINT BindPoint; 79 | UINT BindCount; 80 | UINT uFlags; 81 | D3D10_RESOURCE_RETURN_TYPE ReturnType; 82 | D3D10_SRV_DIMENSION Dimension; 83 | UINT NumSamples; 84 | } D3D10_SHADER_INPUT_BIND_DESC; 85 | 86 | typedef struct _D3D10_SIGNATURE_PARAMETER_DESC 87 | { 88 | const char *SemanticName; 89 | UINT SemanticIndex; 90 | UINT Register; 91 | D3D10_NAME SystemValueType; 92 | D3D10_REGISTER_COMPONENT_TYPE ComponentType; 93 | BYTE Mask; 94 | BYTE ReadWriteMask; 95 | } D3D10_SIGNATURE_PARAMETER_DESC; 96 | 97 | typedef struct _D3D10_SHADER_DESC 98 | { 99 | UINT Version; 100 | const char *Creator; 101 | UINT Flags; 102 | UINT ConstantBuffers; 103 | UINT BoundResources; 104 | UINT InputParameters; 105 | UINT OutputParameters; 106 | UINT InstructionCount; 107 | UINT TempRegisterCount; 108 | UINT TempArrayCount; 109 | UINT DefCount; 110 | UINT DclCount; 111 | UINT TextureNormalInstructions; 112 | UINT TextureLoadInstructions; 113 | UINT TextureCompInstructions; 114 | UINT TextureBiasInstructions; 115 | UINT TextureGradientInstructions; 116 | UINT FloatInstructionCount; 117 | UINT IntInstructionCount; 118 | UINT UintInstructionCount; 119 | UINT StaticFlowControlCount; 120 | UINT DynamicFlowControlCount; 121 | UINT MacroInstructionCount; 122 | UINT ArrayInstructionCount; 123 | UINT CutInstructionCount; 124 | UINT EmitInstructionCount; 125 | D3D10_PRIMITIVE_TOPOLOGY GSOutputTopology; 126 | UINT GSMaxOutputVertexCount; 127 | } D3D10_SHADER_DESC; 128 | 129 | typedef struct _D3D10_SHADER_BUFFER_DESC 130 | { 131 | const char *Name; 132 | D3D10_CBUFFER_TYPE Type; 133 | UINT Variables; 134 | UINT Size; 135 | UINT uFlags; 136 | } D3D10_SHADER_BUFFER_DESC; 137 | 138 | typedef struct _D3D10_SHADER_VARIABLE_DESC 139 | { 140 | const char *Name; 141 | UINT StartOffset; 142 | UINT Size; 143 | UINT uFlags; 144 | void *DefaultValue; 145 | } D3D10_SHADER_VARIABLE_DESC; 146 | 147 | typedef struct _D3D10_SHADER_TYPE_DESC 148 | { 149 | D3D10_SHADER_VARIABLE_CLASS Class; 150 | D3D10_SHADER_VARIABLE_TYPE Type; 151 | UINT Rows; 152 | UINT Columns; 153 | UINT Elements; 154 | UINT Members; 155 | UINT Offset; 156 | } D3D10_SHADER_TYPE_DESC; 157 | 158 | DEFINE_GUID(IID_ID3D10ShaderReflectionType, 0xc530ad7d, 0x9b16, 0x4395, 0xa9, 0x79, 0xba, 0x2e, 0xcf, 0xf8, 0x3a, 0xdd); 159 | 160 | #define INTERFACE ID3D10ShaderReflectionType 161 | DECLARE_INTERFACE(ID3D10ShaderReflectionType) 162 | { 163 | STDMETHOD(GetDesc)(THIS_ D3D10_SHADER_TYPE_DESC *desc) PURE; 164 | STDMETHOD_(struct ID3D10ShaderReflectionType *, GetMemberTypeByIndex)(THIS_ UINT index) PURE; 165 | STDMETHOD_(struct ID3D10ShaderReflectionType *, GetMemberTypeByName)(THIS_ const char *name) PURE; 166 | STDMETHOD_(const char *, GetMemberTypeName)(THIS_ UINT index) PURE; 167 | }; 168 | #undef INTERFACE 169 | 170 | DEFINE_GUID(IID_ID3D10ShaderReflectionVariable, 0x1bf63c95, 0x2650, 0x405d, 0x99, 0xc1, 0x36, 0x36, 0xbd, 0x1d, 0xa0, 0xa1); 171 | 172 | #define INTERFACE ID3D10ShaderReflectionVariable 173 | DECLARE_INTERFACE(ID3D10ShaderReflectionVariable) 174 | { 175 | STDMETHOD(GetDesc)(THIS_ D3D10_SHADER_VARIABLE_DESC *desc) PURE; 176 | STDMETHOD_(struct ID3D10ShaderReflectionType *, GetType)(THIS) PURE; 177 | }; 178 | #undef INTERFACE 179 | 180 | DEFINE_GUID(IID_ID3D10ShaderReflectionConstantBuffer, 0x66c66a94, 0xdddd, 0x4b62, 0xa6, 0x6a, 0xf0, 0xda, 0x33, 0xc2, 0xb4, 0xd0); 181 | 182 | #define INTERFACE ID3D10ShaderReflectionConstantBuffer 183 | DECLARE_INTERFACE(ID3D10ShaderReflectionConstantBuffer) 184 | { 185 | STDMETHOD(GetDesc)(THIS_ D3D10_SHADER_BUFFER_DESC *desc) PURE; 186 | STDMETHOD_(struct ID3D10ShaderReflectionVariable *, GetVariableByIndex)(THIS_ UINT index) PURE; 187 | STDMETHOD_(struct ID3D10ShaderReflectionVariable *, GetVariableByName)(THIS_ const char *name) PURE; 188 | }; 189 | #undef INTERFACE 190 | 191 | DEFINE_GUID(IID_ID3D10ShaderReflection, 0xd40e20b6, 0xf8f7, 0x42ad, 0xab, 0x20, 0x4b, 0xaf, 0x8f, 0x15, 0xdf, 0xaa); 192 | 193 | #define INTERFACE ID3D10ShaderReflection 194 | DECLARE_INTERFACE_(ID3D10ShaderReflection, IUnknown) 195 | { 196 | /* IUnknown methods */ 197 | STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **out) PURE; 198 | STDMETHOD_(ULONG, AddRef)(THIS) PURE; 199 | STDMETHOD_(ULONG, Release)(THIS) PURE; 200 | /* ID3D10ShaderReflection methods */ 201 | STDMETHOD(GetDesc)(THIS_ D3D10_SHADER_DESC *desc) PURE; 202 | STDMETHOD_(struct ID3D10ShaderReflectionConstantBuffer *, GetConstantBufferByIndex)(THIS_ UINT index) PURE; 203 | STDMETHOD_(struct ID3D10ShaderReflectionConstantBuffer *, GetConstantBufferByName)(THIS_ const char *name) PURE; 204 | STDMETHOD(GetResourceBindingDesc)(THIS_ UINT index, D3D10_SHADER_INPUT_BIND_DESC *desc) PURE; 205 | STDMETHOD(GetInputParameterDesc)(THIS_ UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc) PURE; 206 | STDMETHOD(GetOutputParameterDesc)(THIS_ UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc) PURE; 207 | }; 208 | #undef INTERFACE 209 | 210 | 211 | #ifdef __cplusplus 212 | extern "C" { 213 | #endif 214 | 215 | HRESULT WINAPI D3D10CompileShader(const char *data, SIZE_T data_size, const char *filename, 216 | const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entrypoint, 217 | const char *profile, UINT flags, ID3D10Blob **shader, ID3D10Blob **error_messages); 218 | HRESULT WINAPI D3D10DisassembleShader(const void *data, SIZE_T data_size, 219 | WINBOOL color_code, const char *comments, ID3D10Blob **disassembly); 220 | const char * WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device); 221 | const char * WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device); 222 | const char * WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device); 223 | 224 | HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector); 225 | HRESULT WINAPI D3D10GetInputSignatureBlob(const void *data, SIZE_T data_size, ID3D10Blob **blob); 226 | HRESULT WINAPI D3D10GetOutputSignatureBlob(const void *data, SIZE_T data_size, ID3D10Blob **blob); 227 | HRESULT WINAPI D3D10GetInputAndOutputSignatureBlob(const void *data, SIZE_T data_size, ID3D10Blob **blob); 228 | HRESULT WINAPI D3D10GetShaderDebugInfo(const void *data, SIZE_T data_size, ID3D10Blob **blob); 229 | 230 | #ifdef __cplusplus 231 | } 232 | #endif 233 | 234 | #endif /* __WINE_D3D10SHADER_H */ 235 | -------------------------------------------------------------------------------- /lib/mingw/d3dcommon.h: -------------------------------------------------------------------------------- 1 | /*** Autogenerated by WIDL 1.6 from direct-x/include/d3dcommon.idl - Do not edit ***/ 2 | 3 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 4 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 5 | #endif 6 | 7 | #include 8 | #include 9 | 10 | #ifndef COM_NO_WINDOWS_H 11 | #include 12 | #include 13 | #endif 14 | 15 | #ifndef __d3dcommon_h__ 16 | #define __d3dcommon_h__ 17 | 18 | /* Forward declarations */ 19 | 20 | #ifndef __ID3D10Blob_FWD_DEFINED__ 21 | #define __ID3D10Blob_FWD_DEFINED__ 22 | typedef interface ID3D10Blob ID3D10Blob; 23 | #endif 24 | 25 | #ifndef __ID3DInclude_FWD_DEFINED__ 26 | #define __ID3DInclude_FWD_DEFINED__ 27 | typedef interface ID3DInclude ID3DInclude; 28 | #endif 29 | 30 | /* Headers for imported files */ 31 | 32 | #include 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | typedef struct _D3D_SHADER_MACRO { 40 | const char *Name; 41 | const char *Definition; 42 | } D3D_SHADER_MACRO; 43 | typedef struct _D3D_SHADER_MACRO *LPD3D_SHADER_MACRO; 44 | /***************************************************************************** 45 | * ID3D10Blob interface 46 | */ 47 | #ifndef __ID3D10Blob_INTERFACE_DEFINED__ 48 | #define __ID3D10Blob_INTERFACE_DEFINED__ 49 | 50 | DEFINE_GUID(IID_ID3D10Blob, 0x8ba5fb08, 0x5195, 0x40e2, 0xac,0x58, 0x0d,0x98,0x9c,0x3a,0x01,0x02); 51 | #if defined(__cplusplus) && !defined(CINTERFACE) 52 | MIDL_INTERFACE("8ba5fb08-5195-40e2-ac58-0d989c3a0102") 53 | ID3D10Blob : public IUnknown 54 | { 55 | virtual void * STDMETHODCALLTYPE GetBufferPointer( 56 | ) = 0; 57 | 58 | virtual SIZE_T STDMETHODCALLTYPE GetBufferSize( 59 | ) = 0; 60 | 61 | }; 62 | #ifdef __CRT_UUID_DECL 63 | __CRT_UUID_DECL(ID3D10Blob, 0x8ba5fb08, 0x5195, 0x40e2, 0xac,0x58, 0x0d,0x98,0x9c,0x3a,0x01,0x02) 64 | #endif 65 | #else 66 | typedef struct ID3D10BlobVtbl { 67 | BEGIN_INTERFACE 68 | 69 | /*** IUnknown methods ***/ 70 | HRESULT (STDMETHODCALLTYPE *QueryInterface)( 71 | ID3D10Blob* This, 72 | REFIID riid, 73 | void **ppvObject); 74 | 75 | ULONG (STDMETHODCALLTYPE *AddRef)( 76 | ID3D10Blob* This); 77 | 78 | ULONG (STDMETHODCALLTYPE *Release)( 79 | ID3D10Blob* This); 80 | 81 | /*** ID3D10Blob methods ***/ 82 | void * (STDMETHODCALLTYPE *GetBufferPointer)( 83 | ID3D10Blob* This); 84 | 85 | SIZE_T (STDMETHODCALLTYPE *GetBufferSize)( 86 | ID3D10Blob* This); 87 | 88 | END_INTERFACE 89 | } ID3D10BlobVtbl; 90 | interface ID3D10Blob { 91 | CONST_VTBL ID3D10BlobVtbl* lpVtbl; 92 | }; 93 | 94 | #ifdef COBJMACROS 95 | #ifndef WIDL_C_INLINE_WRAPPERS 96 | /*** IUnknown methods ***/ 97 | #define ID3D10Blob_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject) 98 | #define ID3D10Blob_AddRef(This) (This)->lpVtbl->AddRef(This) 99 | #define ID3D10Blob_Release(This) (This)->lpVtbl->Release(This) 100 | /*** ID3D10Blob methods ***/ 101 | #define ID3D10Blob_GetBufferPointer(This) (This)->lpVtbl->GetBufferPointer(This) 102 | #define ID3D10Blob_GetBufferSize(This) (This)->lpVtbl->GetBufferSize(This) 103 | #else 104 | /*** IUnknown methods ***/ 105 | static FORCEINLINE HRESULT ID3D10Blob_QueryInterface(ID3D10Blob* This,REFIID riid,void **ppvObject) { 106 | return This->lpVtbl->QueryInterface(This,riid,ppvObject); 107 | } 108 | static FORCEINLINE ULONG ID3D10Blob_AddRef(ID3D10Blob* This) { 109 | return This->lpVtbl->AddRef(This); 110 | } 111 | static FORCEINLINE ULONG ID3D10Blob_Release(ID3D10Blob* This) { 112 | return This->lpVtbl->Release(This); 113 | } 114 | /*** ID3D10Blob methods ***/ 115 | static FORCEINLINE void * ID3D10Blob_GetBufferPointer(ID3D10Blob* This) { 116 | return This->lpVtbl->GetBufferPointer(This); 117 | } 118 | static FORCEINLINE SIZE_T ID3D10Blob_GetBufferSize(ID3D10Blob* This) { 119 | return This->lpVtbl->GetBufferSize(This); 120 | } 121 | #endif 122 | #endif 123 | 124 | #endif 125 | 126 | void * STDMETHODCALLTYPE ID3D10Blob_GetBufferPointer_Proxy( 127 | ID3D10Blob* This); 128 | void __RPC_STUB ID3D10Blob_GetBufferPointer_Stub( 129 | IRpcStubBuffer* This, 130 | IRpcChannelBuffer* pRpcChannelBuffer, 131 | PRPC_MESSAGE pRpcMessage, 132 | DWORD* pdwStubPhase); 133 | SIZE_T STDMETHODCALLTYPE ID3D10Blob_GetBufferSize_Proxy( 134 | ID3D10Blob* This); 135 | void __RPC_STUB ID3D10Blob_GetBufferSize_Stub( 136 | IRpcStubBuffer* This, 137 | IRpcChannelBuffer* pRpcChannelBuffer, 138 | PRPC_MESSAGE pRpcMessage, 139 | DWORD* pdwStubPhase); 140 | 141 | #endif /* __ID3D10Blob_INTERFACE_DEFINED__ */ 142 | 143 | typedef ID3D10Blob *LPD3D10BLOB; 144 | typedef ID3D10Blob ID3DBlob; 145 | typedef ID3DBlob *LPD3DBLOB; 146 | #define IID_ID3DBlob IID_ID3D10Blob 147 | typedef enum _D3D_INCLUDE_TYPE { 148 | D3D_INCLUDE_LOCAL = 0, 149 | D3D_INCLUDE_SYSTEM = 1, 150 | D3D10_INCLUDE_LOCAL = D3D_INCLUDE_LOCAL, 151 | D3D10_INCLUDE_SYSTEM = D3D_INCLUDE_SYSTEM, 152 | D3D_INCLUDE_FORCE_DWORD = 0x7fffffff 153 | } D3D_INCLUDE_TYPE; 154 | /***************************************************************************** 155 | * ID3DInclude interface 156 | */ 157 | #ifndef __ID3DInclude_INTERFACE_DEFINED__ 158 | #define __ID3DInclude_INTERFACE_DEFINED__ 159 | 160 | #if defined(__cplusplus) && !defined(CINTERFACE) 161 | interface ID3DInclude 162 | { 163 | BEGIN_INTERFACE 164 | 165 | virtual HRESULT STDMETHODCALLTYPE Open( 166 | D3D_INCLUDE_TYPE include_type, 167 | const char *filename, 168 | const void *parent_data, 169 | const void **data, 170 | UINT *bytes) = 0; 171 | 172 | virtual HRESULT STDMETHODCALLTYPE Close( 173 | const void *data) = 0; 174 | 175 | END_INTERFACE 176 | }; 177 | #else 178 | typedef struct ID3DIncludeVtbl { 179 | BEGIN_INTERFACE 180 | 181 | /*** ID3DInclude methods ***/ 182 | HRESULT (STDMETHODCALLTYPE *Open)( 183 | ID3DInclude* This, 184 | D3D_INCLUDE_TYPE include_type, 185 | const char *filename, 186 | const void *parent_data, 187 | const void **data, 188 | UINT *bytes); 189 | 190 | HRESULT (STDMETHODCALLTYPE *Close)( 191 | ID3DInclude* This, 192 | const void *data); 193 | 194 | END_INTERFACE 195 | } ID3DIncludeVtbl; 196 | interface ID3DInclude { 197 | CONST_VTBL ID3DIncludeVtbl* lpVtbl; 198 | }; 199 | 200 | #ifdef COBJMACROS 201 | #ifndef WIDL_C_INLINE_WRAPPERS 202 | /*** ID3DInclude methods ***/ 203 | #define ID3DInclude_Open(This,include_type,filename,parent_data,data,bytes) (This)->lpVtbl->Open(This,include_type,filename,parent_data,data,bytes) 204 | #define ID3DInclude_Close(This,data) (This)->lpVtbl->Close(This,data) 205 | #else 206 | /*** ID3DInclude methods ***/ 207 | static FORCEINLINE HRESULT ID3DInclude_Open(ID3DInclude* This,D3D_INCLUDE_TYPE include_type,const char *filename,const void *parent_data,const void **data,UINT *bytes) { 208 | return This->lpVtbl->Open(This,include_type,filename,parent_data,data,bytes); 209 | } 210 | static FORCEINLINE HRESULT ID3DInclude_Close(ID3DInclude* This,const void *data) { 211 | return This->lpVtbl->Close(This,data); 212 | } 213 | #endif 214 | #endif 215 | 216 | #endif 217 | 218 | HRESULT STDMETHODCALLTYPE ID3DInclude_Open_Proxy( 219 | ID3DInclude* This, 220 | D3D_INCLUDE_TYPE include_type, 221 | const char *filename, 222 | const void *parent_data, 223 | const void **data, 224 | UINT *bytes); 225 | void __RPC_STUB ID3DInclude_Open_Stub( 226 | IRpcStubBuffer* This, 227 | IRpcChannelBuffer* pRpcChannelBuffer, 228 | PRPC_MESSAGE pRpcMessage, 229 | DWORD* pdwStubPhase); 230 | HRESULT STDMETHODCALLTYPE ID3DInclude_Close_Proxy( 231 | ID3DInclude* This, 232 | const void *data); 233 | void __RPC_STUB ID3DInclude_Close_Stub( 234 | IRpcStubBuffer* This, 235 | IRpcChannelBuffer* pRpcChannelBuffer, 236 | PRPC_MESSAGE pRpcMessage, 237 | DWORD* pdwStubPhase); 238 | 239 | #endif /* __ID3DInclude_INTERFACE_DEFINED__ */ 240 | 241 | typedef ID3DInclude *LPD3DINCLUDE; 242 | typedef enum D3D_DRIVER_TYPE { 243 | D3D_DRIVER_TYPE_UNKNOWN = 0, 244 | D3D_DRIVER_TYPE_HARDWARE = 1, 245 | D3D_DRIVER_TYPE_REFERENCE = 2, 246 | D3D_DRIVER_TYPE_NULL = 3, 247 | D3D_DRIVER_TYPE_SOFTWARE = 4, 248 | D3D_DRIVER_TYPE_WARP = 5 249 | } D3D_DRIVER_TYPE; 250 | typedef enum D3D_FEATURE_LEVEL { 251 | D3D_FEATURE_LEVEL_9_1 = 0x9100, 252 | D3D_FEATURE_LEVEL_9_2 = 0x9200, 253 | D3D_FEATURE_LEVEL_9_3 = 0x9300, 254 | D3D_FEATURE_LEVEL_10_0 = 0xa000, 255 | D3D_FEATURE_LEVEL_10_1 = 0xa100, 256 | D3D_FEATURE_LEVEL_11_0 = 0xb000, 257 | D3D_FEATURE_LEVEL_11_1 = 0xb100 258 | } D3D_FEATURE_LEVEL; 259 | #define D3D_FL9_1_REQ_TEXTURE1D_U_DIMENSION 2048 260 | #define D3D_FL9_3_REQ_TEXTURE1D_U_DIMENSION 4096 261 | #define D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION 2048 262 | #define D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION 4096 263 | #define D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION 512 264 | #define D3D_FL9_3_REQ_TEXTURECUBE_DIMENSION 4096 265 | #define D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION 256 266 | #define D3D_FL9_1_DEFAULT_MAX_ANISOTROPY 2 267 | #define D3D_FL9_1_IA_PRIMITIVE_MAX_COUNT 65535 268 | #define D3D_FL9_2_IA_PRIMITIVE_MAX_COUNT 1048575 269 | #define D3D_FL9_1_SIMULTANEOUS_RENDER_TARGET_COUNT 1 270 | #define D3D_FL9_3_SIMULTANEOUS_RENDER_TARGET_COUNT 4 271 | #define D3D_FL9_1_MAX_TEXTURE_REPEAT 128 272 | #define D3D_FL9_2_MAX_TEXTURE_REPEAT 2048 273 | #define D3D_FL9_3_MAX_TEXTURE_REPEAT 8192 274 | typedef enum _D3D_SHADER_VARIABLE_CLASS { 275 | D3D_SVC_SCALAR = 0, 276 | D3D_SVC_VECTOR = 1, 277 | D3D_SVC_MATRIX_ROWS = 2, 278 | D3D_SVC_MATRIX_COLUMNS = 3, 279 | D3D_SVC_OBJECT = 4, 280 | D3D_SVC_STRUCT = 5, 281 | D3D_SVC_INTERFACE_CLASS = 6, 282 | D3D_SVC_INTERFACE_POINTER = 7, 283 | D3D10_SVC_SCALAR = 0, 284 | D3D10_SVC_VECTOR = 1, 285 | D3D10_SVC_MATRIX_ROWS = 2, 286 | D3D10_SVC_MATRIX_COLUMNS = 3, 287 | D3D10_SVC_OBJECT = 4, 288 | D3D10_SVC_STRUCT = 5, 289 | D3D11_SVC_INTERFACE_CLASS = 6, 290 | D3D11_SVC_INTERFACE_POINTER = 7, 291 | D3D_SVC_FORCE_DWORD = 0x7fffffff 292 | } D3D_SHADER_VARIABLE_CLASS; 293 | typedef enum _D3D_SHADER_VARIABLE_FLAGS { 294 | D3D_SVF_USERPACKED = 0x1, 295 | D3D_SVF_USED = 0x2, 296 | D3D_SVF_INTERFACE_POINTER = 0x4, 297 | D3D_SVF_INTERFACE_PARAMETER = 0x8, 298 | D3D10_SVF_USERPACKED = D3D_SVF_USERPACKED, 299 | D3D10_SVF_USED = D3D_SVF_USED, 300 | D3D11_SVF_INTERFACE_POINTER = D3D_SVF_INTERFACE_POINTER, 301 | D3D11_SVF_INTERFACE_PARAMETER = D3D_SVF_INTERFACE_PARAMETER, 302 | D3D_SVF_FORCE_DWORD = 0x7fffffff 303 | } D3D_SHADER_VARIABLE_FLAGS; 304 | typedef enum _D3D_SHADER_VARIABLE_TYPE { 305 | D3D_SVT_VOID = 0, 306 | D3D_SVT_BOOL = 1, 307 | D3D_SVT_INT = 2, 308 | D3D_SVT_FLOAT = 3, 309 | D3D_SVT_STRING = 4, 310 | D3D_SVT_TEXTURE = 5, 311 | D3D_SVT_TEXTURE1D = 6, 312 | D3D_SVT_TEXTURE2D = 7, 313 | D3D_SVT_TEXTURE3D = 8, 314 | D3D_SVT_TEXTURECUBE = 9, 315 | D3D_SVT_SAMPLER = 10, 316 | D3D_SVT_SAMPLER1D = 11, 317 | D3D_SVT_SAMPLER2D = 12, 318 | D3D_SVT_SAMPLER3D = 13, 319 | D3D_SVT_SAMPLERCUBE = 14, 320 | D3D_SVT_PIXELSHADER = 15, 321 | D3D_SVT_VERTEXSHADER = 16, 322 | D3D_SVT_PIXELFRAGMENT = 17, 323 | D3D_SVT_VERTEXFRAGMENT = 18, 324 | D3D_SVT_UINT = 19, 325 | D3D_SVT_UINT8 = 20, 326 | D3D_SVT_GEOMETRYSHADER = 21, 327 | D3D_SVT_RASTERIZER = 22, 328 | D3D_SVT_DEPTHSTENCIL = 23, 329 | D3D_SVT_BLEND = 24, 330 | D3D_SVT_BUFFER = 25, 331 | D3D_SVT_CBUFFER = 26, 332 | D3D_SVT_TBUFFER = 27, 333 | D3D_SVT_TEXTURE1DARRAY = 28, 334 | D3D_SVT_TEXTURE2DARRAY = 29, 335 | D3D_SVT_RENDERTARGETVIEW = 30, 336 | D3D_SVT_DEPTHSTENCILVIEW = 31, 337 | D3D_SVT_TEXTURE2DMS = 32, 338 | D3D_SVT_TEXTURE2DMSARRAY = 33, 339 | D3D_SVT_TEXTURECUBEARRAY = 34, 340 | D3D_SVT_HULLSHADER = 35, 341 | D3D_SVT_DOMAINSHADER = 36, 342 | D3D_SVT_INTERFACE_POINTER = 37, 343 | D3D_SVT_COMPUTESHADER = 38, 344 | D3D_SVT_DOUBLE = 39, 345 | D3D_SVT_RWTEXTURE1D = 40, 346 | D3D_SVT_RWTEXTURE1DARRAY = 41, 347 | D3D_SVT_RWTEXTURE2D = 42, 348 | D3D_SVT_RWTEXTURE2DARRAY = 43, 349 | D3D_SVT_RWTEXTURE3D = 44, 350 | D3D_SVT_RWBUFFER = 45, 351 | D3D_SVT_BYTEADDRESS_BUFFER = 46, 352 | D3D_SVT_RWBYTEADDRESS_BUFFER = 47, 353 | D3D_SVT_STRUCTURED_BUFFER = 48, 354 | D3D_SVT_RWSTRUCTURED_BUFFER = 49, 355 | D3D_SVT_APPEND_STRUCTURED_BUFFER = 50, 356 | D3D_SVT_CONSUME_STRUCTURED_BUFFER = 51, 357 | D3D10_SVT_VOID = 0, 358 | D3D10_SVT_BOOL = 1, 359 | D3D10_SVT_INT = 2, 360 | D3D10_SVT_FLOAT = 3, 361 | D3D10_SVT_STRING = 4, 362 | D3D10_SVT_TEXTURE = 5, 363 | D3D10_SVT_TEXTURE1D = 6, 364 | D3D10_SVT_TEXTURE2D = 7, 365 | D3D10_SVT_TEXTURE3D = 8, 366 | D3D10_SVT_TEXTURECUBE = 9, 367 | D3D10_SVT_SAMPLER = 10, 368 | D3D10_SVT_SAMPLER1D = 11, 369 | D3D10_SVT_SAMPLER2D = 12, 370 | D3D10_SVT_SAMPLER3D = 13, 371 | D3D10_SVT_SAMPLERCUBE = 14, 372 | D3D10_SVT_PIXELSHADER = 15, 373 | D3D10_SVT_VERTEXSHADER = 16, 374 | D3D10_SVT_PIXELFRAGMENT = 17, 375 | D3D10_SVT_VERTEXFRAGMENT = 18, 376 | D3D10_SVT_UINT = 19, 377 | D3D10_SVT_UINT8 = 20, 378 | D3D10_SVT_GEOMETRYSHADER = 21, 379 | D3D10_SVT_RASTERIZER = 22, 380 | D3D10_SVT_DEPTHSTENCIL = 23, 381 | D3D10_SVT_BLEND = 24, 382 | D3D10_SVT_BUFFER = 25, 383 | D3D10_SVT_CBUFFER = 26, 384 | D3D10_SVT_TBUFFER = 27, 385 | D3D10_SVT_TEXTURE1DARRAY = 28, 386 | D3D10_SVT_TEXTURE2DARRAY = 29, 387 | D3D10_SVT_RENDERTARGETVIEW = 30, 388 | D3D10_SVT_DEPTHSTENCILVIEW = 31, 389 | D3D10_SVT_TEXTURE2DMS = 32, 390 | D3D10_SVT_TEXTURE2DMSARRAY = 33, 391 | D3D10_SVT_TEXTURECUBEARRAY = 34, 392 | D3D11_SVT_HULLSHADER = 35, 393 | D3D11_SVT_DOMAINSHADER = 36, 394 | D3D11_SVT_INTERFACE_POINTER = 37, 395 | D3D11_SVT_COMPUTESHADER = 38, 396 | D3D11_SVT_DOUBLE = 39, 397 | D3D11_SVT_RWTEXTURE1D = 40, 398 | D3D11_SVT_RWTEXTURE1DARRAY = 41, 399 | D3D11_SVT_RWTEXTURE2D = 42, 400 | D3D11_SVT_RWTEXTURE2DARRAY = 43, 401 | D3D11_SVT_RWTEXTURE3D = 44, 402 | D3D11_SVT_RWBUFFER = 45, 403 | D3D11_SVT_BYTEADDRESS_BUFFER = 46, 404 | D3D11_SVT_RWBYTEADDRESS_BUFFER = 47, 405 | D3D11_SVT_STRUCTURED_BUFFER = 48, 406 | D3D11_SVT_RWSTRUCTURED_BUFFER = 49, 407 | D3D11_SVT_APPEND_STRUCTURED_BUFFER = 50, 408 | D3D11_SVT_CONSUME_STRUCTURED_BUFFER = 51, 409 | D3D_SVT_FORCE_DWORD = 0x7fffffff 410 | } D3D_SHADER_VARIABLE_TYPE; 411 | typedef enum _D3D_SHADER_INPUT_FLAGS { 412 | D3D_SIF_USERPACKED = 0x1, 413 | D3D_SIF_COMPARISON_SAMPLER = 0x2, 414 | D3D_SIF_TEXTURE_COMPONENT_0 = 0x4, 415 | D3D_SIF_TEXTURE_COMPONENT_1 = 0x8, 416 | D3D_SIF_TEXTURE_COMPONENTS = 0xc, 417 | D3D_SIF_UNUSED = 0x10, 418 | D3D10_SIF_USERPACKED = D3D_SIF_USERPACKED, 419 | D3D10_SIF_COMPARISON_SAMPLER = D3D_SIF_COMPARISON_SAMPLER, 420 | D3D10_SIF_TEXTURE_COMPONENT_0 = D3D_SIF_TEXTURE_COMPONENT_0, 421 | D3D10_SIF_TEXTURE_COMPONENT_1 = D3D_SIF_TEXTURE_COMPONENT_1, 422 | D3D10_SIF_TEXTURE_COMPONENTS = D3D_SIF_TEXTURE_COMPONENTS, 423 | D3D_SIF_FORCE_DWORD = 0x7fffffff 424 | } D3D_SHADER_INPUT_FLAGS; 425 | typedef enum D3D_PRIMITIVE { 426 | D3D_PRIMITIVE_UNDEFINED = 0, 427 | D3D_PRIMITIVE_POINT = 1, 428 | D3D_PRIMITIVE_LINE = 2, 429 | D3D_PRIMITIVE_TRIANGLE = 3, 430 | D3D_PRIMITIVE_LINE_ADJ = 6, 431 | D3D_PRIMITIVE_TRIANGLE_ADJ = 7, 432 | D3D_PRIMITIVE_1_CONTROL_POINT_PATCH = 8, 433 | D3D_PRIMITIVE_2_CONTROL_POINT_PATCH = 9, 434 | D3D_PRIMITIVE_3_CONTROL_POINT_PATCH = 10, 435 | D3D_PRIMITIVE_4_CONTROL_POINT_PATCH = 11, 436 | D3D_PRIMITIVE_5_CONTROL_POINT_PATCH = 12, 437 | D3D_PRIMITIVE_6_CONTROL_POINT_PATCH = 13, 438 | D3D_PRIMITIVE_7_CONTROL_POINT_PATCH = 14, 439 | D3D_PRIMITIVE_8_CONTROL_POINT_PATCH = 15, 440 | D3D_PRIMITIVE_9_CONTROL_POINT_PATCH = 16, 441 | D3D_PRIMITIVE_10_CONTROL_POINT_PATCH = 17, 442 | D3D_PRIMITIVE_11_CONTROL_POINT_PATCH = 18, 443 | D3D_PRIMITIVE_12_CONTROL_POINT_PATCH = 19, 444 | D3D_PRIMITIVE_13_CONTROL_POINT_PATCH = 20, 445 | D3D_PRIMITIVE_14_CONTROL_POINT_PATCH = 21, 446 | D3D_PRIMITIVE_15_CONTROL_POINT_PATCH = 22, 447 | D3D_PRIMITIVE_16_CONTROL_POINT_PATCH = 23, 448 | D3D_PRIMITIVE_17_CONTROL_POINT_PATCH = 24, 449 | D3D_PRIMITIVE_18_CONTROL_POINT_PATCH = 25, 450 | D3D_PRIMITIVE_19_CONTROL_POINT_PATCH = 26, 451 | D3D_PRIMITIVE_20_CONTROL_POINT_PATCH = 28, 452 | D3D_PRIMITIVE_21_CONTROL_POINT_PATCH = 29, 453 | D3D_PRIMITIVE_22_CONTROL_POINT_PATCH = 30, 454 | D3D_PRIMITIVE_23_CONTROL_POINT_PATCH = 31, 455 | D3D_PRIMITIVE_24_CONTROL_POINT_PATCH = 32, 456 | D3D_PRIMITIVE_25_CONTROL_POINT_PATCH = 33, 457 | D3D_PRIMITIVE_26_CONTROL_POINT_PATCH = 34, 458 | D3D_PRIMITIVE_27_CONTROL_POINT_PATCH = 35, 459 | D3D_PRIMITIVE_28_CONTROL_POINT_PATCH = 36, 460 | D3D_PRIMITIVE_29_CONTROL_POINT_PATCH = 37, 461 | D3D_PRIMITIVE_30_CONTROL_POINT_PATCH = 38, 462 | D3D_PRIMITIVE_31_CONTROL_POINT_PATCH = 39, 463 | D3D_PRIMITIVE_32_CONTROL_POINT_PATCH = 40, 464 | D3D10_PRIMITIVE_UNDEFINED = 0, 465 | D3D10_PRIMITIVE_POINT = 1, 466 | D3D10_PRIMITIVE_LINE = 2, 467 | D3D10_PRIMITIVE_TRIANGLE = 3, 468 | D3D10_PRIMITIVE_LINE_ADJ = 6, 469 | D3D10_PRIMITIVE_TRIANGLE_ADJ = 7, 470 | D3D11_PRIMITIVE_UNDEFINED = 0, 471 | D3D11_PRIMITIVE_POINT = 1, 472 | D3D11_PRIMITIVE_LINE = 2, 473 | D3D11_PRIMITIVE_TRIANGLE = 3, 474 | D3D11_PRIMITIVE_LINE_ADJ = 6, 475 | D3D11_PRIMITIVE_TRIANGLE_ADJ = 7, 476 | D3D11_PRIMITIVE_1_CONTROL_POINT_PATCH = 8, 477 | D3D11_PRIMITIVE_2_CONTROL_POINT_PATCH = 9, 478 | D3D11_PRIMITIVE_3_CONTROL_POINT_PATCH = 10, 479 | D3D11_PRIMITIVE_4_CONTROL_POINT_PATCH = 11, 480 | D3D11_PRIMITIVE_5_CONTROL_POINT_PATCH = 12, 481 | D3D11_PRIMITIVE_6_CONTROL_POINT_PATCH = 13, 482 | D3D11_PRIMITIVE_7_CONTROL_POINT_PATCH = 14, 483 | D3D11_PRIMITIVE_8_CONTROL_POINT_PATCH = 15, 484 | D3D11_PRIMITIVE_9_CONTROL_POINT_PATCH = 16, 485 | D3D11_PRIMITIVE_10_CONTROL_POINT_PATCH = 17, 486 | D3D11_PRIMITIVE_11_CONTROL_POINT_PATCH = 18, 487 | D3D11_PRIMITIVE_12_CONTROL_POINT_PATCH = 19, 488 | D3D11_PRIMITIVE_13_CONTROL_POINT_PATCH = 20, 489 | D3D11_PRIMITIVE_14_CONTROL_POINT_PATCH = 21, 490 | D3D11_PRIMITIVE_15_CONTROL_POINT_PATCH = 22, 491 | D3D11_PRIMITIVE_16_CONTROL_POINT_PATCH = 23, 492 | D3D11_PRIMITIVE_17_CONTROL_POINT_PATCH = 24, 493 | D3D11_PRIMITIVE_18_CONTROL_POINT_PATCH = 25, 494 | D3D11_PRIMITIVE_19_CONTROL_POINT_PATCH = 26, 495 | D3D11_PRIMITIVE_20_CONTROL_POINT_PATCH = 28, 496 | D3D11_PRIMITIVE_21_CONTROL_POINT_PATCH = 29, 497 | D3D11_PRIMITIVE_22_CONTROL_POINT_PATCH = 30, 498 | D3D11_PRIMITIVE_23_CONTROL_POINT_PATCH = 31, 499 | D3D11_PRIMITIVE_24_CONTROL_POINT_PATCH = 32, 500 | D3D11_PRIMITIVE_25_CONTROL_POINT_PATCH = 33, 501 | D3D11_PRIMITIVE_26_CONTROL_POINT_PATCH = 34, 502 | D3D11_PRIMITIVE_27_CONTROL_POINT_PATCH = 35, 503 | D3D11_PRIMITIVE_28_CONTROL_POINT_PATCH = 36, 504 | D3D11_PRIMITIVE_29_CONTROL_POINT_PATCH = 37, 505 | D3D11_PRIMITIVE_30_CONTROL_POINT_PATCH = 38, 506 | D3D11_PRIMITIVE_31_CONTROL_POINT_PATCH = 39, 507 | D3D11_PRIMITIVE_32_CONTROL_POINT_PATCH = 40 508 | } D3D_PRIMITIVE; 509 | typedef enum D3D_PRIMITIVE_TOPOLOGY { 510 | D3D_PRIMITIVE_TOPOLOGY_UNDEFINED = 0, 511 | D3D_PRIMITIVE_TOPOLOGY_POINTLIST = 1, 512 | D3D_PRIMITIVE_TOPOLOGY_LINELIST = 2, 513 | D3D_PRIMITIVE_TOPOLOGY_LINESTRIP = 3, 514 | D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4, 515 | D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5, 516 | D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10, 517 | D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11, 518 | D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12, 519 | D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13, 520 | D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = 33, 521 | D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST = 34, 522 | D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST = 35, 523 | D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST = 36, 524 | D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST = 37, 525 | D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST = 38, 526 | D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST = 39, 527 | D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST = 40, 528 | D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST = 41, 529 | D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST = 42, 530 | D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST = 43, 531 | D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST = 44, 532 | D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST = 45, 533 | D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST = 46, 534 | D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST = 47, 535 | D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST = 48, 536 | D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST = 49, 537 | D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST = 50, 538 | D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST = 51, 539 | D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST = 52, 540 | D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST = 53, 541 | D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST = 54, 542 | D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST = 55, 543 | D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST = 56, 544 | D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST = 57, 545 | D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST = 58, 546 | D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST = 59, 547 | D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST = 60, 548 | D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST = 61, 549 | D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST = 62, 550 | D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST = 63, 551 | D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST = 64, 552 | D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED = 0, 553 | D3D10_PRIMITIVE_TOPOLOGY_POINTLIST = 1, 554 | D3D10_PRIMITIVE_TOPOLOGY_LINELIST = 2, 555 | D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP = 3, 556 | D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4, 557 | D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5, 558 | D3D10_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10, 559 | D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11, 560 | D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12, 561 | D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13, 562 | D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED = 0, 563 | D3D11_PRIMITIVE_TOPOLOGY_POINTLIST = 1, 564 | D3D11_PRIMITIVE_TOPOLOGY_LINELIST = 2, 565 | D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP = 3, 566 | D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4, 567 | D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5, 568 | D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10, 569 | D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11, 570 | D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12, 571 | D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13, 572 | D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = 33, 573 | D3D11_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST = 34, 574 | D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST = 35, 575 | D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST = 36, 576 | D3D11_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST = 37, 577 | D3D11_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST = 38, 578 | D3D11_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST = 39, 579 | D3D11_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST = 40, 580 | D3D11_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST = 41, 581 | D3D11_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST = 42, 582 | D3D11_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST = 43, 583 | D3D11_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST = 44, 584 | D3D11_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST = 45, 585 | D3D11_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST = 46, 586 | D3D11_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST = 47, 587 | D3D11_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST = 48, 588 | D3D11_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST = 49, 589 | D3D11_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST = 50, 590 | D3D11_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST = 51, 591 | D3D11_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST = 52, 592 | D3D11_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST = 53, 593 | D3D11_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST = 54, 594 | D3D11_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST = 55, 595 | D3D11_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST = 56, 596 | D3D11_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST = 57, 597 | D3D11_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST = 58, 598 | D3D11_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST = 59, 599 | D3D11_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST = 60, 600 | D3D11_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST = 61, 601 | D3D11_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST = 62, 602 | D3D11_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST = 63, 603 | D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST = 64 604 | } D3D_PRIMITIVE_TOPOLOGY; 605 | typedef enum D3D_TESSELLATOR_DOMAIN { 606 | D3D_TESSELLATOR_DOMAIN_UNDEFINED = 0, 607 | D3D_TESSELLATOR_DOMAIN_ISOLINE = 1, 608 | D3D_TESSELLATOR_DOMAIN_TRI = 2, 609 | D3D_TESSELLATOR_DOMAIN_QUAD = 3, 610 | D3D11_TESSELLATOR_DOMAIN_UNDEFINED = 0, 611 | D3D11_TESSELLATOR_DOMAIN_ISOLINE = 1, 612 | D3D11_TESSELLATOR_DOMAIN_TRI = 2, 613 | D3D11_TESSELLATOR_DOMAIN_QUAD = 3 614 | } D3D_TESSELLATOR_DOMAIN; 615 | typedef enum D3D_TESSELLATOR_PARTITIONING { 616 | D3D_TESSELLATOR_PARTITIONING_UNDEFINED = 0, 617 | D3D_TESSELLATOR_PARTITIONING_INTEGER = 1, 618 | D3D_TESSELLATOR_PARTITIONING_POW2 = 2, 619 | D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3, 620 | D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4, 621 | D3D11_TESSELLATOR_PARTITIONING_UNDEFINED = 0, 622 | D3D11_TESSELLATOR_PARTITIONING_INTEGER = 1, 623 | D3D11_TESSELLATOR_PARTITIONING_POW2 = 2, 624 | D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3, 625 | D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4 626 | } D3D_TESSELLATOR_PARTITIONING; 627 | typedef enum D3D_TESSELLATOR_OUTPUT_PRIMITIVE { 628 | D3D_TESSELLATOR_OUTPUT_UNDEFINED = 0, 629 | D3D_TESSELLATOR_OUTPUT_POINT = 1, 630 | D3D_TESSELLATOR_OUTPUT_LINE = 2, 631 | D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3, 632 | D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4, 633 | D3D11_TESSELLATOR_OUTPUT_UNDEFINED = 0, 634 | D3D11_TESSELLATOR_OUTPUT_POINT = 1, 635 | D3D11_TESSELLATOR_OUTPUT_LINE = 2, 636 | D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3, 637 | D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4 638 | } D3D_TESSELLATOR_OUTPUT_PRIMITIVE; 639 | typedef enum D3D_CBUFFER_TYPE { 640 | D3D_CT_CBUFFER = 0, 641 | D3D_CT_TBUFFER = 1, 642 | D3D_CT_INTERFACE_POINTERS = 2, 643 | D3D_CT_RESOURCE_BIND_INFO = 3, 644 | D3D10_CT_CBUFFER = 0, 645 | D3D10_CT_TBUFFER = 1, 646 | D3D11_CT_CBUFFER = 0, 647 | D3D11_CT_TBUFFER = 1, 648 | D3D11_CT_INTERFACE_POINTERS = 2, 649 | D3D11_CT_RESOURCE_BIND_INFO = 3 650 | } D3D_CBUFFER_TYPE; 651 | typedef enum D3D_SRV_DIMENSION { 652 | D3D_SRV_DIMENSION_UNKNOWN = 0, 653 | D3D_SRV_DIMENSION_BUFFER = 1, 654 | D3D_SRV_DIMENSION_TEXTURE1D = 2, 655 | D3D_SRV_DIMENSION_TEXTURE1DARRAY = 3, 656 | D3D_SRV_DIMENSION_TEXTURE2D = 4, 657 | D3D_SRV_DIMENSION_TEXTURE2DARRAY = 5, 658 | D3D_SRV_DIMENSION_TEXTURE2DMS = 6, 659 | D3D_SRV_DIMENSION_TEXTURE2DMSARRAY = 7, 660 | D3D_SRV_DIMENSION_TEXTURE3D = 8, 661 | D3D_SRV_DIMENSION_TEXTURECUBE = 9, 662 | D3D_SRV_DIMENSION_TEXTURECUBEARRAY = 10, 663 | D3D_SRV_DIMENSION_BUFFEREX = 11, 664 | D3D10_SRV_DIMENSION_UNKNOWN = 0, 665 | D3D10_SRV_DIMENSION_BUFFER = 1, 666 | D3D10_SRV_DIMENSION_TEXTURE1D = 2, 667 | D3D10_SRV_DIMENSION_TEXTURE1DARRAY = 3, 668 | D3D10_SRV_DIMENSION_TEXTURE2D = 4, 669 | D3D10_SRV_DIMENSION_TEXTURE2DARRAY = 5, 670 | D3D10_SRV_DIMENSION_TEXTURE2DMS = 6, 671 | D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY = 7, 672 | D3D10_SRV_DIMENSION_TEXTURE3D = 8, 673 | D3D10_SRV_DIMENSION_TEXTURECUBE = 9, 674 | D3D10_1_SRV_DIMENSION_UNKNOWN = 0, 675 | D3D10_1_SRV_DIMENSION_BUFFER = 1, 676 | D3D10_1_SRV_DIMENSION_TEXTURE1D = 2, 677 | D3D10_1_SRV_DIMENSION_TEXTURE1DARRAY = 3, 678 | D3D10_1_SRV_DIMENSION_TEXTURE2D = 4, 679 | D3D10_1_SRV_DIMENSION_TEXTURE2DARRAY = 5, 680 | D3D10_1_SRV_DIMENSION_TEXTURE2DMS = 6, 681 | D3D10_1_SRV_DIMENSION_TEXTURE2DMSARRAY = 7, 682 | D3D10_1_SRV_DIMENSION_TEXTURE3D = 8, 683 | D3D10_1_SRV_DIMENSION_TEXTURECUBE = 9, 684 | D3D10_1_SRV_DIMENSION_TEXTURECUBEARRAY = 10, 685 | D3D11_SRV_DIMENSION_UNKNOWN = 0, 686 | D3D11_SRV_DIMENSION_BUFFER = 1, 687 | D3D11_SRV_DIMENSION_TEXTURE1D = 2, 688 | D3D11_SRV_DIMENSION_TEXTURE1DARRAY = 3, 689 | D3D11_SRV_DIMENSION_TEXTURE2D = 4, 690 | D3D11_SRV_DIMENSION_TEXTURE2DARRAY = 5, 691 | D3D11_SRV_DIMENSION_TEXTURE2DMS = 6, 692 | D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY = 7, 693 | D3D11_SRV_DIMENSION_TEXTURE3D = 8, 694 | D3D11_SRV_DIMENSION_TEXTURECUBE = 9, 695 | D3D11_SRV_DIMENSION_TEXTURECUBEARRAY = 10, 696 | D3D11_SRV_DIMENSION_BUFFEREX = 11 697 | } D3D_SRV_DIMENSION; 698 | typedef enum D3D_REGISTER_COMPONENT_TYPE { 699 | D3D_REGISTER_COMPONENT_UNKNOWN = 0, 700 | D3D_REGISTER_COMPONENT_UINT32 = 1, 701 | D3D_REGISTER_COMPONENT_SINT32 = 2, 702 | D3D_REGISTER_COMPONENT_FLOAT32 = 3, 703 | D3D10_REGISTER_COMPONENT_UNKNOWN = 0, 704 | D3D10_REGISTER_COMPONENT_UINT32 = 1, 705 | D3D10_REGISTER_COMPONENT_SINT32 = 2, 706 | D3D10_REGISTER_COMPONENT_FLOAT32 = 3 707 | } D3D_REGISTER_COMPONENT_TYPE; 708 | typedef enum D3D_RESOURCE_RETURN_TYPE { 709 | D3D_RETURN_TYPE_UNORM = 1, 710 | D3D_RETURN_TYPE_SNORM = 2, 711 | D3D_RETURN_TYPE_SINT = 3, 712 | D3D_RETURN_TYPE_UINT = 4, 713 | D3D_RETURN_TYPE_FLOAT = 5, 714 | D3D_RETURN_TYPE_MIXED = 6, 715 | D3D_RETURN_TYPE_DOUBLE = 7, 716 | D3D_RETURN_TYPE_CONTINUED = 8, 717 | D3D10_RETURN_TYPE_UNORM = 1, 718 | D3D10_RETURN_TYPE_SNORM = 2, 719 | D3D10_RETURN_TYPE_SINT = 3, 720 | D3D10_RETURN_TYPE_UINT = 4, 721 | D3D10_RETURN_TYPE_FLOAT = 5, 722 | D3D10_RETURN_TYPE_MIXED = 6, 723 | D3D11_RETURN_TYPE_UNORM = 1, 724 | D3D11_RETURN_TYPE_SNORM = 2, 725 | D3D11_RETURN_TYPE_SINT = 3, 726 | D3D11_RETURN_TYPE_UINT = 4, 727 | D3D11_RETURN_TYPE_FLOAT = 5, 728 | D3D11_RETURN_TYPE_MIXED = 6, 729 | D3D11_RETURN_TYPE_DOUBLE = 7, 730 | D3D11_RETURN_TYPE_CONTINUED = 8 731 | } D3D_RESOURCE_RETURN_TYPE; 732 | typedef enum D3D_NAME { 733 | D3D_NAME_UNDEFINED = 0, 734 | D3D_NAME_POSITION = 1, 735 | D3D_NAME_CLIP_DISTANCE = 2, 736 | D3D_NAME_CULL_DISTANCE = 3, 737 | D3D_NAME_RENDER_TARGET_ARRAY_INDEX = 4, 738 | D3D_NAME_VIEWPORT_ARRAY_INDEX = 5, 739 | D3D_NAME_VERTEX_ID = 6, 740 | D3D_NAME_PRIMITIVE_ID = 7, 741 | D3D_NAME_INSTANCE_ID = 8, 742 | D3D_NAME_IS_FRONT_FACE = 9, 743 | D3D_NAME_SAMPLE_INDEX = 10, 744 | D3D_NAME_FINAL_QUAD_EDGE_TESSFACTOR = 11, 745 | D3D_NAME_FINAL_QUAD_INSIDE_TESSFACTOR = 12, 746 | D3D_NAME_FINAL_TRI_EDGE_TESSFACTOR = 13, 747 | D3D_NAME_FINAL_TRI_INSIDE_TESSFACTOR = 14, 748 | D3D_NAME_FINAL_LINE_DETAIL_TESSFACTOR = 15, 749 | D3D_NAME_FINAL_LINE_DENSITY_TESSFACTOR = 16, 750 | D3D_NAME_TARGET = 64, 751 | D3D_NAME_DEPTH = 65, 752 | D3D_NAME_COVERAGE = 66, 753 | D3D_NAME_DEPTH_GREATER_EQUAL = 67, 754 | D3D_NAME_DEPTH_LESS_EQUAL = 68, 755 | D3D10_NAME_UNDEFINED = 0, 756 | D3D10_NAME_POSITION = 1, 757 | D3D10_NAME_CLIP_DISTANCE = 2, 758 | D3D10_NAME_CULL_DISTANCE = 3, 759 | D3D10_NAME_RENDER_TARGET_ARRAY_INDEX = 4, 760 | D3D10_NAME_VIEWPORT_ARRAY_INDEX = 5, 761 | D3D10_NAME_VERTEX_ID = 6, 762 | D3D10_NAME_PRIMITIVE_ID = 7, 763 | D3D10_NAME_INSTANCE_ID = 8, 764 | D3D10_NAME_IS_FRONT_FACE = 9, 765 | D3D10_NAME_SAMPLE_INDEX = 10, 766 | D3D11_NAME_FINAL_QUAD_EDGE_TESSFACTOR = 11, 767 | D3D11_NAME_FINAL_QUAD_INSIDE_TESSFACTOR = 12, 768 | D3D11_NAME_FINAL_TRI_EDGE_TESSFACTOR = 13, 769 | D3D11_NAME_FINAL_TRI_INSIDE_TESSFACTOR = 14, 770 | D3D11_NAME_FINAL_LINE_DETAIL_TESSFACTOR = 15, 771 | D3D11_NAME_FINAL_LINE_DENSITY_TESSFACTOR = 16, 772 | D3D10_NAME_TARGET = 64, 773 | D3D10_NAME_DEPTH = 65, 774 | D3D10_NAME_COVERAGE = 66, 775 | D3D11_NAME_DEPTH_GREATER_EQUAL = 67, 776 | D3D11_NAME_DEPTH_LESS_EQUAL = 68 777 | } D3D_NAME; 778 | typedef enum _D3D_SHADER_INPUT_TYPE { 779 | D3D_SIT_CBUFFER = 0, 780 | D3D_SIT_TBUFFER = 1, 781 | D3D_SIT_TEXTURE = 2, 782 | D3D_SIT_SAMPLER = 3, 783 | D3D_SIT_UAV_RWTYPED = 4, 784 | D3D_SIT_STRUCTURED = 5, 785 | D3D_SIT_UAV_RWSTRUCTURED = 6, 786 | D3D_SIT_BYTEADDRESS = 7, 787 | D3D_SIT_UAV_RWBYTEADDRESS = 8, 788 | D3D_SIT_UAV_APPEND_STRUCTURED = 9, 789 | D3D_SIT_UAV_CONSUME_STRUCTURED = 10, 790 | D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER = 11, 791 | D3D10_SIT_CBUFFER = 0, 792 | D3D10_SIT_TBUFFER = 1, 793 | D3D10_SIT_TEXTURE = 2, 794 | D3D10_SIT_SAMPLER = 3, 795 | D3D11_SIT_UAV_RWTYPED = 4, 796 | D3D11_SIT_STRUCTURED = 5, 797 | D3D11_SIT_UAV_RWSTRUCTURED = 6, 798 | D3D11_SIT_BYTEADDRESS = 7, 799 | D3D11_SIT_UAV_RWBYTEADDRESS = 8, 800 | D3D11_SIT_UAV_APPEND_STRUCTURED = 9, 801 | D3D11_SIT_UAV_CONSUME_STRUCTURED = 10, 802 | D3D11_SIT_UAV_RWSTRUCTURED_WITH_COUNTER = 11 803 | } D3D_SHADER_INPUT_TYPE; 804 | typedef enum _D3D_SHADER_CBUFFER_FLAGS { 805 | D3D_CBF_USERPACKED = 0x1, 806 | D3D10_CBF_USERPACKED = D3D_CBF_USERPACKED, 807 | D3D_CBF_FORCE_DWORD = 0x7fffffff 808 | } D3D_SHADER_CBUFFER_FLAGS; 809 | DEFINE_GUID(WKPDID_D3DDebugObjectName,0x429b8c22,0x9188,0x4b0c,0x87,0x42,0xac,0xb0,0xbf,0x85,0xc2,0x00); 810 | /* Begin additional prototypes for all interfaces */ 811 | 812 | 813 | /* End additional prototypes */ 814 | 815 | #ifdef __cplusplus 816 | } 817 | #endif 818 | 819 | #endif /* __d3dcommon_h__ */ 820 | -------------------------------------------------------------------------------- /lib/mingw/dxgiformat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 Andras Kovacs 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | #ifndef __dxgiformat_h__ 20 | #define __dxgiformat_h__ 21 | 22 | #define DXGI_FORMAT_DEFINED 1 23 | 24 | typedef enum DXGI_FORMAT { 25 | DXGI_FORMAT_UNKNOWN = 0, 26 | DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, 27 | DXGI_FORMAT_R32G32B32A32_FLOAT = 2, 28 | DXGI_FORMAT_R32G32B32A32_UINT = 3, 29 | DXGI_FORMAT_R32G32B32A32_SINT = 4, 30 | DXGI_FORMAT_R32G32B32_TYPELESS = 5, 31 | DXGI_FORMAT_R32G32B32_FLOAT = 6, 32 | DXGI_FORMAT_R32G32B32_UINT = 7, 33 | DXGI_FORMAT_R32G32B32_SINT = 8, 34 | DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, 35 | DXGI_FORMAT_R16G16B16A16_FLOAT = 10, 36 | DXGI_FORMAT_R16G16B16A16_UNORM = 11, 37 | DXGI_FORMAT_R16G16B16A16_UINT = 12, 38 | DXGI_FORMAT_R16G16B16A16_SNORM = 13, 39 | DXGI_FORMAT_R16G16B16A16_SINT = 14, 40 | DXGI_FORMAT_R32G32_TYPELESS = 15, 41 | DXGI_FORMAT_R32G32_FLOAT = 16, 42 | DXGI_FORMAT_R32G32_UINT = 17, 43 | DXGI_FORMAT_R32G32_SINT = 18, 44 | DXGI_FORMAT_R32G8X24_TYPELESS = 19, 45 | DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, 46 | DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS= 21, 47 | DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, 48 | DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, 49 | DXGI_FORMAT_R10G10B10A2_UNORM = 24, 50 | DXGI_FORMAT_R10G10B10A2_UINT = 25, 51 | DXGI_FORMAT_R11G11B10_FLOAT = 26, 52 | DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, 53 | DXGI_FORMAT_R8G8B8A8_UNORM = 28, 54 | DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, 55 | DXGI_FORMAT_R8G8B8A8_UINT = 30, 56 | DXGI_FORMAT_R8G8B8A8_SNORM = 31, 57 | DXGI_FORMAT_R8G8B8A8_SINT = 32, 58 | DXGI_FORMAT_R16G16_TYPELESS = 33, 59 | DXGI_FORMAT_R16G16_FLOAT = 34, 60 | DXGI_FORMAT_R16G16_UNORM = 35, 61 | DXGI_FORMAT_R16G16_UINT = 36, 62 | DXGI_FORMAT_R16G16_SNORM = 37, 63 | DXGI_FORMAT_R16G16_SINT = 38, 64 | DXGI_FORMAT_R32_TYPELESS = 39, 65 | DXGI_FORMAT_D32_FLOAT = 40, 66 | DXGI_FORMAT_R32_FLOAT = 41, 67 | DXGI_FORMAT_R32_UINT = 42, 68 | DXGI_FORMAT_R32_SINT = 43, 69 | DXGI_FORMAT_R24G8_TYPELESS = 44, 70 | DXGI_FORMAT_D24_UNORM_S8_UINT = 45, 71 | DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, 72 | DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, 73 | DXGI_FORMAT_R8G8_TYPELESS = 48, 74 | DXGI_FORMAT_R8G8_UNORM = 49, 75 | DXGI_FORMAT_R8G8_UINT = 50, 76 | DXGI_FORMAT_R8G8_SNORM = 51, 77 | DXGI_FORMAT_R8G8_SINT = 52, 78 | DXGI_FORMAT_R16_TYPELESS = 53, 79 | DXGI_FORMAT_R16_FLOAT = 54, 80 | DXGI_FORMAT_D16_UNORM = 55, 81 | DXGI_FORMAT_R16_UNORM = 56, 82 | DXGI_FORMAT_R16_UINT = 57, 83 | DXGI_FORMAT_R16_SNORM = 58, 84 | DXGI_FORMAT_R16_SINT = 59, 85 | DXGI_FORMAT_R8_TYPELESS = 60, 86 | DXGI_FORMAT_R8_UNORM = 61, 87 | DXGI_FORMAT_R8_UINT = 62, 88 | DXGI_FORMAT_R8_SNORM = 63, 89 | DXGI_FORMAT_R8_SINT = 64, 90 | DXGI_FORMAT_A8_UNORM = 65, 91 | DXGI_FORMAT_R1_UNORM = 66, 92 | DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, 93 | DXGI_FORMAT_R8G8_B8G8_UNORM = 68, 94 | DXGI_FORMAT_G8R8_G8B8_UNORM = 69, 95 | DXGI_FORMAT_BC1_TYPELESS = 70, 96 | DXGI_FORMAT_BC1_UNORM = 71, 97 | DXGI_FORMAT_BC1_UNORM_SRGB = 72, 98 | DXGI_FORMAT_BC2_TYPELESS = 73, 99 | DXGI_FORMAT_BC2_UNORM = 74, 100 | DXGI_FORMAT_BC2_UNORM_SRGB = 75, 101 | DXGI_FORMAT_BC3_TYPELESS = 76, 102 | DXGI_FORMAT_BC3_UNORM = 77, 103 | DXGI_FORMAT_BC3_UNORM_SRGB = 78, 104 | DXGI_FORMAT_BC4_TYPELESS = 79, 105 | DXGI_FORMAT_BC4_UNORM = 80, 106 | DXGI_FORMAT_BC4_SNORM = 81, 107 | DXGI_FORMAT_BC5_TYPELESS = 82, 108 | DXGI_FORMAT_BC5_UNORM = 83, 109 | DXGI_FORMAT_BC5_SNORM = 84, 110 | DXGI_FORMAT_B5G6R5_UNORM = 85, 111 | DXGI_FORMAT_B5G5R5A1_UNORM = 86, 112 | DXGI_FORMAT_B8G8R8A8_UNORM = 87, 113 | DXGI_FORMAT_B8G8R8X8_UNORM = 88, 114 | DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, 115 | DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, 116 | DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, 117 | DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, 118 | DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, 119 | DXGI_FORMAT_BC6H_TYPELESS = 94, 120 | DXGI_FORMAT_BC6H_UF16 = 95, 121 | DXGI_FORMAT_BC6H_SF16 = 96, 122 | DXGI_FORMAT_BC7_TYPELESS = 97, 123 | DXGI_FORMAT_BC7_UNORM = 98, 124 | DXGI_FORMAT_BC7_UNORM_SRGB = 99, 125 | DXGI_FORMAT_AYUV = 100, 126 | DXGI_FORMAT_Y410 = 101, 127 | DXGI_FORMAT_Y416 = 102, 128 | DXGI_FORMAT_NV12 = 103, 129 | DXGI_FORMAT_P010 = 104, 130 | DXGI_FORMAT_P016 = 105, 131 | DXGI_FORMAT_420_OPAQUE = 106, 132 | DXGI_FORMAT_YUY2 = 107, 133 | DXGI_FORMAT_Y210 = 108, 134 | DXGI_FORMAT_Y216 = 109, 135 | DXGI_FORMAT_NV11 = 110, 136 | DXGI_FORMAT_AI44 = 111, 137 | DXGI_FORMAT_IA44 = 112, 138 | DXGI_FORMAT_P8 = 113, 139 | DXGI_FORMAT_A8P8 = 114, 140 | DXGI_FORMAT_B4G4R4A4_UNORM = 115, 141 | DXGI_FORMAT_FORCE_UINT = 0xffffffff 142 | } DXGI_FORMAT; 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /lib/mingw/dxgitype.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 Andras Kovacs 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | #ifndef __dxgitype_h__ 20 | #define __dxgitype_h__ 21 | 22 | #include "dxgiformat.h" 23 | 24 | #ifndef D3DCOLORVALUE_DEFINED 25 | typedef struct _D3DCOLORVALUE { 26 | float r; 27 | float g; 28 | float b; 29 | float a; 30 | } D3DCOLORVALUE; 31 | #define D3DCOLORVALUE_DEFINED 32 | #endif 33 | 34 | typedef D3DCOLORVALUE DXGI_RGBA; 35 | 36 | typedef struct DXGI_SAMPLE_DESC { 37 | UINT Count; 38 | UINT Quality; 39 | } DXGI_SAMPLE_DESC; 40 | 41 | typedef enum DXGI_MODE_ROTATION { 42 | DXGI_MODE_ROTATION_UNSPECIFIED = 0, 43 | DXGI_MODE_ROTATION_IDENTITY = 1, 44 | DXGI_MODE_ROTATION_ROTATE90 = 2, 45 | DXGI_MODE_ROTATION_ROTATE180 = 3, 46 | DXGI_MODE_ROTATION_ROTATE270 = 4, 47 | } DXGI_MODE_ROTATION; 48 | 49 | typedef enum DXGI_MODE_SCANLINE_ORDER { 50 | DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED = 0, 51 | DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE = 1, 52 | DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST = 2, 53 | DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST = 3, 54 | } DXGI_MODE_SCANLINE_ORDER; 55 | 56 | typedef enum DXGI_MODE_SCALING { 57 | DXGI_MODE_SCALING_UNSPECIFIED = 0, 58 | DXGI_MODE_SCALING_CENTERED = 1, 59 | DXGI_MODE_SCALING_STRETCHED = 2, 60 | } DXGI_MODE_SCALING; 61 | 62 | typedef struct DXGI_RATIONAL { 63 | UINT Numerator; 64 | UINT Denominator; 65 | } DXGI_RATIONAL; 66 | 67 | typedef struct DXGI_MODE_DESC { 68 | UINT Width; 69 | UINT Height; 70 | DXGI_RATIONAL RefreshRate; 71 | DXGI_FORMAT Format; 72 | DXGI_MODE_SCANLINE_ORDER ScanlineOrdering; 73 | DXGI_MODE_SCALING Scaling; 74 | } DXGI_MODE_DESC; 75 | 76 | typedef struct DXGI_GAMMA_CONTROL_CAPABILITIES { 77 | WINBOOL ScaleAndOffsetSupported; 78 | float MaxConvertedValue; 79 | float MinConvertedValue; 80 | UINT NumGammaControlPoints; 81 | float ControlPointPositions[1025]; 82 | } DXGI_GAMMA_CONTROL_CAPABILITIES; 83 | 84 | typedef struct DXGI_RGB { 85 | float Red; 86 | float Green; 87 | float Blue; 88 | } DXGI_RGB; 89 | 90 | typedef struct DXGI_GAMMA_CONTROL { 91 | DXGI_RGB Scale; 92 | DXGI_RGB Offset; 93 | DXGI_RGB GammaCurve[1025]; 94 | } DXGI_GAMMA_CONTROL; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /lib/punity-sdl.c: -------------------------------------------------------------------------------- 1 | #include "SDL.h" 2 | #include "SDL_opengl.h" 3 | 4 | static struct 5 | { 6 | SDL_Window *window; 7 | SDL_Renderer *renderer; 8 | SDL_GLContext *context; 9 | 10 | GLuint texture; 11 | } 12 | punp_runtime_sdl; 13 | 14 | bool 15 | window_is_fullscreen() 16 | { 17 | Uint32 flags = SDL_GetWindowFlags(punp_runtime_sdl.window); 18 | return (flags & SDL_WINDOW_FULLSCREEN_DESKTOP); 19 | } 20 | 21 | void 22 | window_fullscreen_toggle() 23 | { 24 | if (window_is_fullscreen()) { 25 | SDL_SetWindowFullscreen(punp_runtime_sdl.window, 0); 26 | } else { 27 | SDL_SetWindowFullscreen(punp_runtime_sdl.window, SDL_WINDOW_FULLSCREEN_DESKTOP); 28 | } 29 | } 30 | 31 | void 32 | window_resize(int width, int height, int scale) 33 | { 34 | CORE->window.width = width; 35 | CORE->window.height = height; 36 | CORE->window.scale_normal = scale; 37 | SDL_SetWindowSize(punp_runtime_sdl.window, 38 | width * scale, height * scale); 39 | } 40 | 41 | void 42 | window_title(const char *title) 43 | { 44 | SDL_SetWindowTitle(punp_runtime_sdl.window, title); 45 | } 46 | 47 | static u8 pun_sdl_remap_vkey_table[256] = {0}; 48 | static u8 pun_sdl_remap_scan_table[SDL_NUM_SCANCODES] = {0}; 49 | 50 | enum { 51 | SDLK_A = SDLK_a, SDLK_B = SDLK_b, SDLK_C = SDLK_c, SDLK_D = SDLK_d, 52 | SDLK_E = SDLK_e, SDLK_F = SDLK_f, SDLK_G = SDLK_g, SDLK_H = SDLK_h, 53 | SDLK_I = SDLK_i, SDLK_J = SDLK_j, SDLK_K = SDLK_k, SDLK_L = SDLK_l, 54 | SDLK_M = SDLK_m, SDLK_N = SDLK_n, SDLK_O = SDLK_o, SDLK_P = SDLK_p, 55 | SDLK_Q = SDLK_q, SDLK_R = SDLK_r, SDLK_S = SDLK_s, SDLK_T = SDLK_t, 56 | SDLK_U = SDLK_u, SDLK_V = SDLK_v, SDLK_W = SDLK_w, SDLK_X = SDLK_x, 57 | SDLK_Y = SDLK_y, SDLK_Z = SDLK_z, 58 | SDLK_APOSTROPHE = SDLK_QUOTE, 59 | SDLK_EQUAL = SDLK_EQUALS, 60 | SDLK_LEFT_BRACKET = SDLK_LEFTBRACKET, 61 | SDLK_RIGHT_BRACKET = SDLK_RIGHTBRACKET, 62 | SDLK_BACK_QUOTE = SDLK_BACKQUOTE, 63 | SDLK_BACK_SLASH = SDLK_BACKSLASH, 64 | SDLK_MOUSE_LEFT = 0, 65 | SDLK_MOUSE_RIGHT = 0, 66 | SDLK_MOUSE_MIDDLE = 0, 67 | }; 68 | 69 | void 70 | pun_sdl_make_key_maps() 71 | { 72 | 73 | struct { int key, sym; } table[] = { 74 | #define PUN_KEY_MAPPING_ENTRY(k, v, s) { KEY_##k, SDLK_##k }, 75 | PUN_KEY_MAPPING 76 | #undef PUN_KEY_MAPPING_ENTRY 77 | }; 78 | 79 | u8 *vkey = pun_sdl_remap_vkey_table; 80 | u8 *scan = pun_sdl_remap_scan_table; 81 | SDL_Log("%d", array_count(table)); 82 | for (int i = 0; i != array_count(table); ++i) { 83 | if (table[i].sym & (1 << 30)) { 84 | int s = table[i].sym & ~(1 << 30); 85 | ASSERT(s < array_count(pun_sdl_remap_scan_table)); 86 | scan[s] = table[i].key; 87 | } else { 88 | ASSERT(table[i].sym < array_count(pun_sdl_remap_vkey_table)); 89 | vkey[table[i].sym] = table[i].key; 90 | } 91 | } 92 | } 93 | 94 | u8 95 | pun_sdl_remap_sym(int sym) 96 | { 97 | if (sym & (1 << 30)) { 98 | sym = sym & ~(1 << 30); 99 | if (sym > array_count(pun_sdl_remap_scan_table)) { 100 | return KEY_UNKNOWN; 101 | } 102 | return pun_sdl_remap_scan_table[sym]; 103 | } else { 104 | if (sym > array_count(pun_sdl_remap_vkey_table)) { 105 | return KEY_UNKNOWN; 106 | } 107 | return pun_sdl_remap_vkey_table[sym]; 108 | } 109 | } 110 | 111 | extern int 112 | main(int argc, char **argv) 113 | { 114 | pun_sdl_make_key_maps(); 115 | 116 | // TODO: Concat `argv`. 117 | const char *args = ""; 118 | punity_init(args); 119 | 120 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); 121 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); 122 | 123 | i32 window_width = CORE->window.width * CORE->window.scale_normal; 124 | i32 window_height = CORE->window.height * CORE->window.scale_normal; 125 | punp_runtime_sdl.window = SDL_CreateWindow( 126 | "Punity (SDL)", 127 | SDL_WINDOWPOS_CENTERED, 128 | SDL_WINDOWPOS_CENTERED, 129 | window_width, window_height, 130 | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); 131 | 132 | if (punp_runtime_sdl.window == 0) { 133 | printf("SDL_CreateWindow: %s\n", SDL_GetError()); 134 | SDL_Quit(); 135 | return 1; 136 | } 137 | 138 | #if PUN_CONSOLE 139 | // printf("Debug build..."); 140 | // if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole()) { 141 | if (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole()) { 142 | freopen("CONOUT$", "w", stdout); 143 | freopen("CONOUT$", "w", stderr); 144 | } 145 | #endif 146 | 147 | #if 0 148 | punp_runtime_sdl.renderer = SDL_CreateRenderer( 149 | punp_runtime_sdl.window, -1, 150 | SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 151 | 152 | if (punp_runtime_sdl.renderer == 0) { 153 | SDL_DestroyWindow(punp_runtime_sdl.window); 154 | SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError()); 155 | SDL_Quit(); 156 | return 1; 157 | } 158 | #endif 159 | 160 | punp_runtime_sdl.context = SDL_GL_CreateContext(punp_runtime_sdl.window); 161 | 162 | if (SDL_GL_SetSwapInterval(1) < 0) { 163 | printf("Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError()); 164 | } 165 | 166 | int display_refresh_rate = 0; 167 | SDL_DisplayMode display_mode; 168 | int display_index = SDL_GetWindowDisplayIndex(punp_runtime_sdl.window); 169 | if (SDL_GetDesktopDisplayMode(display_index, &display_mode) == 0) { 170 | if (display_mode.refresh_rate != 0) { 171 | display_refresh_rate = display_mode.refresh_rate; 172 | } 173 | } 174 | 175 | if (display_refresh_rate == 0) { 176 | printf("Warning: Display refresh rate is unknown.\n"); 177 | display_refresh_rate = 60; 178 | } else { 179 | printf("Display refresh rate: %d\n", display_refresh_rate); 180 | } 181 | 182 | glViewport(0.f, 0.f, window_width, window_height); 183 | 184 | glMatrixMode(GL_PROJECTION); 185 | glLoadIdentity(); 186 | glOrtho(0.0, window_width, window_height, 0.0, 1.0, -1.0); 187 | 188 | glMatrixMode(GL_MODELVIEW); 189 | glLoadIdentity(); 190 | 191 | glEnable(GL_TEXTURE_2D); 192 | 193 | glGenTextrues(1, &punp_runtime_sdl.texture); 194 | glBindTexture(GL_TEXTURE_2D, punp_runtime_sdl.texture); 195 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 196 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 197 | 198 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 199 | 200 | // init(); 201 | 202 | SDL_StartTextInput(); 203 | 204 | GLuint *window_buffer = bank_push(CORE->storage, CORE->window.width * CORE->window.height * sizeof(u32)); 205 | GLuint *window_row; 206 | u8 *canvas_it; 207 | 208 | int x, y; 209 | u8 key; 210 | SDL_Event sdl_event; 211 | while (CORE->running) 212 | { 213 | punity_frame_begin(); 214 | 215 | while (SDL_PollEvent(&sdl_event) != 0) 216 | { 217 | switch(sdl_event.type) 218 | { 219 | case SDL_QUIT: 220 | CORE->running = 0; 221 | break; 222 | case SDL_KEYDOWN: 223 | if (key = pun_sdl_remap_sym(sdl_event.key.keysym.sym)) { 224 | punity_on_key_down(key, 0); 225 | } 226 | break; 227 | case SDL_KEYUP: 228 | if (key = pun_sdl_remap_sym(sdl_event.key.keysym.sym)) { 229 | punity_on_key_up(key, 0); 230 | } 231 | break; 232 | case SDL_TEXTINPUT: 233 | punity_on_text(sdl_event.text.text); 234 | break; 235 | case SDL_WINDOWEVENT: 236 | if (sdl_event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { 237 | window_width = sdl_event.window.data1; 238 | window_height = sdl_event.window.data2; 239 | printf("width = %d, height = %d\n", window_width, window_height); 240 | glViewport(0.f, 0.f, window_width, window_height); 241 | glMatrixMode(GL_PROJECTION); 242 | glLoadIdentity(); 243 | glOrtho(0.0, window_width, window_height, 0.0, 1.0, -1.0); 244 | } 245 | break; 246 | } 247 | } 248 | 249 | SDL_GetMouseState(&x, &y); 250 | CORE->mouse_x = ((f32)x) / CORE->window.scale_current; 251 | CORE->mouse_y = ((f32)y) / CORE->window.scale_current; 252 | 253 | punity_frame_step(); 254 | 255 | glClear(GL_COLOR_BUFFER_BIT); 256 | 257 | window_row = window_buffer; 258 | canvas_it = CORE->canvas.bitmap->pixels; 259 | for (y = 0; y != CORE->window.height; ++y) { 260 | for (x = 0; x != CORE->window.width; ++x) { 261 | *(window_row++) = CORE->palette->colors[*canvas_it++].rgba; 262 | } 263 | } 264 | 265 | glBindTexture(GL_TEXTURE_2D, punp_runtime_sdl.texture); 266 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, CORE->window.width, CORE->window.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, window_buffer); 267 | 268 | glBegin(GL_QUADS); 269 | glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 270 | glTexCoord2f(1.0f, 0.0f); glVertex2f(window_width, 0.0f); 271 | glTexCoord2f(1.0f, 1.0f); glVertex2f(window_width, window_height); 272 | glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, window_height); 273 | glEnd(); 274 | 275 | SDL_GL_SwapWindow(punp_runtime_sdl.window); 276 | 277 | punity_frame_end(); 278 | } 279 | terminate(); 280 | 281 | return 0; 282 | } 283 | -------------------------------------------------------------------------------- /lib/punity-tiled.h: -------------------------------------------------------------------------------- 1 | #ifndef TILED_HEADER_INCLUDED 2 | #define TILED_HEADER_INCLUDED 3 | 4 | #include "json.h" 5 | 6 | typedef struct Tiled Tiled; 7 | typedef struct TiledCacheEntry TiledCacheEntry; 8 | typedef struct TiledScene TiledScene; 9 | typedef struct TiledObject TiledObject; 10 | typedef struct TiledItem TiledItem; 11 | typedef struct TiledProperties TiledProperties; 12 | typedef struct TiledProperty TiledProperty; 13 | 14 | enum { 15 | TiledCache_Bitmap, 16 | TiledCache_Tileset 17 | }; 18 | 19 | struct TiledCacheEntry 20 | { 21 | char *path; 22 | Bitmap *bitmap; 23 | }; 24 | 25 | struct Tiled 26 | { 27 | TiledCacheEntry *cache; 28 | size_t cache_count; 29 | size_t cache_capacity; 30 | }; 31 | 32 | struct TiledScene 33 | { 34 | int width; 35 | int height; 36 | int tile_width; 37 | int tile_height; 38 | Color background; 39 | 40 | // Z-index sorted drawable items. 41 | TiledItem *items; 42 | TiledItem *items_end; 43 | size_t items_count; 44 | 45 | #ifdef TILED_CUSTOM 46 | TILED_CUSTOM 47 | #endif 48 | }; 49 | 50 | #if 0 51 | enum { 52 | TiledProperty_Boolean, 53 | TiledProperty_Integer, 54 | TiledProperty_Number, 55 | TiledProperty_String 56 | }; 57 | 58 | struct TiledProperty 59 | { 60 | const char *key; 61 | size_t key_length; 62 | int type; 63 | union { 64 | int i; 65 | float n; 66 | const char *s; 67 | bool b; 68 | }; 69 | size_t s_length; 70 | }; 71 | 72 | struct TiledProperties 73 | { 74 | TiledProperty *properties; 75 | size_t properties_count; 76 | }; 77 | #endif 78 | 79 | enum { 80 | // Use `item.tilemap` to read. 81 | TiledType_TileMap, 82 | // Use `item.tile` to read. 83 | TiledType_Image, 84 | // Not using union properties. 85 | TiledType_Rectangle, 86 | 87 | // These are used for meta callback. 88 | 89 | // `data` passed is TiledScene struct. 90 | TiledType_Scene, 91 | // `data` passed is Tile struct. 92 | TiledType_Tile, 93 | // `data` passed is TiledItem struct. 94 | TiledType_Item, 95 | }; 96 | 97 | struct TiledItem 98 | { 99 | size_t size; 100 | int type; 101 | Rect rect; 102 | char *name; 103 | union { 104 | TileMap tilemap; 105 | Tile tile; 106 | }; 107 | #ifdef TILEDITEM_CUSTOM 108 | TILEDITEM_CUSTOM 109 | #endif 110 | }; 111 | 112 | // Callback that gets called for every new item or tile. 113 | // You are required to read the meta information from json values passed and set them to `meta`. 114 | #define TILED_CALLBACK(name) void name(int type, void *data, json_object_entry *properties, size_t properties_count, void *user) 115 | typedef TILED_CALLBACK(TiledCallback); 116 | 117 | void tiled_init(Tiled *T); 118 | void tiled_free(Tiled *T); 119 | 120 | // Loads tiled 121 | void tiledscene_load_resource(Tiled *T, TiledScene *S, const char *resource_name, 122 | TiledCallback *meta_callback, void *meta_callback_user); 123 | // Finds TiledItem by name. 124 | // You can optionally pass `begin` to search from that. 125 | TiledItem *tiledscene_find(TiledScene *S, const char *name, TiledItem *begin); 126 | // Returns next item (doesn't check for boundaries). 127 | TiledItem *tileditem_next(TiledItem *item); 128 | 129 | // Does a simple linear-search for an entry with given key. 130 | // `value` has to be json_object. 131 | json_value *json_find_value(json_value *value, const char *key); 132 | 133 | #endif // #ifndef TILED_HEADER_INCLUDED 134 | 135 | #ifdef TILED_IMPLEMENTATION 136 | #undef TILED_IMPLEMENTATION 137 | 138 | #define JSON_IMPLEMENTATION 139 | #include "json.h" 140 | 141 | // Json tools. 142 | 143 | static Color 144 | json_color_(json_value *value) { 145 | // TODO: Read color from value->string.ptr. 146 | return color_make(0, 0, 0, 0); 147 | } 148 | 149 | json_value * 150 | json_find_value(json_value *value, const char *key) 151 | { 152 | ASSERT(value->type == json_object); 153 | json_object_entry *entry = value->object.values; 154 | for (uint i = 0; i != value->object.length; ++i, ++entry) { 155 | if (strcmp(entry->name, key) == 0) { 156 | return entry->value; 157 | } 158 | } 159 | return 0; 160 | } 161 | 162 | 163 | // TiledScene loader. 164 | typedef struct 165 | { 166 | int gid_begin; 167 | int gid_end; 168 | Tile *tiles; 169 | } 170 | TiledLoaderTileset_; 171 | 172 | 173 | typedef struct 174 | { 175 | i32 palette_range; 176 | Bank *storage; 177 | Tiled *tiled; 178 | TiledScene *scene; 179 | 180 | TiledLoaderTileset_ *tilesets; 181 | size_t tilesets_count; 182 | size_t tilesets_capacity; 183 | 184 | TiledCallback *meta_callback; 185 | void *meta_callback_user; 186 | } 187 | TiledLoader_; 188 | 189 | static Bitmap * 190 | tiled_load_bitmap_(TiledLoader_ *L, const char *path) 191 | { 192 | // Look into the cache. 193 | for (uint i = 0; i != L->tiled->cache_count; ++i) { 194 | if (strcmp(path, L->tiled->cache[i].path) == 0) { 195 | return L->tiled->cache[i].bitmap; 196 | } 197 | } 198 | 199 | Bitmap *bitmap = bank_push_t(L->storage, Bitmap, 1); 200 | bitmap_load_resource_ex(L->storage, bitmap, path, L->palette_range); 201 | bitmap->tile_width = bitmap->width; 202 | bitmap->tile_height = bitmap->height; 203 | 204 | // Add to the cache 205 | if (L->tiled->cache_count == L->tiled->cache_capacity) { 206 | L->tiled->cache_capacity += 16; 207 | L->tiled->cache = realloc(L->tiled->cache, sizeof(TiledCacheEntry) * L->tiled->cache_capacity); 208 | } 209 | TiledCacheEntry *entry = &L->tiled->cache[L->tiled->cache_count++]; 210 | size_t path_length = strlen(path); 211 | entry->path = bank_push(L->storage, path_length + 1); 212 | memcpy(entry->path, path, path_length + 1); 213 | entry->bitmap = bitmap; 214 | 215 | return bitmap; 216 | } 217 | 218 | static TiledLoaderTileset_ * 219 | tiled_add_tileset_(TiledLoader_ *L, int gid_first, int count) 220 | { 221 | if (L->tilesets_count == L->tilesets_capacity) { 222 | L->tilesets_capacity += 16; 223 | L->tilesets = realloc(L->tilesets, sizeof(TiledLoaderTileset_) * L->tilesets_capacity); 224 | } 225 | TiledLoaderTileset_ *tileset = &L->tilesets[L->tilesets_count]; 226 | L->tilesets_count++; 227 | 228 | tileset->gid_begin = gid_first; 229 | tileset->gid_end = gid_first + count; 230 | tileset->tiles = malloc(count * sizeof(Tile)); 231 | memset(tileset->tiles, 0, count * sizeof(Tile)); 232 | 233 | return tileset; 234 | } 235 | 236 | static Tile * 237 | tiled_find_tile_(TiledLoader_ *L, int gid) 238 | { 239 | if (gid > 0) { 240 | TiledLoaderTileset_ *it = L->tilesets; 241 | for (int i = 0; i != L->tilesets_count; ++i, ++it) { 242 | if (gid >= it->gid_begin && gid < it->gid_end) { 243 | return it->tiles + (gid - it->gid_begin); 244 | } 245 | } 246 | } 247 | return 0; 248 | } 249 | 250 | static int 251 | tiled_setup_tile_(TiledLoader_ *L, int gid, Tile *tile) 252 | { 253 | Tile *tiled_tile = tiled_find_tile_(L, gid); 254 | if (tiled_tile) { 255 | *tile = *tiled_tile; 256 | return 1; 257 | } 258 | return 0; 259 | } 260 | 261 | static void 262 | tiled_load_meta_(TiledLoader_ *L, int type, void *data, json_value *properties) 263 | { 264 | if (!properties) { 265 | return; 266 | } 267 | 268 | json_value *v; 269 | switch (type) 270 | { 271 | case TiledType_Tile: 272 | Tile *tile = (Tile*)data; 273 | v = json_find_value(properties, "edges"); 274 | if (v && v->type == json_string) { 275 | for (char *it = v->string.ptr; *it; ++it) { 276 | switch (*it) 277 | { 278 | case 'T': case 't': 279 | tile->flags |= Edge_Top; 280 | break; 281 | case 'B': case 'b': 282 | tile->flags |= Edge_Bottom; 283 | break; 284 | case 'L': case 'l': 285 | tile->flags |= Edge_Left; 286 | break; 287 | case 'R': case 'r': 288 | tile->flags |= Edge_Right; 289 | break; 290 | } 291 | } 292 | #ifdef TILEDTILE_DEFAULT_LAYER 293 | if (tile->flags != 0) { 294 | tile->layer = TILEDTILE_DEFAULT_LAYER; 295 | } 296 | #endif 297 | } 298 | 299 | v = json_find_value(properties, "layer"); 300 | if (v && v->type == json_integer) { 301 | tile->layer = v->integer; 302 | } 303 | break; 304 | } 305 | 306 | if (L->meta_callback) { 307 | L->meta_callback(type, data, properties->object.values, properties->object.length, L->meta_callback_user); 308 | } 309 | } 310 | 311 | static void 312 | tiled_load_tileset_(TiledLoader_ *L, json_value *value, int *firstgid) 313 | { 314 | json_value *v; 315 | TiledLoaderTileset_ *tiled_tileset; 316 | 317 | int gid_first; 318 | if (firstgid == 0) { 319 | v = json_find_value(value, "firstgid"); 320 | ASSERT_MESSAGE(v, "`firstgid` not specified for tileset"); 321 | gid_first = v->integer; 322 | } else { 323 | gid_first = *firstgid; 324 | } 325 | 326 | // Standard single-image tileset. 327 | json_value *value_image = json_find_value(value, "image"); 328 | 329 | if (value_image) 330 | { 331 | Bitmap *tileset = tiled_load_bitmap_(L, value_image->string.ptr); 332 | 333 | v = json_find_value(value, "tilewidth"); 334 | ASSERT_MESSAGE(v, "`tilewidth` not specified for tileset"); 335 | tileset->tile_width = v->integer; 336 | 337 | v = json_find_value(value, "tileheight"); 338 | ASSERT_MESSAGE(v, "`tileheight` not specified for tileset"); 339 | tileset->tile_height = v->integer; 340 | 341 | uint tiles_count = (tileset->width / tileset->tile_width) * (tileset->height / tileset->tile_height); 342 | tiled_tileset = tiled_add_tileset_(L, gid_first, tiles_count); 343 | for (uint j = 0; j != tiles_count; ++j) { 344 | tiled_tileset->tiles[j].tileset = tileset; 345 | tiled_tileset->tiles[j].index = j; 346 | } 347 | 348 | // Load properties. 349 | v = json_find_value(value, "tileproperties"); 350 | if (v) 351 | { 352 | json_object_entry *it_tile = v->object.values; 353 | for (uint j = 0; j != v->object.length; ++j, ++it_tile) { 354 | char *name_end = it_tile->name + it_tile->name_length; 355 | int index = strtol(it_tile->name, &name_end, 10); 356 | tiled_load_meta_(L, TiledType_Tile, &tiled_tileset->tiles[index], it_tile->value); 357 | } 358 | } 359 | return; 360 | } 361 | 362 | // Collection of images. 363 | json_value *value_tiles = json_find_value(value, "tiles"); 364 | if (value_tiles) 365 | { 366 | tiled_tileset = tiled_add_tileset_(L, gid_first, value_tiles->object.length); 367 | json_object_entry *it_tile = value_tiles->object.values; 368 | for (uint j = 0; j != value_tiles->object.length; ++j, ++it_tile) { 369 | value_image = json_find_value(it_tile->value, "image"); 370 | if (value_image) { 371 | Bitmap *tileset = tiled_load_bitmap_(L, value_image->string.ptr); 372 | char *name_end = it_tile->name + it_tile->name_length; 373 | int index = strtol(it_tile->name, &name_end, 10); 374 | tiled_tileset->tiles[index].tileset = tileset; 375 | tiled_tileset->tiles[index].index = index; 376 | } 377 | } 378 | 379 | return; 380 | } 381 | } 382 | 383 | static void 384 | tiled_load_tilesets_(TiledLoader_ *L, json_value *value) 385 | { 386 | json_value **it = value->array.values; 387 | for (uint i = 0; i != value->array.length; ++i, ++it) 388 | { 389 | json_value *value_source = json_find_value(*it, "source"); 390 | if (value_source) { 391 | json_value *value_firstgid = json_find_value(*it, "firstgid"); 392 | ASSERT_MESSAGE(value_firstgid, "invalid firstgid in reference to external tileset `%s`", value_source->string.ptr); 393 | // External tileset. 394 | size_t json_size; 395 | char *json = resource_get(value_source->string.ptr, &json_size); 396 | json_value *root = json_parse(json, json_size); 397 | ASSERT_MESSAGE(root, "invalid json in `%s`", value_source->string.ptr); 398 | ASSERT_MESSAGE(root->type == json_object, "root is not an object in `%s`", value_source->string.ptr); 399 | int firstgid = value_firstgid->integer; 400 | tiled_load_tileset_(L, root, &firstgid); 401 | } else { 402 | // Internal tileset. 403 | tiled_load_tileset_(L, *it, 0); 404 | } 405 | } 406 | } 407 | 408 | static TiledItem * 409 | tiled_add_item_(TiledLoader_ *L, int type, const char *name, size_t name_length) 410 | { 411 | if (L->scene->items == 0) { 412 | L->scene->items = (TiledItem*)L->storage->it; 413 | } 414 | 415 | TiledItem *item = bank_push(L->storage, sizeof(TiledItem) + name_length + 1); 416 | memset(item, 0, sizeof(TiledItem) + name_length + 1); 417 | item->name = (char*)(item + 1); 418 | if (name) { 419 | memcpy(item->name, name, name_length + 1); 420 | } 421 | 422 | item->type = type; 423 | item->size = sizeof(TiledItem) + name_length + 1; 424 | L->scene->items_count++; 425 | 426 | L->scene->items_end = (TiledItem*)L->storage->it; 427 | 428 | return item; 429 | } 430 | 431 | static void 432 | tiled_load_tilemap_(TiledLoader_ *L, json_value *value) 433 | { 434 | const char *name = 0; 435 | size_t name_length = 0; 436 | json_value *v = json_find_value(value, "name"); 437 | if (v && v->type == json_string) { 438 | name = v->string.ptr; 439 | name_length = v->string.length; 440 | } 441 | TiledItem *item = tiled_add_item_(L, TiledType_TileMap, name, name_length); 442 | item->tilemap.tile_width = L->scene->tile_width; 443 | item->tilemap.tile_height = L->scene->tile_height; 444 | 445 | json_object_entry *it; 446 | it = value->object.values; 447 | for (uint i = 0; i != value->object.length; ++i, ++it) 448 | { 449 | if (strcmp(it->name, "data") == 0) { 450 | item->tilemap.tiles = bank_push_t(L->storage, Tile, it->value->array.length); 451 | memset(item->tilemap.tiles, 0, sizeof(Tile) * it->value->array.length); 452 | Tile *tile = item->tilemap.tiles; 453 | Tile *tiled_tile; 454 | json_value **value_tile = it->value->array.values; 455 | for (uint i = 0; i != it->value->array.length; ++i, ++value_tile, ++tile) { 456 | tiled_setup_tile_(L, (*value_tile)->integer, tile); 457 | } 458 | } else if (strcmp(it->name, "width") == 0) { 459 | item->tilemap.width = item->rect.max_x = it->value->integer; 460 | } else if (strcmp(it->name, "height") == 0) { 461 | item->tilemap.height = item->rect.max_y = it->value->integer; 462 | } 463 | } 464 | 465 | tiled_load_meta_(L, TiledType_Item, item, json_find_value(value, "properties")); 466 | item->size += (item->tilemap.width * item->tilemap.height * sizeof(Tile)); 467 | } 468 | 469 | static void 470 | tiled_load_objects_(TiledLoader_ *L, json_value *value) 471 | { 472 | json_value *root = json_find_value(value, "objects"); 473 | if (!root) { 474 | return; 475 | } 476 | ASSERT_MESSAGE(root->type == json_array, "`objects` is not an array"); 477 | 478 | uint i, j; 479 | json_value *v; 480 | json_object_entry *value_object_property; 481 | json_value **value_object = root->array.values; 482 | for (i = 0; i != root->array.length; ++i, ++value_object) 483 | { 484 | ASSERT_MESSAGE((*value_object)->type == json_object, "object expected"); 485 | 486 | // Ellipses are ignored for now. 487 | v = json_find_value(*value_object, "ellipse"); 488 | if (v) continue; 489 | 490 | // Polygons are ignored for now. 491 | v = json_find_value(*value_object, "polygon"); 492 | if (v) continue; 493 | 494 | // Polylines are ignored for now. 495 | v = json_find_value(*value_object, "polyline"); 496 | if (v) continue; 497 | 498 | const char *name = 0; 499 | size_t name_length = 0; 500 | json_value *v = json_find_value(*value_object, "name"); 501 | if (v && v->type == json_string) { 502 | name = v->string.ptr; 503 | name_length = v->string.length; 504 | } 505 | 506 | TiledItem *item = tiled_add_item_(L, TiledType_Rectangle, name, name_length); 507 | 508 | v = json_find_value(*value_object, "x"); 509 | ASSERT_MESSAGE(v, "`x` coordinate not found"); 510 | item->rect.min_x = v->integer; 511 | 512 | v = json_find_value(*value_object, "y"); 513 | ASSERT_MESSAGE(v, "`y` coordinate not found"); 514 | item->rect.min_y = v->integer; 515 | 516 | v = json_find_value(*value_object, "width"); 517 | ASSERT_MESSAGE(v, "`width` coordinate not found"); 518 | item->rect.max_x = item->rect.min_x + v->integer; 519 | 520 | v = json_find_value(*value_object, "height"); 521 | ASSERT_MESSAGE(v, "`height` coordinate not found"); 522 | item->rect.max_y = item->rect.min_y + v->integer; 523 | 524 | v = json_find_value(*value_object, "gid"); 525 | if (v) { 526 | item->type = TiledType_Image; 527 | ASSERT_MESSAGE(tiled_setup_tile_(L, v->integer, &item->tile), "tile not found"); 528 | } 529 | 530 | tiled_load_meta_(L, TiledType_Item, item, json_find_value(*value_object, "properties")); 531 | } 532 | } 533 | 534 | static void 535 | tiled_load_layers_(TiledLoader_ *L, json_value *value) 536 | { 537 | ASSERT_MESSAGE(value->type == json_array, "Layers are not an array."); 538 | 539 | // R->map->layers = bank_push_t(R->storage, TiledLayer*, value->array.length); 540 | // R->map->layers_count = value->array.length; 541 | 542 | json_value *v; 543 | json_value **value_layer = value->array.values; 544 | for (uint i = 0; i != value->array.length; ++i, ++value_layer) 545 | { 546 | v = json_find_value(*value_layer, "type"); 547 | ASSERT_MESSAGE(v && v->type == json_string, "Layer type not found."); 548 | if (strcmp(v->string.ptr, "tilelayer") == 0) { 549 | tiled_load_tilemap_(L, *value_layer); 550 | } else if (strcmp(v->string.ptr, "objectgroup") == 0) { 551 | // TODO: Load objects. 552 | tiled_load_objects_(L, *value_layer); 553 | } 554 | // *layer = tiledreader_load_layer_(R, *value_layer); 555 | } 556 | } 557 | 558 | static void 559 | tiled_load_scene_(TiledLoader_ *L, const char *json, size_t json_size) 560 | { 561 | f64 t = perf_get(); 562 | json_value *root = json_parse(json, json_size); 563 | LOG("json_parse %f\n", (perf_get() - t) * 1e3); 564 | ASSERT_MESSAGE(root, "Invalid JSON."); 565 | ASSERT_MESSAGE(root->type == json_object, "Root is not an object."); 566 | 567 | json_value *v; 568 | // Load tilesets first. 569 | v = json_find_value(root, "tilesets"); 570 | if (v) { 571 | tiled_load_tilesets_(L, v); 572 | } 573 | 574 | v = json_find_value(root, "tilewidth"); 575 | ASSERT_MESSAGE(v, "`tilewidth` is not set"); 576 | L->scene->tile_width = v->integer; 577 | 578 | v = json_find_value(root, "tileheight"); 579 | ASSERT_MESSAGE(v, "`tileheight` is not set"); 580 | L->scene->tile_height = v->integer; 581 | 582 | json_object_entry *entry; 583 | entry = root->object.values; 584 | for (uint i = 0; i != root->object.length; ++i, ++entry) 585 | { 586 | if (strcmp(entry->name, "backgroundcolor") == 0) { 587 | L->scene->background = json_color_(entry->value); 588 | } 589 | else if (strcmp(entry->name, "width") == 0) { 590 | L->scene->width = entry->value->integer; 591 | } 592 | else if (strcmp(entry->name, "height") == 0) { 593 | L->scene->height = entry->value->integer; 594 | } 595 | else if (strcmp(entry->name, "layers") == 0) { 596 | tiled_load_layers_(L, entry->value); 597 | } 598 | } 599 | 600 | json_value_free(root); 601 | 602 | for (uint i = 0; i != L->tilesets_count; ++i) { 603 | free(L->tilesets[i].tiles); 604 | } 605 | free(L->tilesets); 606 | } 607 | 608 | // 609 | // Public API. 610 | // 611 | 612 | void 613 | tiled_init(Tiled *T) 614 | { 615 | memset(T, 0, sizeof(Tiled)); 616 | } 617 | 618 | void 619 | tiled_free(Tiled *T) 620 | { 621 | free(T->cache); 622 | T->cache_count = 0; 623 | T->cache_capacity = 0; 624 | } 625 | 626 | void 627 | tiledscene_load_resource(Tiled *T, TiledScene *S, const char *resource_name, 628 | TiledCallback *meta_callback, void *meta_callback_user) 629 | { 630 | TiledLoader_ L = {0}; 631 | L.storage = CORE->storage; 632 | L.scene = S; 633 | L.tiled = T; 634 | L.meta_callback = meta_callback; 635 | L.meta_callback_user = meta_callback_user; 636 | memset(L.scene, 0, sizeof(TiledScene)); 637 | 638 | size_t json_size; 639 | char *json = resource_get(resource_name, &json_size); 640 | tiled_load_scene_(&L, json, json_size); 641 | } 642 | 643 | TiledItem * 644 | tileditem_next(TiledItem *item) 645 | { 646 | return (TiledItem*)(((u8*)item) + item->size); 647 | } 648 | 649 | TiledItem * 650 | tiledscene_find(TiledScene *S, const char *name, TiledItem *begin) 651 | { 652 | size_t i = 0; 653 | TiledItem *it = S->items; 654 | if (begin) { 655 | ASSERT_MESSAGE(begin < S->items_end, "`begin` does not point to item in this array"); 656 | it = begin; 657 | } 658 | for (; it != S->items_end; it = tileditem_next(it)) { 659 | if (strcmp(it->name, name) == 0) { 660 | return it; 661 | } 662 | } 663 | return 0; 664 | } 665 | 666 | #endif // TILED_IMPLEMENTATION -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #define PUNITY_IMPLEMENTATION 2 | #include "punity.h" 3 | 4 | typedef struct Game_ 5 | { 6 | Bitmap font; 7 | } 8 | Game; 9 | 10 | static Game *GAME = 0; 11 | 12 | int 13 | init() 14 | { 15 | GAME = bank_push_t(CORE->storage, Game, 1); 16 | 17 | font_load_resource(&GAME->font, "font.png", 4, 7); 18 | CORE->canvas.font = &GAME->font; 19 | 20 | return 1; 21 | } 22 | 23 | void 24 | step() 25 | { 26 | canvas_clear(1); 27 | 28 | if (key_down(KEY_ESCAPE)) { 29 | CORE->running = 0; 30 | } 31 | 32 | char buf[256]; 33 | sprintf(buf, "%.3fms", CORE->time_delta * 1e3); 34 | text_draw(buf, 0, 0, 2); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /main.rc: -------------------------------------------------------------------------------- 1 | icon.ico ICON "res\\icon.ico" 2 | font.png RESOURCE "res\\font-4x7.png" -------------------------------------------------------------------------------- /res/example-platformer/hit.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/hit.ogg -------------------------------------------------------------------------------- /res/example-platformer/jump.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/jump.ogg -------------------------------------------------------------------------------- /res/example-platformer/land.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/land.ogg -------------------------------------------------------------------------------- /res/example-platformer/map1.json: -------------------------------------------------------------------------------- 1 | { "backgroundcolor":"#1d2828", 2 | "height":16, 3 | "layers":[ 4 | { 5 | "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 12, 13, 12, 12, 11, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 16, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 5, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 8, 0, 0, 0, 16, 0, 0, 0, 0, 0, 2, 3, 4, 3, 3, 4, 3, 4, 4, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 6 | "height":16, 7 | "name":"base", 8 | "opacity":1, 9 | "properties": 10 | { 11 | "tilemap_property":"miblo" 12 | }, 13 | "propertytypes": 14 | { 15 | "tilemap_property":"string" 16 | }, 17 | "type":"tilelayer", 18 | "visible":true, 19 | "width":16, 20 | "x":0, 21 | "y":0 22 | }, 23 | { 24 | "draworder":"topdown", 25 | "height":64, 26 | "name":"Object Layer 1", 27 | "objects":[ 28 | { 29 | "height":8, 30 | "id":12, 31 | "name":"player", 32 | "rotation":0, 33 | "type":"", 34 | "visible":true, 35 | "width":8, 36 | "x":32, 37 | "y":96 38 | }], 39 | "opacity":1, 40 | "type":"objectgroup", 41 | "visible":true, 42 | "width":64, 43 | "x":0, 44 | "y":0 45 | }], 46 | "nextobjectid":13, 47 | "orientation":"orthogonal", 48 | "renderorder":"right-down", 49 | "tileheight":8, 50 | "tilesets":[ 51 | { 52 | "columns":8, 53 | "firstgid":1, 54 | "image":"tileset.png", 55 | "imageheight":64, 56 | "imagewidth":64, 57 | "margin":0, 58 | "name":"tileset", 59 | "properties": 60 | { 61 | "tileset_property":"hello" 62 | }, 63 | "propertytypes": 64 | { 65 | "tileset_property":"string" 66 | }, 67 | "spacing":0, 68 | "tilecount":64, 69 | "tileheight":8, 70 | "tileproperties": 71 | { 72 | "1": 73 | { 74 | "edges":"T" 75 | }, 76 | "10": 77 | { 78 | "edges":"T" 79 | }, 80 | "11": 81 | { 82 | "edges":"T" 83 | }, 84 | "12": 85 | { 86 | "edges":"T" 87 | }, 88 | "13": 89 | { 90 | "edges":"T" 91 | }, 92 | "17": 93 | { 94 | "wall":"top" 95 | }, 96 | "18": 97 | { 98 | "wall":"top" 99 | }, 100 | "19": 101 | { 102 | "wall":"top" 103 | }, 104 | "2": 105 | { 106 | "edges":"T" 107 | }, 108 | "20": 109 | { 110 | "wall":"top" 111 | }, 112 | "21": 113 | { 114 | "wall":"top" 115 | }, 116 | "22": 117 | { 118 | "wall":"top" 119 | }, 120 | "23": 121 | { 122 | "wall":"top" 123 | }, 124 | "3": 125 | { 126 | "edges":"T" 127 | }, 128 | "4": 129 | { 130 | "edges":"T" 131 | }, 132 | "5": 133 | { 134 | "edges":"T" 135 | }, 136 | "9": 137 | { 138 | "edges":"T" 139 | } 140 | }, 141 | "tilepropertytypes": 142 | { 143 | "1": 144 | { 145 | "edges":"string" 146 | }, 147 | "10": 148 | { 149 | "edges":"string" 150 | }, 151 | "11": 152 | { 153 | "edges":"string" 154 | }, 155 | "12": 156 | { 157 | "edges":"string" 158 | }, 159 | "13": 160 | { 161 | "edges":"string" 162 | }, 163 | "17": 164 | { 165 | "wall":"string" 166 | }, 167 | "18": 168 | { 169 | "wall":"string" 170 | }, 171 | "19": 172 | { 173 | "wall":"string" 174 | }, 175 | "2": 176 | { 177 | "edges":"string" 178 | }, 179 | "20": 180 | { 181 | "wall":"string" 182 | }, 183 | "21": 184 | { 185 | "wall":"string" 186 | }, 187 | "22": 188 | { 189 | "wall":"string" 190 | }, 191 | "23": 192 | { 193 | "wall":"string" 194 | }, 195 | "3": 196 | { 197 | "edges":"string" 198 | }, 199 | "4": 200 | { 201 | "edges":"string" 202 | }, 203 | "5": 204 | { 205 | "edges":"string" 206 | }, 207 | "9": 208 | { 209 | "edges":"string" 210 | } 211 | }, 212 | "tilewidth":8 213 | }, 214 | { 215 | "columns":0, 216 | "firstgid":65, 217 | "margin":0, 218 | "name":"collection", 219 | "spacing":0, 220 | "tilecount":1, 221 | "tileheight":128, 222 | "tiles": 223 | { 224 | "0": 225 | { 226 | "image":"tileset.png" 227 | } 228 | }, 229 | "tilewidth":128 230 | }, 231 | { 232 | "columns":8, 233 | "firstgid":66, 234 | "image":"tileset.png", 235 | "imageheight":64, 236 | "imagewidth":64, 237 | "margin":0, 238 | "name":"tileset", 239 | "spacing":0, 240 | "tilecount":64, 241 | "tileheight":8, 242 | "tileproperties": 243 | { 244 | "17": 245 | { 246 | "wall":"top" 247 | }, 248 | "18": 249 | { 250 | "wall":"top" 251 | }, 252 | "19": 253 | { 254 | "wall":"top" 255 | }, 256 | "20": 257 | { 258 | "wall":"top" 259 | }, 260 | "21": 261 | { 262 | "wall":"top" 263 | }, 264 | "22": 265 | { 266 | "wall":"top" 267 | }, 268 | "23": 269 | { 270 | "wall":"top" 271 | } 272 | }, 273 | "tilepropertytypes": 274 | { 275 | "17": 276 | { 277 | "wall":"string" 278 | }, 279 | "18": 280 | { 281 | "wall":"string" 282 | }, 283 | "19": 284 | { 285 | "wall":"string" 286 | }, 287 | "20": 288 | { 289 | "wall":"string" 290 | }, 291 | "21": 292 | { 293 | "wall":"string" 294 | }, 295 | "22": 296 | { 297 | "wall":"string" 298 | }, 299 | "23": 300 | { 301 | "wall":"string" 302 | } 303 | }, 304 | "tilewidth":8 305 | }], 306 | "tilewidth":8, 307 | "version":1, 308 | "width":16 309 | } -------------------------------------------------------------------------------- /res/example-platformer/map_test.json: -------------------------------------------------------------------------------- 1 | { "backgroundcolor":"#1d2828", 2 | "height":64, 3 | "layers":[ 4 | { 5 | "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 68, 69, 70, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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":"tilelayer", 18 | "visible":true, 19 | "width":64, 20 | "x":0, 21 | "y":0 22 | }, 23 | { 24 | "draworder":"topdown", 25 | "height":64, 26 | "name":"Object Layer 1", 27 | "objects":[ 28 | { 29 | "height":24, 30 | "id":1, 31 | "name":"", 32 | "rotation":0, 33 | "type":"", 34 | "visible":true, 35 | "width":16, 36 | "x":112, 37 | "y":344 38 | }, 39 | { 40 | "height":16, 41 | "id":2, 42 | "name":"", 43 | "rotation":0, 44 | "type":"", 45 | "visible":true, 46 | "width":16, 47 | "x":72, 48 | "y":352 49 | }, 50 | { 51 | "height":16, 52 | "id":3, 53 | "name":"", 54 | "rotation":0, 55 | "type":"", 56 | "visible":true, 57 | "width":16, 58 | "x":264, 59 | "y":352 60 | }, 61 | { 62 | "ellipse":true, 63 | "height":24, 64 | "id":4, 65 | "name":"", 66 | "rotation":0, 67 | "type":"", 68 | "visible":true, 69 | "width":24, 70 | "x":144, 71 | "y":336 72 | }, 73 | { 74 | "height":0, 75 | "id":5, 76 | "name":"", 77 | "polygon":[ 78 | { 79 | "x":0, 80 | "y":0 81 | }, 82 | { 83 | "x":45.2727272727273, 84 | "y":-10.3636363636364 85 | }, 86 | { 87 | "x":-4, 88 | "y":-26 89 | }, 90 | { 91 | "x":-26.3636363636364, 92 | "y":-12 93 | }, 94 | { 95 | "x":-20.7272727272727, 96 | "y":3.27272727272725 97 | }], 98 | "rotation":0, 99 | "type":"", 100 | "visible":true, 101 | "width":0, 102 | "x":169.454545454545, 103 | "y":308.363636363636 104 | }, 105 | { 106 | "height":0, 107 | "id":6, 108 | "name":"", 109 | "polyline":[ 110 | { 111 | "x":0, 112 | "y":0 113 | }, 114 | { 115 | "x":49.4545454545455, 116 | "y":31.2727272727273 117 | }, 118 | { 119 | "x":55.6363636363637, 120 | "y":-0.545454545454504 121 | }, 122 | { 123 | "x":8.90909090909091, 124 | "y":-24.9090909090909 125 | }, 126 | { 127 | "x":-15.6363636363637, 128 | "y":-18.1818181818182 129 | }], 130 | "rotation":0, 131 | "type":"", 132 | "visible":true, 133 | "width":0, 134 | "x":229.454545454545, 135 | "y":259.636363636364 136 | }, 137 | { 138 | "gid":65, 139 | "height":128, 140 | "id":7, 141 | "name":"", 142 | "rotation":0, 143 | "type":"", 144 | "visible":true, 145 | "width":128, 146 | "x":320, 147 | "y":376 148 | }, 149 | { 150 | "gid":16, 151 | "height":8, 152 | "id":9, 153 | "name":"", 154 | "rotation":0, 155 | "type":"", 156 | "visible":true, 157 | "width":8, 158 | "x":342.727272727273, 159 | "y":372 160 | }, 161 | { 162 | "height":16, 163 | "id":10, 164 | "name":"", 165 | "rotation":0, 166 | "type":"", 167 | "visible":true, 168 | "width":16, 169 | "x":24, 170 | "y":8 171 | }], 172 | "opacity":1, 173 | "type":"objectgroup", 174 | "visible":true, 175 | "width":64, 176 | "x":0, 177 | "y":0 178 | }], 179 | "nextobjectid":11, 180 | "orientation":"orthogonal", 181 | "renderorder":"right-down", 182 | "tileheight":8, 183 | "tilesets":[ 184 | { 185 | "firstgid":1, 186 | "source":"tileset.json" 187 | }, 188 | { 189 | "columns":0, 190 | "firstgid":65, 191 | "margin":0, 192 | "name":"collection", 193 | "spacing":0, 194 | "tilecount":1, 195 | "tileheight":128, 196 | "tiles": 197 | { 198 | "0": 199 | { 200 | "image":"tileset.png" 201 | } 202 | }, 203 | "tilewidth":128 204 | }, 205 | { 206 | "columns":8, 207 | "firstgid":66, 208 | "image":"tileset.png", 209 | "imageheight":64, 210 | "imagewidth":64, 211 | "margin":0, 212 | "name":"tileset", 213 | "spacing":0, 214 | "tilecount":64, 215 | "tileheight":8, 216 | "tileproperties": 217 | { 218 | "17": 219 | { 220 | "wall":"top" 221 | }, 222 | "18": 223 | { 224 | "wall":"top" 225 | }, 226 | "19": 227 | { 228 | "wall":"top" 229 | }, 230 | "20": 231 | { 232 | "wall":"top" 233 | }, 234 | "21": 235 | { 236 | "wall":"top" 237 | }, 238 | "22": 239 | { 240 | "wall":"top" 241 | }, 242 | "23": 243 | { 244 | "wall":"top" 245 | } 246 | }, 247 | "tilepropertytypes": 248 | { 249 | "17": 250 | { 251 | "wall":"string" 252 | }, 253 | "18": 254 | { 255 | "wall":"string" 256 | }, 257 | "19": 258 | { 259 | "wall":"string" 260 | }, 261 | "20": 262 | { 263 | "wall":"string" 264 | }, 265 | "21": 266 | { 267 | "wall":"string" 268 | }, 269 | "22": 270 | { 271 | "wall":"string" 272 | }, 273 | "23": 274 | { 275 | "wall":"string" 276 | } 277 | }, 278 | "tilewidth":8 279 | }], 280 | "tilewidth":8, 281 | "version":1, 282 | "width":64 283 | } -------------------------------------------------------------------------------- /res/example-platformer/music.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/music.ogg -------------------------------------------------------------------------------- /res/example-platformer/src/tileset-minimal.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/src/tileset-minimal.psd -------------------------------------------------------------------------------- /res/example-platformer/src/tileset.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/src/tileset.psd -------------------------------------------------------------------------------- /res/example-platformer/tileset.json: -------------------------------------------------------------------------------- 1 | { "columns":8, 2 | "image":"tileset.png", 3 | "imageheight":64, 4 | "imagewidth":64, 5 | "margin":0, 6 | "name":"tileset", 7 | "properties": 8 | { 9 | "tileset_property":"hello" 10 | }, 11 | "propertytypes": 12 | { 13 | "tileset_property":"string" 14 | }, 15 | "spacing":0, 16 | "tilecount":64, 17 | "tileheight":8, 18 | "tileproperties": 19 | { 20 | "17": 21 | { 22 | "wall":"top" 23 | }, 24 | "18": 25 | { 26 | "wall":"top" 27 | }, 28 | "19": 29 | { 30 | "wall":"top" 31 | }, 32 | "20": 33 | { 34 | "wall":"top" 35 | }, 36 | "21": 37 | { 38 | "wall":"top" 39 | }, 40 | "22": 41 | { 42 | "wall":"top" 43 | }, 44 | "23": 45 | { 46 | "wall":"top" 47 | } 48 | }, 49 | "tilepropertytypes": 50 | { 51 | "17": 52 | { 53 | "wall":"string" 54 | }, 55 | "18": 56 | { 57 | "wall":"string" 58 | }, 59 | "19": 60 | { 61 | "wall":"string" 62 | }, 63 | "20": 64 | { 65 | "wall":"string" 66 | }, 67 | "21": 68 | { 69 | "wall":"string" 70 | }, 71 | "22": 72 | { 73 | "wall":"string" 74 | }, 75 | "23": 76 | { 77 | "wall":"string" 78 | } 79 | }, 80 | "tilewidth":8 81 | } -------------------------------------------------------------------------------- /res/example-platformer/tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/example-platformer/tileset.png -------------------------------------------------------------------------------- /res/font-4x10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/font-4x10.png -------------------------------------------------------------------------------- /res/font-4x7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/font-4x7.png -------------------------------------------------------------------------------- /res/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martincohen/Punity/b5c03da10617ec76a37a03607f19969b29c06057/res/icon.ico --------------------------------------------------------------------------------