trunk/3rdparty/bgfx/examples/25-c99/helloworld.c
| r0 | r244992 | |
| 1 | /* |
| 2 | * Copyright 2011-2015 Branimir Karadzic. All rights reserved. |
| 3 | * License: http://www.opensource.org/licenses/BSD-2-Clause |
| 4 | */ |
| 5 | |
| 6 | #include <bgfx.c99.h> |
| 7 | #include "../00-helloworld/logo.h" |
| 8 | |
| 9 | extern bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset); |
| 10 | |
| 11 | uint16_t uint16_max(uint16_t _a, uint16_t _b) |
| 12 | { |
| 13 | return _a < _b ? _b : _a; |
| 14 | } |
| 15 | |
| 16 | int _main_(int _argc, char** _argv) |
| 17 | { |
| 18 | (void)_argc; |
| 19 | (void)_argv; |
| 20 | uint32_t width = 1280; |
| 21 | uint32_t height = 720; |
| 22 | uint32_t debug = BGFX_DEBUG_TEXT; |
| 23 | uint32_t reset = BGFX_RESET_VSYNC; |
| 24 | |
| 25 | bgfx_init(BGFX_RENDERER_TYPE_COUNT, NULL, NULL); |
| 26 | bgfx_reset(width, height, reset); |
| 27 | |
| 28 | // Enable debug text. |
| 29 | bgfx_set_debug(debug); |
| 30 | |
| 31 | bgfx_set_view_clear(0 |
| 32 | , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH |
| 33 | , 0x303030ff |
| 34 | , 1.0f |
| 35 | , 0 |
| 36 | ); |
| 37 | |
| 38 | while (!entry_process_events(&width, &height, &debug, &reset) ) |
| 39 | { |
| 40 | // Set view 0 default viewport. |
| 41 | bgfx_set_view_rect(0, 0, 0, width, height); |
| 42 | |
| 43 | // This dummy draw call is here to make sure that view 0 is cleared |
| 44 | // if no other draw calls are submitted to view 0. |
| 45 | bgfx_submit(0, 0); |
| 46 | |
| 47 | // Use debug font to print information about this example. |
| 48 | bgfx_dbg_text_clear(0, false); |
| 49 | bgfx_dbg_text_image(uint16_max(width/2/8, 20)-20 |
| 50 | , uint16_max(height/2/16, 6)-6 |
| 51 | , 40 |
| 52 | , 12 |
| 53 | , s_logo |
| 54 | , 160 |
| 55 | ); |
| 56 | bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/25-c99"); |
| 57 | bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Initialization and debug text with C99 API."); |
| 58 | |
| 59 | // Advance to next frame. Rendering thread will be kicked to |
| 60 | // process submitted rendering primitives. |
| 61 | bgfx_frame(); |
| 62 | } |
| 63 | |
| 64 | // Shutdown bgfx. |
| 65 | bgfx_shutdown(); |
| 66 | |
| 67 | return 0; |
| 68 | } |
trunk/3rdparty/bgfx/scripts/genie.lua
| r244991 | r244992 | |
| 84 | 84 | end |
| 85 | 85 | |
| 86 | 86 | includedirs { |
| 87 | | path.join(BX_DIR, "include"), |
| 87 | path.join(BX_DIR, "include"), |
| 88 | 88 | path.join(BGFX_DIR, "include"), |
| 89 | 89 | path.join(BGFX_DIR, "3rdparty"), |
| 90 | 90 | path.join(BGFX_DIR, "examples/common"), |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | files { |
| 94 | path.join(BGFX_DIR, "examples", _name, "**.c"), |
| 94 | 95 | path.join(BGFX_DIR, "examples", _name, "**.cpp"), |
| 95 | 96 | path.join(BGFX_DIR, "examples", _name, "**.h"), |
| 96 | 97 | } |
| r244991 | r244992 | |
| 308 | 309 | exampleProject("22-windows") |
| 309 | 310 | exampleProject("23-vectordisplay") |
| 310 | 311 | exampleProject("24-nbody") |
| 312 | exampleProject("25-c99") |
| 311 | 313 | |
| 312 | 314 | if _OPTIONS["with-shared-lib"] then |
| 313 | 315 | group "libs" |
trunk/3rdparty/bgfx/src/bgfx_shader.sh
| r244991 | r244992 | |
| 74 | 74 | Texture3D m_texture; |
| 75 | 75 | }; |
| 76 | 76 | |
| 77 | struct BgfxISampler3D |
| 78 | { |
| 79 | Texture3D<ivec4> m_texture; |
| 80 | }; |
| 81 | |
| 82 | struct BgfxUSampler3D |
| 83 | { |
| 84 | Texture3D<uvec4> m_texture; |
| 85 | }; |
| 86 | |
| 77 | 87 | vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord) |
| 78 | 88 | { |
| 79 | 89 | return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); |
| r244991 | r244992 | |
| 84 | 94 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); |
| 85 | 95 | } |
| 86 | 96 | |
| 97 | ivec4 bgfxTexture3D(BgfxISampler3D _sampler, vec3 _coord) |
| 98 | { |
| 99 | ivec3 size; |
| 100 | _sampler.m_texture.GetDimensions(size.x, size.y, size.z); |
| 101 | return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); |
| 102 | } |
| 103 | |
| 104 | uvec4 bgfxTexture3D(BgfxUSampler3D _sampler, vec3 _coord) |
| 105 | { |
| 106 | uvec3 size; |
| 107 | _sampler.m_texture.GetDimensions(size.x, size.y, size.z); |
| 108 | return _sampler.m_texture.Load(uvec4(_coord * size, 0) ); |
| 109 | } |
| 110 | |
| 87 | 111 | struct BgfxSamplerCube |
| 88 | 112 | { |
| 89 | 113 | SamplerState m_sampler; |
| r244991 | r244992 | |
| 121 | 145 | uniform SamplerState _name ## Sampler : register(s[_reg]); \ |
| 122 | 146 | uniform Texture3D _name ## Texture : register(t[_reg]); \ |
| 123 | 147 | static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture } |
| 148 | # define ISAMPLER3D(_name, _reg) \ |
| 149 | uniform Texture3D<ivec4> _name ## Texture : register(t[_reg]); \ |
| 150 | static BgfxISampler3D _name = { _name ## Texture } |
| 151 | # define USAMPLER3D(_name, _reg) \ |
| 152 | uniform Texture3D<uvec4> _name ## Texture : register(t[_reg]); \ |
| 153 | static BgfxUSampler3D _name = { _name ## Texture } |
| 124 | 154 | # define sampler3D BgfxSampler3D |
| 125 | 155 | # define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord) |
| 126 | 156 | # define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level) |
| r244991 | r244992 | |
| 247 | 277 | # define uvec3_splat(_x) uvec3(_x) |
| 248 | 278 | # define uvec4_splat(_x) uvec4(_x) |
| 249 | 279 | |
| 280 | # if BGFX_SHADER_LANGUAGE_GLSL >= 130 |
| 281 | # define ISAMPLER3D(_name, _reg) uniform isampler3D _name |
| 282 | # define USAMPLER3D(_name, _reg) uniform usampler3D _name |
| 283 | ivec4 texture3D(isampler3D _sampler, vec3 _coord) { return texture(_sampler, _coord); } |
| 284 | uvec4 texture3D(usampler3D _sampler, vec3 _coord) { return texture(_sampler, _coord); } |
| 285 | # endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 |
| 286 | |
| 250 | 287 | vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } |
| 251 | 288 | vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); } |
| 252 | 289 | vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); } |
trunk/3rdparty/bgfx/src/renderer_d3d11.cpp
| r244991 | r244992 | |
| 203 | 203 | { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown |
| 204 | 204 | { DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN }, // R1 |
| 205 | 205 | { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN }, // R8 |
| 206 | | { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN }, // R16 |
| 206 | { DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_UNKNOWN }, // R16 |
| 207 | 207 | { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN }, // R16F |
| 208 | 208 | { DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN }, // R32 |
| 209 | 209 | { DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN }, // R32F |
trunk/3rdparty/bgfx/src/vertexdecl.cpp
| r244991 | r244992 | |
| 41 | 41 | |
| 42 | 42 | static const uint8_t (*s_attribTypeSize[])[AttribType::Count][4] = |
| 43 | 43 | { |
| 44 | | #if BGFX_CONFIG_RENDERER_DIRECT3D9 |
| 45 | | &s_attribTypeSizeDx9, |
| 46 | | #elif BGFX_CONFIG_RENDERER_DIRECT3D11 || BGFX_CONFIG_RENDERER_DIRECT3D12 |
| 47 | | &s_attribTypeSizeDx1x, |
| 48 | | #elif BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_VULKAN |
| 49 | | &s_attribTypeSizeGl, |
| 50 | | #else |
| 51 | | &s_attribTypeSizeDx9, |
| 52 | | #endif // BGFX_CONFIG_RENDERER_ |
| 44 | &s_attribTypeSizeDx9, // Null |
| 53 | 45 | &s_attribTypeSizeDx9, // Direct3D9 |
| 54 | 46 | &s_attribTypeSizeDx1x, // Direct3D11 |
| 55 | 47 | &s_attribTypeSizeDx1x, // Direct3D12 |
| 56 | 48 | &s_attribTypeSizeGl, // OpenGLES |
| 57 | 49 | &s_attribTypeSizeGl, // OpenGL |
| 58 | 50 | &s_attribTypeSizeGl, // Vulkan |
| 51 | &s_attribTypeSizeDx9, // Count |
| 59 | 52 | }; |
| 60 | | BX_STATIC_ASSERT(BX_COUNTOF(s_attribTypeSize) == bgfx::RendererType::Count); |
| 53 | BX_STATIC_ASSERT(BX_COUNTOF(s_attribTypeSize) == RendererType::Count+1); |
| 61 | 54 | |
| 62 | 55 | void initAttribTypeSizeTable(RendererType::Enum _type) |
| 63 | 56 | { |
| 64 | | s_attribTypeSize[0] = s_attribTypeSize[_type]; |
| 57 | s_attribTypeSize[0] = s_attribTypeSize[_type]; |
| 58 | s_attribTypeSize[RendererType::Count] = s_attribTypeSize[_type]; |
| 65 | 59 | } |
| 66 | 60 | |
| 67 | 61 | void dbgPrintfVargs(const char* _format, va_list _argList) |
trunk/3rdparty/bgfx/tools/shaderc/shaderc.cpp
| r244991 | r244992 | |
| 751 | 751 | |
| 752 | 752 | bool raw = cmdLine.hasArg('\0', "raw"); |
| 753 | 753 | |
| 754 | | uint32_t gles = 0; |
| 754 | uint32_t glsl = 0; |
| 755 | uint32_t essl = 0; |
| 755 | 756 | uint32_t hlsl = 2; |
| 756 | 757 | uint32_t d3d = 11; |
| 757 | 758 | const char* profile = cmdLine.findOption('p', "profile"); |
| r244991 | r244992 | |
| 774 | 775 | { |
| 775 | 776 | hlsl = 5; |
| 776 | 777 | } |
| 778 | else |
| 779 | { |
| 780 | glsl = atoi(profile); |
| 781 | } |
| 777 | 782 | } |
| 778 | 783 | else |
| 779 | 784 | { |
| 780 | | gles = 2; |
| 785 | essl = 2; |
| 781 | 786 | } |
| 782 | 787 | |
| 783 | 788 | const char* bin2c = NULL; |
| r244991 | r244992 | |
| 811 | 816 | bool preprocessOnly = cmdLine.hasArg("preprocess"); |
| 812 | 817 | const char* includeDir = cmdLine.findOption('i'); |
| 813 | 818 | |
| 814 | | Preprocessor preprocessor(filePath, 0 != gles, includeDir); |
| 819 | Preprocessor preprocessor(filePath, 0 != essl, includeDir); |
| 815 | 820 | |
| 816 | 821 | std::string dir; |
| 817 | 822 | { |
| r244991 | r244992 | |
| 839 | 844 | preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_FRAGMENT"); |
| 840 | 845 | preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_VERTEX"); |
| 841 | 846 | |
| 842 | | bool glsl = false; |
| 847 | char glslDefine[128]; |
| 848 | bx::snprintf(glslDefine, BX_COUNTOF(glslDefine), "BGFX_SHADER_LANGUAGE_GLSL=%d", glsl); |
| 843 | 849 | |
| 844 | 850 | if (0 == bx::stricmp(platform, "android") ) |
| 845 | 851 | { |
| 846 | 852 | preprocessor.setDefine("BX_PLATFORM_ANDROID=1"); |
| 847 | 853 | preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1"); |
| 848 | | glsl = true; |
| 849 | 854 | } |
| 850 | 855 | else if (0 == bx::stricmp(platform, "asm.js") ) |
| 851 | 856 | { |
| 852 | 857 | preprocessor.setDefine("BX_PLATFORM_EMSCRIPTEN=1"); |
| 853 | 858 | preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1"); |
| 854 | | glsl = true; |
| 855 | 859 | } |
| 856 | 860 | else if (0 == bx::stricmp(platform, "ios") ) |
| 857 | 861 | { |
| 858 | 862 | preprocessor.setDefine("BX_PLATFORM_IOS=1"); |
| 859 | 863 | preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1"); |
| 860 | | glsl = true; |
| 861 | 864 | } |
| 862 | 865 | else if (0 == bx::stricmp(platform, "linux") ) |
| 863 | 866 | { |
| 864 | 867 | preprocessor.setDefine("BX_PLATFORM_LINUX=1"); |
| 865 | | preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1"); |
| 866 | | glsl = true; |
| 868 | preprocessor.setDefine(glslDefine); |
| 867 | 869 | } |
| 868 | 870 | else if (0 == bx::stricmp(platform, "nacl") ) |
| 869 | 871 | { |
| 870 | 872 | preprocessor.setDefine("BX_PLATFORM_NACL=1"); |
| 871 | 873 | preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1"); |
| 872 | | glsl = true; |
| 873 | 874 | } |
| 874 | 875 | else if (0 == bx::stricmp(platform, "osx") ) |
| 875 | 876 | { |
| 876 | 877 | preprocessor.setDefine("BX_PLATFORM_OSX=1"); |
| 877 | | preprocessor.setDefine("BGFX_SHADER_LANGUAGE_GLSL=1"); |
| 878 | | glsl = true; |
| 878 | preprocessor.setDefine(glslDefine); |
| 879 | 879 | } |
| 880 | 880 | else if (0 == bx::stricmp(platform, "windows") ) |
| 881 | 881 | { |
| r244991 | r244992 | |
| 1120 | 1120 | bx::write(writer, outputHash); |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | | if (glsl) |
| 1123 | if (0 != glsl) |
| 1124 | 1124 | { |
| 1125 | 1125 | bx::write(writer, uint16_t(0) ); |
| 1126 | 1126 | |
| r244991 | r244992 | |
| 1155 | 1155 | } |
| 1156 | 1156 | else |
| 1157 | 1157 | { |
| 1158 | | if (glsl) |
| 1158 | if (0 != glsl) |
| 1159 | 1159 | { |
| 1160 | 1160 | } |
| 1161 | 1161 | else |
| r244991 | r244992 | |
| 1269 | 1269 | bx::write(writer, BGFX_CHUNK_MAGIC_CSH); |
| 1270 | 1270 | bx::write(writer, outputHash); |
| 1271 | 1271 | |
| 1272 | | if (glsl) |
| 1272 | if (0 != glsl) |
| 1273 | 1273 | { |
| 1274 | 1274 | std::string code; |
| 1275 | 1275 | |
| 1276 | | if (gles) |
| 1276 | if (essl) |
| 1277 | 1277 | { |
| 1278 | 1278 | bx::stringPrintf(code, "#version 310 es\n"); |
| 1279 | 1279 | } |
| 1280 | 1280 | else |
| 1281 | 1281 | { |
| 1282 | | int32_t version = atoi(profile); |
| 1283 | | bx::stringPrintf(code, "#version %d\n", version == 0 ? 430 : version); |
| 1282 | bx::stringPrintf(code, "#version %d\n", glsl == 0 ? 430 : glsl); |
| 1284 | 1283 | } |
| 1285 | 1284 | |
| 1286 | 1285 | code += preprocessor.m_preprocessed; |
| r244991 | r244992 | |
| 1294 | 1293 | |
| 1295 | 1294 | compiled = true; |
| 1296 | 1295 | #else |
| 1297 | | compiled = compileGLSLShader(cmdLine, gles, code, writer); |
| 1296 | compiled = compileGLSLShader(cmdLine, essl, code, writer); |
| 1298 | 1297 | #endif // 0 |
| 1299 | 1298 | } |
| 1300 | 1299 | else |
| r244991 | r244992 | |
| 1339 | 1338 | } |
| 1340 | 1339 | else |
| 1341 | 1340 | { |
| 1342 | | if (glsl) |
| 1341 | if (0 != glsl) |
| 1343 | 1342 | { |
| 1344 | | preprocessor.writef( |
| 1345 | | "#define ivec2 vec2\n" |
| 1346 | | "#define ivec3 vec3\n" |
| 1347 | | "#define ivec4 vec4\n" |
| 1348 | | ); |
| 1343 | if (120 == glsl |
| 1344 | || essl) |
| 1345 | { |
| 1346 | preprocessor.writef( |
| 1347 | "#define ivec2 vec2\n" |
| 1348 | "#define ivec3 vec3\n" |
| 1349 | "#define ivec4 vec4\n" |
| 1350 | ); |
| 1351 | } |
| 1349 | 1352 | |
| 1350 | | if (0 == gles) |
| 1353 | if (0 == essl) |
| 1351 | 1354 | { |
| 1352 | 1355 | // bgfx shadow2D/Proj behave like EXT_shadow_samplers |
| 1353 | 1356 | // not as GLSL language 1.2 specs shadow2D/Proj. |
| r244991 | r244992 | |
| 1645 | 1648 | return EXIT_FAILURE; |
| 1646 | 1649 | } |
| 1647 | 1650 | |
| 1648 | | if (glsl) |
| 1651 | if (0 != glsl) |
| 1649 | 1652 | { |
| 1650 | 1653 | const char* profile = cmdLine.findOption('p', "profile"); |
| 1651 | 1654 | if (NULL == profile) |
| r244991 | r244992 | |
| 1697 | 1700 | bx::write(writer, outputHash); |
| 1698 | 1701 | } |
| 1699 | 1702 | |
| 1700 | | if (glsl) |
| 1703 | if (0 != glsl) |
| 1701 | 1704 | { |
| 1702 | 1705 | std::string code; |
| 1703 | 1706 | |
| 1704 | 1707 | bool hasTextureLod = NULL != bx::findIdentifierMatch(input, s_ARB_shader_texture_lod /*EXT_shader_texture_lod*/); |
| 1705 | 1708 | |
| 1706 | | if (0 == gles) |
| 1709 | if (0 == essl) |
| 1707 | 1710 | { |
| 1708 | 1711 | bx::stringPrintf(code, "#version %s\n", profile); |
| 1709 | | int32_t version = atoi(profile); |
| 1710 | 1712 | |
| 1711 | 1713 | bx::stringPrintf(code |
| 1712 | 1714 | , "#define bgfxShadow2D shadow2D\n" |
| r244991 | r244992 | |
| 1714 | 1716 | ); |
| 1715 | 1717 | |
| 1716 | 1718 | if (hasTextureLod |
| 1717 | | && 130 > version) |
| 1719 | && 130 > glsl) |
| 1718 | 1720 | { |
| 1719 | 1721 | bx::stringPrintf(code |
| 1720 | 1722 | , "#extension GL_ARB_shader_texture_lod : enable\n" |
| r244991 | r244992 | |
| 1767 | 1769 | } |
| 1768 | 1770 | |
| 1769 | 1771 | code += preprocessor.m_preprocessed; |
| 1770 | | compiled = compileGLSLShader(cmdLine, gles, code, writer); |
| 1772 | compiled = compileGLSLShader(cmdLine, essl, code, writer); |
| 1771 | 1773 | } |
| 1772 | 1774 | else |
| 1773 | 1775 | { |