koffi 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +661 -0
- package/README.md +195 -162
- package/package.json +36 -19
- package/src/call.hh +28 -27
- package/src/call_arm32.cc +498 -514
- package/src/call_arm32_fwd.S +108 -108
- package/src/call_arm64.cc +482 -497
- package/src/call_arm64_fwd.S +110 -110
- package/src/call_x64_sysv.cc +463 -477
- package/src/call_x64_sysv_fwd.S +131 -131
- package/src/call_x64_win.cc +240 -243
- package/src/call_x64_win_fwd.asm +105 -105
- package/src/call_x86.cc +246 -259
- package/src/call_x86_fwd.S +48 -48
- package/src/call_x86_fwd.asm +50 -50
- package/src/ffi.cc +506 -504
- package/src/ffi.hh +142 -136
- package/src/util.cc +330 -297
- package/src/util.hh +164 -80
- package/test/qemu/.gitkeep +0 -0
- package/test/registry/machines.json +112 -0
- package/test/registry/sha256sum.txt +21 -0
- package/test/test.js +493 -0
- package/vendor/dragonbox/include/dragonbox/dragonbox.h +2674 -2674
- package/vendor/dragonbox/subproject/test/results/binary32.csv +255 -255
- package/vendor/dragonbox/subproject/test/results/binary64.csv +2047 -2047
- package/vendor/libcc/libcc.cc +7669 -7651
- package/vendor/libcc/libcc.hh +4334 -4312
- package/vendor/node-addon-api/CHANGELOG.md +859 -859
- package/vendor/node-addon-api/CODE_OF_CONDUCT.md +4 -4
- package/vendor/node-addon-api/CONTRIBUTING.md +93 -93
- package/vendor/node-addon-api/LICENSE.md +12 -12
- package/vendor/node-addon-api/README.md +293 -293
- package/vendor/node-addon-api/appveyor.yml +37 -37
- package/vendor/node-addon-api/benchmark/README.md +47 -47
- package/vendor/node-addon-api/benchmark/binding.gyp +25 -25
- package/vendor/node-addon-api/benchmark/function_args.cc +217 -217
- package/vendor/node-addon-api/benchmark/function_args.js +60 -60
- package/vendor/node-addon-api/benchmark/index.js +34 -34
- package/vendor/node-addon-api/benchmark/property_descriptor.cc +91 -91
- package/vendor/node-addon-api/benchmark/property_descriptor.js +37 -37
- package/vendor/node-addon-api/common.gypi +21 -21
- package/vendor/node-addon-api/doc/addon.md +163 -163
- package/vendor/node-addon-api/doc/array.md +81 -81
- package/vendor/node-addon-api/doc/array_buffer.md +155 -155
- package/vendor/node-addon-api/doc/async_context.md +86 -86
- package/vendor/node-addon-api/doc/async_operations.md +31 -31
- package/vendor/node-addon-api/doc/async_worker.md +427 -427
- package/vendor/node-addon-api/doc/async_worker_variants.md +557 -557
- package/vendor/node-addon-api/doc/bigint.md +97 -97
- package/vendor/node-addon-api/doc/boolean.md +68 -68
- package/vendor/node-addon-api/doc/buffer.md +150 -150
- package/vendor/node-addon-api/doc/callback_scope.md +54 -54
- package/vendor/node-addon-api/doc/callbackinfo.md +97 -97
- package/vendor/node-addon-api/doc/checker-tool.md +32 -32
- package/vendor/node-addon-api/doc/class_property_descriptor.md +115 -115
- package/vendor/node-addon-api/doc/cmake-js.md +68 -68
- package/vendor/node-addon-api/doc/conversion-tool.md +27 -27
- package/vendor/node-addon-api/doc/creating_a_release.md +62 -62
- package/vendor/node-addon-api/doc/dataview.md +248 -248
- package/vendor/node-addon-api/doc/date.md +68 -68
- package/vendor/node-addon-api/doc/env.md +196 -196
- package/vendor/node-addon-api/doc/error.md +120 -120
- package/vendor/node-addon-api/doc/error_handling.md +254 -254
- package/vendor/node-addon-api/doc/escapable_handle_scope.md +80 -80
- package/vendor/node-addon-api/doc/external.md +63 -63
- package/vendor/node-addon-api/doc/function.md +402 -402
- package/vendor/node-addon-api/doc/function_reference.md +238 -238
- package/vendor/node-addon-api/doc/generator.md +13 -13
- package/vendor/node-addon-api/doc/handle_scope.md +63 -63
- package/vendor/node-addon-api/doc/hierarchy.md +91 -91
- package/vendor/node-addon-api/doc/instance_wrap.md +408 -408
- package/vendor/node-addon-api/doc/maybe.md +76 -76
- package/vendor/node-addon-api/doc/memory_management.md +27 -27
- package/vendor/node-addon-api/doc/name.md +29 -29
- package/vendor/node-addon-api/doc/node-gyp.md +82 -82
- package/vendor/node-addon-api/doc/number.md +163 -163
- package/vendor/node-addon-api/doc/object.md +432 -432
- package/vendor/node-addon-api/doc/object_lifetime_management.md +83 -83
- package/vendor/node-addon-api/doc/object_reference.md +117 -117
- package/vendor/node-addon-api/doc/object_wrap.md +561 -561
- package/vendor/node-addon-api/doc/prebuild_tools.md +16 -16
- package/vendor/node-addon-api/doc/promises.md +79 -79
- package/vendor/node-addon-api/doc/property_descriptor.md +286 -286
- package/vendor/node-addon-api/doc/propertylvalue.md +50 -50
- package/vendor/node-addon-api/doc/range_error.md +59 -59
- package/vendor/node-addon-api/doc/reference.md +113 -113
- package/vendor/node-addon-api/doc/setup.md +110 -110
- package/vendor/node-addon-api/doc/string.md +93 -93
- package/vendor/node-addon-api/doc/symbol.md +60 -60
- package/vendor/node-addon-api/doc/threadsafe.md +121 -121
- package/vendor/node-addon-api/doc/threadsafe_function.md +290 -290
- package/vendor/node-addon-api/doc/type_error.md +59 -59
- package/vendor/node-addon-api/doc/typed_array.md +78 -78
- package/vendor/node-addon-api/doc/typed_array_of.md +137 -137
- package/vendor/node-addon-api/doc/typed_threadsafe_function.md +306 -306
- package/vendor/node-addon-api/doc/value.md +340 -340
- package/vendor/node-addon-api/doc/version_management.md +43 -43
- package/vendor/node-addon-api/except.gypi +25 -25
- package/vendor/node-addon-api/index.js +11 -11
- package/vendor/node-addon-api/napi-inl.deprecated.h +192 -192
- package/vendor/node-addon-api/napi-inl.h +6209 -6209
- package/vendor/node-addon-api/napi.h +2983 -2983
- package/vendor/node-addon-api/node_api.gyp +9 -9
- package/vendor/node-addon-api/noexcept.gypi +26 -26
- package/vendor/node-addon-api/package-support.json +21 -21
- package/vendor/node-addon-api/package.json +399 -399
- package/vendor/node-addon-api/test/README.md +91 -91
- package/vendor/node-addon-api/test/addon.cc +36 -36
- package/vendor/node-addon-api/test/addon.js +11 -11
- package/vendor/node-addon-api/test/addon_build/index.js +49 -49
- package/vendor/node-addon-api/test/addon_build/tpl/addon.cc +17 -17
- package/vendor/node-addon-api/test/addon_build/tpl/binding.gyp +62 -62
- package/vendor/node-addon-api/test/addon_build/tpl/index.js +9 -9
- package/vendor/node-addon-api/test/addon_build/tpl/package.json +11 -11
- package/vendor/node-addon-api/test/addon_data.cc +99 -99
- package/vendor/node-addon-api/test/addon_data.js +46 -46
- package/vendor/node-addon-api/test/array_buffer.cc +243 -243
- package/vendor/node-addon-api/test/array_buffer.js +69 -69
- package/vendor/node-addon-api/test/async_context.cc +21 -21
- package/vendor/node-addon-api/test/async_context.js +86 -86
- package/vendor/node-addon-api/test/async_progress_queue_worker.cc +83 -83
- package/vendor/node-addon-api/test/async_progress_queue_worker.js +46 -46
- package/vendor/node-addon-api/test/async_progress_worker.cc +134 -134
- package/vendor/node-addon-api/test/async_progress_worker.js +61 -61
- package/vendor/node-addon-api/test/async_worker.cc +106 -106
- package/vendor/node-addon-api/test/async_worker.js +179 -179
- package/vendor/node-addon-api/test/async_worker_nocallback.js +13 -13
- package/vendor/node-addon-api/test/async_worker_persistent.cc +63 -63
- package/vendor/node-addon-api/test/async_worker_persistent.js +24 -24
- package/vendor/node-addon-api/test/basic_types/array.cc +40 -40
- package/vendor/node-addon-api/test/basic_types/array.js +35 -35
- package/vendor/node-addon-api/test/basic_types/boolean.cc +38 -38
- package/vendor/node-addon-api/test/basic_types/boolean.js +35 -35
- package/vendor/node-addon-api/test/basic_types/number.cc +99 -99
- package/vendor/node-addon-api/test/basic_types/number.js +114 -114
- package/vendor/node-addon-api/test/basic_types/value.cc +120 -120
- package/vendor/node-addon-api/test/basic_types/value.js +133 -133
- package/vendor/node-addon-api/test/bigint.cc +91 -91
- package/vendor/node-addon-api/test/bigint.js +53 -53
- package/vendor/node-addon-api/test/binding-swallowexcept.cc +12 -12
- package/vendor/node-addon-api/test/binding.cc +171 -171
- package/vendor/node-addon-api/test/binding.gyp +117 -117
- package/vendor/node-addon-api/test/buffer.cc +183 -183
- package/vendor/node-addon-api/test/buffer.js +69 -69
- package/vendor/node-addon-api/test/callbackscope.cc +22 -22
- package/vendor/node-addon-api/test/callbackscope.js +49 -49
- package/vendor/node-addon-api/test/common/index.js +113 -113
- package/vendor/node-addon-api/test/common/test_helper.h +61 -61
- package/vendor/node-addon-api/test/dataview/dataview.cc +48 -48
- package/vendor/node-addon-api/test/dataview/dataview.js +35 -35
- package/vendor/node-addon-api/test/dataview/dataview_read_write.cc +115 -115
- package/vendor/node-addon-api/test/dataview/dataview_read_write.js +90 -90
- package/vendor/node-addon-api/test/date.cc +44 -44
- package/vendor/node-addon-api/test/date.js +18 -18
- package/vendor/node-addon-api/test/env_cleanup.cc +88 -88
- package/vendor/node-addon-api/test/env_cleanup.js +56 -56
- package/vendor/node-addon-api/test/error.cc +287 -287
- package/vendor/node-addon-api/test/error.js +81 -81
- package/vendor/node-addon-api/test/error_handling_for_primitives.cc +13 -13
- package/vendor/node-addon-api/test/error_handling_for_primitives.js +29 -29
- package/vendor/node-addon-api/test/error_terminating_environment.js +94 -94
- package/vendor/node-addon-api/test/external.cc +81 -81
- package/vendor/node-addon-api/test/external.js +88 -88
- package/vendor/node-addon-api/test/function.cc +295 -295
- package/vendor/node-addon-api/test/function.js +121 -121
- package/vendor/node-addon-api/test/function_reference.cc +202 -202
- package/vendor/node-addon-api/test/function_reference.js +157 -157
- package/vendor/node-addon-api/test/globalObject/global_object.cc +61 -61
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.cc +31 -31
- package/vendor/node-addon-api/test/globalObject/global_object_delete_property.js +61 -61
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.cc +40 -40
- package/vendor/node-addon-api/test/globalObject/global_object_get_property.js +57 -57
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.cc +28 -28
- package/vendor/node-addon-api/test/globalObject/global_object_has_own_property.js +48 -48
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.cc +30 -30
- package/vendor/node-addon-api/test/globalObject/global_object_set_property.js +58 -58
- package/vendor/node-addon-api/test/handlescope.cc +60 -60
- package/vendor/node-addon-api/test/handlescope.js +14 -14
- package/vendor/node-addon-api/test/index.js +136 -136
- package/vendor/node-addon-api/test/maybe/check.cc +23 -23
- package/vendor/node-addon-api/test/maybe/index.js +38 -38
- package/vendor/node-addon-api/test/memory_management.cc +17 -17
- package/vendor/node-addon-api/test/memory_management.js +9 -9
- package/vendor/node-addon-api/test/movable_callbacks.cc +23 -23
- package/vendor/node-addon-api/test/movable_callbacks.js +21 -21
- package/vendor/node-addon-api/test/name.cc +108 -108
- package/vendor/node-addon-api/test/name.js +59 -59
- package/vendor/node-addon-api/test/napi_child.js +14 -14
- package/vendor/node-addon-api/test/object/delete_property.cc +38 -38
- package/vendor/node-addon-api/test/object/delete_property.js +41 -41
- package/vendor/node-addon-api/test/object/finalizer.cc +29 -29
- package/vendor/node-addon-api/test/object/finalizer.js +28 -28
- package/vendor/node-addon-api/test/object/get_property.cc +34 -34
- package/vendor/node-addon-api/test/object/get_property.js +40 -40
- package/vendor/node-addon-api/test/object/has_own_property.cc +34 -34
- package/vendor/node-addon-api/test/object/has_own_property.js +34 -34
- package/vendor/node-addon-api/test/object/has_property.cc +38 -38
- package/vendor/node-addon-api/test/object/has_property.js +37 -37
- package/vendor/node-addon-api/test/object/object.cc +348 -348
- package/vendor/node-addon-api/test/object/object.js +217 -217
- package/vendor/node-addon-api/test/object/object_deprecated.cc +66 -66
- package/vendor/node-addon-api/test/object/object_deprecated.js +47 -47
- package/vendor/node-addon-api/test/object/object_freeze_seal.cc +25 -25
- package/vendor/node-addon-api/test/object/object_freeze_seal.js +61 -61
- package/vendor/node-addon-api/test/object/set_property.cc +37 -37
- package/vendor/node-addon-api/test/object/set_property.js +29 -29
- package/vendor/node-addon-api/test/object/subscript_operator.cc +42 -42
- package/vendor/node-addon-api/test/object/subscript_operator.js +17 -17
- package/vendor/node-addon-api/test/object_reference.cc +219 -219
- package/vendor/node-addon-api/test/object_reference.js +259 -259
- package/vendor/node-addon-api/test/objectwrap.cc +268 -268
- package/vendor/node-addon-api/test/objectwrap.js +284 -284
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.cc +26 -26
- package/vendor/node-addon-api/test/objectwrap_constructor_exception.js +18 -18
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.cc +30 -30
- package/vendor/node-addon-api/test/objectwrap_multiple_inheritance.js +13 -13
- package/vendor/node-addon-api/test/objectwrap_removewrap.cc +45 -45
- package/vendor/node-addon-api/test/objectwrap_removewrap.js +40 -40
- package/vendor/node-addon-api/test/objectwrap_worker_thread.js +19 -19
- package/vendor/node-addon-api/test/promise.cc +29 -29
- package/vendor/node-addon-api/test/promise.js +18 -18
- package/vendor/node-addon-api/test/reference.cc +24 -24
- package/vendor/node-addon-api/test/reference.js +14 -14
- package/vendor/node-addon-api/test/run_script.cc +56 -56
- package/vendor/node-addon-api/test/run_script.js +45 -45
- package/vendor/node-addon-api/test/symbol.cc +79 -79
- package/vendor/node-addon-api/test/symbol.js +73 -73
- package/vendor/node-addon-api/test/testUtil.js +54 -54
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.cc +195 -195
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function.js +188 -188
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.cc +63 -63
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ctx.js +12 -12
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.cc +115 -115
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_existing_tsfn.js +14 -14
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.cc +26 -26
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_ptr.js +7 -7
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.cc +225 -225
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_sum.js +59 -59
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.cc +42 -42
- package/vendor/node-addon-api/test/threadsafe_function/threadsafe_function_unref.js +53 -53
- package/vendor/node-addon-api/test/thunking_manual.cc +140 -140
- package/vendor/node-addon-api/test/thunking_manual.js +17 -17
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.cc +215 -215
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function.js +188 -188
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.cc +68 -68
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +12 -12
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.cc +127 -127
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +14 -14
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.cc +28 -28
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +7 -7
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +237 -237
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +59 -59
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.cc +53 -53
- package/vendor/node-addon-api/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +53 -53
- package/vendor/node-addon-api/test/typedarray-bigint.js +58 -58
- package/vendor/node-addon-api/test/typedarray.cc +216 -216
- package/vendor/node-addon-api/test/typedarray.js +69 -69
- package/vendor/node-addon-api/test/version_management.cc +27 -27
- package/vendor/node-addon-api/test/version_management.js +31 -31
- package/vendor/node-addon-api/tools/README.md +73 -73
- package/vendor/node-addon-api/tools/check-napi.js +100 -100
- package/vendor/node-addon-api/tools/clang-format.js +68 -68
- package/vendor/node-addon-api/tools/conversion.js +309 -309
- package/vendor/node-addon-api/tools/eslint-format.js +71 -71
- package/vendor/raylib/BINDINGS.md +123 -0
- package/vendor/raylib/CHANGELOG +1495 -0
- package/vendor/raylib/CMakeLists.txt +33 -0
- package/vendor/raylib/CMakeOptions.txt +87 -0
- package/vendor/raylib/CONTRIBUTING.md +76 -0
- package/vendor/raylib/CONTRIBUTORS.md +63 -0
- package/vendor/raylib/CONVENTIONS.md +95 -0
- package/vendor/raylib/HISTORY.md +364 -0
- package/vendor/raylib/LICENSE +16 -0
- package/vendor/raylib/README.md +141 -0
- package/vendor/raylib/ROADMAP.md +76 -0
- package/vendor/raylib/SPONSORS.md +68 -0
- package/vendor/raylib/cmake/AddIfFlagCompiles.cmake +12 -0
- package/vendor/raylib/cmake/BuildOptions.cmake +18 -0
- package/vendor/raylib/cmake/CompileDefinitions.cmake +110 -0
- package/vendor/raylib/cmake/CompilerFlags.cmake +79 -0
- package/vendor/raylib/cmake/EnumOption.cmake +9 -0
- package/vendor/raylib/cmake/GlfwImport.cmake +34 -0
- package/vendor/raylib/cmake/InstallConfigurations.cmake +29 -0
- package/vendor/raylib/cmake/JoinPaths.cmake +26 -0
- package/vendor/raylib/cmake/LibraryConfigurations.cmake +108 -0
- package/vendor/raylib/cmake/LibraryPathToLinkerFlags.cmake +24 -0
- package/vendor/raylib/cmake/PackConfigurations.cmake +13 -0
- package/vendor/raylib/cmake/PopulateConfigVariablesLocally.cmake +11 -0
- package/vendor/raylib/cmake/raylib-config-version.cmake +21 -0
- package/vendor/raylib/cmake/raylib-config.cmake +76 -0
- package/vendor/raylib/examples/CMakeLists.txt +139 -0
- package/vendor/raylib/examples/Makefile +565 -0
- package/vendor/raylib/examples/Makefile.Android +405 -0
- package/vendor/raylib/examples/Makefile.Web +1053 -0
- package/vendor/raylib/examples/README.md +203 -0
- package/vendor/raylib/examples/audio/audio_module_playing.c +146 -0
- package/vendor/raylib/examples/audio/audio_module_playing.png +0 -0
- package/vendor/raylib/examples/audio/audio_multichannel_sound.c +73 -0
- package/vendor/raylib/examples/audio/audio_multichannel_sound.png +0 -0
- package/vendor/raylib/examples/audio/audio_music_stream.c +93 -0
- package/vendor/raylib/examples/audio/audio_music_stream.png +0 -0
- package/vendor/raylib/examples/audio/audio_raw_stream.c +167 -0
- package/vendor/raylib/examples/audio/audio_raw_stream.png +0 -0
- package/vendor/raylib/examples/audio/audio_sound_loading.c +64 -0
- package/vendor/raylib/examples/audio/audio_sound_loading.png +0 -0
- package/vendor/raylib/examples/audio/resources/LICENSE.md +10 -0
- package/vendor/raylib/examples/audio/resources/coin.wav +0 -0
- package/vendor/raylib/examples/audio/resources/country.mp3 +0 -0
- package/vendor/raylib/examples/audio/resources/mini1111.xm +0 -0
- package/vendor/raylib/examples/audio/resources/sound.wav +0 -0
- package/vendor/raylib/examples/audio/resources/spring.wav +0 -0
- package/vendor/raylib/examples/audio/resources/target.flac +0 -0
- package/vendor/raylib/examples/audio/resources/target.ogg +0 -0
- package/vendor/raylib/examples/audio/resources/weird.wav +0 -0
- package/vendor/raylib/examples/build.zig +86 -0
- package/vendor/raylib/examples/core/core_2d_camera.c +132 -0
- package/vendor/raylib/examples/core/core_2d_camera.png +0 -0
- package/vendor/raylib/examples/core/core_2d_camera_platformer.c +293 -0
- package/vendor/raylib/examples/core/core_2d_camera_platformer.png +0 -0
- package/vendor/raylib/examples/core/core_2d_camera_smooth_pixelperfect.png +0 -0
- package/vendor/raylib/examples/core/core_3d_camera_first_person.c +97 -0
- package/vendor/raylib/examples/core/core_3d_camera_first_person.png +0 -0
- package/vendor/raylib/examples/core/core_3d_camera_free.c +83 -0
- package/vendor/raylib/examples/core/core_3d_camera_free.png +0 -0
- package/vendor/raylib/examples/core/core_3d_camera_mode.c +73 -0
- package/vendor/raylib/examples/core/core_3d_camera_mode.png +0 -0
- package/vendor/raylib/examples/core/core_3d_picking.c +107 -0
- package/vendor/raylib/examples/core/core_3d_picking.png +0 -0
- package/vendor/raylib/examples/core/core_basic_screen_manager.c +150 -0
- package/vendor/raylib/examples/core/core_basic_screen_manager.png +0 -0
- package/vendor/raylib/examples/core/core_basic_window.c +62 -0
- package/vendor/raylib/examples/core/core_basic_window.png +0 -0
- package/vendor/raylib/examples/core/core_basic_window_web.c +85 -0
- package/vendor/raylib/examples/core/core_custom_frame_control.c +125 -0
- package/vendor/raylib/examples/core/core_custom_frame_control.png +0 -0
- package/vendor/raylib/examples/core/core_custom_logging.c +84 -0
- package/vendor/raylib/examples/core/core_custom_logging.png +0 -0
- package/vendor/raylib/examples/core/core_drop_files.c +76 -0
- package/vendor/raylib/examples/core/core_drop_files.png +0 -0
- package/vendor/raylib/examples/core/core_input_gamepad.c +195 -0
- package/vendor/raylib/examples/core/core_input_gamepad.png +0 -0
- package/vendor/raylib/examples/core/core_input_gestures.c +115 -0
- package/vendor/raylib/examples/core/core_input_gestures.png +0 -0
- package/vendor/raylib/examples/core/core_input_keys.c +59 -0
- package/vendor/raylib/examples/core/core_input_keys.png +0 -0
- package/vendor/raylib/examples/core/core_input_mouse.c +65 -0
- package/vendor/raylib/examples/core/core_input_mouse.png +0 -0
- package/vendor/raylib/examples/core/core_input_mouse_wheel.c +58 -0
- package/vendor/raylib/examples/core/core_input_mouse_wheel.png +0 -0
- package/vendor/raylib/examples/core/core_input_multitouch.c +70 -0
- package/vendor/raylib/examples/core/core_input_multitouch.png +0 -0
- package/vendor/raylib/examples/core/core_loading_thread.c +147 -0
- package/vendor/raylib/examples/core/core_loading_thread.png +0 -0
- package/vendor/raylib/examples/core/core_quat_conversion.c +132 -0
- package/vendor/raylib/examples/core/core_quat_conversion.png +0 -0
- package/vendor/raylib/examples/core/core_random_values.c +67 -0
- package/vendor/raylib/examples/core/core_random_values.png +0 -0
- package/vendor/raylib/examples/core/core_scissor_test.c +71 -0
- package/vendor/raylib/examples/core/core_scissor_test.png +0 -0
- package/vendor/raylib/examples/core/core_smooth_pixelperfect.c +117 -0
- package/vendor/raylib/examples/core/core_smooth_pixelperfect.png +0 -0
- package/vendor/raylib/examples/core/core_split_screen.c +155 -0
- package/vendor/raylib/examples/core/core_split_screen.png +0 -0
- package/vendor/raylib/examples/core/core_storage_values.c +87 -0
- package/vendor/raylib/examples/core/core_storage_values.png +0 -0
- package/vendor/raylib/examples/core/core_vr_simulator.c +143 -0
- package/vendor/raylib/examples/core/core_vr_simulator.png +0 -0
- package/vendor/raylib/examples/core/core_window_flags.c +191 -0
- package/vendor/raylib/examples/core/core_window_flags.png +0 -0
- package/vendor/raylib/examples/core/core_window_letterbox.c +112 -0
- package/vendor/raylib/examples/core/core_window_letterbox.png +0 -0
- package/vendor/raylib/examples/core/core_world_screen.c +78 -0
- package/vendor/raylib/examples/core/core_world_screen.png +0 -0
- package/vendor/raylib/examples/core/resources/LICENSE.md +4 -0
- package/vendor/raylib/examples/core/resources/distortion100.fs +52 -0
- package/vendor/raylib/examples/core/resources/distortion330.fs +53 -0
- package/vendor/raylib/examples/core/resources/ps3.png +0 -0
- package/vendor/raylib/examples/core/resources/xbox.png +0 -0
- package/vendor/raylib/examples/examples_template.c +100 -0
- package/vendor/raylib/examples/models/models_animation.c +114 -0
- package/vendor/raylib/examples/models/models_animation.png +0 -0
- package/vendor/raylib/examples/models/models_billboard.c +75 -0
- package/vendor/raylib/examples/models/models_billboard.png +0 -0
- package/vendor/raylib/examples/models/models_box_collisions.c +121 -0
- package/vendor/raylib/examples/models/models_box_collisions.png +0 -0
- package/vendor/raylib/examples/models/models_cubicmap.c +87 -0
- package/vendor/raylib/examples/models/models_cubicmap.png +0 -0
- package/vendor/raylib/examples/models/models_first_person_maze.c +122 -0
- package/vendor/raylib/examples/models/models_first_person_maze.png +0 -0
- package/vendor/raylib/examples/models/models_geometric_shapes.c +80 -0
- package/vendor/raylib/examples/models/models_geometric_shapes.png +0 -0
- package/vendor/raylib/examples/models/models_heightmap.c +82 -0
- package/vendor/raylib/examples/models/models_heightmap.png +0 -0
- package/vendor/raylib/examples/models/models_loading.c +146 -0
- package/vendor/raylib/examples/models/models_loading.png +0 -0
- package/vendor/raylib/examples/models/models_loading_gltf.c +105 -0
- package/vendor/raylib/examples/models/models_loading_gltf.png +0 -0
- package/vendor/raylib/examples/models/models_loading_vox.c +130 -0
- package/vendor/raylib/examples/models/models_loading_vox.png +0 -0
- package/vendor/raylib/examples/models/models_mesh_generation.c +179 -0
- package/vendor/raylib/examples/models/models_mesh_generation.png +0 -0
- package/vendor/raylib/examples/models/models_mesh_picking.c +223 -0
- package/vendor/raylib/examples/models/models_mesh_picking.png +0 -0
- package/vendor/raylib/examples/models/models_orthographic_projection.c +99 -0
- package/vendor/raylib/examples/models/models_orthographic_projection.png +0 -0
- package/vendor/raylib/examples/models/models_rlgl_solar_system.c +172 -0
- package/vendor/raylib/examples/models/models_rlgl_solar_system.png +0 -0
- package/vendor/raylib/examples/models/models_skybox.c +262 -0
- package/vendor/raylib/examples/models/models_skybox.png +0 -0
- package/vendor/raylib/examples/models/models_waving_cubes.c +112 -0
- package/vendor/raylib/examples/models/models_waving_cubes.png +0 -0
- package/vendor/raylib/examples/models/models_yaw_pitch_roll.c +117 -0
- package/vendor/raylib/examples/models/models_yaw_pitch_roll.png +0 -0
- package/vendor/raylib/examples/models/resources/LICENSE.md +23 -0
- package/vendor/raylib/examples/models/resources/billboard.png +0 -0
- package/vendor/raylib/examples/models/resources/cubicmap.png +0 -0
- package/vendor/raylib/examples/models/resources/cubicmap_atlas.png +0 -0
- package/vendor/raylib/examples/models/resources/dresden_square_1k.hdr +0 -0
- package/vendor/raylib/examples/models/resources/dresden_square_2k.hdr +0 -0
- package/vendor/raylib/examples/models/resources/heightmap.png +0 -0
- package/vendor/raylib/examples/models/resources/models/gltf/AnimatedMorphCube.glb +0 -0
- package/vendor/raylib/examples/models/resources/models/gltf/AnimatedTriangle.gltf +118 -0
- package/vendor/raylib/examples/models/resources/models/gltf/BoxAnimated.glb +0 -0
- package/vendor/raylib/examples/models/resources/models/gltf/LICENSE +23 -0
- package/vendor/raylib/examples/models/resources/models/gltf/girl.glb +0 -0
- package/vendor/raylib/examples/models/resources/models/gltf/raylib_32x32.glb +0 -0
- package/vendor/raylib/examples/models/resources/models/gltf/rigged_figure.glb +0 -0
- package/vendor/raylib/examples/models/resources/models/gltf/vertex_colored_object.glb +0 -0
- package/vendor/raylib/examples/models/resources/models/iqm/guy.blend +0 -0
- package/vendor/raylib/examples/models/resources/models/iqm/guy.iqm +0 -0
- package/vendor/raylib/examples/models/resources/models/iqm/guyanim.iqm +0 -0
- package/vendor/raylib/examples/models/resources/models/iqm/guytex.png +0 -0
- package/vendor/raylib/examples/models/resources/models/iqm/vertex_colored_object.iqm +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/bridge.obj +1725 -0
- package/vendor/raylib/examples/models/resources/models/obj/bridge_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/castle.obj +12919 -0
- package/vendor/raylib/examples/models/resources/models/obj/castle_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/cube.obj +68 -0
- package/vendor/raylib/examples/models/resources/models/obj/cube_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/house.obj +4564 -0
- package/vendor/raylib/examples/models/resources/models/obj/house_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/market.obj +7301 -0
- package/vendor/raylib/examples/models/resources/models/obj/market_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/plane.obj +10858 -0
- package/vendor/raylib/examples/models/resources/models/obj/plane_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/turret.obj +1888 -0
- package/vendor/raylib/examples/models/resources/models/obj/turret_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/obj/well.obj +1030 -0
- package/vendor/raylib/examples/models/resources/models/obj/well_diffuse.png +0 -0
- package/vendor/raylib/examples/models/resources/models/vox/LICENSE +9 -0
- package/vendor/raylib/examples/models/resources/models/vox/chr_knight.vox +0 -0
- package/vendor/raylib/examples/models/resources/models/vox/chr_sword.vox +0 -0
- package/vendor/raylib/examples/models/resources/models/vox/monu9.vox +0 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl100/cubemap.fs +29 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl100/cubemap.vs +20 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl100/skybox.fs +31 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl100/skybox.vs +24 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl330/cubemap.fs +30 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl330/cubemap.vs +20 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl330/skybox.fs +30 -0
- package/vendor/raylib/examples/models/resources/shaders/glsl330/skybox.vs +24 -0
- package/vendor/raylib/examples/models/resources/skybox.png +0 -0
- package/vendor/raylib/examples/models/rlights.h +183 -0
- package/vendor/raylib/examples/others/easings.h +263 -0
- package/vendor/raylib/examples/others/easings_testbed.c +227 -0
- package/vendor/raylib/examples/others/embedded_files_loading.c +103 -0
- package/vendor/raylib/examples/others/external/include/GLFW/glfw3.h +5538 -0
- package/vendor/raylib/examples/others/external/include/GLFW/glfw3native.h +572 -0
- package/vendor/raylib/examples/others/external/include/glad.h +5466 -0
- package/vendor/raylib/examples/others/external/lib/libglfw3.a +0 -0
- package/vendor/raylib/examples/others/raudio_standalone.c +152 -0
- package/vendor/raylib/examples/others/raylib_opengl_interop.c +152 -0
- package/vendor/raylib/examples/others/raylib_opengl_interop.png +0 -0
- package/vendor/raylib/examples/others/resources/audio/country.mp3 +0 -0
- package/vendor/raylib/examples/others/resources/audio/target.ogg +0 -0
- package/vendor/raylib/examples/others/resources/audio/weird.wav +0 -0
- package/vendor/raylib/examples/others/resources/audio_data.h +4893 -0
- package/vendor/raylib/examples/others/resources/image_data.h +9848 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl100/point_particle.fs +16 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl100/point_particle.vs +24 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl330/point_particle.fs +17 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl330/point_particle.vs +24 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl430/gol.glsl +41 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl430/gol_render.glsl +29 -0
- package/vendor/raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl +51 -0
- package/vendor/raylib/examples/others/rlgl_compute_shader.c +173 -0
- package/vendor/raylib/examples/others/rlgl_standalone.c +469 -0
- package/vendor/raylib/examples/physics/physics_demo.c +128 -0
- package/vendor/raylib/examples/physics/physics_demo.png +0 -0
- package/vendor/raylib/examples/physics/physics_friction.c +142 -0
- package/vendor/raylib/examples/physics/physics_friction.png +0 -0
- package/vendor/raylib/examples/physics/physics_movement.c +128 -0
- package/vendor/raylib/examples/physics/physics_movement.png +0 -0
- package/vendor/raylib/examples/physics/physics_restitution.c +129 -0
- package/vendor/raylib/examples/physics/physics_restitution.png +0 -0
- package/vendor/raylib/examples/physics/physics_shatter.c +111 -0
- package/vendor/raylib/examples/physics/physics_shatter.png +0 -0
- package/vendor/raylib/examples/raylib_compile_execute.bat +32 -0
- package/vendor/raylib/examples/raylib_makefile_example.bat +27 -0
- package/vendor/raylib/examples/shaders/resources/LICENSE.md +11 -0
- package/vendor/raylib/examples/shaders/resources/fudesumi.png +0 -0
- package/vendor/raylib/examples/shaders/resources/mask.png +0 -0
- package/vendor/raylib/examples/shaders/resources/models/barracks.obj +22251 -0
- package/vendor/raylib/examples/shaders/resources/models/barracks_diffuse.png +0 -0
- package/vendor/raylib/examples/shaders/resources/models/church.obj +5116 -0
- package/vendor/raylib/examples/shaders/resources/models/church_diffuse.png +0 -0
- package/vendor/raylib/examples/shaders/resources/models/watermill.obj +5316 -0
- package/vendor/raylib/examples/shaders/resources/models/watermill_diffuse.png +0 -0
- package/vendor/raylib/examples/shaders/resources/plasma.png +0 -0
- package/vendor/raylib/examples/shaders/resources/raysan.png +0 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/base.fs +23 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/base.vs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/base_lighting.vs +59 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/base_lighting_instanced.vs +36 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/bloom.fs +39 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/blur.fs +34 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/color_mix.fs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/cross_hatching.fs +47 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/cross_stitching.fs +57 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/cubes_panning.fs +60 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/depth.fs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/distortion.fs +54 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/dream_vision.fs +37 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/eratosthenes.fs +60 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/fisheye.fs +43 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/fog.fs +94 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/grayscale.fs +25 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/julia_set.fs +83 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/lighting.fs +81 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/mask.fs +24 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/outline.fs +34 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/palette_switch.fs +41 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/pixelizer.fs +32 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/posterization.fs +29 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/predator.fs +31 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/raymarching.fs +431 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/reload.fs +39 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/scanlines.fs +44 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/sobel.fs +40 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/spotlight.fs +77 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/swirl.fs +46 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl100/wave.fs +36 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/base.fs +22 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/base.vs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/base_lighting.vs +59 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/bloom.fs +37 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/blur.fs +32 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/cross_hatching.fs +45 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/cross_stitching.fs +55 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/distortion.fs +52 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/dream_vision.fs +35 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/fisheye.fs +41 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/fog.fs +92 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/grayscale.fs +23 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/palette_switch.fs +27 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/pixelizer.fs +30 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/posterization.fs +27 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/predator.fs +29 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/scanlines.fs +42 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/sobel.fs +38 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl120/swirl.fs +44 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/base.fs +25 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/base.vs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/base_lighting.vs +32 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs +36 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/bloom.fs +40 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/blur.fs +35 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/color_mix.fs +27 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/cross_hatching.fs +48 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/cross_stitching.fs +59 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/cubes_panning.fs +61 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/depth.fs +27 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/distortion.fs +56 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/dream_vision.fs +34 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/eratosthenes.fs +59 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/fisheye.fs +40 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/fog.fs +95 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/grayscale.fs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/julia_set.fs +81 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/lighting.fs +82 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/mask.fs +22 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/outline.fs +35 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/overdraw.fs +26 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/palette_switch.fs +30 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/pixelizer.fs +33 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/posterization.fs +31 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/predator.fs +32 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/raymarching.fs +430 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/reload.fs +40 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/scanlines.fs +49 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/sobel.fs +41 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/spotlight.fs +65 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/swirl.fs +47 -0
- package/vendor/raylib/examples/shaders/resources/shaders/glsl330/wave.fs +37 -0
- package/vendor/raylib/examples/shaders/resources/space.png +0 -0
- package/vendor/raylib/examples/shaders/resources/texel_checker.png +0 -0
- package/vendor/raylib/examples/shaders/rlights.h +183 -0
- package/vendor/raylib/examples/shaders/shaders_basic_lighting.c +152 -0
- package/vendor/raylib/examples/shaders/shaders_basic_lighting.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_custom_uniform.c +127 -0
- package/vendor/raylib/examples/shaders/shaders_custom_uniform.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_eratosthenes.c +92 -0
- package/vendor/raylib/examples/shaders/shaders_eratosthenes.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_fog.c +160 -0
- package/vendor/raylib/examples/shaders/shaders_fog.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_hot_reloading.c +130 -0
- package/vendor/raylib/examples/shaders/shaders_hot_reloading.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_julia_set.c +191 -0
- package/vendor/raylib/examples/shaders/shaders_julia_set.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_mesh_instancing.c +224 -0
- package/vendor/raylib/examples/shaders/shaders_mesh_instancing.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_model_shader.c +103 -0
- package/vendor/raylib/examples/shaders/shaders_model_shader.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_multi_sample2d.c +105 -0
- package/vendor/raylib/examples/shaders/shaders_multi_sample2d.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_palette_switch.c +147 -0
- package/vendor/raylib/examples/shaders/shaders_palette_switch.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_postprocessing.c +170 -0
- package/vendor/raylib/examples/shaders/shaders_postprocessing.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_raymarching.c +113 -0
- package/vendor/raylib/examples/shaders/shaders_raymarching.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_shapes_textures.c +116 -0
- package/vendor/raylib/examples/shaders/shaders_shapes_textures.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_simple_mask.c +144 -0
- package/vendor/raylib/examples/shaders/shaders_simple_mask.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_spotlight.c +254 -0
- package/vendor/raylib/examples/shaders/shaders_spotlight.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_texture_drawing.c +80 -0
- package/vendor/raylib/examples/shaders/shaders_texture_drawing.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_texture_outline.c +97 -0
- package/vendor/raylib/examples/shaders/shaders_texture_outline.png +0 -0
- package/vendor/raylib/examples/shaders/shaders_texture_waves.c +110 -0
- package/vendor/raylib/examples/shaders/shaders_texture_waves.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_basic_shapes.c +78 -0
- package/vendor/raylib/examples/shapes/shapes_basic_shapes.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_bouncing_ball.c +76 -0
- package/vendor/raylib/examples/shapes/shapes_bouncing_ball.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_collision_area.c +108 -0
- package/vendor/raylib/examples/shapes/shapes_collision_area.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_colors_palette.c +99 -0
- package/vendor/raylib/examples/shapes/shapes_colors_palette.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_draw_circle_sector.c +83 -0
- package/vendor/raylib/examples/shapes/shapes_draw_circle_sector.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_draw_rectangle_rounded.c +89 -0
- package/vendor/raylib/examples/shapes/shapes_draw_rectangle_rounded.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_draw_ring.c +96 -0
- package/vendor/raylib/examples/shapes/shapes_draw_ring.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_easings_ball_anim.c +110 -0
- package/vendor/raylib/examples/shapes/shapes_easings_ball_anim.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_easings_box_anim.c +136 -0
- package/vendor/raylib/examples/shapes/shapes_easings_box_anim.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_easings_rectangle_array.c +118 -0
- package/vendor/raylib/examples/shapes/shapes_easings_rectangle_array.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_following_eyes.c +104 -0
- package/vendor/raylib/examples/shapes/shapes_following_eyes.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_lines_bezier.c +59 -0
- package/vendor/raylib/examples/shapes/shapes_lines_bezier.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_logo_raylib.c +56 -0
- package/vendor/raylib/examples/shapes/shapes_logo_raylib.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_logo_raylib_anim.c +160 -0
- package/vendor/raylib/examples/shapes/shapes_logo_raylib_anim.png +0 -0
- package/vendor/raylib/examples/shapes/shapes_rectangle_scaling.c +94 -0
- package/vendor/raylib/examples/shapes/shapes_rectangle_scaling.png +0 -0
- package/vendor/raylib/examples/text/resources/KAISG.ttf +0 -0
- package/vendor/raylib/examples/text/resources/LICENSE.md +20 -0
- package/vendor/raylib/examples/text/resources/anonymous_pro_bold.ttf +0 -0
- package/vendor/raylib/examples/text/resources/custom_alagard.png +0 -0
- package/vendor/raylib/examples/text/resources/custom_jupiter_crash.png +0 -0
- package/vendor/raylib/examples/text/resources/custom_mecha.png +0 -0
- package/vendor/raylib/examples/text/resources/dejavu.fnt +1115 -0
- package/vendor/raylib/examples/text/resources/dejavu.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/alagard.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/alpha_beta.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/jupiter_crash.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/mecha.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/pixantiqua.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/pixelplay.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/romulus.png +0 -0
- package/vendor/raylib/examples/text/resources/fonts/setback.png +0 -0
- package/vendor/raylib/examples/text/resources/noto_cjk.fnt +580 -0
- package/vendor/raylib/examples/text/resources/noto_cjk.png +0 -0
- package/vendor/raylib/examples/text/resources/pixantiqua.fnt +188 -0
- package/vendor/raylib/examples/text/resources/pixantiqua.png +0 -0
- package/vendor/raylib/examples/text/resources/pixantiqua.ttf +0 -0
- package/vendor/raylib/examples/text/resources/shaders/glsl100/alpha_discard.fs +20 -0
- package/vendor/raylib/examples/text/resources/shaders/glsl100/sdf.fs +25 -0
- package/vendor/raylib/examples/text/resources/shaders/glsl330/alpha_discard.fs +19 -0
- package/vendor/raylib/examples/text/resources/shaders/glsl330/sdf.fs +26 -0
- package/vendor/raylib/examples/text/resources/symbola.fnt +191 -0
- package/vendor/raylib/examples/text/resources/symbola.png +0 -0
- package/vendor/raylib/examples/text/text_draw_3d.c +739 -0
- package/vendor/raylib/examples/text/text_draw_3d.png +0 -0
- package/vendor/raylib/examples/text/text_font_filters.c +134 -0
- package/vendor/raylib/examples/text/text_font_filters.png +0 -0
- package/vendor/raylib/examples/text/text_font_loading.c +91 -0
- package/vendor/raylib/examples/text/text_font_loading.png +0 -0
- package/vendor/raylib/examples/text/text_font_sdf.c +141 -0
- package/vendor/raylib/examples/text/text_font_sdf.png +0 -0
- package/vendor/raylib/examples/text/text_font_spritefont.c +85 -0
- package/vendor/raylib/examples/text/text_font_spritefont.png +0 -0
- package/vendor/raylib/examples/text/text_format_text.c +62 -0
- package/vendor/raylib/examples/text/text_format_text.png +0 -0
- package/vendor/raylib/examples/text/text_input_box.c +127 -0
- package/vendor/raylib/examples/text/text_input_box.png +0 -0
- package/vendor/raylib/examples/text/text_raylib_fonts.c +105 -0
- package/vendor/raylib/examples/text/text_raylib_fonts.png +0 -0
- package/vendor/raylib/examples/text/text_rectangle_bounds.c +264 -0
- package/vendor/raylib/examples/text/text_rectangle_bounds.png +0 -0
- package/vendor/raylib/examples/text/text_unicode.c +465 -0
- package/vendor/raylib/examples/text/text_unicode.png +0 -0
- package/vendor/raylib/examples/text/text_writing_anim.c +62 -0
- package/vendor/raylib/examples/text/text_writing_anim.png +0 -0
- package/vendor/raylib/examples/textures/resources/KAISG.ttf +0 -0
- package/vendor/raylib/examples/textures/resources/LICENSE.md +18 -0
- package/vendor/raylib/examples/textures/resources/boom.wav +0 -0
- package/vendor/raylib/examples/textures/resources/button.png +0 -0
- package/vendor/raylib/examples/textures/resources/buttonfx.wav +0 -0
- package/vendor/raylib/examples/textures/resources/cat.png +0 -0
- package/vendor/raylib/examples/textures/resources/custom_jupiter_crash.png +0 -0
- package/vendor/raylib/examples/textures/resources/cyberpunk_street_background.png +0 -0
- package/vendor/raylib/examples/textures/resources/cyberpunk_street_foreground.png +0 -0
- package/vendor/raylib/examples/textures/resources/cyberpunk_street_midground.png +0 -0
- package/vendor/raylib/examples/textures/resources/explosion.png +0 -0
- package/vendor/raylib/examples/textures/resources/fudesumi.png +0 -0
- package/vendor/raylib/examples/textures/resources/fudesumi.raw +0 -0
- package/vendor/raylib/examples/textures/resources/ninepatch_button.png +0 -0
- package/vendor/raylib/examples/textures/resources/parrots.png +0 -0
- package/vendor/raylib/examples/textures/resources/patterns.png +0 -0
- package/vendor/raylib/examples/textures/resources/raylib_logo.png +0 -0
- package/vendor/raylib/examples/textures/resources/scarfy.png +0 -0
- package/vendor/raylib/examples/textures/resources/spark_flame.png +0 -0
- package/vendor/raylib/examples/textures/resources/wabbit_alpha.png +0 -0
- package/vendor/raylib/examples/textures/textures_background_scrolling.c +87 -0
- package/vendor/raylib/examples/textures/textures_background_scrolling.png +0 -0
- package/vendor/raylib/examples/textures/textures_blend_modes.c +93 -0
- package/vendor/raylib/examples/textures/textures_blend_modes.png +0 -0
- package/vendor/raylib/examples/textures/textures_bunnymark.c +120 -0
- package/vendor/raylib/examples/textures/textures_bunnymark.png +0 -0
- package/vendor/raylib/examples/textures/textures_draw_tiled.c +165 -0
- package/vendor/raylib/examples/textures/textures_draw_tiled.png +0 -0
- package/vendor/raylib/examples/textures/textures_image_drawing.c +91 -0
- package/vendor/raylib/examples/textures/textures_image_drawing.png +0 -0
- package/vendor/raylib/examples/textures/textures_image_generation.c +102 -0
- package/vendor/raylib/examples/textures/textures_image_generation.png +0 -0
- package/vendor/raylib/examples/textures/textures_image_loading.c +64 -0
- package/vendor/raylib/examples/textures/textures_image_loading.png +0 -0
- package/vendor/raylib/examples/textures/textures_image_processing.c +169 -0
- package/vendor/raylib/examples/textures/textures_image_processing.png +0 -0
- package/vendor/raylib/examples/textures/textures_image_text.c +83 -0
- package/vendor/raylib/examples/textures/textures_image_text.png +0 -0
- package/vendor/raylib/examples/textures/textures_logo_raylib.c +57 -0
- package/vendor/raylib/examples/textures/textures_logo_raylib.png +0 -0
- package/vendor/raylib/examples/textures/textures_mouse_painting.c +221 -0
- package/vendor/raylib/examples/textures/textures_mouse_painting.png +0 -0
- package/vendor/raylib/examples/textures/textures_npatch_drawing.c +109 -0
- package/vendor/raylib/examples/textures/textures_npatch_drawing.png +0 -0
- package/vendor/raylib/examples/textures/textures_particles_blending.c +135 -0
- package/vendor/raylib/examples/textures/textures_particles_blending.png +0 -0
- package/vendor/raylib/examples/textures/textures_polygon.c +100 -0
- package/vendor/raylib/examples/textures/textures_polygon.png +0 -0
- package/vendor/raylib/examples/textures/textures_raw_data.c +99 -0
- package/vendor/raylib/examples/textures/textures_raw_data.png +0 -0
- package/vendor/raylib/examples/textures/textures_rectangle.c +99 -0
- package/vendor/raylib/examples/textures/textures_rectangle.png +0 -0
- package/vendor/raylib/examples/textures/textures_sprite_button.c +97 -0
- package/vendor/raylib/examples/textures/textures_sprite_button.png +0 -0
- package/vendor/raylib/examples/textures/textures_sprite_explosion.c +120 -0
- package/vendor/raylib/examples/textures/textures_sprite_explosion.png +0 -0
- package/vendor/raylib/examples/textures/textures_srcrec_dstrec.c +82 -0
- package/vendor/raylib/examples/textures/textures_srcrec_dstrec.png +0 -0
- package/vendor/raylib/examples/textures/textures_to_image.c +68 -0
- package/vendor/raylib/examples/textures/textures_to_image.png +0 -0
- package/vendor/raylib/logo/raylib.ico +0 -0
- package/vendor/raylib/logo/raylib_128x128.png +0 -0
- package/vendor/raylib/logo/raylib_144x144.png +0 -0
- package/vendor/raylib/logo/raylib_16x16.png +0 -0
- package/vendor/raylib/logo/raylib_180x180.png +0 -0
- package/vendor/raylib/logo/raylib_24x24.png +0 -0
- package/vendor/raylib/logo/raylib_256x256.png +0 -0
- package/vendor/raylib/logo/raylib_32x32.png +0 -0
- package/vendor/raylib/logo/raylib_36x36.png +0 -0
- package/vendor/raylib/logo/raylib_48x48.png +0 -0
- package/vendor/raylib/logo/raylib_512x512.png +0 -0
- package/vendor/raylib/logo/raylib_64x64.png +0 -0
- package/vendor/raylib/logo/raylib_72x72.png +0 -0
- package/vendor/raylib/logo/raylib_96x96.png +0 -0
- package/vendor/raylib/logo/raylib_logo_animation.gif +0 -0
- package/vendor/raylib/parser/LICENSE +16 -0
- package/vendor/raylib/parser/README.md +63 -0
- package/vendor/raylib/parser/raylib_api.json +6668 -0
- package/vendor/raylib/parser/raylib_api.txt +3568 -0
- package/vendor/raylib/parser/raylib_api.xml +2509 -0
- package/vendor/raylib/parser/raylib_parser.c +1003 -0
- package/vendor/raylib/projects/4coder/Makefile +401 -0
- package/vendor/raylib/projects/4coder/Makefile.Android +300 -0
- package/vendor/raylib/projects/4coder/main.c +39 -0
- package/vendor/raylib/projects/4coder/project.4coder +54 -0
- package/vendor/raylib/projects/Builder/README.md +24 -0
- package/vendor/raylib/projects/Builder/examples/README.md +1 -0
- package/vendor/raylib/projects/Builder/examples/meson.build +25 -0
- package/vendor/raylib/projects/Builder/meson.build +25 -0
- package/vendor/raylib/projects/CMake/CMakeLists.txt +44 -0
- package/vendor/raylib/projects/CMake/core_basic_window.c +62 -0
- package/vendor/raylib/projects/CodeBlocks/README.md +22 -0
- package/vendor/raylib/projects/CodeBlocks/compiler_settings.png +0 -0
- package/vendor/raylib/projects/CodeBlocks/core_basic_window.c +58 -0
- package/vendor/raylib/projects/CodeBlocks/core_basic_window.cbp +137 -0
- package/vendor/raylib/projects/Geany/core_basic_window.c +52 -0
- package/vendor/raylib/projects/Geany/raylib.c.tags +452 -0
- package/vendor/raylib/projects/Geany/raylib_compile_execute.bat +21 -0
- package/vendor/raylib/projects/Geany/raylib_compile_sources.bat +42 -0
- package/vendor/raylib/projects/Geany/raylib_project.geany +41 -0
- package/vendor/raylib/projects/Notepad++/README.md +19 -0
- package/vendor/raylib/projects/Notepad++/c_raylib.xml +3104 -0
- package/vendor/raylib/projects/Notepad++/npes_saved_mingw.txt +0 -0
- package/vendor/raylib/projects/Notepad++/npes_saved_tcc.txt +0 -0
- package/vendor/raylib/projects/Notepad++/npes_saved_w64devkit.txt +0 -0
- package/vendor/raylib/projects/Notepad++/npes_saved_zig.txt +0 -0
- package/vendor/raylib/projects/Notepad++/raylib_npp_parser/raylib_npp.xml +3060 -0
- package/vendor/raylib/projects/Notepad++/raylib_npp_parser/raylib_npp_parser.c +150 -0
- package/vendor/raylib/projects/Notepad++/raylib_npp_parser/raylib_to_parse.h +631 -0
- package/vendor/raylib/projects/README.md +18 -0
- package/vendor/raylib/projects/SublimeText/README.md +13 -0
- package/vendor/raylib/projects/SublimeText/raylib.sublime-build +13 -0
- package/vendor/raylib/projects/SublimeText/raylib.sublime-project +8 -0
- package/vendor/raylib/projects/VS2019/raylib/raylib.rc +0 -0
- package/vendor/raylib/projects/VS2019/raylib/resource.h +14 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/android_native_app_glue.c +437 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/android_native_app_glue.h +344 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/main.c +64 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.Packaging/AndroidManifest.xml +22 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.Packaging/build.xml +90 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.Packaging/project.properties +3 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.Packaging/raylib_android.Packaging.androidproj +134 -0
- package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.Packaging/res/values/strings.xml +4 -0
- package/vendor/raylib/projects/VSCode/.vscode/c_cpp_properties.json +63 -0
- package/vendor/raylib/projects/VSCode/.vscode/launch.json +60 -0
- package/vendor/raylib/projects/VSCode/.vscode/settings.json +11 -0
- package/vendor/raylib/projects/VSCode/.vscode/tasks.json +71 -0
- package/vendor/raylib/projects/VSCode/Makefile +408 -0
- package/vendor/raylib/projects/VSCode/Makefile.Android +300 -0
- package/vendor/raylib/projects/VSCode/main.c +83 -0
- package/vendor/raylib/projects/VSCode/main.code-workspace +16 -0
- package/vendor/raylib/projects/scripts/README.md +68 -0
- package/vendor/raylib/projects/scripts/build-linux.sh +169 -0
- package/vendor/raylib/projects/scripts/build-osx.sh +171 -0
- package/vendor/raylib/projects/scripts/build-rpi.sh +169 -0
- package/vendor/raylib/projects/scripts/build-windows.bat +219 -0
- package/vendor/raylib/projects/scripts/core_basic_window.c +61 -0
- package/vendor/raylib/raylib.pc.in +13 -0
- package/vendor/raylib/src/CMakeLists.txt +121 -0
- package/vendor/raylib/src/Makefile +696 -0
- package/vendor/raylib/src/build.zig +60 -0
- package/vendor/raylib/src/config.h +230 -0
- package/vendor/raylib/src/external/cgltf.h +6501 -0
- package/vendor/raylib/src/external/dirent.h +183 -0
- package/vendor/raylib/src/external/dr_flac.h +12269 -0
- package/vendor/raylib/src/external/dr_mp3.h +4787 -0
- package/vendor/raylib/src/external/dr_wav.h +8019 -0
- package/vendor/raylib/src/external/glad.h +8640 -0
- package/vendor/raylib/src/external/glfw/.mailmap +10 -0
- package/vendor/raylib/src/external/glfw/CMake/GenerateMappings.cmake +33 -0
- package/vendor/raylib/src/external/glfw/CMake/Info.plist.in +38 -0
- package/vendor/raylib/src/external/glfw/CMake/MacOSXBundleInfo.plist.in +38 -0
- package/vendor/raylib/src/external/glfw/CMake/cmake_uninstall.cmake.in +29 -0
- package/vendor/raylib/src/external/glfw/CMake/glfw3.pc.in +13 -0
- package/vendor/raylib/src/external/glfw/CMake/glfw3Config.cmake.in +3 -0
- package/vendor/raylib/src/external/glfw/CMake/i686-w64-mingw32-clang.cmake +13 -0
- package/vendor/raylib/src/external/glfw/CMake/i686-w64-mingw32.cmake +13 -0
- package/vendor/raylib/src/external/glfw/CMake/modules/FindEpollShim.cmake +17 -0
- package/vendor/raylib/src/external/glfw/CMake/modules/FindOSMesa.cmake +18 -0
- package/vendor/raylib/src/external/glfw/CMake/modules/FindWaylandProtocols.cmake +26 -0
- package/vendor/raylib/src/external/glfw/CMake/modules/FindXKBCommon.cmake +34 -0
- package/vendor/raylib/src/external/glfw/CMake/x86_64-w64-mingw32-clang.cmake +13 -0
- package/vendor/raylib/src/external/glfw/CMake/x86_64-w64-mingw32.cmake +13 -0
- package/vendor/raylib/src/external/glfw/CMakeLists.txt +323 -0
- package/vendor/raylib/src/external/glfw/LICENSE.md +23 -0
- package/vendor/raylib/src/external/glfw/README.md +477 -0
- package/vendor/raylib/src/external/glfw/deps/getopt.c +230 -0
- package/vendor/raylib/src/external/glfw/deps/getopt.h +57 -0
- package/vendor/raylib/src/external/glfw/deps/glad/gl.h +3840 -0
- package/vendor/raylib/src/external/glfw/deps/glad/khrplatform.h +282 -0
- package/vendor/raylib/src/external/glfw/deps/glad/vk_platform.h +92 -0
- package/vendor/raylib/src/external/glfw/deps/glad/vulkan.h +3480 -0
- package/vendor/raylib/src/external/glfw/deps/glad_gl.c +1791 -0
- package/vendor/raylib/src/external/glfw/deps/glad_vulkan.c +593 -0
- package/vendor/raylib/src/external/glfw/deps/mingw/_mingw_dxhelper.h +117 -0
- package/vendor/raylib/src/external/glfw/deps/mingw/dinput.h +2467 -0
- package/vendor/raylib/src/external/glfw/deps/mingw/xinput.h +239 -0
- package/vendor/raylib/src/external/glfw/deps/vs2008/stdint.h +247 -0
- package/vendor/raylib/src/external/glfw/include/GLFW/glfw3.h +6075 -0
- package/vendor/raylib/src/external/glfw/include/GLFW/glfw3native.h +530 -0
- package/vendor/raylib/src/external/glfw/src/CMakeLists.txt +246 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_init.m +620 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_joystick.h +46 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_joystick.m +483 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_monitor.m +631 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_platform.h +206 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_time.c +62 -0
- package/vendor/raylib/src/external/glfw/src/cocoa_window.m +1923 -0
- package/vendor/raylib/src/external/glfw/src/context.c +756 -0
- package/vendor/raylib/src/external/glfw/src/egl_context.c +846 -0
- package/vendor/raylib/src/external/glfw/src/egl_context.h +229 -0
- package/vendor/raylib/src/external/glfw/src/glfw.rc.in +30 -0
- package/vendor/raylib/src/external/glfw/src/glfw_config.h.in +58 -0
- package/vendor/raylib/src/external/glfw/src/glx_context.c +699 -0
- package/vendor/raylib/src/external/glfw/src/glx_context.h +181 -0
- package/vendor/raylib/src/external/glfw/src/init.c +357 -0
- package/vendor/raylib/src/external/glfw/src/input.c +1406 -0
- package/vendor/raylib/src/external/glfw/src/internal.h +799 -0
- package/vendor/raylib/src/external/glfw/src/linux_joystick.c +428 -0
- package/vendor/raylib/src/external/glfw/src/linux_joystick.h +59 -0
- package/vendor/raylib/src/external/glfw/src/mappings.h +1550 -0
- package/vendor/raylib/src/external/glfw/src/mappings.h.in +73 -0
- package/vendor/raylib/src/external/glfw/src/monitor.c +542 -0
- package/vendor/raylib/src/external/glfw/src/nsgl_context.h +66 -0
- package/vendor/raylib/src/external/glfw/src/nsgl_context.m +369 -0
- package/vendor/raylib/src/external/glfw/src/null_init.c +57 -0
- package/vendor/raylib/src/external/glfw/src/null_joystick.c +53 -0
- package/vendor/raylib/src/external/glfw/src/null_joystick.h +31 -0
- package/vendor/raylib/src/external/glfw/src/null_monitor.c +159 -0
- package/vendor/raylib/src/external/glfw/src/null_platform.h +89 -0
- package/vendor/raylib/src/external/glfw/src/null_window.c +670 -0
- package/vendor/raylib/src/external/glfw/src/osmesa_context.c +372 -0
- package/vendor/raylib/src/external/glfw/src/osmesa_context.h +90 -0
- package/vendor/raylib/src/external/glfw/src/posix_thread.c +105 -0
- package/vendor/raylib/src/external/glfw/src/posix_thread.h +51 -0
- package/vendor/raylib/src/external/glfw/src/posix_time.c +90 -0
- package/vendor/raylib/src/external/glfw/src/posix_time.h +44 -0
- package/vendor/raylib/src/external/glfw/src/vulkan.c +332 -0
- package/vendor/raylib/src/external/glfw/src/wgl_context.c +798 -0
- package/vendor/raylib/src/external/glfw/src/wgl_context.h +160 -0
- package/vendor/raylib/src/external/glfw/src/win32_init.c +636 -0
- package/vendor/raylib/src/external/glfw/src/win32_joystick.c +753 -0
- package/vendor/raylib/src/external/glfw/src/win32_joystick.h +53 -0
- package/vendor/raylib/src/external/glfw/src/win32_monitor.c +537 -0
- package/vendor/raylib/src/external/glfw/src/win32_platform.h +462 -0
- package/vendor/raylib/src/external/glfw/src/win32_thread.c +99 -0
- package/vendor/raylib/src/external/glfw/src/win32_time.c +76 -0
- package/vendor/raylib/src/external/glfw/src/win32_window.c +2405 -0
- package/vendor/raylib/src/external/glfw/src/window.c +1114 -0
- package/vendor/raylib/src/external/glfw/src/wl_init.c +1310 -0
- package/vendor/raylib/src/external/glfw/src/wl_monitor.c +231 -0
- package/vendor/raylib/src/external/glfw/src/wl_platform.h +352 -0
- package/vendor/raylib/src/external/glfw/src/wl_window.c +1814 -0
- package/vendor/raylib/src/external/glfw/src/x11_init.c +1500 -0
- package/vendor/raylib/src/external/glfw/src/x11_monitor.c +614 -0
- package/vendor/raylib/src/external/glfw/src/x11_platform.h +798 -0
- package/vendor/raylib/src/external/glfw/src/x11_window.c +3310 -0
- package/vendor/raylib/src/external/glfw/src/xkb_unicode.c +942 -0
- package/vendor/raylib/src/external/glfw/src/xkb_unicode.h +28 -0
- package/vendor/raylib/src/external/jar_mod.h +1596 -0
- package/vendor/raylib/src/external/jar_xm.h +2470 -0
- package/vendor/raylib/src/external/miniaudio.h +70273 -0
- package/vendor/raylib/src/external/msf_gif.h +717 -0
- package/vendor/raylib/src/external/par_shapes.h +2155 -0
- package/vendor/raylib/src/external/sdefl.h +696 -0
- package/vendor/raylib/src/external/sinfl.h +584 -0
- package/vendor/raylib/src/external/stb_image.h +7897 -0
- package/vendor/raylib/src/external/stb_image_resize.h +2634 -0
- package/vendor/raylib/src/external/stb_image_write.h +1724 -0
- package/vendor/raylib/src/external/stb_rect_pack.h +623 -0
- package/vendor/raylib/src/external/stb_truetype.h +5077 -0
- package/vendor/raylib/src/external/stb_vorbis.h +5475 -0
- package/vendor/raylib/src/external/tinyobj_loader_c.h +1589 -0
- package/vendor/raylib/src/external/vox_loader.h +710 -0
- package/vendor/raylib/src/extras/easings.h +263 -0
- package/vendor/raylib/src/extras/physac.h +1977 -0
- package/vendor/raylib/src/extras/raygui.h +4342 -0
- package/vendor/raylib/src/extras/rmem.h +751 -0
- package/vendor/raylib/src/raudio.c +2380 -0
- package/vendor/raylib/src/raudio.h +198 -0
- package/vendor/raylib/src/raylib.dll.rc +27 -0
- package/vendor/raylib/src/raylib.dll.rc.data +0 -0
- package/vendor/raylib/src/raylib.h +1536 -0
- package/vendor/raylib/src/raylib.ico +0 -0
- package/vendor/raylib/src/raylib.rc +27 -0
- package/vendor/raylib/src/raylib.rc.data +0 -0
- package/vendor/raylib/src/raymath.h +1853 -0
- package/vendor/raylib/src/rcamera.h +567 -0
- package/vendor/raylib/src/rcore.c +6772 -0
- package/vendor/raylib/src/rgestures.h +566 -0
- package/vendor/raylib/src/rglfw.c +126 -0
- package/vendor/raylib/src/rlgl.h +4677 -0
- package/vendor/raylib/src/rmodels.c +5041 -0
- package/vendor/raylib/src/rshapes.c +1759 -0
- package/vendor/raylib/src/rtext.c +1790 -0
- package/vendor/raylib/src/rtextures.c +4761 -0
- package/vendor/raylib/src/shell.html +328 -0
- package/vendor/raylib/src/utils.c +433 -0
- package/vendor/raylib/src/utils.h +81 -0
- package/vendor/sqlite3/shell.c +23487 -0
- package/vendor/sqlite3/sqlite3.c +239246 -0
- package/vendor/sqlite3/sqlite3.h +12802 -0
- package/vendor/sqlite3/sqlite3ext.h +689 -0
- package/CMakeLists.txt +0 -63
|
@@ -0,0 +1,4677 @@
|
|
|
1
|
+
/**********************************************************************************************
|
|
2
|
+
*
|
|
3
|
+
* rlgl v4.0 - A multi-OpenGL abstraction layer with an immediate-mode style API
|
|
4
|
+
*
|
|
5
|
+
* An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0)
|
|
6
|
+
* that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...)
|
|
7
|
+
*
|
|
8
|
+
* When chosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
|
|
9
|
+
* initialized on rlglInit() to accumulate vertex data.
|
|
10
|
+
*
|
|
11
|
+
* When an internal state change is required all the stored vertex data is renderer in batch,
|
|
12
|
+
* additioanlly, rlDrawRenderBatchActive() could be called to force flushing of the batch.
|
|
13
|
+
*
|
|
14
|
+
* Some additional resources are also loaded for convenience, here the complete list:
|
|
15
|
+
* - Default batch (RLGL.defaultBatch): RenderBatch system to accumulate vertex data
|
|
16
|
+
* - Default texture (RLGL.defaultTextureId): 1x1 white pixel R8G8B8A8
|
|
17
|
+
* - Default shader (RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs)
|
|
18
|
+
*
|
|
19
|
+
* Internal buffer (and additional resources) must be manually unloaded calling rlglClose().
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* CONFIGURATION:
|
|
23
|
+
*
|
|
24
|
+
* #define GRAPHICS_API_OPENGL_11
|
|
25
|
+
* #define GRAPHICS_API_OPENGL_21
|
|
26
|
+
* #define GRAPHICS_API_OPENGL_33
|
|
27
|
+
* #define GRAPHICS_API_OPENGL_43
|
|
28
|
+
* #define GRAPHICS_API_OPENGL_ES2
|
|
29
|
+
* Use selected OpenGL graphics backend, should be supported by platform
|
|
30
|
+
* Those preprocessor defines are only used on rlgl module, if OpenGL version is
|
|
31
|
+
* required by any other module, use rlGetVersion() to check it
|
|
32
|
+
*
|
|
33
|
+
* #define RLGL_IMPLEMENTATION
|
|
34
|
+
* Generates the implementation of the library into the included file.
|
|
35
|
+
* If not defined, the library is in header only mode and can be included in other headers
|
|
36
|
+
* or source files without problems. But only ONE file should hold the implementation.
|
|
37
|
+
*
|
|
38
|
+
* #define RLGL_RENDER_TEXTURES_HINT
|
|
39
|
+
* Enable framebuffer objects (fbo) support (enabled by default)
|
|
40
|
+
* Some GPUs could not support them despite the OpenGL version
|
|
41
|
+
*
|
|
42
|
+
* #define RLGL_SHOW_GL_DETAILS_INFO
|
|
43
|
+
* Show OpenGL extensions and capabilities detailed logs on init
|
|
44
|
+
*
|
|
45
|
+
* #define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT
|
|
46
|
+
* Enable debug context (only available on OpenGL 4.3)
|
|
47
|
+
*
|
|
48
|
+
* rlgl capabilities could be customized just defining some internal
|
|
49
|
+
* values before library inclusion (default values listed):
|
|
50
|
+
*
|
|
51
|
+
* #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 8192 // Default internal render batch elements limits
|
|
52
|
+
* #define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
|
|
53
|
+
* #define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
|
|
54
|
+
* #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
|
|
55
|
+
*
|
|
56
|
+
* #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
|
|
57
|
+
* #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
|
58
|
+
* #define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
|
|
59
|
+
* #define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
|
|
60
|
+
*
|
|
61
|
+
* When loading a shader, the following vertex attribute and uniform
|
|
62
|
+
* location names are tried to be set automatically:
|
|
63
|
+
*
|
|
64
|
+
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
|
65
|
+
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
|
66
|
+
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
|
67
|
+
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
|
68
|
+
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
|
69
|
+
* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
|
70
|
+
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
|
71
|
+
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
|
72
|
+
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
|
73
|
+
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
|
74
|
+
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
|
75
|
+
* #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
|
76
|
+
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
|
77
|
+
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
|
78
|
+
* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
|
79
|
+
*
|
|
80
|
+
* DEPENDENCIES:
|
|
81
|
+
*
|
|
82
|
+
* - OpenGL libraries (depending on platform and OpenGL version selected)
|
|
83
|
+
* - GLAD OpenGL extensions loading library (only for OpenGL 3.3 Core, 4.3 Core)
|
|
84
|
+
*
|
|
85
|
+
*
|
|
86
|
+
* LICENSE: zlib/libpng
|
|
87
|
+
*
|
|
88
|
+
* Copyright (c) 2014-2021 Ramon Santamaria (@raysan5)
|
|
89
|
+
*
|
|
90
|
+
* This software is provided "as-is", without any express or implied warranty. In no event
|
|
91
|
+
* will the authors be held liable for any damages arising from the use of this software.
|
|
92
|
+
*
|
|
93
|
+
* Permission is granted to anyone to use this software for any purpose, including commercial
|
|
94
|
+
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
|
95
|
+
*
|
|
96
|
+
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
|
97
|
+
* wrote the original software. If you use this software in a product, an acknowledgment
|
|
98
|
+
* in the product documentation would be appreciated but is not required.
|
|
99
|
+
*
|
|
100
|
+
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
|
101
|
+
* as being the original software.
|
|
102
|
+
*
|
|
103
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
|
104
|
+
*
|
|
105
|
+
**********************************************************************************************/
|
|
106
|
+
|
|
107
|
+
#ifndef RLGL_H
|
|
108
|
+
#define RLGL_H
|
|
109
|
+
|
|
110
|
+
#define RLGL_VERSION "4.0"
|
|
111
|
+
|
|
112
|
+
// Function specifiers in case library is build/used as a shared library (Windows)
|
|
113
|
+
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
|
114
|
+
#if defined(_WIN32)
|
|
115
|
+
#if defined(BUILD_LIBTYPE_SHARED)
|
|
116
|
+
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
|
117
|
+
#elif defined(USE_LIBTYPE_SHARED)
|
|
118
|
+
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
|
119
|
+
#endif
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
// Function specifiers definition
|
|
123
|
+
#ifndef RLAPI
|
|
124
|
+
#define RLAPI // Functions defined as 'extern' by default (implicit specifiers)
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
// Support TRACELOG macros
|
|
128
|
+
#ifndef TRACELOG
|
|
129
|
+
#define TRACELOG(level, ...) (void)0
|
|
130
|
+
#define TRACELOGD(...) (void)0
|
|
131
|
+
#endif
|
|
132
|
+
|
|
133
|
+
// Allow custom memory allocators
|
|
134
|
+
#ifndef RL_MALLOC
|
|
135
|
+
#define RL_MALLOC(sz) malloc(sz)
|
|
136
|
+
#endif
|
|
137
|
+
#ifndef RL_CALLOC
|
|
138
|
+
#define RL_CALLOC(n,sz) calloc(n,sz)
|
|
139
|
+
#endif
|
|
140
|
+
#ifndef RL_REALLOC
|
|
141
|
+
#define RL_REALLOC(n,sz) realloc(n,sz)
|
|
142
|
+
#endif
|
|
143
|
+
#ifndef RL_FREE
|
|
144
|
+
#define RL_FREE(p) free(p)
|
|
145
|
+
#endif
|
|
146
|
+
|
|
147
|
+
// Security check in case no GRAPHICS_API_OPENGL_* defined
|
|
148
|
+
#if !defined(GRAPHICS_API_OPENGL_11) && \
|
|
149
|
+
!defined(GRAPHICS_API_OPENGL_21) && \
|
|
150
|
+
!defined(GRAPHICS_API_OPENGL_33) && \
|
|
151
|
+
!defined(GRAPHICS_API_OPENGL_43) && \
|
|
152
|
+
!defined(GRAPHICS_API_OPENGL_ES2)
|
|
153
|
+
#define GRAPHICS_API_OPENGL_33
|
|
154
|
+
#endif
|
|
155
|
+
|
|
156
|
+
// Security check in case multiple GRAPHICS_API_OPENGL_* defined
|
|
157
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
158
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
159
|
+
#undef GRAPHICS_API_OPENGL_21
|
|
160
|
+
#endif
|
|
161
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
162
|
+
#undef GRAPHICS_API_OPENGL_33
|
|
163
|
+
#endif
|
|
164
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
165
|
+
#undef GRAPHICS_API_OPENGL_43
|
|
166
|
+
#endif
|
|
167
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
168
|
+
#undef GRAPHICS_API_OPENGL_ES2
|
|
169
|
+
#endif
|
|
170
|
+
#endif
|
|
171
|
+
|
|
172
|
+
// OpenGL 2.1 uses most of OpenGL 3.3 Core functionality
|
|
173
|
+
// WARNING: Specific parts are checked with #if defines
|
|
174
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
175
|
+
#define GRAPHICS_API_OPENGL_33
|
|
176
|
+
#endif
|
|
177
|
+
|
|
178
|
+
// OpenGL 4.3 uses OpenGL 3.3 Core functionality
|
|
179
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
180
|
+
#define GRAPHICS_API_OPENGL_33
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
// Support framebuffer objects by default
|
|
184
|
+
// NOTE: Some driver implementation do not support it, despite they should
|
|
185
|
+
#define RLGL_RENDER_TEXTURES_HINT
|
|
186
|
+
|
|
187
|
+
//----------------------------------------------------------------------------------
|
|
188
|
+
// Defines and Macros
|
|
189
|
+
//----------------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
// Default internal render batch elements limits
|
|
192
|
+
#ifndef RL_DEFAULT_BATCH_BUFFER_ELEMENTS
|
|
193
|
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
|
194
|
+
// This is the maximum amount of elements (quads) per batch
|
|
195
|
+
// NOTE: Be careful with text, every letter maps to a quad
|
|
196
|
+
#define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 8192
|
|
197
|
+
#endif
|
|
198
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
199
|
+
// We reduce memory sizes for embedded systems (RPI and HTML5)
|
|
200
|
+
// NOTE: On HTML5 (emscripten) this is allocated on heap,
|
|
201
|
+
// by default it's only 16MB!...just take care...
|
|
202
|
+
#define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 2048
|
|
203
|
+
#endif
|
|
204
|
+
#endif
|
|
205
|
+
#ifndef RL_DEFAULT_BATCH_BUFFERS
|
|
206
|
+
#define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
|
|
207
|
+
#endif
|
|
208
|
+
#ifndef RL_DEFAULT_BATCH_DRAWCALLS
|
|
209
|
+
#define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
|
|
210
|
+
#endif
|
|
211
|
+
#ifndef RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS
|
|
212
|
+
#define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
|
|
213
|
+
#endif
|
|
214
|
+
|
|
215
|
+
// Internal Matrix stack
|
|
216
|
+
#ifndef RL_MAX_MATRIX_STACK_SIZE
|
|
217
|
+
#define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of Matrix stack
|
|
218
|
+
#endif
|
|
219
|
+
|
|
220
|
+
// Shader limits
|
|
221
|
+
#ifndef RL_MAX_SHADER_LOCATIONS
|
|
222
|
+
#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
|
223
|
+
#endif
|
|
224
|
+
|
|
225
|
+
// Projection matrix culling
|
|
226
|
+
#ifndef RL_CULL_DISTANCE_NEAR
|
|
227
|
+
#define RL_CULL_DISTANCE_NEAR 0.01 // Default near cull distance
|
|
228
|
+
#endif
|
|
229
|
+
#ifndef RL_CULL_DISTANCE_FAR
|
|
230
|
+
#define RL_CULL_DISTANCE_FAR 1000.0 // Default far cull distance
|
|
231
|
+
#endif
|
|
232
|
+
|
|
233
|
+
// Texture parameters (equivalent to OpenGL defines)
|
|
234
|
+
#define RL_TEXTURE_WRAP_S 0x2802 // GL_TEXTURE_WRAP_S
|
|
235
|
+
#define RL_TEXTURE_WRAP_T 0x2803 // GL_TEXTURE_WRAP_T
|
|
236
|
+
#define RL_TEXTURE_MAG_FILTER 0x2800 // GL_TEXTURE_MAG_FILTER
|
|
237
|
+
#define RL_TEXTURE_MIN_FILTER 0x2801 // GL_TEXTURE_MIN_FILTER
|
|
238
|
+
|
|
239
|
+
#define RL_TEXTURE_FILTER_NEAREST 0x2600 // GL_NEAREST
|
|
240
|
+
#define RL_TEXTURE_FILTER_LINEAR 0x2601 // GL_LINEAR
|
|
241
|
+
#define RL_TEXTURE_FILTER_MIP_NEAREST 0x2700 // GL_NEAREST_MIPMAP_NEAREST
|
|
242
|
+
#define RL_TEXTURE_FILTER_NEAREST_MIP_LINEAR 0x2702 // GL_NEAREST_MIPMAP_LINEAR
|
|
243
|
+
#define RL_TEXTURE_FILTER_LINEAR_MIP_NEAREST 0x2701 // GL_LINEAR_MIPMAP_NEAREST
|
|
244
|
+
#define RL_TEXTURE_FILTER_MIP_LINEAR 0x2703 // GL_LINEAR_MIPMAP_LINEAR
|
|
245
|
+
#define RL_TEXTURE_FILTER_ANISOTROPIC 0x3000 // Anisotropic filter (custom identifier)
|
|
246
|
+
|
|
247
|
+
#define RL_TEXTURE_WRAP_REPEAT 0x2901 // GL_REPEAT
|
|
248
|
+
#define RL_TEXTURE_WRAP_CLAMP 0x812F // GL_CLAMP_TO_EDGE
|
|
249
|
+
#define RL_TEXTURE_WRAP_MIRROR_REPEAT 0x8370 // GL_MIRRORED_REPEAT
|
|
250
|
+
#define RL_TEXTURE_WRAP_MIRROR_CLAMP 0x8742 // GL_MIRROR_CLAMP_EXT
|
|
251
|
+
|
|
252
|
+
// Matrix modes (equivalent to OpenGL)
|
|
253
|
+
#define RL_MODELVIEW 0x1700 // GL_MODELVIEW
|
|
254
|
+
#define RL_PROJECTION 0x1701 // GL_PROJECTION
|
|
255
|
+
#define RL_TEXTURE 0x1702 // GL_TEXTURE
|
|
256
|
+
|
|
257
|
+
// Primitive assembly draw modes
|
|
258
|
+
#define RL_LINES 0x0001 // GL_LINES
|
|
259
|
+
#define RL_TRIANGLES 0x0004 // GL_TRIANGLES
|
|
260
|
+
#define RL_QUADS 0x0007 // GL_QUADS
|
|
261
|
+
|
|
262
|
+
// GL equivalent data types
|
|
263
|
+
#define RL_UNSIGNED_BYTE 0x1401 // GL_UNSIGNED_BYTE
|
|
264
|
+
#define RL_FLOAT 0x1406 // GL_FLOAT
|
|
265
|
+
|
|
266
|
+
// Buffer usage hint
|
|
267
|
+
#define RL_STREAM_DRAW 0x88E0 // GL_STREAM_DRAW
|
|
268
|
+
#define RL_STREAM_READ 0x88E1 // GL_STREAM_READ
|
|
269
|
+
#define RL_STREAM_COPY 0x88E2 // GL_STREAM_COPY
|
|
270
|
+
#define RL_STATIC_DRAW 0x88E4 // GL_STATIC_DRAW
|
|
271
|
+
#define RL_STATIC_READ 0x88E5 // GL_STATIC_READ
|
|
272
|
+
#define RL_STATIC_COPY 0x88E6 // GL_STATIC_COPY
|
|
273
|
+
#define RL_DYNAMIC_DRAW 0x88E8 // GL_DYNAMIC_DRAW
|
|
274
|
+
#define RL_DYNAMIC_READ 0x88E9 // GL_DYNAMIC_READ
|
|
275
|
+
#define RL_DYNAMIC_COPY 0x88EA // GL_DYNAMIC_COPY
|
|
276
|
+
|
|
277
|
+
// GL Shader type
|
|
278
|
+
#define RL_FRAGMENT_SHADER 0x8B30 // GL_FRAGMENT_SHADER
|
|
279
|
+
#define RL_VERTEX_SHADER 0x8B31 // GL_VERTEX_SHADER
|
|
280
|
+
#define RL_COMPUTE_SHADER 0x91B9 // GL_COMPUTE_SHADER
|
|
281
|
+
|
|
282
|
+
//----------------------------------------------------------------------------------
|
|
283
|
+
// Types and Structures Definition
|
|
284
|
+
//----------------------------------------------------------------------------------
|
|
285
|
+
typedef enum {
|
|
286
|
+
OPENGL_11 = 1,
|
|
287
|
+
OPENGL_21,
|
|
288
|
+
OPENGL_33,
|
|
289
|
+
OPENGL_43,
|
|
290
|
+
OPENGL_ES_20
|
|
291
|
+
} rlGlVersion;
|
|
292
|
+
|
|
293
|
+
typedef enum {
|
|
294
|
+
RL_ATTACHMENT_COLOR_CHANNEL0 = 0,
|
|
295
|
+
RL_ATTACHMENT_COLOR_CHANNEL1,
|
|
296
|
+
RL_ATTACHMENT_COLOR_CHANNEL2,
|
|
297
|
+
RL_ATTACHMENT_COLOR_CHANNEL3,
|
|
298
|
+
RL_ATTACHMENT_COLOR_CHANNEL4,
|
|
299
|
+
RL_ATTACHMENT_COLOR_CHANNEL5,
|
|
300
|
+
RL_ATTACHMENT_COLOR_CHANNEL6,
|
|
301
|
+
RL_ATTACHMENT_COLOR_CHANNEL7,
|
|
302
|
+
RL_ATTACHMENT_DEPTH = 100,
|
|
303
|
+
RL_ATTACHMENT_STENCIL = 200,
|
|
304
|
+
} rlFramebufferAttachType;
|
|
305
|
+
|
|
306
|
+
typedef enum {
|
|
307
|
+
RL_ATTACHMENT_CUBEMAP_POSITIVE_X = 0,
|
|
308
|
+
RL_ATTACHMENT_CUBEMAP_NEGATIVE_X,
|
|
309
|
+
RL_ATTACHMENT_CUBEMAP_POSITIVE_Y,
|
|
310
|
+
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Y,
|
|
311
|
+
RL_ATTACHMENT_CUBEMAP_POSITIVE_Z,
|
|
312
|
+
RL_ATTACHMENT_CUBEMAP_NEGATIVE_Z,
|
|
313
|
+
RL_ATTACHMENT_TEXTURE2D = 100,
|
|
314
|
+
RL_ATTACHMENT_RENDERBUFFER = 200,
|
|
315
|
+
} rlFramebufferAttachTextureType;
|
|
316
|
+
|
|
317
|
+
// Dynamic vertex buffers (position + texcoords + colors + indices arrays)
|
|
318
|
+
typedef struct rlVertexBuffer {
|
|
319
|
+
int elementCount; // Number of elements in the buffer (QUADS)
|
|
320
|
+
|
|
321
|
+
float *vertices; // Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
|
|
322
|
+
float *texcoords; // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
|
|
323
|
+
unsigned char *colors; // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
|
|
324
|
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
|
325
|
+
unsigned int *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
|
|
326
|
+
#endif
|
|
327
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
328
|
+
unsigned short *indices; // Vertex indices (in case vertex data comes indexed) (6 indices per quad)
|
|
329
|
+
#endif
|
|
330
|
+
unsigned int vaoId; // OpenGL Vertex Array Object id
|
|
331
|
+
unsigned int vboId[4]; // OpenGL Vertex Buffer Objects id (4 types of vertex data)
|
|
332
|
+
} rlVertexBuffer;
|
|
333
|
+
|
|
334
|
+
// Draw call type
|
|
335
|
+
// NOTE: Only texture changes register a new draw, other state-change-related elements are not
|
|
336
|
+
// used at this moment (vaoId, shaderId, matrices), raylib just forces a batch draw call if any
|
|
337
|
+
// of those state-change happens (this is done in core module)
|
|
338
|
+
typedef struct rlDrawCall {
|
|
339
|
+
int mode; // Drawing mode: LINES, TRIANGLES, QUADS
|
|
340
|
+
int vertexCount; // Number of vertex of the draw
|
|
341
|
+
int vertexAlignment; // Number of vertex required for index alignment (LINES, TRIANGLES)
|
|
342
|
+
//unsigned int vaoId; // Vertex array id to be used on the draw -> Using RLGL.currentBatch->vertexBuffer.vaoId
|
|
343
|
+
//unsigned int shaderId; // Shader id to be used on the draw -> Using RLGL.currentShaderId
|
|
344
|
+
unsigned int textureId; // Texture id to be used on the draw -> Use to create new draw call if changes
|
|
345
|
+
|
|
346
|
+
//Matrix projection; // Projection matrix for this draw -> Using RLGL.projection by default
|
|
347
|
+
//Matrix modelview; // Modelview matrix for this draw -> Using RLGL.modelview by default
|
|
348
|
+
} rlDrawCall;
|
|
349
|
+
|
|
350
|
+
// rlRenderBatch type
|
|
351
|
+
typedef struct rlRenderBatch {
|
|
352
|
+
int bufferCount; // Number of vertex buffers (multi-buffering support)
|
|
353
|
+
int currentBuffer; // Current buffer tracking in case of multi-buffering
|
|
354
|
+
rlVertexBuffer *vertexBuffer; // Dynamic buffer(s) for vertex data
|
|
355
|
+
|
|
356
|
+
rlDrawCall *draws; // Draw calls array, depends on textureId
|
|
357
|
+
int drawCounter; // Draw calls counter
|
|
358
|
+
float currentDepth; // Current depth value for next draw
|
|
359
|
+
} rlRenderBatch;
|
|
360
|
+
|
|
361
|
+
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
|
362
|
+
#include <stdbool.h>
|
|
363
|
+
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
|
364
|
+
// Boolean type
|
|
365
|
+
typedef enum bool { false, true } bool;
|
|
366
|
+
#endif
|
|
367
|
+
|
|
368
|
+
#if !defined(RL_MATRIX_TYPE)
|
|
369
|
+
// Matrix, 4x4 components, column major, OpenGL style, right handed
|
|
370
|
+
typedef struct Matrix {
|
|
371
|
+
float m0, m4, m8, m12; // Matrix first row (4 components)
|
|
372
|
+
float m1, m5, m9, m13; // Matrix second row (4 components)
|
|
373
|
+
float m2, m6, m10, m14; // Matrix third row (4 components)
|
|
374
|
+
float m3, m7, m11, m15; // Matrix fourth row (4 components)
|
|
375
|
+
} Matrix;
|
|
376
|
+
#define RL_MATRIX_TYPE
|
|
377
|
+
#endif
|
|
378
|
+
|
|
379
|
+
// Trace log level
|
|
380
|
+
// NOTE: Organized by priority level
|
|
381
|
+
typedef enum {
|
|
382
|
+
RL_LOG_ALL = 0, // Display all logs
|
|
383
|
+
RL_LOG_TRACE, // Trace logging, intended for internal use only
|
|
384
|
+
RL_LOG_DEBUG, // Debug logging, used for internal debugging, it should be disabled on release builds
|
|
385
|
+
RL_LOG_INFO, // Info logging, used for program execution info
|
|
386
|
+
RL_LOG_WARNING, // Warning logging, used on recoverable failures
|
|
387
|
+
RL_LOG_ERROR, // Error logging, used on unrecoverable failures
|
|
388
|
+
RL_LOG_FATAL, // Fatal logging, used to abort program: exit(EXIT_FAILURE)
|
|
389
|
+
RL_LOG_NONE // Disable logging
|
|
390
|
+
} rlTraceLogLevel;
|
|
391
|
+
|
|
392
|
+
// Texture formats (support depends on OpenGL version)
|
|
393
|
+
typedef enum {
|
|
394
|
+
RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE = 1, // 8 bit per pixel (no alpha)
|
|
395
|
+
RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA, // 8*2 bpp (2 channels)
|
|
396
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5, // 16 bpp
|
|
397
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8, // 24 bpp
|
|
398
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1, // 16 bpp (1 bit alpha)
|
|
399
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4, // 16 bpp (4 bit alpha)
|
|
400
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, // 32 bpp
|
|
401
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R32, // 32 bpp (1 channel - float)
|
|
402
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32, // 32*3 bpp (3 channels - float)
|
|
403
|
+
RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32, // 32*4 bpp (4 channels - float)
|
|
404
|
+
RL_PIXELFORMAT_COMPRESSED_DXT1_RGB, // 4 bpp (no alpha)
|
|
405
|
+
RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA, // 4 bpp (1 bit alpha)
|
|
406
|
+
RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA, // 8 bpp
|
|
407
|
+
RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA, // 8 bpp
|
|
408
|
+
RL_PIXELFORMAT_COMPRESSED_ETC1_RGB, // 4 bpp
|
|
409
|
+
RL_PIXELFORMAT_COMPRESSED_ETC2_RGB, // 4 bpp
|
|
410
|
+
RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA, // 8 bpp
|
|
411
|
+
RL_PIXELFORMAT_COMPRESSED_PVRT_RGB, // 4 bpp
|
|
412
|
+
RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA, // 4 bpp
|
|
413
|
+
RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA, // 8 bpp
|
|
414
|
+
RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA // 2 bpp
|
|
415
|
+
} rlPixelFormat;
|
|
416
|
+
|
|
417
|
+
// Texture parameters: filter mode
|
|
418
|
+
// NOTE 1: Filtering considers mipmaps if available in the texture
|
|
419
|
+
// NOTE 2: Filter is accordingly set for minification and magnification
|
|
420
|
+
typedef enum {
|
|
421
|
+
RL_TEXTURE_FILTER_POINT = 0, // No filter, just pixel aproximation
|
|
422
|
+
RL_TEXTURE_FILTER_BILINEAR, // Linear filtering
|
|
423
|
+
RL_TEXTURE_FILTER_TRILINEAR, // Trilinear filtering (linear with mipmaps)
|
|
424
|
+
RL_TEXTURE_FILTER_ANISOTROPIC_4X, // Anisotropic filtering 4x
|
|
425
|
+
RL_TEXTURE_FILTER_ANISOTROPIC_8X, // Anisotropic filtering 8x
|
|
426
|
+
RL_TEXTURE_FILTER_ANISOTROPIC_16X, // Anisotropic filtering 16x
|
|
427
|
+
} rlTextureFilter;
|
|
428
|
+
|
|
429
|
+
// Color blending modes (pre-defined)
|
|
430
|
+
typedef enum {
|
|
431
|
+
RL_BLEND_ALPHA = 0, // Blend textures considering alpha (default)
|
|
432
|
+
RL_BLEND_ADDITIVE, // Blend textures adding colors
|
|
433
|
+
RL_BLEND_MULTIPLIED, // Blend textures multiplying colors
|
|
434
|
+
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
|
|
435
|
+
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
|
|
436
|
+
RL_BLEND_CUSTOM // Belnd textures using custom src/dst factors (use SetBlendModeCustom())
|
|
437
|
+
} rlBlendMode;
|
|
438
|
+
|
|
439
|
+
// Shader location point type
|
|
440
|
+
typedef enum {
|
|
441
|
+
RL_SHADER_LOC_VERTEX_POSITION = 0, // Shader location: vertex attribute: position
|
|
442
|
+
RL_SHADER_LOC_VERTEX_TEXCOORD01, // Shader location: vertex attribute: texcoord01
|
|
443
|
+
RL_SHADER_LOC_VERTEX_TEXCOORD02, // Shader location: vertex attribute: texcoord02
|
|
444
|
+
RL_SHADER_LOC_VERTEX_NORMAL, // Shader location: vertex attribute: normal
|
|
445
|
+
RL_SHADER_LOC_VERTEX_TANGENT, // Shader location: vertex attribute: tangent
|
|
446
|
+
RL_SHADER_LOC_VERTEX_COLOR, // Shader location: vertex attribute: color
|
|
447
|
+
RL_SHADER_LOC_MATRIX_MVP, // Shader location: matrix uniform: model-view-projection
|
|
448
|
+
RL_SHADER_LOC_MATRIX_VIEW, // Shader location: matrix uniform: view (camera transform)
|
|
449
|
+
RL_SHADER_LOC_MATRIX_PROJECTION, // Shader location: matrix uniform: projection
|
|
450
|
+
RL_SHADER_LOC_MATRIX_MODEL, // Shader location: matrix uniform: model (transform)
|
|
451
|
+
RL_SHADER_LOC_MATRIX_NORMAL, // Shader location: matrix uniform: normal
|
|
452
|
+
RL_SHADER_LOC_VECTOR_VIEW, // Shader location: vector uniform: view
|
|
453
|
+
RL_SHADER_LOC_COLOR_DIFFUSE, // Shader location: vector uniform: diffuse color
|
|
454
|
+
RL_SHADER_LOC_COLOR_SPECULAR, // Shader location: vector uniform: specular color
|
|
455
|
+
RL_SHADER_LOC_COLOR_AMBIENT, // Shader location: vector uniform: ambient color
|
|
456
|
+
RL_SHADER_LOC_MAP_ALBEDO, // Shader location: sampler2d texture: albedo (same as: RL_SHADER_LOC_MAP_DIFFUSE)
|
|
457
|
+
RL_SHADER_LOC_MAP_METALNESS, // Shader location: sampler2d texture: metalness (same as: RL_SHADER_LOC_MAP_SPECULAR)
|
|
458
|
+
RL_SHADER_LOC_MAP_NORMAL, // Shader location: sampler2d texture: normal
|
|
459
|
+
RL_SHADER_LOC_MAP_ROUGHNESS, // Shader location: sampler2d texture: roughness
|
|
460
|
+
RL_SHADER_LOC_MAP_OCCLUSION, // Shader location: sampler2d texture: occlusion
|
|
461
|
+
RL_SHADER_LOC_MAP_EMISSION, // Shader location: sampler2d texture: emission
|
|
462
|
+
RL_SHADER_LOC_MAP_HEIGHT, // Shader location: sampler2d texture: height
|
|
463
|
+
RL_SHADER_LOC_MAP_CUBEMAP, // Shader location: samplerCube texture: cubemap
|
|
464
|
+
RL_SHADER_LOC_MAP_IRRADIANCE, // Shader location: samplerCube texture: irradiance
|
|
465
|
+
RL_SHADER_LOC_MAP_PREFILTER, // Shader location: samplerCube texture: prefilter
|
|
466
|
+
RL_SHADER_LOC_MAP_BRDF // Shader location: sampler2d texture: brdf
|
|
467
|
+
} rlShaderLocationIndex;
|
|
468
|
+
|
|
469
|
+
#define RL_SHADER_LOC_MAP_DIFFUSE RL_SHADER_LOC_MAP_ALBEDO
|
|
470
|
+
#define RL_SHADER_LOC_MAP_SPECULAR RL_SHADER_LOC_MAP_METALNESS
|
|
471
|
+
|
|
472
|
+
// Shader uniform data type
|
|
473
|
+
typedef enum {
|
|
474
|
+
RL_SHADER_UNIFORM_FLOAT = 0, // Shader uniform type: float
|
|
475
|
+
RL_SHADER_UNIFORM_VEC2, // Shader uniform type: vec2 (2 float)
|
|
476
|
+
RL_SHADER_UNIFORM_VEC3, // Shader uniform type: vec3 (3 float)
|
|
477
|
+
RL_SHADER_UNIFORM_VEC4, // Shader uniform type: vec4 (4 float)
|
|
478
|
+
RL_SHADER_UNIFORM_INT, // Shader uniform type: int
|
|
479
|
+
RL_SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int)
|
|
480
|
+
RL_SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
|
481
|
+
RL_SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int)
|
|
482
|
+
RL_SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d
|
|
483
|
+
} rlShaderUniformDataType;
|
|
484
|
+
|
|
485
|
+
// Shader attribute data types
|
|
486
|
+
typedef enum {
|
|
487
|
+
RL_SHADER_ATTRIB_FLOAT = 0, // Shader attribute type: float
|
|
488
|
+
RL_SHADER_ATTRIB_VEC2, // Shader attribute type: vec2 (2 float)
|
|
489
|
+
RL_SHADER_ATTRIB_VEC3, // Shader attribute type: vec3 (3 float)
|
|
490
|
+
RL_SHADER_ATTRIB_VEC4 // Shader attribute type: vec4 (4 float)
|
|
491
|
+
} rlShaderAttributeDataType;
|
|
492
|
+
|
|
493
|
+
//------------------------------------------------------------------------------------
|
|
494
|
+
// Functions Declaration - Matrix operations
|
|
495
|
+
//------------------------------------------------------------------------------------
|
|
496
|
+
|
|
497
|
+
#if defined(__cplusplus)
|
|
498
|
+
extern "C" { // Prevents name mangling of functions
|
|
499
|
+
#endif
|
|
500
|
+
|
|
501
|
+
RLAPI void rlMatrixMode(int mode); // Choose the current matrix to be transformed
|
|
502
|
+
RLAPI void rlPushMatrix(void); // Push the current matrix to stack
|
|
503
|
+
RLAPI void rlPopMatrix(void); // Pop lattest inserted matrix from stack
|
|
504
|
+
RLAPI void rlLoadIdentity(void); // Reset current matrix to identity matrix
|
|
505
|
+
RLAPI void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix
|
|
506
|
+
RLAPI void rlRotatef(float angle, float x, float y, float z); // Multiply the current matrix by a rotation matrix
|
|
507
|
+
RLAPI void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix
|
|
508
|
+
RLAPI void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix
|
|
509
|
+
RLAPI void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar);
|
|
510
|
+
RLAPI void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar);
|
|
511
|
+
RLAPI void rlViewport(int x, int y, int width, int height); // Set the viewport area
|
|
512
|
+
|
|
513
|
+
//------------------------------------------------------------------------------------
|
|
514
|
+
// Functions Declaration - Vertex level operations
|
|
515
|
+
//------------------------------------------------------------------------------------
|
|
516
|
+
RLAPI void rlBegin(int mode); // Initialize drawing mode (how to organize vertex)
|
|
517
|
+
RLAPI void rlEnd(void); // Finish vertex providing
|
|
518
|
+
RLAPI void rlVertex2i(int x, int y); // Define one vertex (position) - 2 int
|
|
519
|
+
RLAPI void rlVertex2f(float x, float y); // Define one vertex (position) - 2 float
|
|
520
|
+
RLAPI void rlVertex3f(float x, float y, float z); // Define one vertex (position) - 3 float
|
|
521
|
+
RLAPI void rlTexCoord2f(float x, float y); // Define one vertex (texture coordinate) - 2 float
|
|
522
|
+
RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (normal) - 3 float
|
|
523
|
+
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
|
|
524
|
+
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
|
|
525
|
+
RLAPI void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
|
|
526
|
+
|
|
527
|
+
//------------------------------------------------------------------------------------
|
|
528
|
+
// Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)
|
|
529
|
+
// NOTE: This functions are used to completely abstract raylib code from OpenGL layer,
|
|
530
|
+
// some of them are direct wrappers over OpenGL calls, some others are custom
|
|
531
|
+
//------------------------------------------------------------------------------------
|
|
532
|
+
|
|
533
|
+
// Vertex buffers state
|
|
534
|
+
RLAPI bool rlEnableVertexArray(unsigned int vaoId); // Enable vertex array (VAO, if supported)
|
|
535
|
+
RLAPI void rlDisableVertexArray(void); // Disable vertex array (VAO, if supported)
|
|
536
|
+
RLAPI void rlEnableVertexBuffer(unsigned int id); // Enable vertex buffer (VBO)
|
|
537
|
+
RLAPI void rlDisableVertexBuffer(void); // Disable vertex buffer (VBO)
|
|
538
|
+
RLAPI void rlEnableVertexBufferElement(unsigned int id);// Enable vertex buffer element (VBO element)
|
|
539
|
+
RLAPI void rlDisableVertexBufferElement(void); // Disable vertex buffer element (VBO element)
|
|
540
|
+
RLAPI void rlEnableVertexAttribute(unsigned int index); // Enable vertex attribute index
|
|
541
|
+
RLAPI void rlDisableVertexAttribute(unsigned int index);// Disable vertex attribute index
|
|
542
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
543
|
+
RLAPI void rlEnableStatePointer(int vertexAttribType, void *buffer); // Enable attribute state pointer
|
|
544
|
+
RLAPI void rlDisableStatePointer(int vertexAttribType); // Disable attribute state pointer
|
|
545
|
+
#endif
|
|
546
|
+
|
|
547
|
+
// Textures state
|
|
548
|
+
RLAPI void rlActiveTextureSlot(int slot); // Select and active a texture slot
|
|
549
|
+
RLAPI void rlEnableTexture(unsigned int id); // Enable texture
|
|
550
|
+
RLAPI void rlDisableTexture(void); // Disable texture
|
|
551
|
+
RLAPI void rlEnableTextureCubemap(unsigned int id); // Enable texture cubemap
|
|
552
|
+
RLAPI void rlDisableTextureCubemap(void); // Disable texture cubemap
|
|
553
|
+
RLAPI void rlTextureParameters(unsigned int id, int param, int value); // Set texture parameters (filter, wrap)
|
|
554
|
+
|
|
555
|
+
// Shader state
|
|
556
|
+
RLAPI void rlEnableShader(unsigned int id); // Enable shader program
|
|
557
|
+
RLAPI void rlDisableShader(void); // Disable shader program
|
|
558
|
+
|
|
559
|
+
// Framebuffer state
|
|
560
|
+
RLAPI void rlEnableFramebuffer(unsigned int id); // Enable render texture (fbo)
|
|
561
|
+
RLAPI void rlDisableFramebuffer(void); // Disable render texture (fbo), return to default framebuffer
|
|
562
|
+
RLAPI void rlActiveDrawBuffers(int count); // Activate multiple draw color buffers
|
|
563
|
+
|
|
564
|
+
// General render state
|
|
565
|
+
RLAPI void rlEnableColorBlend(void); // Enable color blending
|
|
566
|
+
RLAPI void rlDisableColorBlend(void); // Disable color blending
|
|
567
|
+
RLAPI void rlEnableDepthTest(void); // Enable depth test
|
|
568
|
+
RLAPI void rlDisableDepthTest(void); // Disable depth test
|
|
569
|
+
RLAPI void rlEnableDepthMask(void); // Enable depth write
|
|
570
|
+
RLAPI void rlDisableDepthMask(void); // Disable depth write
|
|
571
|
+
RLAPI void rlEnableBackfaceCulling(void); // Enable backface culling
|
|
572
|
+
RLAPI void rlDisableBackfaceCulling(void); // Disable backface culling
|
|
573
|
+
RLAPI void rlEnableScissorTest(void); // Enable scissor test
|
|
574
|
+
RLAPI void rlDisableScissorTest(void); // Disable scissor test
|
|
575
|
+
RLAPI void rlScissor(int x, int y, int width, int height); // Scissor test
|
|
576
|
+
RLAPI void rlEnableWireMode(void); // Enable wire mode
|
|
577
|
+
RLAPI void rlDisableWireMode(void); // Disable wire mode
|
|
578
|
+
RLAPI void rlSetLineWidth(float width); // Set the line drawing width
|
|
579
|
+
RLAPI float rlGetLineWidth(void); // Get the line drawing width
|
|
580
|
+
RLAPI void rlEnableSmoothLines(void); // Enable line aliasing
|
|
581
|
+
RLAPI void rlDisableSmoothLines(void); // Disable line aliasing
|
|
582
|
+
RLAPI void rlEnableStereoRender(void); // Enable stereo rendering
|
|
583
|
+
RLAPI void rlDisableStereoRender(void); // Disable stereo rendering
|
|
584
|
+
RLAPI bool rlIsStereoRenderEnabled(void); // Check if stereo render is enabled
|
|
585
|
+
|
|
586
|
+
RLAPI void rlClearColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Clear color buffer with color
|
|
587
|
+
RLAPI void rlClearScreenBuffers(void); // Clear used screen buffers (color and depth)
|
|
588
|
+
RLAPI void rlCheckErrors(void); // Check and log OpenGL error codes
|
|
589
|
+
RLAPI void rlSetBlendMode(int mode); // Set blending mode
|
|
590
|
+
RLAPI void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation); // Set blending mode factor and equation (using OpenGL factors)
|
|
591
|
+
|
|
592
|
+
//------------------------------------------------------------------------------------
|
|
593
|
+
// Functions Declaration - rlgl functionality
|
|
594
|
+
//------------------------------------------------------------------------------------
|
|
595
|
+
// rlgl initialization functions
|
|
596
|
+
RLAPI void rlglInit(int width, int height); // Initialize rlgl (buffers, shaders, textures, states)
|
|
597
|
+
RLAPI void rlglClose(void); // De-inititialize rlgl (buffers, shaders, textures)
|
|
598
|
+
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions (loader function required)
|
|
599
|
+
RLAPI int rlGetVersion(void); // Get current OpenGL version
|
|
600
|
+
RLAPI int rlGetFramebufferWidth(void); // Get default framebuffer width
|
|
601
|
+
RLAPI int rlGetFramebufferHeight(void); // Get default framebuffer height
|
|
602
|
+
|
|
603
|
+
RLAPI unsigned int rlGetTextureIdDefault(void); // Get default texture id
|
|
604
|
+
RLAPI unsigned int rlGetShaderIdDefault(void); // Get default shader id
|
|
605
|
+
RLAPI int *rlGetShaderLocsDefault(void); // Get default shader locations
|
|
606
|
+
|
|
607
|
+
// Render batch management
|
|
608
|
+
// NOTE: rlgl provides a default render batch to behave like OpenGL 1.1 immediate mode
|
|
609
|
+
// but this render batch API is exposed in case of custom batches are required
|
|
610
|
+
RLAPI rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements); // Load a render batch system
|
|
611
|
+
RLAPI void rlUnloadRenderBatch(rlRenderBatch batch); // Unload render batch system
|
|
612
|
+
RLAPI void rlDrawRenderBatch(rlRenderBatch *batch); // Draw render batch data (Update->Draw->Reset)
|
|
613
|
+
RLAPI void rlSetRenderBatchActive(rlRenderBatch *batch); // Set the active render batch for rlgl (NULL for default internal)
|
|
614
|
+
RLAPI void rlDrawRenderBatchActive(void); // Update and draw internal render batch
|
|
615
|
+
RLAPI bool rlCheckRenderBatchLimit(int vCount); // Check internal buffer overflow for a given number of vertex
|
|
616
|
+
RLAPI void rlSetTexture(unsigned int id); // Set current texture for render batch and check buffers limits
|
|
617
|
+
|
|
618
|
+
//------------------------------------------------------------------------------------------------------------------------
|
|
619
|
+
|
|
620
|
+
// Vertex buffers management
|
|
621
|
+
RLAPI unsigned int rlLoadVertexArray(void); // Load vertex array (vao) if supported
|
|
622
|
+
RLAPI unsigned int rlLoadVertexBuffer(void *buffer, int size, bool dynamic); // Load a vertex buffer attribute
|
|
623
|
+
RLAPI unsigned int rlLoadVertexBufferElement(void *buffer, int size, bool dynamic); // Load a new attributes element buffer
|
|
624
|
+
RLAPI void rlUpdateVertexBuffer(unsigned int bufferId, void *data, int dataSize, int offset); // Update GPU buffer with new data
|
|
625
|
+
RLAPI void rlUnloadVertexArray(unsigned int vaoId);
|
|
626
|
+
RLAPI void rlUnloadVertexBuffer(unsigned int vboId);
|
|
627
|
+
RLAPI void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, void *pointer);
|
|
628
|
+
RLAPI void rlSetVertexAttributeDivisor(unsigned int index, int divisor);
|
|
629
|
+
RLAPI void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count); // Set vertex attribute default value
|
|
630
|
+
RLAPI void rlDrawVertexArray(int offset, int count);
|
|
631
|
+
RLAPI void rlDrawVertexArrayElements(int offset, int count, void *buffer);
|
|
632
|
+
RLAPI void rlDrawVertexArrayInstanced(int offset, int count, int instances);
|
|
633
|
+
RLAPI void rlDrawVertexArrayElementsInstanced(int offset, int count, void *buffer, int instances);
|
|
634
|
+
|
|
635
|
+
// Textures management
|
|
636
|
+
RLAPI unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
|
|
637
|
+
RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer); // Load depth texture/renderbuffer (to be attached to fbo)
|
|
638
|
+
RLAPI unsigned int rlLoadTextureCubemap(void *data, int size, int format); // Load texture cubemap
|
|
639
|
+
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
|
|
640
|
+
RLAPI void rlGetGlTextureFormats(int format, int *glInternalFormat, int *glFormat, int *glType); // Get OpenGL internal formats
|
|
641
|
+
RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
|
|
642
|
+
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
|
|
643
|
+
RLAPI void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps); // Generate mipmap data for selected texture
|
|
644
|
+
RLAPI void *rlReadTexturePixels(unsigned int id, int width, int height, int format); // Read texture pixel data
|
|
645
|
+
RLAPI unsigned char *rlReadScreenPixels(int width, int height); // Read screen pixel data (color buffer)
|
|
646
|
+
|
|
647
|
+
// Framebuffer management (fbo)
|
|
648
|
+
RLAPI unsigned int rlLoadFramebuffer(int width, int height); // Load an empty framebuffer
|
|
649
|
+
RLAPI void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel); // Attach texture/renderbuffer to a framebuffer
|
|
650
|
+
RLAPI bool rlFramebufferComplete(unsigned int id); // Verify framebuffer is complete
|
|
651
|
+
RLAPI void rlUnloadFramebuffer(unsigned int id); // Delete framebuffer from GPU
|
|
652
|
+
|
|
653
|
+
// Shaders management
|
|
654
|
+
RLAPI unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode); // Load shader from code strings
|
|
655
|
+
RLAPI unsigned int rlCompileShader(const char *shaderCode, int type); // Compile custom shader and return shader id (type: RL_VERTEX_SHADER, RL_FRAGMENT_SHADER, RL_COMPUTE_SHADER)
|
|
656
|
+
RLAPI unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId); // Load custom shader program
|
|
657
|
+
RLAPI void rlUnloadShaderProgram(unsigned int id); // Unload shader program
|
|
658
|
+
RLAPI int rlGetLocationUniform(unsigned int shaderId, const char *uniformName); // Get shader location uniform
|
|
659
|
+
RLAPI int rlGetLocationAttrib(unsigned int shaderId, const char *attribName); // Get shader location attribute
|
|
660
|
+
RLAPI void rlSetUniform(int locIndex, const void *value, int uniformType, int count); // Set shader value uniform
|
|
661
|
+
RLAPI void rlSetUniformMatrix(int locIndex, Matrix mat); // Set shader value matrix
|
|
662
|
+
RLAPI void rlSetUniformSampler(int locIndex, unsigned int textureId); // Set shader value sampler
|
|
663
|
+
RLAPI void rlSetShader(unsigned int id, int *locs); // Set shader currently active (id and locations)
|
|
664
|
+
|
|
665
|
+
// Compute shader management
|
|
666
|
+
RLAPI unsigned int rlLoadComputeShaderProgram(unsigned int shaderId); // Load compute shader program
|
|
667
|
+
RLAPI void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ); // Dispatch compute shader (equivalent to *draw* for graphics pilepine)
|
|
668
|
+
|
|
669
|
+
// Shader buffer storage object management (ssbo)
|
|
670
|
+
RLAPI unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint); // Load shader storage buffer object (SSBO)
|
|
671
|
+
RLAPI void rlUnloadShaderBuffer(unsigned int ssboId); // Unload shader storage buffer object (SSBO)
|
|
672
|
+
RLAPI void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned long long dataSize, unsigned long long offset); // Update SSBO buffer data
|
|
673
|
+
RLAPI unsigned long long rlGetShaderBufferSize(unsigned int id); // Get SSBO buffer size
|
|
674
|
+
RLAPI void rlReadShaderBufferElements(unsigned int id, void *dest, unsigned long long count, unsigned long long offset); // Bind SSBO buffer
|
|
675
|
+
RLAPI void rlBindShaderBuffer(unsigned int id, unsigned int index); // Copy SSBO buffer data
|
|
676
|
+
|
|
677
|
+
// Buffer management
|
|
678
|
+
RLAPI void rlCopyBuffersElements(unsigned int destId, unsigned int srcId, unsigned long long destOffset, unsigned long long srcOffset, unsigned long long count); // Copy SSBO buffer data
|
|
679
|
+
RLAPI void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly); // Bind image texture
|
|
680
|
+
|
|
681
|
+
// Matrix state management
|
|
682
|
+
RLAPI Matrix rlGetMatrixModelview(void); // Get internal modelview matrix
|
|
683
|
+
RLAPI Matrix rlGetMatrixProjection(void); // Get internal projection matrix
|
|
684
|
+
RLAPI Matrix rlGetMatrixTransform(void); // Get internal accumulated transform matrix
|
|
685
|
+
RLAPI Matrix rlGetMatrixProjectionStereo(int eye); // Get internal projection matrix for stereo render (selected eye)
|
|
686
|
+
RLAPI Matrix rlGetMatrixViewOffsetStereo(int eye); // Get internal view offset matrix for stereo render (selected eye)
|
|
687
|
+
RLAPI void rlSetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
|
|
688
|
+
RLAPI void rlSetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
|
|
689
|
+
RLAPI void rlSetMatrixProjectionStereo(Matrix right, Matrix left); // Set eyes projection matrices for stereo rendering
|
|
690
|
+
RLAPI void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left); // Set eyes view offsets matrices for stereo rendering
|
|
691
|
+
|
|
692
|
+
// Quick and dirty cube/quad buffers load->draw->unload
|
|
693
|
+
RLAPI void rlLoadDrawCube(void); // Load and draw a cube
|
|
694
|
+
RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|
695
|
+
|
|
696
|
+
#if defined(__cplusplus)
|
|
697
|
+
}
|
|
698
|
+
#endif
|
|
699
|
+
|
|
700
|
+
#endif // RLGL_H
|
|
701
|
+
|
|
702
|
+
/***********************************************************************************
|
|
703
|
+
*
|
|
704
|
+
* RLGL IMPLEMENTATION
|
|
705
|
+
*
|
|
706
|
+
************************************************************************************/
|
|
707
|
+
|
|
708
|
+
#if defined(RLGL_IMPLEMENTATION)
|
|
709
|
+
|
|
710
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
711
|
+
#if defined(__APPLE__)
|
|
712
|
+
#include <OpenGL/gl.h> // OpenGL 1.1 library for OSX
|
|
713
|
+
#include <OpenGL/glext.h> // OpenGL extensions library
|
|
714
|
+
#else
|
|
715
|
+
// APIENTRY for OpenGL function pointer declarations is required
|
|
716
|
+
#ifndef APIENTRY
|
|
717
|
+
#if defined(_WIN32)
|
|
718
|
+
#define APIENTRY __stdcall
|
|
719
|
+
#else
|
|
720
|
+
#define APIENTRY
|
|
721
|
+
#endif
|
|
722
|
+
#endif
|
|
723
|
+
// WINGDIAPI definition. Some Windows OpenGL headers need it
|
|
724
|
+
#if !defined(WINGDIAPI) && defined(_WIN32)
|
|
725
|
+
#define WINGDIAPI __declspec(dllimport)
|
|
726
|
+
#endif
|
|
727
|
+
|
|
728
|
+
#include <GL/gl.h> // OpenGL 1.1 library
|
|
729
|
+
#endif
|
|
730
|
+
#endif
|
|
731
|
+
|
|
732
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
733
|
+
#if defined(__APPLE__)
|
|
734
|
+
#include <OpenGL/gl3.h> // OpenGL 3 library for OSX
|
|
735
|
+
#include <OpenGL/gl3ext.h> // OpenGL 3 extensions library for OSX
|
|
736
|
+
#else
|
|
737
|
+
#define GLAD_MALLOC RL_MALLOC
|
|
738
|
+
#define GLAD_FREE RL_FREE
|
|
739
|
+
|
|
740
|
+
#define GLAD_GL_IMPLEMENTATION
|
|
741
|
+
#include "external/glad.h" // GLAD extensions loading library, includes OpenGL headers
|
|
742
|
+
#endif
|
|
743
|
+
#endif
|
|
744
|
+
|
|
745
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
746
|
+
#define GL_GLEXT_PROTOTYPES
|
|
747
|
+
//#include <EGL/egl.h> // EGL library -> not required, platform layer
|
|
748
|
+
#include <GLES2/gl2.h> // OpenGL ES 2.0 library
|
|
749
|
+
#include <GLES2/gl2ext.h> // OpenGL ES 2.0 extensions library
|
|
750
|
+
|
|
751
|
+
// It seems OpenGL ES 2.0 instancing entry points are not defined on Raspberry Pi
|
|
752
|
+
// provided headers (despite being defined in official Khronos GLES2 headers)
|
|
753
|
+
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
|
|
754
|
+
typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
|
|
755
|
+
typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
|
|
756
|
+
typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISOREXTPROC) (GLuint index, GLuint divisor);
|
|
757
|
+
#endif
|
|
758
|
+
#endif
|
|
759
|
+
|
|
760
|
+
#include <stdlib.h> // Required for: malloc(), free()
|
|
761
|
+
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
|
|
762
|
+
#include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log()
|
|
763
|
+
|
|
764
|
+
//----------------------------------------------------------------------------------
|
|
765
|
+
// Defines and Macros
|
|
766
|
+
//----------------------------------------------------------------------------------
|
|
767
|
+
#ifndef PI
|
|
768
|
+
#define PI 3.14159265358979323846f
|
|
769
|
+
#endif
|
|
770
|
+
#ifndef DEG2RAD
|
|
771
|
+
#define DEG2RAD (PI/180.0f)
|
|
772
|
+
#endif
|
|
773
|
+
#ifndef RAD2DEG
|
|
774
|
+
#define RAD2DEG (180.0f/PI)
|
|
775
|
+
#endif
|
|
776
|
+
|
|
777
|
+
#ifndef GL_SHADING_LANGUAGE_VERSION
|
|
778
|
+
#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
|
|
779
|
+
#endif
|
|
780
|
+
|
|
781
|
+
#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
|
|
782
|
+
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
|
|
783
|
+
#endif
|
|
784
|
+
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
|
|
785
|
+
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
|
|
786
|
+
#endif
|
|
787
|
+
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
|
|
788
|
+
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
|
789
|
+
#endif
|
|
790
|
+
#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
|
|
791
|
+
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
|
792
|
+
#endif
|
|
793
|
+
#ifndef GL_ETC1_RGB8_OES
|
|
794
|
+
#define GL_ETC1_RGB8_OES 0x8D64
|
|
795
|
+
#endif
|
|
796
|
+
#ifndef GL_COMPRESSED_RGB8_ETC2
|
|
797
|
+
#define GL_COMPRESSED_RGB8_ETC2 0x9274
|
|
798
|
+
#endif
|
|
799
|
+
#ifndef GL_COMPRESSED_RGBA8_ETC2_EAC
|
|
800
|
+
#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
|
|
801
|
+
#endif
|
|
802
|
+
#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
|
|
803
|
+
#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
|
|
804
|
+
#endif
|
|
805
|
+
#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
|
|
806
|
+
#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
|
|
807
|
+
#endif
|
|
808
|
+
#ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR
|
|
809
|
+
#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93b0
|
|
810
|
+
#endif
|
|
811
|
+
#ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR
|
|
812
|
+
#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93b7
|
|
813
|
+
#endif
|
|
814
|
+
|
|
815
|
+
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
|
|
816
|
+
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
|
817
|
+
#endif
|
|
818
|
+
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
|
|
819
|
+
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
|
820
|
+
#endif
|
|
821
|
+
|
|
822
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
823
|
+
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
|
|
824
|
+
#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
|
|
825
|
+
#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
|
|
826
|
+
#endif
|
|
827
|
+
|
|
828
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
829
|
+
#define GL_LUMINANCE 0x1909
|
|
830
|
+
#define GL_LUMINANCE_ALPHA 0x190A
|
|
831
|
+
#endif
|
|
832
|
+
|
|
833
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
834
|
+
#define glClearDepth glClearDepthf
|
|
835
|
+
#define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER
|
|
836
|
+
#define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER
|
|
837
|
+
#endif
|
|
838
|
+
|
|
839
|
+
// Default shader vertex attribute names to set location points
|
|
840
|
+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION
|
|
841
|
+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
|
842
|
+
#endif
|
|
843
|
+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD
|
|
844
|
+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
|
845
|
+
#endif
|
|
846
|
+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL
|
|
847
|
+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
|
848
|
+
#endif
|
|
849
|
+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR
|
|
850
|
+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
|
851
|
+
#endif
|
|
852
|
+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT
|
|
853
|
+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
|
854
|
+
#endif
|
|
855
|
+
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2
|
|
856
|
+
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
|
857
|
+
#endif
|
|
858
|
+
|
|
859
|
+
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
|
860
|
+
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
|
861
|
+
#endif
|
|
862
|
+
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW
|
|
863
|
+
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
|
864
|
+
#endif
|
|
865
|
+
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION
|
|
866
|
+
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
|
867
|
+
#endif
|
|
868
|
+
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL
|
|
869
|
+
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
|
870
|
+
#endif
|
|
871
|
+
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL
|
|
872
|
+
#define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
|
873
|
+
#endif
|
|
874
|
+
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR
|
|
875
|
+
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
|
876
|
+
#endif
|
|
877
|
+
#ifndef RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0
|
|
878
|
+
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
|
879
|
+
#endif
|
|
880
|
+
#ifndef RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1
|
|
881
|
+
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
|
882
|
+
#endif
|
|
883
|
+
#ifndef RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2
|
|
884
|
+
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
|
885
|
+
#endif
|
|
886
|
+
|
|
887
|
+
//----------------------------------------------------------------------------------
|
|
888
|
+
// Types and Structures Definition
|
|
889
|
+
//----------------------------------------------------------------------------------
|
|
890
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
891
|
+
typedef struct rlglData {
|
|
892
|
+
rlRenderBatch *currentBatch; // Current render batch
|
|
893
|
+
rlRenderBatch defaultBatch; // Default internal render batch
|
|
894
|
+
|
|
895
|
+
struct {
|
|
896
|
+
int vertexCounter; // Current active render batch vertex counter (generic, used for all batches)
|
|
897
|
+
float texcoordx, texcoordy; // Current active texture coordinate (added on glVertex*())
|
|
898
|
+
float normalx, normaly, normalz; // Current active normal (added on glVertex*())
|
|
899
|
+
unsigned char colorr, colorg, colorb, colora; // Current active color (added on glVertex*())
|
|
900
|
+
|
|
901
|
+
int currentMatrixMode; // Current matrix mode
|
|
902
|
+
Matrix *currentMatrix; // Current matrix pointer
|
|
903
|
+
Matrix modelview; // Default modelview matrix
|
|
904
|
+
Matrix projection; // Default projection matrix
|
|
905
|
+
Matrix transform; // Transform matrix to be used with rlTranslate, rlRotate, rlScale
|
|
906
|
+
bool transformRequired; // Require transform matrix application to current draw-call vertex (if required)
|
|
907
|
+
Matrix stack[RL_MAX_MATRIX_STACK_SIZE];// Matrix stack for push/pop
|
|
908
|
+
int stackCounter; // Matrix stack counter
|
|
909
|
+
|
|
910
|
+
unsigned int defaultTextureId; // Default texture used on shapes/poly drawing (required by shader)
|
|
911
|
+
unsigned int activeTextureId[RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS]; // Active texture ids to be enabled on batch drawing (0 active by default)
|
|
912
|
+
unsigned int defaultVShaderId; // Default vertex shader id (used by default shader program)
|
|
913
|
+
unsigned int defaultFShaderId; // Default fragment shader id (used by default shader program)
|
|
914
|
+
unsigned int defaultShaderId; // Default shader program id, supports vertex color and diffuse texture
|
|
915
|
+
int *defaultShaderLocs; // Default shader locations pointer to be used on rendering
|
|
916
|
+
unsigned int currentShaderId; // Current shader id to be used on rendering (by default, defaultShaderId)
|
|
917
|
+
int *currentShaderLocs; // Current shader locations pointer to be used on rendering (by default, defaultShaderLocs)
|
|
918
|
+
|
|
919
|
+
bool stereoRender; // Stereo rendering flag
|
|
920
|
+
Matrix projectionStereo[2]; // VR stereo rendering eyes projection matrices
|
|
921
|
+
Matrix viewOffsetStereo[2]; // VR stereo rendering eyes view offset matrices
|
|
922
|
+
|
|
923
|
+
int currentBlendMode; // Blending mode active
|
|
924
|
+
int glBlendSrcFactor; // Blending source factor
|
|
925
|
+
int glBlendDstFactor; // Blending destination factor
|
|
926
|
+
int glBlendEquation; // Blending equation
|
|
927
|
+
|
|
928
|
+
int framebufferWidth; // Default framebuffer width
|
|
929
|
+
int framebufferHeight; // Default framebuffer height
|
|
930
|
+
|
|
931
|
+
} State; // Renderer state
|
|
932
|
+
struct {
|
|
933
|
+
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
|
934
|
+
bool instancing; // Instancing supported (GL_ANGLE_instanced_arrays, GL_EXT_draw_instanced + GL_EXT_instanced_arrays)
|
|
935
|
+
bool texNPOT; // NPOT textures full support (GL_ARB_texture_non_power_of_two, GL_OES_texture_npot)
|
|
936
|
+
bool texDepth; // Depth textures supported (GL_ARB_depth_texture, GL_WEBGL_depth_texture, GL_OES_depth_texture)
|
|
937
|
+
bool texFloat32; // float textures support (32 bit per channel) (GL_OES_texture_float)
|
|
938
|
+
bool texCompDXT; // DDS texture compression support (GL_EXT_texture_compression_s3tc, GL_WEBGL_compressed_texture_s3tc, GL_WEBKIT_WEBGL_compressed_texture_s3tc)
|
|
939
|
+
bool texCompETC1; // ETC1 texture compression support (GL_OES_compressed_ETC1_RGB8_texture, GL_WEBGL_compressed_texture_etc1)
|
|
940
|
+
bool texCompETC2; // ETC2/EAC texture compression support (GL_ARB_ES3_compatibility)
|
|
941
|
+
bool texCompPVRT; // PVR texture compression support (GL_IMG_texture_compression_pvrtc)
|
|
942
|
+
bool texCompASTC; // ASTC texture compression support (GL_KHR_texture_compression_astc_hdr, GL_KHR_texture_compression_astc_ldr)
|
|
943
|
+
bool texMirrorClamp; // Clamp mirror wrap mode supported (GL_EXT_texture_mirror_clamp)
|
|
944
|
+
bool texAnisoFilter; // Anisotropic texture filtering support (GL_EXT_texture_filter_anisotropic)
|
|
945
|
+
bool computeShader; // Compute shaders support (GL_ARB_compute_shader)
|
|
946
|
+
bool ssbo; // Shader storage buffer object support (GL_ARB_shader_storage_buffer_object)
|
|
947
|
+
|
|
948
|
+
float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f)
|
|
949
|
+
int maxDepthBits; // Maximum bits for depth component
|
|
950
|
+
|
|
951
|
+
} ExtSupported; // Extensions supported flags
|
|
952
|
+
} rlglData;
|
|
953
|
+
|
|
954
|
+
typedef void *(*rlglLoadProc)(const char *name); // OpenGL extension functions loader signature (same as GLADloadproc)
|
|
955
|
+
|
|
956
|
+
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
|
957
|
+
|
|
958
|
+
//----------------------------------------------------------------------------------
|
|
959
|
+
// Global Variables Definition
|
|
960
|
+
//----------------------------------------------------------------------------------
|
|
961
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
962
|
+
static rlglData RLGL = { 0 };
|
|
963
|
+
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
|
964
|
+
|
|
965
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
966
|
+
// NOTE: VAO functionality is exposed through extensions (OES)
|
|
967
|
+
static PFNGLGENVERTEXARRAYSOESPROC glGenVertexArrays = NULL;
|
|
968
|
+
static PFNGLBINDVERTEXARRAYOESPROC glBindVertexArray = NULL;
|
|
969
|
+
static PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArrays = NULL;
|
|
970
|
+
|
|
971
|
+
// NOTE: Instancing functionality could also be available through extension
|
|
972
|
+
static PFNGLDRAWARRAYSINSTANCEDEXTPROC glDrawArraysInstanced = NULL;
|
|
973
|
+
static PFNGLDRAWELEMENTSINSTANCEDEXTPROC glDrawElementsInstanced = NULL;
|
|
974
|
+
static PFNGLVERTEXATTRIBDIVISOREXTPROC glVertexAttribDivisor = NULL;
|
|
975
|
+
#endif
|
|
976
|
+
|
|
977
|
+
//----------------------------------------------------------------------------------
|
|
978
|
+
// Module specific Functions Declaration
|
|
979
|
+
//----------------------------------------------------------------------------------
|
|
980
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
981
|
+
static void rlLoadShaderDefault(void); // Load default shader
|
|
982
|
+
static void rlUnloadShaderDefault(void); // Unload default shader
|
|
983
|
+
#if defined(RLGL_SHOW_GL_DETAILS_INFO)
|
|
984
|
+
static char *rlGetCompressedFormatName(int format); // Get compressed format official GL identifier name
|
|
985
|
+
#endif // RLGL_SHOW_GL_DETAILS_INFO
|
|
986
|
+
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
|
987
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
988
|
+
static int rlGenTextureMipmapsData(unsigned char *data, int baseWidth, int baseHeight); // Generate mipmaps data on CPU side
|
|
989
|
+
static unsigned char *rlGenNextMipmapData(unsigned char *srcData, int srcWidth, int srcHeight); // Generate next mipmap level on CPU side
|
|
990
|
+
#endif
|
|
991
|
+
static int rlGetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture)
|
|
992
|
+
// Auxiliar matrix math functions
|
|
993
|
+
static Matrix rlMatrixIdentity(void); // Get identity matrix
|
|
994
|
+
static Matrix rlMatrixMultiply(Matrix left, Matrix right); // Multiply two matrices
|
|
995
|
+
|
|
996
|
+
//----------------------------------------------------------------------------------
|
|
997
|
+
// Module Functions Definition - Matrix operations
|
|
998
|
+
//----------------------------------------------------------------------------------
|
|
999
|
+
|
|
1000
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1001
|
+
// Fallback to OpenGL 1.1 function calls
|
|
1002
|
+
//---------------------------------------
|
|
1003
|
+
void rlMatrixMode(int mode)
|
|
1004
|
+
{
|
|
1005
|
+
switch (mode)
|
|
1006
|
+
{
|
|
1007
|
+
case RL_PROJECTION: glMatrixMode(GL_PROJECTION); break;
|
|
1008
|
+
case RL_MODELVIEW: glMatrixMode(GL_MODELVIEW); break;
|
|
1009
|
+
case RL_TEXTURE: glMatrixMode(GL_TEXTURE); break;
|
|
1010
|
+
default: break;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar)
|
|
1015
|
+
{
|
|
1016
|
+
glFrustum(left, right, bottom, top, znear, zfar);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar)
|
|
1020
|
+
{
|
|
1021
|
+
glOrtho(left, right, bottom, top, znear, zfar);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
void rlPushMatrix(void) { glPushMatrix(); }
|
|
1025
|
+
void rlPopMatrix(void) { glPopMatrix(); }
|
|
1026
|
+
void rlLoadIdentity(void) { glLoadIdentity(); }
|
|
1027
|
+
void rlTranslatef(float x, float y, float z) { glTranslatef(x, y, z); }
|
|
1028
|
+
void rlRotatef(float angle, float x, float y, float z) { glRotatef(angle, x, y, z); }
|
|
1029
|
+
void rlScalef(float x, float y, float z) { glScalef(x, y, z); }
|
|
1030
|
+
void rlMultMatrixf(float *matf) { glMultMatrixf(matf); }
|
|
1031
|
+
#endif
|
|
1032
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1033
|
+
// Choose the current matrix to be transformed
|
|
1034
|
+
void rlMatrixMode(int mode)
|
|
1035
|
+
{
|
|
1036
|
+
if (mode == RL_PROJECTION) RLGL.State.currentMatrix = &RLGL.State.projection;
|
|
1037
|
+
else if (mode == RL_MODELVIEW) RLGL.State.currentMatrix = &RLGL.State.modelview;
|
|
1038
|
+
//else if (mode == RL_TEXTURE) // Not supported
|
|
1039
|
+
|
|
1040
|
+
RLGL.State.currentMatrixMode = mode;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
// Push the current matrix into RLGL.State.stack
|
|
1044
|
+
void rlPushMatrix(void)
|
|
1045
|
+
{
|
|
1046
|
+
if (RLGL.State.stackCounter >= RL_MAX_MATRIX_STACK_SIZE) TRACELOG(RL_LOG_ERROR, "RLGL: Matrix stack overflow (RL_MAX_MATRIX_STACK_SIZE)");
|
|
1047
|
+
|
|
1048
|
+
if (RLGL.State.currentMatrixMode == RL_MODELVIEW)
|
|
1049
|
+
{
|
|
1050
|
+
RLGL.State.transformRequired = true;
|
|
1051
|
+
RLGL.State.currentMatrix = &RLGL.State.transform;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
RLGL.State.stack[RLGL.State.stackCounter] = *RLGL.State.currentMatrix;
|
|
1055
|
+
RLGL.State.stackCounter++;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// Pop lattest inserted matrix from RLGL.State.stack
|
|
1059
|
+
void rlPopMatrix(void)
|
|
1060
|
+
{
|
|
1061
|
+
if (RLGL.State.stackCounter > 0)
|
|
1062
|
+
{
|
|
1063
|
+
Matrix mat = RLGL.State.stack[RLGL.State.stackCounter - 1];
|
|
1064
|
+
*RLGL.State.currentMatrix = mat;
|
|
1065
|
+
RLGL.State.stackCounter--;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
if ((RLGL.State.stackCounter == 0) && (RLGL.State.currentMatrixMode == RL_MODELVIEW))
|
|
1069
|
+
{
|
|
1070
|
+
RLGL.State.currentMatrix = &RLGL.State.modelview;
|
|
1071
|
+
RLGL.State.transformRequired = false;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// Reset current matrix to identity matrix
|
|
1076
|
+
void rlLoadIdentity(void)
|
|
1077
|
+
{
|
|
1078
|
+
*RLGL.State.currentMatrix = rlMatrixIdentity();
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// Multiply the current matrix by a translation matrix
|
|
1082
|
+
void rlTranslatef(float x, float y, float z)
|
|
1083
|
+
{
|
|
1084
|
+
Matrix matTranslation = {
|
|
1085
|
+
1.0f, 0.0f, 0.0f, x,
|
|
1086
|
+
0.0f, 1.0f, 0.0f, y,
|
|
1087
|
+
0.0f, 0.0f, 1.0f, z,
|
|
1088
|
+
0.0f, 0.0f, 0.0f, 1.0f
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// NOTE: We transpose matrix with multiplication order
|
|
1092
|
+
*RLGL.State.currentMatrix = rlMatrixMultiply(matTranslation, *RLGL.State.currentMatrix);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// Multiply the current matrix by a rotation matrix
|
|
1096
|
+
// NOTE: The provided angle must be in degrees
|
|
1097
|
+
void rlRotatef(float angle, float x, float y, float z)
|
|
1098
|
+
{
|
|
1099
|
+
Matrix matRotation = rlMatrixIdentity();
|
|
1100
|
+
|
|
1101
|
+
// Axis vector (x, y, z) normalization
|
|
1102
|
+
float lengthSquared = x*x + y*y + z*z;
|
|
1103
|
+
if ((lengthSquared != 1.0f) && (lengthSquared != 0.0f))
|
|
1104
|
+
{
|
|
1105
|
+
float inverseLength = 1.0f/sqrtf(lengthSquared);
|
|
1106
|
+
x *= inverseLength;
|
|
1107
|
+
y *= inverseLength;
|
|
1108
|
+
z *= inverseLength;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// Rotation matrix generation
|
|
1112
|
+
float sinres = sinf(DEG2RAD*angle);
|
|
1113
|
+
float cosres = cosf(DEG2RAD*angle);
|
|
1114
|
+
float t = 1.0f - cosres;
|
|
1115
|
+
|
|
1116
|
+
matRotation.m0 = x*x*t + cosres;
|
|
1117
|
+
matRotation.m1 = y*x*t + z*sinres;
|
|
1118
|
+
matRotation.m2 = z*x*t - y*sinres;
|
|
1119
|
+
matRotation.m3 = 0.0f;
|
|
1120
|
+
|
|
1121
|
+
matRotation.m4 = x*y*t - z*sinres;
|
|
1122
|
+
matRotation.m5 = y*y*t + cosres;
|
|
1123
|
+
matRotation.m6 = z*y*t + x*sinres;
|
|
1124
|
+
matRotation.m7 = 0.0f;
|
|
1125
|
+
|
|
1126
|
+
matRotation.m8 = x*z*t + y*sinres;
|
|
1127
|
+
matRotation.m9 = y*z*t - x*sinres;
|
|
1128
|
+
matRotation.m10 = z*z*t + cosres;
|
|
1129
|
+
matRotation.m11 = 0.0f;
|
|
1130
|
+
|
|
1131
|
+
matRotation.m12 = 0.0f;
|
|
1132
|
+
matRotation.m13 = 0.0f;
|
|
1133
|
+
matRotation.m14 = 0.0f;
|
|
1134
|
+
matRotation.m15 = 1.0f;
|
|
1135
|
+
|
|
1136
|
+
// NOTE: We transpose matrix with multiplication order
|
|
1137
|
+
*RLGL.State.currentMatrix = rlMatrixMultiply(matRotation, *RLGL.State.currentMatrix);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// Multiply the current matrix by a scaling matrix
|
|
1141
|
+
void rlScalef(float x, float y, float z)
|
|
1142
|
+
{
|
|
1143
|
+
Matrix matScale = {
|
|
1144
|
+
x, 0.0f, 0.0f, 0.0f,
|
|
1145
|
+
0.0f, y, 0.0f, 0.0f,
|
|
1146
|
+
0.0f, 0.0f, z, 0.0f,
|
|
1147
|
+
0.0f, 0.0f, 0.0f, 1.0f
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
// NOTE: We transpose matrix with multiplication order
|
|
1151
|
+
*RLGL.State.currentMatrix = rlMatrixMultiply(matScale, *RLGL.State.currentMatrix);
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// Multiply the current matrix by another matrix
|
|
1155
|
+
void rlMultMatrixf(float *matf)
|
|
1156
|
+
{
|
|
1157
|
+
// Matrix creation from array
|
|
1158
|
+
Matrix mat = { matf[0], matf[4], matf[8], matf[12],
|
|
1159
|
+
matf[1], matf[5], matf[9], matf[13],
|
|
1160
|
+
matf[2], matf[6], matf[10], matf[14],
|
|
1161
|
+
matf[3], matf[7], matf[11], matf[15] };
|
|
1162
|
+
|
|
1163
|
+
*RLGL.State.currentMatrix = rlMatrixMultiply(*RLGL.State.currentMatrix, mat);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// Multiply the current matrix by a perspective matrix generated by parameters
|
|
1167
|
+
void rlFrustum(double left, double right, double bottom, double top, double znear, double zfar)
|
|
1168
|
+
{
|
|
1169
|
+
Matrix matFrustum = { 0 };
|
|
1170
|
+
|
|
1171
|
+
float rl = (float)(right - left);
|
|
1172
|
+
float tb = (float)(top - bottom);
|
|
1173
|
+
float fn = (float)(zfar - znear);
|
|
1174
|
+
|
|
1175
|
+
matFrustum.m0 = ((float) znear*2.0f)/rl;
|
|
1176
|
+
matFrustum.m1 = 0.0f;
|
|
1177
|
+
matFrustum.m2 = 0.0f;
|
|
1178
|
+
matFrustum.m3 = 0.0f;
|
|
1179
|
+
|
|
1180
|
+
matFrustum.m4 = 0.0f;
|
|
1181
|
+
matFrustum.m5 = ((float) znear*2.0f)/tb;
|
|
1182
|
+
matFrustum.m6 = 0.0f;
|
|
1183
|
+
matFrustum.m7 = 0.0f;
|
|
1184
|
+
|
|
1185
|
+
matFrustum.m8 = ((float)right + (float)left)/rl;
|
|
1186
|
+
matFrustum.m9 = ((float)top + (float)bottom)/tb;
|
|
1187
|
+
matFrustum.m10 = -((float)zfar + (float)znear)/fn;
|
|
1188
|
+
matFrustum.m11 = -1.0f;
|
|
1189
|
+
|
|
1190
|
+
matFrustum.m12 = 0.0f;
|
|
1191
|
+
matFrustum.m13 = 0.0f;
|
|
1192
|
+
matFrustum.m14 = -((float)zfar*(float)znear*2.0f)/fn;
|
|
1193
|
+
matFrustum.m15 = 0.0f;
|
|
1194
|
+
|
|
1195
|
+
*RLGL.State.currentMatrix = rlMatrixMultiply(*RLGL.State.currentMatrix, matFrustum);
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// Multiply the current matrix by an orthographic matrix generated by parameters
|
|
1199
|
+
void rlOrtho(double left, double right, double bottom, double top, double znear, double zfar)
|
|
1200
|
+
{
|
|
1201
|
+
// NOTE: If left-right and top-botton values are equal it could create a division by zero,
|
|
1202
|
+
// response to it is platform/compiler dependant
|
|
1203
|
+
Matrix matOrtho = { 0 };
|
|
1204
|
+
|
|
1205
|
+
float rl = (float)(right - left);
|
|
1206
|
+
float tb = (float)(top - bottom);
|
|
1207
|
+
float fn = (float)(zfar - znear);
|
|
1208
|
+
|
|
1209
|
+
matOrtho.m0 = 2.0f/rl;
|
|
1210
|
+
matOrtho.m1 = 0.0f;
|
|
1211
|
+
matOrtho.m2 = 0.0f;
|
|
1212
|
+
matOrtho.m3 = 0.0f;
|
|
1213
|
+
matOrtho.m4 = 0.0f;
|
|
1214
|
+
matOrtho.m5 = 2.0f/tb;
|
|
1215
|
+
matOrtho.m6 = 0.0f;
|
|
1216
|
+
matOrtho.m7 = 0.0f;
|
|
1217
|
+
matOrtho.m8 = 0.0f;
|
|
1218
|
+
matOrtho.m9 = 0.0f;
|
|
1219
|
+
matOrtho.m10 = -2.0f/fn;
|
|
1220
|
+
matOrtho.m11 = 0.0f;
|
|
1221
|
+
matOrtho.m12 = -((float)left + (float)right)/rl;
|
|
1222
|
+
matOrtho.m13 = -((float)top + (float)bottom)/tb;
|
|
1223
|
+
matOrtho.m14 = -((float)zfar + (float)znear)/fn;
|
|
1224
|
+
matOrtho.m15 = 1.0f;
|
|
1225
|
+
|
|
1226
|
+
*RLGL.State.currentMatrix = rlMatrixMultiply(*RLGL.State.currentMatrix, matOrtho);
|
|
1227
|
+
}
|
|
1228
|
+
#endif
|
|
1229
|
+
|
|
1230
|
+
// Set the viewport area (transformation from normalized device coordinates to window coordinates)
|
|
1231
|
+
void rlViewport(int x, int y, int width, int height)
|
|
1232
|
+
{
|
|
1233
|
+
glViewport(x, y, width, height);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
//----------------------------------------------------------------------------------
|
|
1237
|
+
// Module Functions Definition - Vertex level operations
|
|
1238
|
+
//----------------------------------------------------------------------------------
|
|
1239
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1240
|
+
// Fallback to OpenGL 1.1 function calls
|
|
1241
|
+
//---------------------------------------
|
|
1242
|
+
void rlBegin(int mode)
|
|
1243
|
+
{
|
|
1244
|
+
switch (mode)
|
|
1245
|
+
{
|
|
1246
|
+
case RL_LINES: glBegin(GL_LINES); break;
|
|
1247
|
+
case RL_TRIANGLES: glBegin(GL_TRIANGLES); break;
|
|
1248
|
+
case RL_QUADS: glBegin(GL_QUADS); break;
|
|
1249
|
+
default: break;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
void rlEnd() { glEnd(); }
|
|
1254
|
+
void rlVertex2i(int x, int y) { glVertex2i(x, y); }
|
|
1255
|
+
void rlVertex2f(float x, float y) { glVertex2f(x, y); }
|
|
1256
|
+
void rlVertex3f(float x, float y, float z) { glVertex3f(x, y, z); }
|
|
1257
|
+
void rlTexCoord2f(float x, float y) { glTexCoord2f(x, y); }
|
|
1258
|
+
void rlNormal3f(float x, float y, float z) { glNormal3f(x, y, z); }
|
|
1259
|
+
void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { glColor4ub(r, g, b, a); }
|
|
1260
|
+
void rlColor3f(float x, float y, float z) { glColor3f(x, y, z); }
|
|
1261
|
+
void rlColor4f(float x, float y, float z, float w) { glColor4f(x, y, z, w); }
|
|
1262
|
+
#endif
|
|
1263
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1264
|
+
// Initialize drawing mode (how to organize vertex)
|
|
1265
|
+
void rlBegin(int mode)
|
|
1266
|
+
{
|
|
1267
|
+
// Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS
|
|
1268
|
+
// NOTE: In all three cases, vertex are accumulated over default internal vertex buffer
|
|
1269
|
+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode)
|
|
1270
|
+
{
|
|
1271
|
+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
|
|
1272
|
+
{
|
|
1273
|
+
// Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
|
|
1274
|
+
// that way, following QUADS drawing will keep aligned with index processing
|
|
1275
|
+
// It implies adding some extra alignment vertex at the end of the draw,
|
|
1276
|
+
// those vertex are not processed but they are considered as an additional offset
|
|
1277
|
+
// for the next set of vertex to be drawn
|
|
1278
|
+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4);
|
|
1279
|
+
else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4)));
|
|
1280
|
+
else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = 0;
|
|
1281
|
+
|
|
1282
|
+
if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment))
|
|
1283
|
+
{
|
|
1284
|
+
RLGL.State.vertexCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment;
|
|
1285
|
+
RLGL.currentBatch->drawCounter++;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch);
|
|
1290
|
+
|
|
1291
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode;
|
|
1292
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0;
|
|
1293
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// Finish vertex providing
|
|
1298
|
+
void rlEnd(void)
|
|
1299
|
+
{
|
|
1300
|
+
// NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
|
|
1301
|
+
// as well as depth buffer bit-depth (16bit or 24bit or 32bit)
|
|
1302
|
+
// Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
|
|
1303
|
+
RLGL.currentBatch->currentDepth += (1.0f/20000.0f);
|
|
1304
|
+
|
|
1305
|
+
// Verify internal buffers limits
|
|
1306
|
+
// NOTE: This check is combined with usage of rlCheckRenderBatchLimit()
|
|
1307
|
+
if (RLGL.State.vertexCounter >= (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4))
|
|
1308
|
+
{
|
|
1309
|
+
// WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(),
|
|
1310
|
+
// we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call!
|
|
1311
|
+
// If we have multiple matrix pushed, it will require "RLGL.State.stackCounter" pops before launching the draw
|
|
1312
|
+
for (int i = RLGL.State.stackCounter; i >= 0; i--) rlPopMatrix();
|
|
1313
|
+
rlDrawRenderBatch(RLGL.currentBatch);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// Define one vertex (position)
|
|
1318
|
+
// NOTE: Vertex position data is the basic information required for drawing
|
|
1319
|
+
void rlVertex3f(float x, float y, float z)
|
|
1320
|
+
{
|
|
1321
|
+
float tx = x;
|
|
1322
|
+
float ty = y;
|
|
1323
|
+
float tz = z;
|
|
1324
|
+
|
|
1325
|
+
// Transform provided vector if required
|
|
1326
|
+
if (RLGL.State.transformRequired)
|
|
1327
|
+
{
|
|
1328
|
+
tx = RLGL.State.transform.m0*x + RLGL.State.transform.m4*y + RLGL.State.transform.m8*z + RLGL.State.transform.m12;
|
|
1329
|
+
ty = RLGL.State.transform.m1*x + RLGL.State.transform.m5*y + RLGL.State.transform.m9*z + RLGL.State.transform.m13;
|
|
1330
|
+
tz = RLGL.State.transform.m2*x + RLGL.State.transform.m6*y + RLGL.State.transform.m10*z + RLGL.State.transform.m14;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// Verify that current vertex buffer elements limit has not been reached
|
|
1334
|
+
if (RLGL.State.vertexCounter < (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4))
|
|
1335
|
+
{
|
|
1336
|
+
// Add vertices
|
|
1337
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter] = tx;
|
|
1338
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 1] = ty;
|
|
1339
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.State.vertexCounter + 2] = tz;
|
|
1340
|
+
|
|
1341
|
+
// Add current texcoord
|
|
1342
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter] = RLGL.State.texcoordx;
|
|
1343
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].texcoords[2*RLGL.State.vertexCounter + 1] = RLGL.State.texcoordy;
|
|
1344
|
+
|
|
1345
|
+
// TODO: Add current normal
|
|
1346
|
+
// By default rlVertexBuffer type does not store normals
|
|
1347
|
+
|
|
1348
|
+
// Add current color
|
|
1349
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter] = RLGL.State.colorr;
|
|
1350
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 1] = RLGL.State.colorg;
|
|
1351
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 2] = RLGL.State.colorb;
|
|
1352
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].colors[4*RLGL.State.vertexCounter + 3] = RLGL.State.colora;
|
|
1353
|
+
|
|
1354
|
+
RLGL.State.vertexCounter++;
|
|
1355
|
+
|
|
1356
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++;
|
|
1357
|
+
}
|
|
1358
|
+
else TRACELOG(RL_LOG_ERROR, "RLGL: Batch elements overflow");
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// Define one vertex (position)
|
|
1362
|
+
void rlVertex2f(float x, float y)
|
|
1363
|
+
{
|
|
1364
|
+
rlVertex3f(x, y, RLGL.currentBatch->currentDepth);
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// Define one vertex (position)
|
|
1368
|
+
void rlVertex2i(int x, int y)
|
|
1369
|
+
{
|
|
1370
|
+
rlVertex3f((float)x, (float)y, RLGL.currentBatch->currentDepth);
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// Define one vertex (texture coordinate)
|
|
1374
|
+
// NOTE: Texture coordinates are limited to QUADS only
|
|
1375
|
+
void rlTexCoord2f(float x, float y)
|
|
1376
|
+
{
|
|
1377
|
+
RLGL.State.texcoordx = x;
|
|
1378
|
+
RLGL.State.texcoordy = y;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// Define one vertex (normal)
|
|
1382
|
+
// NOTE: Normals limited to TRIANGLES only?
|
|
1383
|
+
void rlNormal3f(float x, float y, float z)
|
|
1384
|
+
{
|
|
1385
|
+
RLGL.State.normalx = x;
|
|
1386
|
+
RLGL.State.normaly = y;
|
|
1387
|
+
RLGL.State.normalz = z;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// Define one vertex (color)
|
|
1391
|
+
void rlColor4ub(unsigned char x, unsigned char y, unsigned char z, unsigned char w)
|
|
1392
|
+
{
|
|
1393
|
+
RLGL.State.colorr = x;
|
|
1394
|
+
RLGL.State.colorg = y;
|
|
1395
|
+
RLGL.State.colorb = z;
|
|
1396
|
+
RLGL.State.colora = w;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// Define one vertex (color)
|
|
1400
|
+
void rlColor4f(float r, float g, float b, float a)
|
|
1401
|
+
{
|
|
1402
|
+
rlColor4ub((unsigned char)(r*255), (unsigned char)(g*255), (unsigned char)(b*255), (unsigned char)(a*255));
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// Define one vertex (color)
|
|
1406
|
+
void rlColor3f(float x, float y, float z)
|
|
1407
|
+
{
|
|
1408
|
+
rlColor4ub((unsigned char)(x*255), (unsigned char)(y*255), (unsigned char)(z*255), 255);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
#endif
|
|
1412
|
+
|
|
1413
|
+
//--------------------------------------------------------------------------------------
|
|
1414
|
+
// Module Functions Definition - OpenGL style functions (common to 1.1, 3.3+, ES2)
|
|
1415
|
+
//--------------------------------------------------------------------------------------
|
|
1416
|
+
|
|
1417
|
+
// Set current texture to use
|
|
1418
|
+
void rlSetTexture(unsigned int id)
|
|
1419
|
+
{
|
|
1420
|
+
if (id == 0)
|
|
1421
|
+
{
|
|
1422
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1423
|
+
rlDisableTexture();
|
|
1424
|
+
#else
|
|
1425
|
+
// NOTE: If quads batch limit is reached, we force a draw call and next batch starts
|
|
1426
|
+
if (RLGL.State.vertexCounter >=
|
|
1427
|
+
RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4)
|
|
1428
|
+
{
|
|
1429
|
+
rlDrawRenderBatch(RLGL.currentBatch);
|
|
1430
|
+
}
|
|
1431
|
+
#endif
|
|
1432
|
+
}
|
|
1433
|
+
else
|
|
1434
|
+
{
|
|
1435
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1436
|
+
rlEnableTexture(id);
|
|
1437
|
+
#else
|
|
1438
|
+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId != id)
|
|
1439
|
+
{
|
|
1440
|
+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0)
|
|
1441
|
+
{
|
|
1442
|
+
// Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4,
|
|
1443
|
+
// that way, following QUADS drawing will keep aligned with index processing
|
|
1444
|
+
// It implies adding some extra alignment vertex at the end of the draw,
|
|
1445
|
+
// those vertex are not processed but they are considered as an additional offset
|
|
1446
|
+
// for the next set of vertex to be drawn
|
|
1447
|
+
if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4);
|
|
1448
|
+
else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4)));
|
|
1449
|
+
else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = 0;
|
|
1450
|
+
|
|
1451
|
+
if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment))
|
|
1452
|
+
{
|
|
1453
|
+
RLGL.State.vertexCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment;
|
|
1454
|
+
|
|
1455
|
+
RLGL.currentBatch->drawCounter++;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch);
|
|
1460
|
+
|
|
1461
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = id;
|
|
1462
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0;
|
|
1463
|
+
}
|
|
1464
|
+
#endif
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
// Select and active a texture slot
|
|
1469
|
+
void rlActiveTextureSlot(int slot)
|
|
1470
|
+
{
|
|
1471
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1472
|
+
glActiveTexture(GL_TEXTURE0 + slot);
|
|
1473
|
+
#endif
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// Enable texture
|
|
1477
|
+
void rlEnableTexture(unsigned int id)
|
|
1478
|
+
{
|
|
1479
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1480
|
+
glEnable(GL_TEXTURE_2D);
|
|
1481
|
+
#endif
|
|
1482
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// Disable texture
|
|
1486
|
+
void rlDisableTexture(void)
|
|
1487
|
+
{
|
|
1488
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1489
|
+
glDisable(GL_TEXTURE_2D);
|
|
1490
|
+
#endif
|
|
1491
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// Enable texture cubemap
|
|
1495
|
+
void rlEnableTextureCubemap(unsigned int id)
|
|
1496
|
+
{
|
|
1497
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1498
|
+
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
|
|
1499
|
+
#endif
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
// Disable texture cubemap
|
|
1503
|
+
void rlDisableTextureCubemap(void)
|
|
1504
|
+
{
|
|
1505
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1506
|
+
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
|
1507
|
+
#endif
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// Set texture parameters (wrap mode/filter mode)
|
|
1511
|
+
void rlTextureParameters(unsigned int id, int param, int value)
|
|
1512
|
+
{
|
|
1513
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
1514
|
+
|
|
1515
|
+
switch (param)
|
|
1516
|
+
{
|
|
1517
|
+
case RL_TEXTURE_WRAP_S:
|
|
1518
|
+
case RL_TEXTURE_WRAP_T:
|
|
1519
|
+
{
|
|
1520
|
+
if (value == RL_TEXTURE_WRAP_MIRROR_CLAMP)
|
|
1521
|
+
{
|
|
1522
|
+
#if !defined(GRAPHICS_API_OPENGL_11)
|
|
1523
|
+
if (RLGL.ExtSupported.texMirrorClamp) glTexParameteri(GL_TEXTURE_2D, param, value);
|
|
1524
|
+
else TRACELOG(RL_LOG_WARNING, "GL: Clamp mirror wrap mode not supported (GL_MIRROR_CLAMP_EXT)");
|
|
1525
|
+
#endif
|
|
1526
|
+
}
|
|
1527
|
+
else glTexParameteri(GL_TEXTURE_2D, param, value);
|
|
1528
|
+
|
|
1529
|
+
} break;
|
|
1530
|
+
case RL_TEXTURE_MAG_FILTER:
|
|
1531
|
+
case RL_TEXTURE_MIN_FILTER: glTexParameteri(GL_TEXTURE_2D, param, value); break;
|
|
1532
|
+
case RL_TEXTURE_FILTER_ANISOTROPIC:
|
|
1533
|
+
{
|
|
1534
|
+
#if !defined(GRAPHICS_API_OPENGL_11)
|
|
1535
|
+
if (value <= RLGL.ExtSupported.maxAnisotropyLevel) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
|
|
1536
|
+
else if (RLGL.ExtSupported.maxAnisotropyLevel > 0.0f)
|
|
1537
|
+
{
|
|
1538
|
+
TRACELOG(RL_LOG_WARNING, "GL: Maximum anisotropic filter level supported is %iX", id, RLGL.ExtSupported.maxAnisotropyLevel);
|
|
1539
|
+
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)value);
|
|
1540
|
+
}
|
|
1541
|
+
else TRACELOG(RL_LOG_WARNING, "GL: Anisotropic filtering not supported");
|
|
1542
|
+
#endif
|
|
1543
|
+
} break;
|
|
1544
|
+
default: break;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// Enable shader program
|
|
1551
|
+
void rlEnableShader(unsigned int id)
|
|
1552
|
+
{
|
|
1553
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2))
|
|
1554
|
+
glUseProgram(id);
|
|
1555
|
+
#endif
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// Disable shader program
|
|
1559
|
+
void rlDisableShader(void)
|
|
1560
|
+
{
|
|
1561
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2))
|
|
1562
|
+
glUseProgram(0);
|
|
1563
|
+
#endif
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// Enable rendering to texture (fbo)
|
|
1567
|
+
void rlEnableFramebuffer(unsigned int id)
|
|
1568
|
+
{
|
|
1569
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
|
1570
|
+
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
|
1571
|
+
#endif
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
// Disable rendering to texture
|
|
1575
|
+
void rlDisableFramebuffer(void)
|
|
1576
|
+
{
|
|
1577
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
|
1578
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
1579
|
+
#endif
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
// Activate multiple draw color buffers
|
|
1583
|
+
// NOTE: One color buffer is always active by default
|
|
1584
|
+
void rlActiveDrawBuffers(int count)
|
|
1585
|
+
{
|
|
1586
|
+
#if (defined(GRAPHICS_API_OPENGL_33) && defined(RLGL_RENDER_TEXTURES_HINT))
|
|
1587
|
+
// NOTE: Maximum number of draw buffers supported is implementation dependant,
|
|
1588
|
+
// it can be queried with glGet*() but it must be at least 8
|
|
1589
|
+
//GLint maxDrawBuffers = 0;
|
|
1590
|
+
//glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
|
|
1591
|
+
|
|
1592
|
+
if (count > 0)
|
|
1593
|
+
{
|
|
1594
|
+
if (count > 8) TRACELOG(LOG_WARNING, "GL: Max color buffers limited to 8");
|
|
1595
|
+
else
|
|
1596
|
+
{
|
|
1597
|
+
unsigned int buffers[8] = {
|
|
1598
|
+
GL_COLOR_ATTACHMENT0,
|
|
1599
|
+
GL_COLOR_ATTACHMENT1,
|
|
1600
|
+
GL_COLOR_ATTACHMENT2,
|
|
1601
|
+
GL_COLOR_ATTACHMENT3,
|
|
1602
|
+
GL_COLOR_ATTACHMENT4,
|
|
1603
|
+
GL_COLOR_ATTACHMENT5,
|
|
1604
|
+
GL_COLOR_ATTACHMENT6,
|
|
1605
|
+
GL_COLOR_ATTACHMENT7,
|
|
1606
|
+
};
|
|
1607
|
+
|
|
1608
|
+
glDrawBuffers(count, buffers);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
else TRACELOG(LOG_WARNING, "GL: One color buffer active by default");
|
|
1612
|
+
#endif
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
//----------------------------------------------------------------------------------
|
|
1616
|
+
// General render state configuration
|
|
1617
|
+
//----------------------------------------------------------------------------------
|
|
1618
|
+
|
|
1619
|
+
// Enable color blending
|
|
1620
|
+
void rlEnableColorBlend(void) { glEnable(GL_BLEND); }
|
|
1621
|
+
|
|
1622
|
+
// Disable color blending
|
|
1623
|
+
void rlDisableColorBlend(void) { glDisable(GL_BLEND); }
|
|
1624
|
+
|
|
1625
|
+
// Enable depth test
|
|
1626
|
+
void rlEnableDepthTest(void) { glEnable(GL_DEPTH_TEST); }
|
|
1627
|
+
|
|
1628
|
+
// Disable depth test
|
|
1629
|
+
void rlDisableDepthTest(void) { glDisable(GL_DEPTH_TEST); }
|
|
1630
|
+
|
|
1631
|
+
// Enable depth write
|
|
1632
|
+
void rlEnableDepthMask(void) { glDepthMask(GL_TRUE); }
|
|
1633
|
+
|
|
1634
|
+
// Disable depth write
|
|
1635
|
+
void rlDisableDepthMask(void) { glDepthMask(GL_FALSE); }
|
|
1636
|
+
|
|
1637
|
+
// Enable backface culling
|
|
1638
|
+
void rlEnableBackfaceCulling(void) { glEnable(GL_CULL_FACE); }
|
|
1639
|
+
|
|
1640
|
+
// Disable backface culling
|
|
1641
|
+
void rlDisableBackfaceCulling(void) { glDisable(GL_CULL_FACE); }
|
|
1642
|
+
|
|
1643
|
+
// Enable scissor test
|
|
1644
|
+
void rlEnableScissorTest(void) { glEnable(GL_SCISSOR_TEST); }
|
|
1645
|
+
|
|
1646
|
+
// Disable scissor test
|
|
1647
|
+
void rlDisableScissorTest(void) { glDisable(GL_SCISSOR_TEST); }
|
|
1648
|
+
|
|
1649
|
+
// Scissor test
|
|
1650
|
+
void rlScissor(int x, int y, int width, int height) { glScissor(x, y, width, height); }
|
|
1651
|
+
|
|
1652
|
+
// Enable wire mode
|
|
1653
|
+
void rlEnableWireMode(void)
|
|
1654
|
+
{
|
|
1655
|
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
|
1656
|
+
// NOTE: glPolygonMode() not available on OpenGL ES
|
|
1657
|
+
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
1658
|
+
#endif
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
// Disable wire mode
|
|
1662
|
+
void rlDisableWireMode(void)
|
|
1663
|
+
{
|
|
1664
|
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
|
1665
|
+
// NOTE: glPolygonMode() not available on OpenGL ES
|
|
1666
|
+
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
1667
|
+
#endif
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// Set the line drawing width
|
|
1671
|
+
void rlSetLineWidth(float width) { glLineWidth(width); }
|
|
1672
|
+
|
|
1673
|
+
// Get the line drawing width
|
|
1674
|
+
float rlGetLineWidth(void)
|
|
1675
|
+
{
|
|
1676
|
+
float width = 0;
|
|
1677
|
+
glGetFloatv(GL_LINE_WIDTH, &width);
|
|
1678
|
+
return width;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
// Enable line aliasing
|
|
1682
|
+
void rlEnableSmoothLines(void)
|
|
1683
|
+
{
|
|
1684
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_11)
|
|
1685
|
+
glEnable(GL_LINE_SMOOTH);
|
|
1686
|
+
#endif
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// Disable line aliasing
|
|
1690
|
+
void rlDisableSmoothLines(void)
|
|
1691
|
+
{
|
|
1692
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_11)
|
|
1693
|
+
glDisable(GL_LINE_SMOOTH);
|
|
1694
|
+
#endif
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// Enable stereo rendering
|
|
1698
|
+
void rlEnableStereoRender(void)
|
|
1699
|
+
{
|
|
1700
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2))
|
|
1701
|
+
RLGL.State.stereoRender = true;
|
|
1702
|
+
#endif
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
// Disable stereo rendering
|
|
1706
|
+
void rlDisableStereoRender(void)
|
|
1707
|
+
{
|
|
1708
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2))
|
|
1709
|
+
RLGL.State.stereoRender = false;
|
|
1710
|
+
#endif
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// Check if stereo render is enabled
|
|
1714
|
+
bool rlIsStereoRenderEnabled(void)
|
|
1715
|
+
{
|
|
1716
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2))
|
|
1717
|
+
return RLGL.State.stereoRender;
|
|
1718
|
+
#else
|
|
1719
|
+
return false;
|
|
1720
|
+
#endif
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// Clear color buffer with color
|
|
1724
|
+
void rlClearColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
|
|
1725
|
+
{
|
|
1726
|
+
// Color values clamp to 0.0f(0) and 1.0f(255)
|
|
1727
|
+
float cr = (float)r/255;
|
|
1728
|
+
float cg = (float)g/255;
|
|
1729
|
+
float cb = (float)b/255;
|
|
1730
|
+
float ca = (float)a/255;
|
|
1731
|
+
|
|
1732
|
+
glClearColor(cr, cg, cb, ca);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// Clear used screen buffers (color and depth)
|
|
1736
|
+
void rlClearScreenBuffers(void)
|
|
1737
|
+
{
|
|
1738
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear used buffers: Color and Depth (Depth is used for 3D)
|
|
1739
|
+
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Stencil buffer not used...
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
// Check and log OpenGL error codes
|
|
1743
|
+
void rlCheckErrors()
|
|
1744
|
+
{
|
|
1745
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1746
|
+
int check = 1;
|
|
1747
|
+
while (check)
|
|
1748
|
+
{
|
|
1749
|
+
const GLenum err = glGetError();
|
|
1750
|
+
switch (err)
|
|
1751
|
+
{
|
|
1752
|
+
case GL_NO_ERROR: check = 0; break;
|
|
1753
|
+
case 0x0500: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_INVALID_ENUM"); break;
|
|
1754
|
+
case 0x0501: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_INVALID_VALUE"); break;
|
|
1755
|
+
case 0x0502: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_INVALID_OPERATION"); break;
|
|
1756
|
+
case 0x0503: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_STACK_OVERFLOW"); break;
|
|
1757
|
+
case 0x0504: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_STACK_UNDERFLOW"); break;
|
|
1758
|
+
case 0x0505: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_OUT_OF_MEMORY"); break;
|
|
1759
|
+
case 0x0506: TRACELOG(RL_LOG_WARNING, "GL: Error detected: GL_INVALID_FRAMEBUFFER_OPERATION"); break;
|
|
1760
|
+
default: TRACELOG(RL_LOG_WARNING, "GL: Error detected: Unknown error code: %x", err); break;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
#endif
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
// Set blend mode
|
|
1767
|
+
void rlSetBlendMode(int mode)
|
|
1768
|
+
{
|
|
1769
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1770
|
+
if (RLGL.State.currentBlendMode != mode)
|
|
1771
|
+
{
|
|
1772
|
+
rlDrawRenderBatch(RLGL.currentBatch);
|
|
1773
|
+
|
|
1774
|
+
switch (mode)
|
|
1775
|
+
{
|
|
1776
|
+
case RL_BLEND_ALPHA: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
|
|
1777
|
+
case RL_BLEND_ADDITIVE: glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
|
|
1778
|
+
case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
|
|
1779
|
+
case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
|
|
1780
|
+
case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break;
|
|
1781
|
+
case RL_BLEND_CUSTOM: glBlendFunc(RLGL.State.glBlendSrcFactor, RLGL.State.glBlendDstFactor); glBlendEquation(RLGL.State.glBlendEquation); break;
|
|
1782
|
+
default: break;
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
RLGL.State.currentBlendMode = mode;
|
|
1786
|
+
}
|
|
1787
|
+
#endif
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
// Set blending mode factor and equation
|
|
1791
|
+
void rlSetBlendFactors(int glSrcFactor, int glDstFactor, int glEquation)
|
|
1792
|
+
{
|
|
1793
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1794
|
+
RLGL.State.glBlendSrcFactor = glSrcFactor;
|
|
1795
|
+
RLGL.State.glBlendDstFactor = glDstFactor;
|
|
1796
|
+
RLGL.State.glBlendEquation = glEquation;
|
|
1797
|
+
#endif
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
//----------------------------------------------------------------------------------
|
|
1801
|
+
// Module Functions Definition - OpenGL Debug
|
|
1802
|
+
//----------------------------------------------------------------------------------
|
|
1803
|
+
#if defined(RLGL_ENABLE_OPENGL_DEBUG_CONTEXT) && defined(GRAPHICS_API_OPENGL_43)
|
|
1804
|
+
static void GLAPIENTRY rlDebugMessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
|
|
1805
|
+
{
|
|
1806
|
+
// Ignore non-significant error/warning codes (NVidia drivers)
|
|
1807
|
+
// NOTE: Here there are the details with a sample output:
|
|
1808
|
+
// - #131169 - Framebuffer detailed info: The driver allocated storage for renderbuffer 2. (severity: low)
|
|
1809
|
+
// - #131185 - Buffer detailed info: Buffer object 1 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_ENUM_88e4)
|
|
1810
|
+
// will use VIDEO memory as the source for buffer object operations. (severity: low)
|
|
1811
|
+
// - #131218 - Program/shader state performance warning: Vertex shader in program 7 is being recompiled based on GL state. (severity: medium)
|
|
1812
|
+
// - #131204 - Texture state usage warning: The texture object (0) bound to texture image unit 0 does not have
|
|
1813
|
+
// a defined base level and cannot be used for texture mapping. (severity: low)
|
|
1814
|
+
if ((id == 131169) || (id == 131185) || (id == 131218) || (id == 131204)) return;
|
|
1815
|
+
|
|
1816
|
+
const char *msgSource = NULL;
|
|
1817
|
+
switch (source)
|
|
1818
|
+
{
|
|
1819
|
+
case GL_DEBUG_SOURCE_API: msgSource = "API"; break;
|
|
1820
|
+
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: msgSource = "WINDOW_SYSTEM"; break;
|
|
1821
|
+
case GL_DEBUG_SOURCE_SHADER_COMPILER: msgSource = "SHADER_COMPILER"; break;
|
|
1822
|
+
case GL_DEBUG_SOURCE_THIRD_PARTY: msgSource = "THIRD_PARTY"; break;
|
|
1823
|
+
case GL_DEBUG_SOURCE_APPLICATION: msgSource = "APPLICATION"; break;
|
|
1824
|
+
case GL_DEBUG_SOURCE_OTHER: msgSource = "OTHER"; break;
|
|
1825
|
+
default: break;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
const char *msgType = NULL;
|
|
1829
|
+
switch (type)
|
|
1830
|
+
{
|
|
1831
|
+
case GL_DEBUG_TYPE_ERROR: msgType = "ERROR"; break;
|
|
1832
|
+
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: msgType = "DEPRECATED_BEHAVIOR"; break;
|
|
1833
|
+
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: msgType = "UNDEFINED_BEHAVIOR"; break;
|
|
1834
|
+
case GL_DEBUG_TYPE_PORTABILITY: msgType = "PORTABILITY"; break;
|
|
1835
|
+
case GL_DEBUG_TYPE_PERFORMANCE: msgType = "PERFORMANCE"; break;
|
|
1836
|
+
case GL_DEBUG_TYPE_MARKER: msgType = "MARKER"; break;
|
|
1837
|
+
case GL_DEBUG_TYPE_PUSH_GROUP: msgType = "PUSH_GROUP"; break;
|
|
1838
|
+
case GL_DEBUG_TYPE_POP_GROUP: msgType = "POP_GROUP"; break;
|
|
1839
|
+
case GL_DEBUG_TYPE_OTHER: msgType = "OTHER"; break;
|
|
1840
|
+
default: break;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
const char *msgSeverity = "DEFAULT";
|
|
1844
|
+
switch (severity)
|
|
1845
|
+
{
|
|
1846
|
+
case GL_DEBUG_SEVERITY_LOW: msgSeverity = "LOW"; break;
|
|
1847
|
+
case GL_DEBUG_SEVERITY_MEDIUM: msgSeverity = "MEDIUM"; break;
|
|
1848
|
+
case GL_DEBUG_SEVERITY_HIGH: msgSeverity = "HIGH"; break;
|
|
1849
|
+
case GL_DEBUG_SEVERITY_NOTIFICATION: msgSeverity = "NOTIFICATION"; break;
|
|
1850
|
+
default: break;
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
TRACELOG(LOG_WARNING, "GL: OpenGL debug message: %s", message);
|
|
1854
|
+
TRACELOG(LOG_WARNING, " > Type: %s", msgType);
|
|
1855
|
+
TRACELOG(LOG_WARNING, " > Source = %s", msgSource);
|
|
1856
|
+
TRACELOG(LOG_WARNING, " > Severity = %s", msgSeverity);
|
|
1857
|
+
}
|
|
1858
|
+
#endif
|
|
1859
|
+
|
|
1860
|
+
//----------------------------------------------------------------------------------
|
|
1861
|
+
// Module Functions Definition - rlgl functionality
|
|
1862
|
+
//----------------------------------------------------------------------------------
|
|
1863
|
+
|
|
1864
|
+
// Initialize rlgl: OpenGL extensions, default buffers/shaders/textures, OpenGL states
|
|
1865
|
+
void rlglInit(int width, int height)
|
|
1866
|
+
{
|
|
1867
|
+
// Enable OpenGL debug context if required
|
|
1868
|
+
#if defined(RLGL_ENABLE_OPENGL_DEBUG_CONTEXT) && defined(GRAPHICS_API_OPENGL_43)
|
|
1869
|
+
if ((glDebugMessageCallback != NULL) && (glDebugMessageControl != NULL))
|
|
1870
|
+
{
|
|
1871
|
+
glDebugMessageCallback(rlDebugMessageCallback, 0);
|
|
1872
|
+
// glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DEBUG_SEVERITY_HIGH, 0, 0, GL_TRUE); // TODO: Filter message
|
|
1873
|
+
|
|
1874
|
+
// Debug context options:
|
|
1875
|
+
// - GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
|
|
1876
|
+
// - GL_DEBUG_OUTPUT_SYNCHRONUS - Callback is in sync with errors, so a breakpoint can be placed on the callback in order to get a stacktrace for the GL error
|
|
1877
|
+
glEnable(GL_DEBUG_OUTPUT);
|
|
1878
|
+
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
|
1879
|
+
}
|
|
1880
|
+
#endif
|
|
1881
|
+
|
|
1882
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1883
|
+
// Init default white texture
|
|
1884
|
+
unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
|
|
1885
|
+
RLGL.State.defaultTextureId = rlLoadTexture(pixels, 1, 1, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
|
|
1886
|
+
|
|
1887
|
+
if (RLGL.State.defaultTextureId != 0) TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture loaded successfully", RLGL.State.defaultTextureId);
|
|
1888
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to load default texture");
|
|
1889
|
+
|
|
1890
|
+
// Init default Shader (customized for GL 3.3 and ES2)
|
|
1891
|
+
// Loaded: RLGL.State.defaultShaderId + RLGL.State.defaultShaderLocs
|
|
1892
|
+
rlLoadShaderDefault();
|
|
1893
|
+
RLGL.State.currentShaderId = RLGL.State.defaultShaderId;
|
|
1894
|
+
RLGL.State.currentShaderLocs = RLGL.State.defaultShaderLocs;
|
|
1895
|
+
|
|
1896
|
+
// Init default vertex arrays buffers
|
|
1897
|
+
RLGL.defaultBatch = rlLoadRenderBatch(RL_DEFAULT_BATCH_BUFFERS, RL_DEFAULT_BATCH_BUFFER_ELEMENTS);
|
|
1898
|
+
RLGL.currentBatch = &RLGL.defaultBatch;
|
|
1899
|
+
|
|
1900
|
+
// Init stack matrices (emulating OpenGL 1.1)
|
|
1901
|
+
for (int i = 0; i < RL_MAX_MATRIX_STACK_SIZE; i++) RLGL.State.stack[i] = rlMatrixIdentity();
|
|
1902
|
+
|
|
1903
|
+
// Init internal matrices
|
|
1904
|
+
RLGL.State.transform = rlMatrixIdentity();
|
|
1905
|
+
RLGL.State.projection = rlMatrixIdentity();
|
|
1906
|
+
RLGL.State.modelview = rlMatrixIdentity();
|
|
1907
|
+
RLGL.State.currentMatrix = &RLGL.State.modelview;
|
|
1908
|
+
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
|
1909
|
+
|
|
1910
|
+
// Initialize OpenGL default states
|
|
1911
|
+
//----------------------------------------------------------
|
|
1912
|
+
// Init state: Depth test
|
|
1913
|
+
glDepthFunc(GL_LEQUAL); // Type of depth testing to apply
|
|
1914
|
+
glDisable(GL_DEPTH_TEST); // Disable depth testing for 2D (only used for 3D)
|
|
1915
|
+
|
|
1916
|
+
// Init state: Blending mode
|
|
1917
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Color blending function (how colors are mixed)
|
|
1918
|
+
glEnable(GL_BLEND); // Enable color blending (required to work with transparencies)
|
|
1919
|
+
|
|
1920
|
+
// Init state: Culling
|
|
1921
|
+
// NOTE: All shapes/models triangles are drawn CCW
|
|
1922
|
+
glCullFace(GL_BACK); // Cull the back face (default)
|
|
1923
|
+
glFrontFace(GL_CCW); // Front face are defined counter clockwise (default)
|
|
1924
|
+
glEnable(GL_CULL_FACE); // Enable backface culling
|
|
1925
|
+
|
|
1926
|
+
// Init state: Cubemap seamless
|
|
1927
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
1928
|
+
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // Seamless cubemaps (not supported on OpenGL ES 2.0)
|
|
1929
|
+
#endif
|
|
1930
|
+
|
|
1931
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
1932
|
+
// Init state: Color hints (deprecated in OpenGL 3.0+)
|
|
1933
|
+
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Improve quality of color and texture coordinate interpolation
|
|
1934
|
+
glShadeModel(GL_SMOOTH); // Smooth shading between vertex (vertex colors interpolation)
|
|
1935
|
+
#endif
|
|
1936
|
+
|
|
1937
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1938
|
+
// Store screen size into global variables
|
|
1939
|
+
RLGL.State.framebufferWidth = width;
|
|
1940
|
+
RLGL.State.framebufferHeight = height;
|
|
1941
|
+
|
|
1942
|
+
TRACELOG(RL_LOG_INFO, "RLGL: Default OpenGL state initialized successfully");
|
|
1943
|
+
//----------------------------------------------------------
|
|
1944
|
+
#endif
|
|
1945
|
+
|
|
1946
|
+
// Init state: Color/Depth buffers clear
|
|
1947
|
+
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set clear color (black)
|
|
1948
|
+
glClearDepth(1.0f); // Set clear depth value (default)
|
|
1949
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers (depth buffer required for 3D)
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
// Vertex Buffer Object deinitialization (memory free)
|
|
1953
|
+
void rlglClose(void)
|
|
1954
|
+
{
|
|
1955
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
1956
|
+
rlUnloadRenderBatch(RLGL.defaultBatch);
|
|
1957
|
+
|
|
1958
|
+
rlUnloadShaderDefault(); // Unload default shader
|
|
1959
|
+
|
|
1960
|
+
glDeleteTextures(1, &RLGL.State.defaultTextureId); // Unload default texture
|
|
1961
|
+
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Default texture unloaded successfully", RLGL.State.defaultTextureId);
|
|
1962
|
+
#endif
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
// Load OpenGL extensions
|
|
1966
|
+
// NOTE: External loader function must be provided
|
|
1967
|
+
void rlLoadExtensions(void *loader)
|
|
1968
|
+
{
|
|
1969
|
+
#if defined(GRAPHICS_API_OPENGL_33) // Also defined for GRAPHICS_API_OPENGL_21
|
|
1970
|
+
// NOTE: glad is generated and contains only required OpenGL 3.3 Core extensions (and lower versions)
|
|
1971
|
+
#if !defined(__APPLE__)
|
|
1972
|
+
if (gladLoadGL((GLADloadfunc)loader) == 0) TRACELOG(RL_LOG_WARNING, "GLAD: Cannot load OpenGL extensions");
|
|
1973
|
+
else TRACELOG(RL_LOG_INFO, "GLAD: OpenGL extensions loaded successfully");
|
|
1974
|
+
#endif
|
|
1975
|
+
|
|
1976
|
+
// Get number of supported extensions
|
|
1977
|
+
GLint numExt = 0;
|
|
1978
|
+
glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);
|
|
1979
|
+
TRACELOG(RL_LOG_INFO, "GL: Supported extensions count: %i", numExt);
|
|
1980
|
+
|
|
1981
|
+
#if defined(RLGL_SHOW_GL_DETAILS_INFO)
|
|
1982
|
+
// Get supported extensions list
|
|
1983
|
+
// WARNING: glGetStringi() not available on OpenGL 2.1
|
|
1984
|
+
TRACELOG(RL_LOG_INFO, "GL: OpenGL extensions:");
|
|
1985
|
+
for (int i = 0; i < numExt; i++) TRACELOG(RL_LOG_INFO, " %s", glGetStringi(GL_EXTENSIONS, i));
|
|
1986
|
+
#endif
|
|
1987
|
+
|
|
1988
|
+
// Register supported extensions flags
|
|
1989
|
+
// OpenGL 3.3 extensions supported by default (core)
|
|
1990
|
+
RLGL.ExtSupported.vao = true;
|
|
1991
|
+
RLGL.ExtSupported.instancing = true;
|
|
1992
|
+
RLGL.ExtSupported.texNPOT = true;
|
|
1993
|
+
RLGL.ExtSupported.texFloat32 = true;
|
|
1994
|
+
RLGL.ExtSupported.texDepth = true;
|
|
1995
|
+
RLGL.ExtSupported.maxDepthBits = 32;
|
|
1996
|
+
RLGL.ExtSupported.texAnisoFilter = true;
|
|
1997
|
+
RLGL.ExtSupported.texMirrorClamp = true;
|
|
1998
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
1999
|
+
if (GLAD_GL_ARB_compute_shader) RLGL.ExtSupported.computeShader = true;
|
|
2000
|
+
if (GLAD_GL_ARB_shader_storage_buffer_object) RLGL.ExtSupported.ssbo = true;
|
|
2001
|
+
#endif
|
|
2002
|
+
#if !defined(__APPLE__)
|
|
2003
|
+
// NOTE: With GLAD, we can check if an extension is supported using the GLAD_GL_xxx booleans
|
|
2004
|
+
if (GLAD_GL_EXT_texture_compression_s3tc) RLGL.ExtSupported.texCompDXT = true; // Texture compression: DXT
|
|
2005
|
+
if (GLAD_GL_ARB_ES3_compatibility) RLGL.ExtSupported.texCompETC2 = true; // Texture compression: ETC2/EAC
|
|
2006
|
+
#endif
|
|
2007
|
+
#endif // GRAPHICS_API_OPENGL_33
|
|
2008
|
+
|
|
2009
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2010
|
+
// Get supported extensions list
|
|
2011
|
+
GLint numExt = 0;
|
|
2012
|
+
const char **extList = RL_MALLOC(512*sizeof(const char *)); // Allocate 512 strings pointers (2 KB)
|
|
2013
|
+
const char *extensions = (const char *)glGetString(GL_EXTENSIONS); // One big const string
|
|
2014
|
+
|
|
2015
|
+
// NOTE: We have to duplicate string because glGetString() returns a const string
|
|
2016
|
+
int size = strlen(extensions) + 1; // Get extensions string size in bytes
|
|
2017
|
+
char *extensionsDup = (char *)RL_CALLOC(size, sizeof(char));
|
|
2018
|
+
strcpy(extensionsDup, extensions);
|
|
2019
|
+
extList[numExt] = extensionsDup;
|
|
2020
|
+
|
|
2021
|
+
for (int i = 0; i < size; i++)
|
|
2022
|
+
{
|
|
2023
|
+
if (extensionsDup[i] == ' ')
|
|
2024
|
+
{
|
|
2025
|
+
extensionsDup[i] = '\0';
|
|
2026
|
+
numExt++;
|
|
2027
|
+
extList[numExt] = &extensionsDup[i + 1];
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
TRACELOG(RL_LOG_INFO, "GL: Supported extensions count: %i", numExt);
|
|
2032
|
+
|
|
2033
|
+
#if defined(RLGL_SHOW_GL_DETAILS_INFO)
|
|
2034
|
+
TRACELOG(RL_LOG_INFO, "GL: OpenGL extensions:");
|
|
2035
|
+
for (int i = 0; i < numExt; i++) TRACELOG(RL_LOG_INFO, " %s", extList[i]);
|
|
2036
|
+
#endif
|
|
2037
|
+
|
|
2038
|
+
// Check required extensions
|
|
2039
|
+
for (int i = 0; i < numExt; i++)
|
|
2040
|
+
{
|
|
2041
|
+
// Check VAO support
|
|
2042
|
+
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
|
|
2043
|
+
if (strcmp(extList[i], (const char *)"GL_OES_vertex_array_object") == 0)
|
|
2044
|
+
{
|
|
2045
|
+
// The extension is supported by our hardware and driver, try to get related functions pointers
|
|
2046
|
+
// NOTE: emscripten does not support VAOs natively, it uses emulation and it reduces overall performance...
|
|
2047
|
+
glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)((rlglLoadProc)loader)("glGenVertexArraysOES");
|
|
2048
|
+
glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)((rlglLoadProc)loader)("glBindVertexArrayOES");
|
|
2049
|
+
glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)((rlglLoadProc)loader)("glDeleteVertexArraysOES");
|
|
2050
|
+
//glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)loader("glIsVertexArrayOES"); // NOTE: Fails in WebGL, omitted
|
|
2051
|
+
|
|
2052
|
+
if ((glGenVertexArrays != NULL) && (glBindVertexArray != NULL) && (glDeleteVertexArrays != NULL)) RLGL.ExtSupported.vao = true;
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
// Check instanced rendering support
|
|
2056
|
+
if (strcmp(extList[i], (const char *)"GL_ANGLE_instanced_arrays") == 0) // Web ANGLE
|
|
2057
|
+
{
|
|
2058
|
+
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawArraysInstancedANGLE");
|
|
2059
|
+
glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawElementsInstancedANGLE");
|
|
2060
|
+
glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISOREXTPROC)((rlglLoadProc)loader)("glVertexAttribDivisorANGLE");
|
|
2061
|
+
|
|
2062
|
+
if ((glDrawArraysInstanced != NULL) && (glDrawElementsInstanced != NULL) && (glVertexAttribDivisor != NULL)) RLGL.ExtSupported.instancing = true;
|
|
2063
|
+
}
|
|
2064
|
+
else
|
|
2065
|
+
{
|
|
2066
|
+
if ((strcmp(extList[i], (const char *)"GL_EXT_draw_instanced") == 0) && // Standard EXT
|
|
2067
|
+
(strcmp(extList[i], (const char *)"GL_EXT_instanced_arrays") == 0))
|
|
2068
|
+
{
|
|
2069
|
+
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawArraysInstancedEXT");
|
|
2070
|
+
glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawElementsInstancedEXT");
|
|
2071
|
+
glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISOREXTPROC)((rlglLoadProc)loader)("glVertexAttribDivisorEXT");
|
|
2072
|
+
|
|
2073
|
+
if ((glDrawArraysInstanced != NULL) && (glDrawElementsInstanced != NULL) && (glVertexAttribDivisor != NULL)) RLGL.ExtSupported.instancing = true;
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
// Check NPOT textures support
|
|
2078
|
+
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
|
|
2079
|
+
if (strcmp(extList[i], (const char *)"GL_OES_texture_npot") == 0) RLGL.ExtSupported.texNPOT = true;
|
|
2080
|
+
|
|
2081
|
+
// Check texture float support
|
|
2082
|
+
if (strcmp(extList[i], (const char *)"GL_OES_texture_float") == 0) RLGL.ExtSupported.texFloat32 = true;
|
|
2083
|
+
|
|
2084
|
+
// Check depth texture support
|
|
2085
|
+
if ((strcmp(extList[i], (const char *)"GL_OES_depth_texture") == 0) ||
|
|
2086
|
+
(strcmp(extList[i], (const char *)"GL_WEBGL_depth_texture") == 0)) RLGL.ExtSupported.texDepth = true;
|
|
2087
|
+
|
|
2088
|
+
if (strcmp(extList[i], (const char *)"GL_OES_depth24") == 0) RLGL.ExtSupported.maxDepthBits = 24;
|
|
2089
|
+
if (strcmp(extList[i], (const char *)"GL_OES_depth32") == 0) RLGL.ExtSupported.maxDepthBits = 32;
|
|
2090
|
+
|
|
2091
|
+
// Check texture compression support: DXT
|
|
2092
|
+
if ((strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) ||
|
|
2093
|
+
(strcmp(extList[i], (const char *)"GL_WEBGL_compressed_texture_s3tc") == 0) ||
|
|
2094
|
+
(strcmp(extList[i], (const char *)"GL_WEBKIT_WEBGL_compressed_texture_s3tc") == 0)) RLGL.ExtSupported.texCompDXT = true;
|
|
2095
|
+
|
|
2096
|
+
// Check texture compression support: ETC1
|
|
2097
|
+
if ((strcmp(extList[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) ||
|
|
2098
|
+
(strcmp(extList[i], (const char *)"GL_WEBGL_compressed_texture_etc1") == 0)) RLGL.ExtSupported.texCompETC1 = true;
|
|
2099
|
+
|
|
2100
|
+
// Check texture compression support: ETC2/EAC
|
|
2101
|
+
if (strcmp(extList[i], (const char *)"GL_ARB_ES3_compatibility") == 0) RLGL.ExtSupported.texCompETC2 = true;
|
|
2102
|
+
|
|
2103
|
+
// Check texture compression support: PVR
|
|
2104
|
+
if (strcmp(extList[i], (const char *)"GL_IMG_texture_compression_pvrtc") == 0) RLGL.ExtSupported.texCompPVRT = true;
|
|
2105
|
+
|
|
2106
|
+
// Check texture compression support: ASTC
|
|
2107
|
+
if (strcmp(extList[i], (const char *)"GL_KHR_texture_compression_astc_hdr") == 0) RLGL.ExtSupported.texCompASTC = true;
|
|
2108
|
+
|
|
2109
|
+
// Check anisotropic texture filter support
|
|
2110
|
+
if (strcmp(extList[i], (const char *)"GL_EXT_texture_filter_anisotropic") == 0) RLGL.ExtSupported.texAnisoFilter = true;
|
|
2111
|
+
|
|
2112
|
+
// Check clamp mirror wrap mode support
|
|
2113
|
+
if (strcmp(extList[i], (const char *)"GL_EXT_texture_mirror_clamp") == 0) RLGL.ExtSupported.texMirrorClamp = true;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
// Free extensions pointers
|
|
2117
|
+
RL_FREE(extList);
|
|
2118
|
+
RL_FREE(extensionsDup); // Duplicated string must be deallocated
|
|
2119
|
+
#endif // GRAPHICS_API_OPENGL_ES2
|
|
2120
|
+
|
|
2121
|
+
// Check OpenGL information and capabilities
|
|
2122
|
+
//------------------------------------------------------------------------------
|
|
2123
|
+
// Show current OpenGL and GLSL version
|
|
2124
|
+
TRACELOG(RL_LOG_INFO, "GL: OpenGL device information:");
|
|
2125
|
+
TRACELOG(RL_LOG_INFO, " > Vendor: %s", glGetString(GL_VENDOR));
|
|
2126
|
+
TRACELOG(RL_LOG_INFO, " > Renderer: %s", glGetString(GL_RENDERER));
|
|
2127
|
+
TRACELOG(RL_LOG_INFO, " > Version: %s", glGetString(GL_VERSION));
|
|
2128
|
+
TRACELOG(RL_LOG_INFO, " > GLSL: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
|
|
2129
|
+
|
|
2130
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2131
|
+
// NOTE: Anisotropy levels capability is an extension
|
|
2132
|
+
#ifndef GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
|
|
2133
|
+
#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
|
2134
|
+
#endif
|
|
2135
|
+
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &RLGL.ExtSupported.maxAnisotropyLevel);
|
|
2136
|
+
|
|
2137
|
+
#if defined(RLGL_SHOW_GL_DETAILS_INFO)
|
|
2138
|
+
// Show some OpenGL GPU capabilities
|
|
2139
|
+
TRACELOG(RL_LOG_INFO, "GL: OpenGL capabilities:");
|
|
2140
|
+
GLint capability = 0;
|
|
2141
|
+
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &capability);
|
|
2142
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_TEXTURE_SIZE: %i", capability);
|
|
2143
|
+
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &capability);
|
|
2144
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_CUBE_MAP_TEXTURE_SIZE: %i", capability);
|
|
2145
|
+
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &capability);
|
|
2146
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_TEXTURE_IMAGE_UNITS: %i", capability);
|
|
2147
|
+
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &capability);
|
|
2148
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_VERTEX_ATTRIBS: %i", capability);
|
|
2149
|
+
#if !defined(GRAPHICS_API_OPENGL_ES2)
|
|
2150
|
+
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &capability);
|
|
2151
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_UNIFORM_BLOCK_SIZE: %i", capability);
|
|
2152
|
+
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &capability);
|
|
2153
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_DRAW_BUFFERS: %i", capability);
|
|
2154
|
+
if (RLGL.ExtSupported.texAnisoFilter) TRACELOG(RL_LOG_INFO, " GL_MAX_TEXTURE_MAX_ANISOTROPY: %.0f", RLGL.ExtSupported.maxAnisotropyLevel);
|
|
2155
|
+
#endif
|
|
2156
|
+
glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &capability);
|
|
2157
|
+
TRACELOG(RL_LOG_INFO, " GL_NUM_COMPRESSED_TEXTURE_FORMATS: %i", capability);
|
|
2158
|
+
GLint *compFormats = (GLint *)RL_CALLOC(capability, sizeof(GLint));
|
|
2159
|
+
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, compFormats);
|
|
2160
|
+
for (int i = 0; i < capability; i++) TRACELOG(RL_LOG_INFO, " %s", rlGetCompressedFormatName(compFormats[i]));
|
|
2161
|
+
RL_FREE(compFormats);
|
|
2162
|
+
|
|
2163
|
+
/*
|
|
2164
|
+
// Following capabilities are only supported by OpenGL 4.3 or greater
|
|
2165
|
+
glGetIntegerv(GL_MAX_VERTEX_ATTRIB_BINDINGS, &capability);
|
|
2166
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_VERTEX_ATTRIB_BINDINGS: %i", capability);
|
|
2167
|
+
glGetIntegerv(GL_MAX_UNIFORM_LOCATIONS, &capability);
|
|
2168
|
+
TRACELOG(RL_LOG_INFO, " GL_MAX_UNIFORM_LOCATIONS: %i", capability);
|
|
2169
|
+
*/
|
|
2170
|
+
#else // RLGL_SHOW_GL_DETAILS_INFO
|
|
2171
|
+
|
|
2172
|
+
// Show some basic info about GL supported features
|
|
2173
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2174
|
+
if (RLGL.ExtSupported.vao) TRACELOG(RL_LOG_INFO, "GL: VAO extension detected, VAO functions loaded successfully");
|
|
2175
|
+
else TRACELOG(RL_LOG_WARNING, "GL: VAO extension not found, VAO not supported");
|
|
2176
|
+
if (RLGL.ExtSupported.texNPOT) TRACELOG(RL_LOG_INFO, "GL: NPOT textures extension detected, full NPOT textures supported");
|
|
2177
|
+
else TRACELOG(RL_LOG_WARNING, "GL: NPOT textures extension not found, limited NPOT support (no-mipmaps, no-repeat)");
|
|
2178
|
+
#endif
|
|
2179
|
+
if (RLGL.ExtSupported.texCompDXT) TRACELOG(RL_LOG_INFO, "GL: DXT compressed textures supported");
|
|
2180
|
+
if (RLGL.ExtSupported.texCompETC1) TRACELOG(RL_LOG_INFO, "GL: ETC1 compressed textures supported");
|
|
2181
|
+
if (RLGL.ExtSupported.texCompETC2) TRACELOG(RL_LOG_INFO, "GL: ETC2/EAC compressed textures supported");
|
|
2182
|
+
if (RLGL.ExtSupported.texCompPVRT) TRACELOG(RL_LOG_INFO, "GL: PVRT compressed textures supported");
|
|
2183
|
+
if (RLGL.ExtSupported.texCompASTC) TRACELOG(RL_LOG_INFO, "GL: ASTC compressed textures supported");
|
|
2184
|
+
if (RLGL.ExtSupported.computeShader) TRACELOG(RL_LOG_INFO, "GL: Compute shaders supported");
|
|
2185
|
+
if (RLGL.ExtSupported.ssbo) TRACELOG(RL_LOG_INFO, "GL: Shader storage buffer objects supported");
|
|
2186
|
+
#endif // RLGL_SHOW_GL_DETAILS_INFO
|
|
2187
|
+
|
|
2188
|
+
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// Get current OpenGL version
|
|
2192
|
+
int rlGetVersion(void)
|
|
2193
|
+
{
|
|
2194
|
+
int glVersion = 0;
|
|
2195
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
2196
|
+
glVersion = OPENGL_11;
|
|
2197
|
+
#endif
|
|
2198
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
2199
|
+
#if defined(__APPLE__)
|
|
2200
|
+
glVersion = OPENGL_33; // NOTE: Force OpenGL 3.3 on OSX
|
|
2201
|
+
#else
|
|
2202
|
+
glVersion = OPENGL_21;
|
|
2203
|
+
#endif
|
|
2204
|
+
#elif defined(GRAPHICS_API_OPENGL_33)
|
|
2205
|
+
glVersion = OPENGL_33;
|
|
2206
|
+
#endif
|
|
2207
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
2208
|
+
glVersion = OPENGL_43;
|
|
2209
|
+
#endif
|
|
2210
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2211
|
+
glVersion = OPENGL_ES_20;
|
|
2212
|
+
#endif
|
|
2213
|
+
return glVersion;
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
// Get default framebuffer width
|
|
2217
|
+
int rlGetFramebufferWidth(void)
|
|
2218
|
+
{
|
|
2219
|
+
int width = 0;
|
|
2220
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2221
|
+
width = RLGL.State.framebufferWidth;
|
|
2222
|
+
#endif
|
|
2223
|
+
return width;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
// Get default framebuffer height
|
|
2227
|
+
int rlGetFramebufferHeight(void)
|
|
2228
|
+
{
|
|
2229
|
+
int height = 0;
|
|
2230
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2231
|
+
height = RLGL.State.framebufferHeight;
|
|
2232
|
+
#endif
|
|
2233
|
+
return height;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
// Get default internal texture (white texture)
|
|
2237
|
+
// NOTE: Default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
|
|
2238
|
+
unsigned int rlGetTextureIdDefault(void)
|
|
2239
|
+
{
|
|
2240
|
+
unsigned int id = 0;
|
|
2241
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2242
|
+
id = RLGL.State.defaultTextureId;
|
|
2243
|
+
#endif
|
|
2244
|
+
return id;
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
// Get default shader id
|
|
2248
|
+
unsigned int rlGetShaderIdDefault(void)
|
|
2249
|
+
{
|
|
2250
|
+
unsigned int id = 0;
|
|
2251
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2252
|
+
id = RLGL.State.defaultShaderId;
|
|
2253
|
+
#endif
|
|
2254
|
+
return id;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
// Get default shader locs
|
|
2258
|
+
int *rlGetShaderLocsDefault(void)
|
|
2259
|
+
{
|
|
2260
|
+
int *locs = NULL;
|
|
2261
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2262
|
+
locs = RLGL.State.defaultShaderLocs;
|
|
2263
|
+
#endif
|
|
2264
|
+
return locs;
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
// Render batch management
|
|
2268
|
+
//------------------------------------------------------------------------------------------------
|
|
2269
|
+
// Load render batch
|
|
2270
|
+
rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
|
|
2271
|
+
{
|
|
2272
|
+
rlRenderBatch batch = { 0 };
|
|
2273
|
+
|
|
2274
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2275
|
+
// Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
|
|
2276
|
+
//--------------------------------------------------------------------------------------------
|
|
2277
|
+
batch.vertexBuffer = (rlVertexBuffer *)RL_MALLOC(numBuffers*sizeof(rlVertexBuffer));
|
|
2278
|
+
|
|
2279
|
+
for (int i = 0; i < numBuffers; i++)
|
|
2280
|
+
{
|
|
2281
|
+
batch.vertexBuffer[i].elementCount = bufferElements;
|
|
2282
|
+
|
|
2283
|
+
batch.vertexBuffer[i].vertices = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
|
|
2284
|
+
batch.vertexBuffer[i].texcoords = (float *)RL_MALLOC(bufferElements*2*4*sizeof(float)); // 2 float by texcoord, 4 texcoord by quad
|
|
2285
|
+
batch.vertexBuffer[i].colors = (unsigned char *)RL_MALLOC(bufferElements*4*4*sizeof(unsigned char)); // 4 float by color, 4 colors by quad
|
|
2286
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2287
|
+
batch.vertexBuffer[i].indices = (unsigned int *)RL_MALLOC(bufferElements*6*sizeof(unsigned int)); // 6 int by quad (indices)
|
|
2288
|
+
#endif
|
|
2289
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2290
|
+
batch.vertexBuffer[i].indices = (unsigned short *)RL_MALLOC(bufferElements*6*sizeof(unsigned short)); // 6 int by quad (indices)
|
|
2291
|
+
#endif
|
|
2292
|
+
|
|
2293
|
+
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].vertices[j] = 0.0f;
|
|
2294
|
+
for (int j = 0; j < (2*4*bufferElements); j++) batch.vertexBuffer[i].texcoords[j] = 0.0f;
|
|
2295
|
+
for (int j = 0; j < (4*4*bufferElements); j++) batch.vertexBuffer[i].colors[j] = 0;
|
|
2296
|
+
|
|
2297
|
+
int k = 0;
|
|
2298
|
+
|
|
2299
|
+
// Indices can be initialized right now
|
|
2300
|
+
for (int j = 0; j < (6*bufferElements); j += 6)
|
|
2301
|
+
{
|
|
2302
|
+
batch.vertexBuffer[i].indices[j] = 4*k;
|
|
2303
|
+
batch.vertexBuffer[i].indices[j + 1] = 4*k + 1;
|
|
2304
|
+
batch.vertexBuffer[i].indices[j + 2] = 4*k + 2;
|
|
2305
|
+
batch.vertexBuffer[i].indices[j + 3] = 4*k;
|
|
2306
|
+
batch.vertexBuffer[i].indices[j + 4] = 4*k + 2;
|
|
2307
|
+
batch.vertexBuffer[i].indices[j + 5] = 4*k + 3;
|
|
2308
|
+
|
|
2309
|
+
k++;
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
RLGL.State.vertexCounter = 0;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
TRACELOG(RL_LOG_INFO, "RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)");
|
|
2316
|
+
//--------------------------------------------------------------------------------------------
|
|
2317
|
+
|
|
2318
|
+
// Upload to GPU (VRAM) vertex data and initialize VAOs/VBOs
|
|
2319
|
+
//--------------------------------------------------------------------------------------------
|
|
2320
|
+
for (int i = 0; i < numBuffers; i++)
|
|
2321
|
+
{
|
|
2322
|
+
if (RLGL.ExtSupported.vao)
|
|
2323
|
+
{
|
|
2324
|
+
// Initialize Quads VAO
|
|
2325
|
+
glGenVertexArrays(1, &batch.vertexBuffer[i].vaoId);
|
|
2326
|
+
glBindVertexArray(batch.vertexBuffer[i].vaoId);
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
// Quads - Vertex buffers binding and attributes enable
|
|
2330
|
+
// Vertex position buffer (shader-location = 0)
|
|
2331
|
+
glGenBuffers(1, &batch.vertexBuffer[i].vboId[0]);
|
|
2332
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[0]);
|
|
2333
|
+
glBufferData(GL_ARRAY_BUFFER, bufferElements*3*4*sizeof(float), batch.vertexBuffer[i].vertices, GL_DYNAMIC_DRAW);
|
|
2334
|
+
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_POSITION]);
|
|
2335
|
+
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
|
|
2336
|
+
|
|
2337
|
+
// Vertex texcoord buffer (shader-location = 1)
|
|
2338
|
+
glGenBuffers(1, &batch.vertexBuffer[i].vboId[1]);
|
|
2339
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[1]);
|
|
2340
|
+
glBufferData(GL_ARRAY_BUFFER, bufferElements*2*4*sizeof(float), batch.vertexBuffer[i].texcoords, GL_DYNAMIC_DRAW);
|
|
2341
|
+
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01]);
|
|
2342
|
+
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
|
2343
|
+
|
|
2344
|
+
// Vertex color buffer (shader-location = 3)
|
|
2345
|
+
glGenBuffers(1, &batch.vertexBuffer[i].vboId[2]);
|
|
2346
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[2]);
|
|
2347
|
+
glBufferData(GL_ARRAY_BUFFER, bufferElements*4*4*sizeof(unsigned char), batch.vertexBuffer[i].colors, GL_DYNAMIC_DRAW);
|
|
2348
|
+
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);
|
|
2349
|
+
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
|
2350
|
+
|
|
2351
|
+
// Fill index buffer
|
|
2352
|
+
glGenBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
|
2353
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.vertexBuffer[i].vboId[3]);
|
|
2354
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2355
|
+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferElements*6*sizeof(int), batch.vertexBuffer[i].indices, GL_STATIC_DRAW);
|
|
2356
|
+
#endif
|
|
2357
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2358
|
+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferElements*6*sizeof(short), batch.vertexBuffer[i].indices, GL_STATIC_DRAW);
|
|
2359
|
+
#endif
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
TRACELOG(RL_LOG_INFO, "RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)");
|
|
2363
|
+
|
|
2364
|
+
// Unbind the current VAO
|
|
2365
|
+
if (RLGL.ExtSupported.vao) glBindVertexArray(0);
|
|
2366
|
+
//--------------------------------------------------------------------------------------------
|
|
2367
|
+
|
|
2368
|
+
// Init draw calls tracking system
|
|
2369
|
+
//--------------------------------------------------------------------------------------------
|
|
2370
|
+
batch.draws = (rlDrawCall *)RL_MALLOC(RL_DEFAULT_BATCH_DRAWCALLS*sizeof(rlDrawCall));
|
|
2371
|
+
|
|
2372
|
+
for (int i = 0; i < RL_DEFAULT_BATCH_DRAWCALLS; i++)
|
|
2373
|
+
{
|
|
2374
|
+
batch.draws[i].mode = RL_QUADS;
|
|
2375
|
+
batch.draws[i].vertexCount = 0;
|
|
2376
|
+
batch.draws[i].vertexAlignment = 0;
|
|
2377
|
+
//batch.draws[i].vaoId = 0;
|
|
2378
|
+
//batch.draws[i].shaderId = 0;
|
|
2379
|
+
batch.draws[i].textureId = RLGL.State.defaultTextureId;
|
|
2380
|
+
//batch.draws[i].RLGL.State.projection = rlMatrixIdentity();
|
|
2381
|
+
//batch.draws[i].RLGL.State.modelview = rlMatrixIdentity();
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
batch.bufferCount = numBuffers; // Record buffer count
|
|
2385
|
+
batch.drawCounter = 1; // Reset draws counter
|
|
2386
|
+
batch.currentDepth = -1.0f; // Reset depth value
|
|
2387
|
+
//--------------------------------------------------------------------------------------------
|
|
2388
|
+
#endif
|
|
2389
|
+
|
|
2390
|
+
return batch;
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
// Unload default internal buffers vertex data from CPU and GPU
|
|
2394
|
+
void rlUnloadRenderBatch(rlRenderBatch batch)
|
|
2395
|
+
{
|
|
2396
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2397
|
+
// Unbind everything
|
|
2398
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
2399
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
2400
|
+
|
|
2401
|
+
// Unload all vertex buffers data
|
|
2402
|
+
for (int i = 0; i < batch.bufferCount; i++)
|
|
2403
|
+
{
|
|
2404
|
+
// Unbind VAO attribs data
|
|
2405
|
+
if (RLGL.ExtSupported.vao)
|
|
2406
|
+
{
|
|
2407
|
+
glBindVertexArray(batch.vertexBuffer[i].vaoId);
|
|
2408
|
+
glDisableVertexAttribArray(0);
|
|
2409
|
+
glDisableVertexAttribArray(1);
|
|
2410
|
+
glDisableVertexAttribArray(2);
|
|
2411
|
+
glDisableVertexAttribArray(3);
|
|
2412
|
+
glBindVertexArray(0);
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
// Delete VBOs from GPU (VRAM)
|
|
2416
|
+
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[0]);
|
|
2417
|
+
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[1]);
|
|
2418
|
+
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[2]);
|
|
2419
|
+
glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[3]);
|
|
2420
|
+
|
|
2421
|
+
// Delete VAOs from GPU (VRAM)
|
|
2422
|
+
if (RLGL.ExtSupported.vao) glDeleteVertexArrays(1, &batch.vertexBuffer[i].vaoId);
|
|
2423
|
+
|
|
2424
|
+
// Free vertex arrays memory from CPU (RAM)
|
|
2425
|
+
RL_FREE(batch.vertexBuffer[i].vertices);
|
|
2426
|
+
RL_FREE(batch.vertexBuffer[i].texcoords);
|
|
2427
|
+
RL_FREE(batch.vertexBuffer[i].colors);
|
|
2428
|
+
RL_FREE(batch.vertexBuffer[i].indices);
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
// Unload arrays
|
|
2432
|
+
RL_FREE(batch.vertexBuffer);
|
|
2433
|
+
RL_FREE(batch.draws);
|
|
2434
|
+
#endif
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
// Draw render batch
|
|
2438
|
+
// NOTE: We require a pointer to reset batch and increase current buffer (multi-buffer)
|
|
2439
|
+
void rlDrawRenderBatch(rlRenderBatch *batch)
|
|
2440
|
+
{
|
|
2441
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2442
|
+
// Update batch vertex buffers
|
|
2443
|
+
//------------------------------------------------------------------------------------------------------------
|
|
2444
|
+
// NOTE: If there is not vertex data, buffers doesn't need to be updated (vertexCount > 0)
|
|
2445
|
+
// TODO: If no data changed on the CPU arrays --> No need to re-update GPU arrays (change flag required)
|
|
2446
|
+
if (RLGL.State.vertexCounter > 0)
|
|
2447
|
+
{
|
|
2448
|
+
// Activate elements VAO
|
|
2449
|
+
if (RLGL.ExtSupported.vao) glBindVertexArray(batch->vertexBuffer[batch->currentBuffer].vaoId);
|
|
2450
|
+
|
|
2451
|
+
// Vertex positions buffer
|
|
2452
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[0]);
|
|
2453
|
+
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*3*sizeof(float), batch->vertexBuffer[batch->currentBuffer].vertices);
|
|
2454
|
+
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer
|
|
2455
|
+
|
|
2456
|
+
// Texture coordinates buffer
|
|
2457
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[1]);
|
|
2458
|
+
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*2*sizeof(float), batch->vertexBuffer[batch->currentBuffer].texcoords);
|
|
2459
|
+
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer
|
|
2460
|
+
|
|
2461
|
+
// Colors buffer
|
|
2462
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]);
|
|
2463
|
+
glBufferSubData(GL_ARRAY_BUFFER, 0, RLGL.State.vertexCounter*4*sizeof(unsigned char), batch->vertexBuffer[batch->currentBuffer].colors);
|
|
2464
|
+
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer
|
|
2465
|
+
|
|
2466
|
+
// NOTE: glMapBuffer() causes sync issue.
|
|
2467
|
+
// If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job.
|
|
2468
|
+
// To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer().
|
|
2469
|
+
// If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new
|
|
2470
|
+
// allocated pointer immediately even if GPU is still working with the previous data.
|
|
2471
|
+
|
|
2472
|
+
// Another option: map the buffer object into client's memory
|
|
2473
|
+
// Probably this code could be moved somewhere else...
|
|
2474
|
+
// batch->vertexBuffer[batch->currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
|
2475
|
+
// if (batch->vertexBuffer[batch->currentBuffer].vertices)
|
|
2476
|
+
// {
|
|
2477
|
+
// Update vertex data
|
|
2478
|
+
// }
|
|
2479
|
+
// glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
2480
|
+
|
|
2481
|
+
// Unbind the current VAO
|
|
2482
|
+
if (RLGL.ExtSupported.vao) glBindVertexArray(0);
|
|
2483
|
+
}
|
|
2484
|
+
//------------------------------------------------------------------------------------------------------------
|
|
2485
|
+
|
|
2486
|
+
// Draw batch vertex buffers (considering VR stereo if required)
|
|
2487
|
+
//------------------------------------------------------------------------------------------------------------
|
|
2488
|
+
Matrix matProjection = RLGL.State.projection;
|
|
2489
|
+
Matrix matModelView = RLGL.State.modelview;
|
|
2490
|
+
|
|
2491
|
+
int eyeCount = 1;
|
|
2492
|
+
if (RLGL.State.stereoRender) eyeCount = 2;
|
|
2493
|
+
|
|
2494
|
+
for (int eye = 0; eye < eyeCount; eye++)
|
|
2495
|
+
{
|
|
2496
|
+
if (eyeCount == 2)
|
|
2497
|
+
{
|
|
2498
|
+
// Setup current eye viewport (half screen width)
|
|
2499
|
+
rlViewport(eye*RLGL.State.framebufferWidth/2, 0, RLGL.State.framebufferWidth/2, RLGL.State.framebufferHeight);
|
|
2500
|
+
|
|
2501
|
+
// Set current eye view offset to modelview matrix
|
|
2502
|
+
rlSetMatrixModelview(rlMatrixMultiply(matModelView, RLGL.State.viewOffsetStereo[eye]));
|
|
2503
|
+
// Set current eye projection matrix
|
|
2504
|
+
rlSetMatrixProjection(RLGL.State.projectionStereo[eye]);
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
// Draw buffers
|
|
2508
|
+
if (RLGL.State.vertexCounter > 0)
|
|
2509
|
+
{
|
|
2510
|
+
// Set current shader and upload current MVP matrix
|
|
2511
|
+
glUseProgram(RLGL.State.currentShaderId);
|
|
2512
|
+
|
|
2513
|
+
// Create modelview-projection matrix and upload to shader
|
|
2514
|
+
Matrix matMVP = rlMatrixMultiply(RLGL.State.modelview, RLGL.State.projection);
|
|
2515
|
+
float matMVPfloat[16] = {
|
|
2516
|
+
matMVP.m0, matMVP.m1, matMVP.m2, matMVP.m3,
|
|
2517
|
+
matMVP.m4, matMVP.m5, matMVP.m6, matMVP.m7,
|
|
2518
|
+
matMVP.m8, matMVP.m9, matMVP.m10, matMVP.m11,
|
|
2519
|
+
matMVP.m12, matMVP.m13, matMVP.m14, matMVP.m15
|
|
2520
|
+
};
|
|
2521
|
+
glUniformMatrix4fv(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MATRIX_MVP], 1, false, matMVPfloat);
|
|
2522
|
+
|
|
2523
|
+
if (RLGL.ExtSupported.vao) glBindVertexArray(batch->vertexBuffer[batch->currentBuffer].vaoId);
|
|
2524
|
+
else
|
|
2525
|
+
{
|
|
2526
|
+
// Bind vertex attrib: position (shader-location = 0)
|
|
2527
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[0]);
|
|
2528
|
+
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_POSITION], 3, GL_FLOAT, 0, 0, 0);
|
|
2529
|
+
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_POSITION]);
|
|
2530
|
+
|
|
2531
|
+
// Bind vertex attrib: texcoord (shader-location = 1)
|
|
2532
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[1]);
|
|
2533
|
+
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01], 2, GL_FLOAT, 0, 0, 0);
|
|
2534
|
+
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01]);
|
|
2535
|
+
|
|
2536
|
+
// Bind vertex attrib: color (shader-location = 3)
|
|
2537
|
+
glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]);
|
|
2538
|
+
glVertexAttribPointer(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR], 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
|
2539
|
+
glEnableVertexAttribArray(RLGL.State.currentShaderLocs[RL_SHADER_LOC_VERTEX_COLOR]);
|
|
2540
|
+
|
|
2541
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[3]);
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
// Setup some default shader values
|
|
2545
|
+
glUniform4f(RLGL.State.currentShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE], 1.0f, 1.0f, 1.0f, 1.0f);
|
|
2546
|
+
glUniform1i(RLGL.State.currentShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE], 0); // Active default sampler2D: texture0
|
|
2547
|
+
|
|
2548
|
+
// Activate additional sampler textures
|
|
2549
|
+
// Those additional textures will be common for all draw calls of the batch
|
|
2550
|
+
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++)
|
|
2551
|
+
{
|
|
2552
|
+
if (RLGL.State.activeTextureId[i] > 0)
|
|
2553
|
+
{
|
|
2554
|
+
glActiveTexture(GL_TEXTURE0 + 1 + i);
|
|
2555
|
+
glBindTexture(GL_TEXTURE_2D, RLGL.State.activeTextureId[i]);
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
// Activate default sampler2D texture0 (one texture is always active for default batch shader)
|
|
2560
|
+
// NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls
|
|
2561
|
+
glActiveTexture(GL_TEXTURE0);
|
|
2562
|
+
|
|
2563
|
+
for (int i = 0, vertexOffset = 0; i < batch->drawCounter; i++)
|
|
2564
|
+
{
|
|
2565
|
+
// Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default
|
|
2566
|
+
glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId);
|
|
2567
|
+
|
|
2568
|
+
if ((batch->draws[i].mode == RL_LINES) || (batch->draws[i].mode == RL_TRIANGLES)) glDrawArrays(batch->draws[i].mode, vertexOffset, batch->draws[i].vertexCount);
|
|
2569
|
+
else
|
|
2570
|
+
{
|
|
2571
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2572
|
+
// We need to define the number of indices to be processed: elementCount*6
|
|
2573
|
+
// NOTE: The final parameter tells the GPU the offset in bytes from the
|
|
2574
|
+
// start of the index buffer to the location of the first index to process
|
|
2575
|
+
glDrawElements(GL_TRIANGLES, batch->draws[i].vertexCount/4*6, GL_UNSIGNED_INT, (GLvoid *)(vertexOffset/4*6*sizeof(GLuint)));
|
|
2576
|
+
#endif
|
|
2577
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2578
|
+
glDrawElements(GL_TRIANGLES, batch->draws[i].vertexCount/4*6, GL_UNSIGNED_SHORT, (GLvoid *)(vertexOffset/4*6*sizeof(GLushort)));
|
|
2579
|
+
#endif
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
vertexOffset += (batch->draws[i].vertexCount + batch->draws[i].vertexAlignment);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
if (!RLGL.ExtSupported.vao)
|
|
2586
|
+
{
|
|
2587
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
2588
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
glBindTexture(GL_TEXTURE_2D, 0); // Unbind textures
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
if (RLGL.ExtSupported.vao) glBindVertexArray(0); // Unbind VAO
|
|
2595
|
+
|
|
2596
|
+
glUseProgram(0); // Unbind shader program
|
|
2597
|
+
}
|
|
2598
|
+
//------------------------------------------------------------------------------------------------------------
|
|
2599
|
+
|
|
2600
|
+
// Reset batch buffers
|
|
2601
|
+
//------------------------------------------------------------------------------------------------------------
|
|
2602
|
+
// Reset vertex counter for next frame
|
|
2603
|
+
RLGL.State.vertexCounter = 0;
|
|
2604
|
+
|
|
2605
|
+
// Reset depth for next draw
|
|
2606
|
+
batch->currentDepth = -1.0f;
|
|
2607
|
+
|
|
2608
|
+
// Restore projection/modelview matrices
|
|
2609
|
+
RLGL.State.projection = matProjection;
|
|
2610
|
+
RLGL.State.modelview = matModelView;
|
|
2611
|
+
|
|
2612
|
+
// Reset RLGL.currentBatch->draws array
|
|
2613
|
+
for (int i = 0; i < RL_DEFAULT_BATCH_DRAWCALLS; i++)
|
|
2614
|
+
{
|
|
2615
|
+
batch->draws[i].mode = RL_QUADS;
|
|
2616
|
+
batch->draws[i].vertexCount = 0;
|
|
2617
|
+
batch->draws[i].textureId = RLGL.State.defaultTextureId;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
// Reset active texture units for next batch
|
|
2621
|
+
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++) RLGL.State.activeTextureId[i] = 0;
|
|
2622
|
+
|
|
2623
|
+
// Reset draws counter to one draw for the batch
|
|
2624
|
+
batch->drawCounter = 1;
|
|
2625
|
+
//------------------------------------------------------------------------------------------------------------
|
|
2626
|
+
|
|
2627
|
+
// Change to next buffer in the list (in case of multi-buffering)
|
|
2628
|
+
batch->currentBuffer++;
|
|
2629
|
+
if (batch->currentBuffer >= batch->bufferCount) batch->currentBuffer = 0;
|
|
2630
|
+
#endif
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
// Set the active render batch for rlgl
|
|
2634
|
+
void rlSetRenderBatchActive(rlRenderBatch *batch)
|
|
2635
|
+
{
|
|
2636
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2637
|
+
rlDrawRenderBatch(RLGL.currentBatch);
|
|
2638
|
+
|
|
2639
|
+
if (batch != NULL) RLGL.currentBatch = batch;
|
|
2640
|
+
else RLGL.currentBatch = &RLGL.defaultBatch;
|
|
2641
|
+
#endif
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2644
|
+
// Update and draw internal render batch
|
|
2645
|
+
void rlDrawRenderBatchActive(void)
|
|
2646
|
+
{
|
|
2647
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2648
|
+
rlDrawRenderBatch(RLGL.currentBatch); // NOTE: Stereo rendering is checked inside
|
|
2649
|
+
#endif
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
// Check internal buffer overflow for a given number of vertex
|
|
2653
|
+
// and force a rlRenderBatch draw call if required
|
|
2654
|
+
bool rlCheckRenderBatchLimit(int vCount)
|
|
2655
|
+
{
|
|
2656
|
+
bool overflow = false;
|
|
2657
|
+
|
|
2658
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2659
|
+
if ((RLGL.State.vertexCounter + vCount) >=
|
|
2660
|
+
(RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4))
|
|
2661
|
+
{
|
|
2662
|
+
int currentMode = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode;
|
|
2663
|
+
int currentTexture = RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId;
|
|
2664
|
+
|
|
2665
|
+
overflow = true;
|
|
2666
|
+
rlDrawRenderBatch(RLGL.currentBatch); // NOTE: Stereo rendering is checked inside
|
|
2667
|
+
|
|
2668
|
+
// Restore state of last batch so we can continue adding vertices
|
|
2669
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = currentMode;
|
|
2670
|
+
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = currentTexture;
|
|
2671
|
+
}
|
|
2672
|
+
#endif
|
|
2673
|
+
|
|
2674
|
+
return overflow;
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
// Textures data management
|
|
2678
|
+
//-----------------------------------------------------------------------------------------
|
|
2679
|
+
// Convert image data to OpenGL texture (returns OpenGL valid Id)
|
|
2680
|
+
unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
|
|
2681
|
+
{
|
|
2682
|
+
glBindTexture(GL_TEXTURE_2D, 0); // Free any old binding
|
|
2683
|
+
|
|
2684
|
+
unsigned int id = 0;
|
|
2685
|
+
|
|
2686
|
+
// Check texture format support by OpenGL 1.1 (compressed textures not supported)
|
|
2687
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
2688
|
+
if (format >= RL_PIXELFORMAT_COMPRESSED_DXT1_RGB)
|
|
2689
|
+
{
|
|
2690
|
+
TRACELOG(RL_LOG_WARNING, "GL: OpenGL 1.1 does not support GPU compressed texture formats");
|
|
2691
|
+
return id;
|
|
2692
|
+
}
|
|
2693
|
+
#else
|
|
2694
|
+
if ((!RLGL.ExtSupported.texCompDXT) && ((format == RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) || (format == RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA) ||
|
|
2695
|
+
(format == RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA) || (format == RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA)))
|
|
2696
|
+
{
|
|
2697
|
+
TRACELOG(RL_LOG_WARNING, "GL: DXT compressed texture format not supported");
|
|
2698
|
+
return id;
|
|
2699
|
+
}
|
|
2700
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2701
|
+
if ((!RLGL.ExtSupported.texCompETC1) && (format == RL_PIXELFORMAT_COMPRESSED_ETC1_RGB))
|
|
2702
|
+
{
|
|
2703
|
+
TRACELOG(RL_LOG_WARNING, "GL: ETC1 compressed texture format not supported");
|
|
2704
|
+
return id;
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
if ((!RLGL.ExtSupported.texCompETC2) && ((format == RL_PIXELFORMAT_COMPRESSED_ETC2_RGB) || (format == RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA)))
|
|
2708
|
+
{
|
|
2709
|
+
TRACELOG(RL_LOG_WARNING, "GL: ETC2 compressed texture format not supported");
|
|
2710
|
+
return id;
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
if ((!RLGL.ExtSupported.texCompPVRT) && ((format == RL_PIXELFORMAT_COMPRESSED_PVRT_RGB) || (format == RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA)))
|
|
2714
|
+
{
|
|
2715
|
+
TRACELOG(RL_LOG_WARNING, "GL: PVRT compressed texture format not supported");
|
|
2716
|
+
return id;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
if ((!RLGL.ExtSupported.texCompASTC) && ((format == RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA) || (format == RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA)))
|
|
2720
|
+
{
|
|
2721
|
+
TRACELOG(RL_LOG_WARNING, "GL: ASTC compressed texture format not supported");
|
|
2722
|
+
return id;
|
|
2723
|
+
}
|
|
2724
|
+
#endif
|
|
2725
|
+
#endif // GRAPHICS_API_OPENGL_11
|
|
2726
|
+
|
|
2727
|
+
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
2728
|
+
|
|
2729
|
+
glGenTextures(1, &id); // Generate texture id
|
|
2730
|
+
|
|
2731
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
2732
|
+
|
|
2733
|
+
int mipWidth = width;
|
|
2734
|
+
int mipHeight = height;
|
|
2735
|
+
int mipOffset = 0; // Mipmap data offset
|
|
2736
|
+
|
|
2737
|
+
// Load the different mipmap levels
|
|
2738
|
+
for (int i = 0; i < mipmapCount; i++)
|
|
2739
|
+
{
|
|
2740
|
+
unsigned int mipSize = rlGetPixelDataSize(mipWidth, mipHeight, format);
|
|
2741
|
+
|
|
2742
|
+
int glInternalFormat, glFormat, glType;
|
|
2743
|
+
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
|
2744
|
+
|
|
2745
|
+
TRACELOGD("TEXTURE: Load mipmap level %i (%i x %i), size: %i, offset: %i", i, mipWidth, mipHeight, mipSize, mipOffset);
|
|
2746
|
+
|
|
2747
|
+
if (glInternalFormat != -1)
|
|
2748
|
+
{
|
|
2749
|
+
if (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) glTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, glFormat, glType, (unsigned char *)data + mipOffset);
|
|
2750
|
+
#if !defined(GRAPHICS_API_OPENGL_11)
|
|
2751
|
+
else glCompressedTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, mipSize, (unsigned char *)data + mipOffset);
|
|
2752
|
+
#endif
|
|
2753
|
+
|
|
2754
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2755
|
+
if (format == RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
|
|
2756
|
+
{
|
|
2757
|
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
|
|
2758
|
+
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
|
|
2759
|
+
}
|
|
2760
|
+
else if (format == RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA)
|
|
2761
|
+
{
|
|
2762
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
2763
|
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA };
|
|
2764
|
+
#elif defined(GRAPHICS_API_OPENGL_33)
|
|
2765
|
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN };
|
|
2766
|
+
#endif
|
|
2767
|
+
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
|
|
2768
|
+
}
|
|
2769
|
+
#endif
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
mipWidth /= 2;
|
|
2773
|
+
mipHeight /= 2;
|
|
2774
|
+
mipOffset += mipSize;
|
|
2775
|
+
|
|
2776
|
+
// Security check for NPOT textures
|
|
2777
|
+
if (mipWidth < 1) mipWidth = 1;
|
|
2778
|
+
if (mipHeight < 1) mipHeight = 1;
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
// Texture parameters configuration
|
|
2782
|
+
// NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
|
|
2783
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2784
|
+
// NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used
|
|
2785
|
+
if (RLGL.ExtSupported.texNPOT)
|
|
2786
|
+
{
|
|
2787
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
|
|
2788
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
|
|
2789
|
+
}
|
|
2790
|
+
else
|
|
2791
|
+
{
|
|
2792
|
+
// NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
|
|
2793
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Set texture to clamp on x-axis
|
|
2794
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Set texture to clamp on y-axis
|
|
2795
|
+
}
|
|
2796
|
+
#else
|
|
2797
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
|
|
2798
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
|
|
2799
|
+
#endif
|
|
2800
|
+
|
|
2801
|
+
// Magnification and minification filters
|
|
2802
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Alternative: GL_LINEAR
|
|
2803
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Alternative: GL_LINEAR
|
|
2804
|
+
|
|
2805
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2806
|
+
if (mipmapCount > 1)
|
|
2807
|
+
{
|
|
2808
|
+
// Activate Trilinear filtering if mipmaps are available
|
|
2809
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
2810
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
2811
|
+
}
|
|
2812
|
+
#endif
|
|
2813
|
+
|
|
2814
|
+
// At this point we have the texture loaded in GPU and texture parameters configured
|
|
2815
|
+
|
|
2816
|
+
// NOTE: If mipmaps were not in data, they are not generated automatically
|
|
2817
|
+
|
|
2818
|
+
// Unbind current texture
|
|
2819
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
2820
|
+
|
|
2821
|
+
if (id > 0) TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Texture loaded successfully (%ix%i | %s | %i mipmaps)", id, width, height, rlGetPixelFormatName(format), mipmapCount);
|
|
2822
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to load texture");
|
|
2823
|
+
|
|
2824
|
+
return id;
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
// Load depth texture/renderbuffer (to be attached to fbo)
|
|
2828
|
+
// WARNING: OpenGL ES 2.0 requires GL_OES_depth_texture/WEBGL_depth_texture extensions
|
|
2829
|
+
unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffer)
|
|
2830
|
+
{
|
|
2831
|
+
unsigned int id = 0;
|
|
2832
|
+
|
|
2833
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2834
|
+
// In case depth textures not supported, we force renderbuffer usage
|
|
2835
|
+
if (!RLGL.ExtSupported.texDepth) useRenderBuffer = true;
|
|
2836
|
+
|
|
2837
|
+
// NOTE: We let the implementation to choose the best bit-depth
|
|
2838
|
+
// Possible formats: GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT32 and GL_DEPTH_COMPONENT32F
|
|
2839
|
+
unsigned int glInternalFormat = GL_DEPTH_COMPONENT;
|
|
2840
|
+
|
|
2841
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
2842
|
+
if (RLGL.ExtSupported.maxDepthBits == 32) glInternalFormat = GL_DEPTH_COMPONENT32_OES;
|
|
2843
|
+
else if (RLGL.ExtSupported.maxDepthBits == 24) glInternalFormat = GL_DEPTH_COMPONENT24_OES;
|
|
2844
|
+
else glInternalFormat = GL_DEPTH_COMPONENT16;
|
|
2845
|
+
#endif
|
|
2846
|
+
|
|
2847
|
+
if (!useRenderBuffer && RLGL.ExtSupported.texDepth)
|
|
2848
|
+
{
|
|
2849
|
+
glGenTextures(1, &id);
|
|
2850
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
2851
|
+
glTexImage2D(GL_TEXTURE_2D, 0, glInternalFormat, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
|
2852
|
+
|
|
2853
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
2854
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
2855
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
2856
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
2857
|
+
|
|
2858
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
2859
|
+
|
|
2860
|
+
TRACELOG(RL_LOG_INFO, "TEXTURE: Depth texture loaded successfully");
|
|
2861
|
+
}
|
|
2862
|
+
else
|
|
2863
|
+
{
|
|
2864
|
+
// Create the renderbuffer that will serve as the depth attachment for the framebuffer
|
|
2865
|
+
// NOTE: A renderbuffer is simpler than a texture and could offer better performance on embedded devices
|
|
2866
|
+
glGenRenderbuffers(1, &id);
|
|
2867
|
+
glBindRenderbuffer(GL_RENDERBUFFER, id);
|
|
2868
|
+
glRenderbufferStorage(GL_RENDERBUFFER, glInternalFormat, width, height);
|
|
2869
|
+
|
|
2870
|
+
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
2871
|
+
|
|
2872
|
+
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Depth renderbuffer loaded successfully (%i bits)", id, (RLGL.ExtSupported.maxDepthBits >= 24)? RLGL.ExtSupported.maxDepthBits : 16);
|
|
2873
|
+
}
|
|
2874
|
+
#endif
|
|
2875
|
+
|
|
2876
|
+
return id;
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
// Load texture cubemap
|
|
2880
|
+
// NOTE: Cubemap data is expected to be 6 images in a single data array (one after the other),
|
|
2881
|
+
// expected the following convention: +X, -X, +Y, -Y, +Z, -Z
|
|
2882
|
+
unsigned int rlLoadTextureCubemap(void *data, int size, int format)
|
|
2883
|
+
{
|
|
2884
|
+
unsigned int id = 0;
|
|
2885
|
+
|
|
2886
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2887
|
+
unsigned int dataSize = rlGetPixelDataSize(size, size, format);
|
|
2888
|
+
|
|
2889
|
+
glGenTextures(1, &id);
|
|
2890
|
+
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
|
|
2891
|
+
|
|
2892
|
+
int glInternalFormat, glFormat, glType;
|
|
2893
|
+
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
|
2894
|
+
|
|
2895
|
+
if (glInternalFormat != -1)
|
|
2896
|
+
{
|
|
2897
|
+
// Load cubemap faces
|
|
2898
|
+
for (unsigned int i = 0; i < 6; i++)
|
|
2899
|
+
{
|
|
2900
|
+
if (data == NULL)
|
|
2901
|
+
{
|
|
2902
|
+
if (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB)
|
|
2903
|
+
{
|
|
2904
|
+
if (format == RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32)
|
|
2905
|
+
{
|
|
2906
|
+
// Instead of using a sized internal texture format (GL_RGB16F, GL_RGB32F), we let the driver to choose the better format for us (GL_RGB)
|
|
2907
|
+
if (RLGL.ExtSupported.texFloat32) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, size, size, 0, GL_RGB, GL_FLOAT, NULL);
|
|
2908
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURES: Cubemap requested format not supported");
|
|
2909
|
+
}
|
|
2910
|
+
else if ((format == RL_PIXELFORMAT_UNCOMPRESSED_R32) || (format == RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32)) TRACELOG(RL_LOG_WARNING, "TEXTURES: Cubemap requested format not supported");
|
|
2911
|
+
else glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, size, size, 0, glFormat, glType, NULL);
|
|
2912
|
+
}
|
|
2913
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURES: Empty cubemap creation does not support compressed format");
|
|
2914
|
+
}
|
|
2915
|
+
else
|
|
2916
|
+
{
|
|
2917
|
+
if (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, size, size, 0, glFormat, glType, (unsigned char *)data + i*dataSize);
|
|
2918
|
+
else glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, size, size, 0, dataSize, (unsigned char *)data + i*dataSize);
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2922
|
+
if (format == RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)
|
|
2923
|
+
{
|
|
2924
|
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ONE };
|
|
2925
|
+
glTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
|
|
2926
|
+
}
|
|
2927
|
+
else if (format == RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA)
|
|
2928
|
+
{
|
|
2929
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
2930
|
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA };
|
|
2931
|
+
#elif defined(GRAPHICS_API_OPENGL_33)
|
|
2932
|
+
GLint swizzleMask[] = { GL_RED, GL_RED, GL_RED, GL_GREEN };
|
|
2933
|
+
#endif
|
|
2934
|
+
glTexParameteriv(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
|
|
2935
|
+
}
|
|
2936
|
+
#endif
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
// Set cubemap texture sampling parameters
|
|
2941
|
+
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
2942
|
+
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
2943
|
+
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
2944
|
+
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
2945
|
+
#if defined(GRAPHICS_API_OPENGL_33)
|
|
2946
|
+
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); // Flag not supported on OpenGL ES 2.0
|
|
2947
|
+
#endif
|
|
2948
|
+
|
|
2949
|
+
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
|
2950
|
+
#endif
|
|
2951
|
+
|
|
2952
|
+
if (id > 0) TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Cubemap texture loaded successfully (%ix%i)", id, size, size);
|
|
2953
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to load cubemap texture");
|
|
2954
|
+
|
|
2955
|
+
return id;
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
// Update already loaded texture in GPU with new data
|
|
2959
|
+
// NOTE: We don't know safely if internal texture format is the expected one...
|
|
2960
|
+
void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data)
|
|
2961
|
+
{
|
|
2962
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
2963
|
+
|
|
2964
|
+
int glInternalFormat, glFormat, glType;
|
|
2965
|
+
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
|
2966
|
+
|
|
2967
|
+
if ((glInternalFormat != -1) && (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB))
|
|
2968
|
+
{
|
|
2969
|
+
glTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, width, height, glFormat, glType, (unsigned char *)data);
|
|
2970
|
+
}
|
|
2971
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Failed to update for current texture format (%i)", id, format);
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
// Get OpenGL internal formats and data type from raylib PixelFormat
|
|
2975
|
+
void rlGetGlTextureFormats(int format, int *glInternalFormat, int *glFormat, int *glType)
|
|
2976
|
+
{
|
|
2977
|
+
*glInternalFormat = -1;
|
|
2978
|
+
*glFormat = -1;
|
|
2979
|
+
*glType = -1;
|
|
2980
|
+
|
|
2981
|
+
switch (format)
|
|
2982
|
+
{
|
|
2983
|
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_21) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
2984
|
+
// NOTE: on OpenGL ES 2.0 (WebGL), internalFormat must match format and options allowed are: GL_LUMINANCE, GL_RGB, GL_RGBA
|
|
2985
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: *glInternalFormat = GL_LUMINANCE; *glFormat = GL_LUMINANCE; *glType = GL_UNSIGNED_BYTE; break;
|
|
2986
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: *glInternalFormat = GL_LUMINANCE_ALPHA; *glFormat = GL_LUMINANCE_ALPHA; *glType = GL_UNSIGNED_BYTE; break;
|
|
2987
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5: *glInternalFormat = GL_RGB; *glFormat = GL_RGB; *glType = GL_UNSIGNED_SHORT_5_6_5; break;
|
|
2988
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8: *glInternalFormat = GL_RGB; *glFormat = GL_RGB; *glType = GL_UNSIGNED_BYTE; break;
|
|
2989
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_SHORT_5_5_5_1; break;
|
|
2990
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_SHORT_4_4_4_4; break;
|
|
2991
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_BYTE; break;
|
|
2992
|
+
#if !defined(GRAPHICS_API_OPENGL_11)
|
|
2993
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_LUMINANCE; *glFormat = GL_LUMINANCE; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float
|
|
2994
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGB; *glFormat = GL_RGB; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float
|
|
2995
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGBA; *glFormat = GL_RGBA; *glType = GL_FLOAT; break; // NOTE: Requires extension OES_texture_float
|
|
2996
|
+
#endif
|
|
2997
|
+
#elif defined(GRAPHICS_API_OPENGL_33)
|
|
2998
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: *glInternalFormat = GL_R8; *glFormat = GL_RED; *glType = GL_UNSIGNED_BYTE; break;
|
|
2999
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: *glInternalFormat = GL_RG8; *glFormat = GL_RG; *glType = GL_UNSIGNED_BYTE; break;
|
|
3000
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5: *glInternalFormat = GL_RGB565; *glFormat = GL_RGB; *glType = GL_UNSIGNED_SHORT_5_6_5; break;
|
|
3001
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8: *glInternalFormat = GL_RGB8; *glFormat = GL_RGB; *glType = GL_UNSIGNED_BYTE; break;
|
|
3002
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: *glInternalFormat = GL_RGB5_A1; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_SHORT_5_5_5_1; break;
|
|
3003
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: *glInternalFormat = GL_RGBA4; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_SHORT_4_4_4_4; break;
|
|
3004
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: *glInternalFormat = GL_RGBA8; *glFormat = GL_RGBA; *glType = GL_UNSIGNED_BYTE; break;
|
|
3005
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_R32F; *glFormat = GL_RED; *glType = GL_FLOAT; break;
|
|
3006
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGB32F; *glFormat = GL_RGB; *glType = GL_FLOAT; break;
|
|
3007
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: if (RLGL.ExtSupported.texFloat32) *glInternalFormat = GL_RGBA32F; *glFormat = GL_RGBA; *glType = GL_FLOAT; break;
|
|
3008
|
+
#endif
|
|
3009
|
+
#if !defined(GRAPHICS_API_OPENGL_11)
|
|
3010
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT1_RGB: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; break;
|
|
3011
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
|
|
3012
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
|
|
3013
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA: if (RLGL.ExtSupported.texCompDXT) *glInternalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
|
|
3014
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC1_RGB: if (RLGL.ExtSupported.texCompETC1) *glInternalFormat = GL_ETC1_RGB8_OES; break; // NOTE: Requires OpenGL ES 2.0 or OpenGL 4.3
|
|
3015
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC2_RGB: if (RLGL.ExtSupported.texCompETC2) *glInternalFormat = GL_COMPRESSED_RGB8_ETC2; break; // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
|
|
3016
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA: if (RLGL.ExtSupported.texCompETC2) *glInternalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC; break; // NOTE: Requires OpenGL ES 3.0 or OpenGL 4.3
|
|
3017
|
+
case RL_PIXELFORMAT_COMPRESSED_PVRT_RGB: if (RLGL.ExtSupported.texCompPVRT) *glInternalFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; break; // NOTE: Requires PowerVR GPU
|
|
3018
|
+
case RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA: if (RLGL.ExtSupported.texCompPVRT) *glInternalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; break; // NOTE: Requires PowerVR GPU
|
|
3019
|
+
case RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: if (RLGL.ExtSupported.texCompASTC) *glInternalFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR; break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
|
|
3020
|
+
case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: if (RLGL.ExtSupported.texCompASTC) *glInternalFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR; break; // NOTE: Requires OpenGL ES 3.1 or OpenGL 4.3
|
|
3021
|
+
#endif
|
|
3022
|
+
default: TRACELOG(RL_LOG_WARNING, "TEXTURE: Current format not supported (%i)", format); break;
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
// Unload texture from GPU memory
|
|
3027
|
+
void rlUnloadTexture(unsigned int id)
|
|
3028
|
+
{
|
|
3029
|
+
glDeleteTextures(1, &id);
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
// Generate mipmap data for selected texture
|
|
3033
|
+
void rlGenTextureMipmaps(unsigned int id, int width, int height, int format, int *mipmaps)
|
|
3034
|
+
{
|
|
3035
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
3036
|
+
|
|
3037
|
+
// Check if texture is power-of-two (POT)
|
|
3038
|
+
bool texIsPOT = false;
|
|
3039
|
+
|
|
3040
|
+
if (((width > 0) && ((width & (width - 1)) == 0)) &&
|
|
3041
|
+
((height > 0) && ((height & (height - 1)) == 0))) texIsPOT = true;
|
|
3042
|
+
|
|
3043
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
3044
|
+
if (texIsPOT)
|
|
3045
|
+
{
|
|
3046
|
+
// WARNING: Manual mipmap generation only works for RGBA 32bit textures!
|
|
3047
|
+
if (format == RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
|
|
3048
|
+
{
|
|
3049
|
+
// Retrieve texture data from VRAM
|
|
3050
|
+
void *texData = rlReadTexturePixels(id, width, height, format);
|
|
3051
|
+
|
|
3052
|
+
// NOTE: Texture data size is reallocated to fit mipmaps data
|
|
3053
|
+
// NOTE: CPU mipmap generation only supports RGBA 32bit data
|
|
3054
|
+
int mipmapCount = rlGenTextureMipmapsData(texData, width, height);
|
|
3055
|
+
|
|
3056
|
+
int size = width*height*4;
|
|
3057
|
+
int offset = size;
|
|
3058
|
+
|
|
3059
|
+
int mipWidth = width/2;
|
|
3060
|
+
int mipHeight = height/2;
|
|
3061
|
+
|
|
3062
|
+
// Load the mipmaps
|
|
3063
|
+
for (int level = 1; level < mipmapCount; level++)
|
|
3064
|
+
{
|
|
3065
|
+
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, mipWidth, mipHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)texData + offset);
|
|
3066
|
+
|
|
3067
|
+
size = mipWidth*mipHeight*4;
|
|
3068
|
+
offset += size;
|
|
3069
|
+
|
|
3070
|
+
mipWidth /= 2;
|
|
3071
|
+
mipHeight /= 2;
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
*mipmaps = mipmapCount + 1;
|
|
3075
|
+
RL_FREE(texData); // Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
|
|
3076
|
+
|
|
3077
|
+
TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Mipmaps generated manually on CPU side, total: %i", id, *mipmaps);
|
|
3078
|
+
}
|
|
3079
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Failed to generate mipmaps for provided texture format", id);
|
|
3080
|
+
}
|
|
3081
|
+
#endif
|
|
3082
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3083
|
+
if ((texIsPOT) || (RLGL.ExtSupported.texNPOT))
|
|
3084
|
+
{
|
|
3085
|
+
//glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE
|
|
3086
|
+
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
|
3087
|
+
|
|
3088
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
3089
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps
|
|
3090
|
+
|
|
3091
|
+
#define MIN(a,b) (((a)<(b))?(a):(b))
|
|
3092
|
+
#define MAX(a,b) (((a)>(b))?(a):(b))
|
|
3093
|
+
|
|
3094
|
+
*mipmaps = 1 + (int)floor(log(MAX(width, height))/log(2));
|
|
3095
|
+
TRACELOG(RL_LOG_INFO, "TEXTURE: [ID %i] Mipmaps generated automatically, total: %i", id, *mipmaps);
|
|
3096
|
+
}
|
|
3097
|
+
#endif
|
|
3098
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Failed to generate mipmaps", id);
|
|
3099
|
+
|
|
3100
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
|
|
3104
|
+
// Read texture pixel data
|
|
3105
|
+
void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
|
3106
|
+
{
|
|
3107
|
+
void *pixels = NULL;
|
|
3108
|
+
|
|
3109
|
+
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
|
3110
|
+
glBindTexture(GL_TEXTURE_2D, id);
|
|
3111
|
+
|
|
3112
|
+
// NOTE: Using texture id, we can retrieve some texture info (but not on OpenGL ES 2.0)
|
|
3113
|
+
// Possible texture info: GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
|
|
3114
|
+
//int width, height, format;
|
|
3115
|
+
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
|
3116
|
+
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
|
|
3117
|
+
//glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
|
|
3118
|
+
|
|
3119
|
+
// NOTE: Each row written to or read from by OpenGL pixel operations like glGetTexImage are aligned to a 4 byte boundary by default, which may add some padding.
|
|
3120
|
+
// Use glPixelStorei to modify padding with the GL_[UN]PACK_ALIGNMENT setting.
|
|
3121
|
+
// GL_PACK_ALIGNMENT affects operations that read from OpenGL memory (glReadPixels, glGetTexImage, etc.)
|
|
3122
|
+
// GL_UNPACK_ALIGNMENT affects operations that write to OpenGL memory (glTexImage, etc.)
|
|
3123
|
+
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
3124
|
+
|
|
3125
|
+
int glInternalFormat, glFormat, glType;
|
|
3126
|
+
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
|
3127
|
+
unsigned int size = rlGetPixelDataSize(width, height, format);
|
|
3128
|
+
|
|
3129
|
+
if ((glInternalFormat != -1) && (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB))
|
|
3130
|
+
{
|
|
3131
|
+
pixels = RL_MALLOC(size);
|
|
3132
|
+
glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels);
|
|
3133
|
+
}
|
|
3134
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Data retrieval not suported for pixel format (%i)", id, format);
|
|
3135
|
+
|
|
3136
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
3137
|
+
#endif
|
|
3138
|
+
|
|
3139
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
3140
|
+
// glGetTexImage() is not available on OpenGL ES 2.0
|
|
3141
|
+
// Texture width and height are required on OpenGL ES 2.0. There is no way to get it from texture id.
|
|
3142
|
+
// Two possible Options:
|
|
3143
|
+
// 1 - Bind texture to color fbo attachment and glReadPixels()
|
|
3144
|
+
// 2 - Create an fbo, activate it, render quad with texture, glReadPixels()
|
|
3145
|
+
// We are using Option 1, just need to care for texture format on retrieval
|
|
3146
|
+
// NOTE: This behaviour could be conditioned by graphic driver...
|
|
3147
|
+
unsigned int fboId = rlLoadFramebuffer(width, height);
|
|
3148
|
+
|
|
3149
|
+
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
|
|
3150
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
|
3151
|
+
|
|
3152
|
+
// Attach our texture to FBO
|
|
3153
|
+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id, 0);
|
|
3154
|
+
|
|
3155
|
+
// We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
|
|
3156
|
+
pixels = (unsigned char *)RL_MALLOC(rlGetPixelDataSize(width, height, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8));
|
|
3157
|
+
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
|
3158
|
+
|
|
3159
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
3160
|
+
|
|
3161
|
+
// Clean up temporal fbo
|
|
3162
|
+
rlUnloadFramebuffer(fboId);
|
|
3163
|
+
#endif
|
|
3164
|
+
|
|
3165
|
+
return pixels;
|
|
3166
|
+
}
|
|
3167
|
+
|
|
3168
|
+
|
|
3169
|
+
// Read screen pixel data (color buffer)
|
|
3170
|
+
unsigned char *rlReadScreenPixels(int width, int height)
|
|
3171
|
+
{
|
|
3172
|
+
unsigned char *screenData = (unsigned char *)RL_CALLOC(width*height*4, sizeof(unsigned char));
|
|
3173
|
+
|
|
3174
|
+
// NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
|
|
3175
|
+
// NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
|
|
3176
|
+
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, screenData);
|
|
3177
|
+
|
|
3178
|
+
// Flip image vertically!
|
|
3179
|
+
unsigned char *imgData = (unsigned char *)RL_MALLOC(width*height*4*sizeof(unsigned char));
|
|
3180
|
+
|
|
3181
|
+
for (int y = height - 1; y >= 0; y--)
|
|
3182
|
+
{
|
|
3183
|
+
for (int x = 0; x < (width*4); x++)
|
|
3184
|
+
{
|
|
3185
|
+
imgData[((height - 1) - y)*width*4 + x] = screenData[(y*width*4) + x]; // Flip line
|
|
3186
|
+
|
|
3187
|
+
// Set alpha component value to 255 (no trasparent image retrieval)
|
|
3188
|
+
// NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it!
|
|
3189
|
+
if (((x + 1)%4) == 0) imgData[((height - 1) - y)*width*4 + x] = 255;
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
RL_FREE(screenData);
|
|
3194
|
+
|
|
3195
|
+
return imgData; // NOTE: image data should be freed
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
// Framebuffer management (fbo)
|
|
3199
|
+
//-----------------------------------------------------------------------------------------
|
|
3200
|
+
// Load a framebuffer to be used for rendering
|
|
3201
|
+
// NOTE: No textures attached
|
|
3202
|
+
unsigned int rlLoadFramebuffer(int width, int height)
|
|
3203
|
+
{
|
|
3204
|
+
unsigned int fboId = 0;
|
|
3205
|
+
|
|
3206
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
|
3207
|
+
glGenFramebuffers(1, &fboId); // Create the framebuffer object
|
|
3208
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind any framebuffer
|
|
3209
|
+
#endif
|
|
3210
|
+
|
|
3211
|
+
return fboId;
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
// Attach color buffer texture to an fbo (unloads previous attachment)
|
|
3215
|
+
// NOTE: Attach type: 0-Color, 1-Depth renderbuffer, 2-Depth texture
|
|
3216
|
+
void rlFramebufferAttach(unsigned int fboId, unsigned int texId, int attachType, int texType, int mipLevel)
|
|
3217
|
+
{
|
|
3218
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
|
3219
|
+
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
|
|
3220
|
+
|
|
3221
|
+
switch (attachType)
|
|
3222
|
+
{
|
|
3223
|
+
case RL_ATTACHMENT_COLOR_CHANNEL0:
|
|
3224
|
+
case RL_ATTACHMENT_COLOR_CHANNEL1:
|
|
3225
|
+
case RL_ATTACHMENT_COLOR_CHANNEL2:
|
|
3226
|
+
case RL_ATTACHMENT_COLOR_CHANNEL3:
|
|
3227
|
+
case RL_ATTACHMENT_COLOR_CHANNEL4:
|
|
3228
|
+
case RL_ATTACHMENT_COLOR_CHANNEL5:
|
|
3229
|
+
case RL_ATTACHMENT_COLOR_CHANNEL6:
|
|
3230
|
+
case RL_ATTACHMENT_COLOR_CHANNEL7:
|
|
3231
|
+
{
|
|
3232
|
+
if (texType == RL_ATTACHMENT_TEXTURE2D) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachType, GL_TEXTURE_2D, texId, mipLevel);
|
|
3233
|
+
else if (texType == RL_ATTACHMENT_RENDERBUFFER) glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachType, GL_RENDERBUFFER, texId);
|
|
3234
|
+
else if (texType >= RL_ATTACHMENT_CUBEMAP_POSITIVE_X) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachType, GL_TEXTURE_CUBE_MAP_POSITIVE_X + texType, texId, mipLevel);
|
|
3235
|
+
|
|
3236
|
+
} break;
|
|
3237
|
+
case RL_ATTACHMENT_DEPTH:
|
|
3238
|
+
{
|
|
3239
|
+
if (texType == RL_ATTACHMENT_TEXTURE2D) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texId, mipLevel);
|
|
3240
|
+
else if (texType == RL_ATTACHMENT_RENDERBUFFER) glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, texId);
|
|
3241
|
+
|
|
3242
|
+
} break;
|
|
3243
|
+
case RL_ATTACHMENT_STENCIL:
|
|
3244
|
+
{
|
|
3245
|
+
if (texType == RL_ATTACHMENT_TEXTURE2D) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texId, mipLevel);
|
|
3246
|
+
else if (texType == RL_ATTACHMENT_RENDERBUFFER) glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, texId);
|
|
3247
|
+
|
|
3248
|
+
} break;
|
|
3249
|
+
default: break;
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
3253
|
+
#endif
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
// Verify render texture is complete
|
|
3257
|
+
bool rlFramebufferComplete(unsigned int id)
|
|
3258
|
+
{
|
|
3259
|
+
bool result = false;
|
|
3260
|
+
|
|
3261
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
|
3262
|
+
glBindFramebuffer(GL_FRAMEBUFFER, id);
|
|
3263
|
+
|
|
3264
|
+
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
3265
|
+
|
|
3266
|
+
if (status != GL_FRAMEBUFFER_COMPLETE)
|
|
3267
|
+
{
|
|
3268
|
+
switch (status)
|
|
3269
|
+
{
|
|
3270
|
+
case GL_FRAMEBUFFER_UNSUPPORTED: TRACELOG(RL_LOG_WARNING, "FBO: [ID %i] Framebuffer is unsupported", id); break;
|
|
3271
|
+
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: TRACELOG(RL_LOG_WARNING, "FBO: [ID %i] Framebuffer has incomplete attachment", id); break;
|
|
3272
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
3273
|
+
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: TRACELOG(RL_LOG_WARNING, "FBO: [ID %i] Framebuffer has incomplete dimensions", id); break;
|
|
3274
|
+
#endif
|
|
3275
|
+
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: TRACELOG(RL_LOG_WARNING, "FBO: [ID %i] Framebuffer has a missing attachment", id); break;
|
|
3276
|
+
default: break;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3280
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
3281
|
+
|
|
3282
|
+
result = (status == GL_FRAMEBUFFER_COMPLETE);
|
|
3283
|
+
#endif
|
|
3284
|
+
|
|
3285
|
+
return result;
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
// Unload framebuffer from GPU memory
|
|
3289
|
+
// NOTE: All attached textures/cubemaps/renderbuffers are also deleted
|
|
3290
|
+
void rlUnloadFramebuffer(unsigned int id)
|
|
3291
|
+
{
|
|
3292
|
+
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(RLGL_RENDER_TEXTURES_HINT)
|
|
3293
|
+
|
|
3294
|
+
// Query depth attachment to automatically delete texture/renderbuffer
|
|
3295
|
+
int depthType = 0, depthId = 0;
|
|
3296
|
+
glBindFramebuffer(GL_FRAMEBUFFER, id); // Bind framebuffer to query depth texture type
|
|
3297
|
+
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &depthType);
|
|
3298
|
+
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &depthId);
|
|
3299
|
+
|
|
3300
|
+
unsigned int depthIdU = (unsigned int)depthId;
|
|
3301
|
+
if (depthType == GL_RENDERBUFFER) glDeleteRenderbuffers(1, &depthIdU);
|
|
3302
|
+
else if (depthType == GL_RENDERBUFFER) glDeleteTextures(1, &depthIdU);
|
|
3303
|
+
|
|
3304
|
+
// NOTE: If a texture object is deleted while its image is attached to the *currently bound* framebuffer,
|
|
3305
|
+
// the texture image is automatically detached from the currently bound framebuffer.
|
|
3306
|
+
|
|
3307
|
+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
3308
|
+
glDeleteFramebuffers(1, &id);
|
|
3309
|
+
|
|
3310
|
+
TRACELOG(RL_LOG_INFO, "FBO: [ID %i] Unloaded framebuffer from VRAM (GPU)", id);
|
|
3311
|
+
#endif
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
// Vertex data management
|
|
3315
|
+
//-----------------------------------------------------------------------------------------
|
|
3316
|
+
// Load a new attributes buffer
|
|
3317
|
+
unsigned int rlLoadVertexBuffer(void *buffer, int size, bool dynamic)
|
|
3318
|
+
{
|
|
3319
|
+
unsigned int id = 0;
|
|
3320
|
+
|
|
3321
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3322
|
+
glGenBuffers(1, &id);
|
|
3323
|
+
glBindBuffer(GL_ARRAY_BUFFER, id);
|
|
3324
|
+
glBufferData(GL_ARRAY_BUFFER, size, buffer, dynamic? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
|
|
3325
|
+
#endif
|
|
3326
|
+
|
|
3327
|
+
return id;
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
// Load a new attributes element buffer
|
|
3331
|
+
unsigned int rlLoadVertexBufferElement(void *buffer, int size, bool dynamic)
|
|
3332
|
+
{
|
|
3333
|
+
unsigned int id = 0;
|
|
3334
|
+
|
|
3335
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3336
|
+
glGenBuffers(1, &id);
|
|
3337
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
|
3338
|
+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, buffer, dynamic? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
|
|
3339
|
+
#endif
|
|
3340
|
+
|
|
3341
|
+
return id;
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
// Enable vertex buffer (VBO)
|
|
3345
|
+
void rlEnableVertexBuffer(unsigned int id)
|
|
3346
|
+
{
|
|
3347
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3348
|
+
glBindBuffer(GL_ARRAY_BUFFER, id);
|
|
3349
|
+
#endif
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3352
|
+
// Disable vertex buffer (VBO)
|
|
3353
|
+
void rlDisableVertexBuffer(void)
|
|
3354
|
+
{
|
|
3355
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3356
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
3357
|
+
#endif
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
// Enable vertex buffer element (VBO element)
|
|
3361
|
+
void rlEnableVertexBufferElement(unsigned int id)
|
|
3362
|
+
{
|
|
3363
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3364
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
|
3365
|
+
#endif
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
// Disable vertex buffer element (VBO element)
|
|
3369
|
+
void rlDisableVertexBufferElement(void)
|
|
3370
|
+
{
|
|
3371
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3372
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
3373
|
+
#endif
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
// Update vertex buffer with new data
|
|
3377
|
+
// NOTE: dataSize and offset must be provided in bytes
|
|
3378
|
+
void rlUpdateVertexBuffer(unsigned int id, void *data, int dataSize, int offset)
|
|
3379
|
+
{
|
|
3380
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3381
|
+
glBindBuffer(GL_ARRAY_BUFFER, id);
|
|
3382
|
+
glBufferSubData(GL_ARRAY_BUFFER, offset, dataSize, data);
|
|
3383
|
+
#endif
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
// Update vertex buffer elements with new data
|
|
3387
|
+
// NOTE: dataSize and offset must be provided in bytes
|
|
3388
|
+
void rlUpdateVertexBufferElements(unsigned int id, void *data, int dataSize, int offset)
|
|
3389
|
+
{
|
|
3390
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3391
|
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
|
|
3392
|
+
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, dataSize, data);
|
|
3393
|
+
#endif
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
// Enable vertex array object (VAO)
|
|
3397
|
+
bool rlEnableVertexArray(unsigned int vaoId)
|
|
3398
|
+
{
|
|
3399
|
+
bool result = false;
|
|
3400
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3401
|
+
if (RLGL.ExtSupported.vao)
|
|
3402
|
+
{
|
|
3403
|
+
glBindVertexArray(vaoId);
|
|
3404
|
+
result = true;
|
|
3405
|
+
}
|
|
3406
|
+
#endif
|
|
3407
|
+
return result;
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
// Disable vertex array object (VAO)
|
|
3411
|
+
void rlDisableVertexArray(void)
|
|
3412
|
+
{
|
|
3413
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3414
|
+
if (RLGL.ExtSupported.vao) glBindVertexArray(0);
|
|
3415
|
+
#endif
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
// Enable vertex attribute index
|
|
3419
|
+
void rlEnableVertexAttribute(unsigned int index)
|
|
3420
|
+
{
|
|
3421
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3422
|
+
glEnableVertexAttribArray(index);
|
|
3423
|
+
#endif
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
// Disable vertex attribute index
|
|
3427
|
+
void rlDisableVertexAttribute(unsigned int index)
|
|
3428
|
+
{
|
|
3429
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3430
|
+
glDisableVertexAttribArray(index);
|
|
3431
|
+
#endif
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
// Draw vertex array
|
|
3435
|
+
void rlDrawVertexArray(int offset, int count)
|
|
3436
|
+
{
|
|
3437
|
+
glDrawArrays(GL_TRIANGLES, offset, count);
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
// Draw vertex array elements
|
|
3441
|
+
void rlDrawVertexArrayElements(int offset, int count, void *buffer)
|
|
3442
|
+
{
|
|
3443
|
+
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (unsigned short *)buffer + offset);
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
// Draw vertex array instanced
|
|
3447
|
+
void rlDrawVertexArrayInstanced(int offset, int count, int instances)
|
|
3448
|
+
{
|
|
3449
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3450
|
+
glDrawArraysInstanced(GL_TRIANGLES, 0, count, instances);
|
|
3451
|
+
#endif
|
|
3452
|
+
}
|
|
3453
|
+
|
|
3454
|
+
// Draw vertex array elements instanced
|
|
3455
|
+
void rlDrawVertexArrayElementsInstanced(int offset, int count, void *buffer, int instances)
|
|
3456
|
+
{
|
|
3457
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3458
|
+
glDrawElementsInstanced(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (unsigned short *)buffer + offset, instances);
|
|
3459
|
+
#endif
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
3463
|
+
// Enable vertex state pointer
|
|
3464
|
+
void rlEnableStatePointer(int vertexAttribType, void *buffer)
|
|
3465
|
+
{
|
|
3466
|
+
if (buffer != NULL) glEnableClientState(vertexAttribType);
|
|
3467
|
+
switch (vertexAttribType)
|
|
3468
|
+
{
|
|
3469
|
+
case GL_VERTEX_ARRAY: glVertexPointer(3, GL_FLOAT, 0, buffer); break;
|
|
3470
|
+
case GL_TEXTURE_COORD_ARRAY: glTexCoordPointer(2, GL_FLOAT, 0, buffer); break;
|
|
3471
|
+
case GL_NORMAL_ARRAY: if (buffer != NULL) glNormalPointer(GL_FLOAT, 0, buffer); break;
|
|
3472
|
+
case GL_COLOR_ARRAY: if (buffer != NULL) glColorPointer(4, GL_UNSIGNED_BYTE, 0, buffer); break;
|
|
3473
|
+
//case GL_INDEX_ARRAY: if (buffer != NULL) glIndexPointer(GL_SHORT, 0, buffer); break; // Indexed colors
|
|
3474
|
+
default: break;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
// Disable vertex state pointer
|
|
3479
|
+
void rlDisableStatePointer(int vertexAttribType)
|
|
3480
|
+
{
|
|
3481
|
+
glDisableClientState(vertexAttribType);
|
|
3482
|
+
}
|
|
3483
|
+
#endif
|
|
3484
|
+
|
|
3485
|
+
// Load vertex array object (VAO)
|
|
3486
|
+
unsigned int rlLoadVertexArray(void)
|
|
3487
|
+
{
|
|
3488
|
+
unsigned int vaoId = 0;
|
|
3489
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3490
|
+
if (RLGL.ExtSupported.vao)
|
|
3491
|
+
{
|
|
3492
|
+
glGenVertexArrays(1, &vaoId);
|
|
3493
|
+
}
|
|
3494
|
+
#endif
|
|
3495
|
+
return vaoId;
|
|
3496
|
+
}
|
|
3497
|
+
|
|
3498
|
+
// Set vertex attribute
|
|
3499
|
+
void rlSetVertexAttribute(unsigned int index, int compSize, int type, bool normalized, int stride, void *pointer)
|
|
3500
|
+
{
|
|
3501
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3502
|
+
glVertexAttribPointer(index, compSize, type, normalized, stride, pointer);
|
|
3503
|
+
#endif
|
|
3504
|
+
}
|
|
3505
|
+
|
|
3506
|
+
// Set vertex attribute divisor
|
|
3507
|
+
void rlSetVertexAttributeDivisor(unsigned int index, int divisor)
|
|
3508
|
+
{
|
|
3509
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3510
|
+
glVertexAttribDivisor(index, divisor);
|
|
3511
|
+
#endif
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
// Unload vertex array object (VAO)
|
|
3515
|
+
void rlUnloadVertexArray(unsigned int vaoId)
|
|
3516
|
+
{
|
|
3517
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3518
|
+
if (RLGL.ExtSupported.vao)
|
|
3519
|
+
{
|
|
3520
|
+
glBindVertexArray(0);
|
|
3521
|
+
glDeleteVertexArrays(1, &vaoId);
|
|
3522
|
+
TRACELOG(RL_LOG_INFO, "VAO: [ID %i] Unloaded vertex array data from VRAM (GPU)", vaoId);
|
|
3523
|
+
}
|
|
3524
|
+
#endif
|
|
3525
|
+
}
|
|
3526
|
+
|
|
3527
|
+
// Unload vertex buffer (VBO)
|
|
3528
|
+
void rlUnloadVertexBuffer(unsigned int vboId)
|
|
3529
|
+
{
|
|
3530
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3531
|
+
glDeleteBuffers(1, &vboId);
|
|
3532
|
+
//TRACELOG(RL_LOG_INFO, "VBO: Unloaded vertex data from VRAM (GPU)");
|
|
3533
|
+
#endif
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3536
|
+
// Shaders management
|
|
3537
|
+
//-----------------------------------------------------------------------------------------------
|
|
3538
|
+
// Load shader from code strings
|
|
3539
|
+
// NOTE: If shader string is NULL, using default vertex/fragment shaders
|
|
3540
|
+
unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode)
|
|
3541
|
+
{
|
|
3542
|
+
unsigned int id = 0;
|
|
3543
|
+
|
|
3544
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3545
|
+
unsigned int vertexShaderId = RLGL.State.defaultVShaderId;
|
|
3546
|
+
unsigned int fragmentShaderId = RLGL.State.defaultFShaderId;
|
|
3547
|
+
|
|
3548
|
+
if (vsCode != NULL) vertexShaderId = rlCompileShader(vsCode, GL_VERTEX_SHADER);
|
|
3549
|
+
if (fsCode != NULL) fragmentShaderId = rlCompileShader(fsCode, GL_FRAGMENT_SHADER);
|
|
3550
|
+
|
|
3551
|
+
if ((vertexShaderId == RLGL.State.defaultVShaderId) && (fragmentShaderId == RLGL.State.defaultFShaderId)) id = RLGL.State.defaultShaderId;
|
|
3552
|
+
else
|
|
3553
|
+
{
|
|
3554
|
+
id = rlLoadShaderProgram(vertexShaderId, fragmentShaderId);
|
|
3555
|
+
|
|
3556
|
+
if (vertexShaderId != RLGL.State.defaultVShaderId)
|
|
3557
|
+
{
|
|
3558
|
+
// Detach shader before deletion to make sure memory is freed
|
|
3559
|
+
glDetachShader(id, vertexShaderId);
|
|
3560
|
+
glDeleteShader(vertexShaderId);
|
|
3561
|
+
}
|
|
3562
|
+
if (fragmentShaderId != RLGL.State.defaultFShaderId)
|
|
3563
|
+
{
|
|
3564
|
+
// Detach shader before deletion to make sure memory is freed
|
|
3565
|
+
glDetachShader(id, fragmentShaderId);
|
|
3566
|
+
glDeleteShader(fragmentShaderId);
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
if (id == 0)
|
|
3570
|
+
{
|
|
3571
|
+
TRACELOG(RL_LOG_WARNING, "SHADER: Failed to load custom shader code");
|
|
3572
|
+
id = RLGL.State.defaultShaderId;
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3576
|
+
// Get available shader uniforms
|
|
3577
|
+
// NOTE: This information is useful for debug...
|
|
3578
|
+
int uniformCount = -1;
|
|
3579
|
+
|
|
3580
|
+
glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &uniformCount);
|
|
3581
|
+
|
|
3582
|
+
for (int i = 0; i < uniformCount; i++)
|
|
3583
|
+
{
|
|
3584
|
+
int namelen = -1;
|
|
3585
|
+
int num = -1;
|
|
3586
|
+
char name[256] = { 0 }; // Assume no variable names longer than 256
|
|
3587
|
+
GLenum type = GL_ZERO;
|
|
3588
|
+
|
|
3589
|
+
// Get the name of the uniforms
|
|
3590
|
+
glGetActiveUniform(id, i, sizeof(name) - 1, &namelen, &num, &type, name);
|
|
3591
|
+
|
|
3592
|
+
name[namelen] = 0;
|
|
3593
|
+
|
|
3594
|
+
TRACELOGD("SHADER: [ID %i] Active uniform (%s) set at location: %i", id, name, glGetUniformLocation(id, name));
|
|
3595
|
+
}
|
|
3596
|
+
#endif
|
|
3597
|
+
|
|
3598
|
+
return id;
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
// Compile custom shader and return shader id
|
|
3602
|
+
unsigned int rlCompileShader(const char *shaderCode, int type)
|
|
3603
|
+
{
|
|
3604
|
+
unsigned int shader = 0;
|
|
3605
|
+
|
|
3606
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3607
|
+
shader = glCreateShader(type);
|
|
3608
|
+
glShaderSource(shader, 1, &shaderCode, NULL);
|
|
3609
|
+
|
|
3610
|
+
GLint success = 0;
|
|
3611
|
+
glCompileShader(shader);
|
|
3612
|
+
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
|
3613
|
+
|
|
3614
|
+
if (success == GL_FALSE)
|
|
3615
|
+
{
|
|
3616
|
+
switch (type)
|
|
3617
|
+
{
|
|
3618
|
+
case GL_VERTEX_SHADER: TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to compile vertex shader code", shader); break;
|
|
3619
|
+
case GL_FRAGMENT_SHADER: TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to compile fragment shader code", shader); break;
|
|
3620
|
+
//case GL_GEOMETRY_SHADER:
|
|
3621
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3622
|
+
case GL_COMPUTE_SHADER: TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to compile compute shader code", shader); break;
|
|
3623
|
+
#endif
|
|
3624
|
+
default: break;
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
int maxLength = 0;
|
|
3628
|
+
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
|
|
3629
|
+
|
|
3630
|
+
if (maxLength > 0)
|
|
3631
|
+
{
|
|
3632
|
+
int length = 0;
|
|
3633
|
+
char *log = RL_CALLOC(maxLength, sizeof(char));
|
|
3634
|
+
glGetShaderInfoLog(shader, maxLength, &length, log);
|
|
3635
|
+
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Compile error: %s", shader, log);
|
|
3636
|
+
RL_FREE(log);
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3639
|
+
else
|
|
3640
|
+
{
|
|
3641
|
+
switch (type)
|
|
3642
|
+
{
|
|
3643
|
+
case GL_VERTEX_SHADER: TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Vertex shader compiled successfully", shader); break;
|
|
3644
|
+
case GL_FRAGMENT_SHADER: TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Fragment shader compiled successfully", shader); break;
|
|
3645
|
+
//case GL_GEOMETRY_SHADER:
|
|
3646
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3647
|
+
case GL_COMPUTE_SHADER: TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Compute shader compiled successfully", shader); break;
|
|
3648
|
+
#endif
|
|
3649
|
+
default: break;
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
#endif
|
|
3653
|
+
|
|
3654
|
+
return shader;
|
|
3655
|
+
}
|
|
3656
|
+
|
|
3657
|
+
// Load custom shader strings and return program id
|
|
3658
|
+
unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
|
|
3659
|
+
{
|
|
3660
|
+
unsigned int program = 0;
|
|
3661
|
+
|
|
3662
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3663
|
+
GLint success = 0;
|
|
3664
|
+
program = glCreateProgram();
|
|
3665
|
+
|
|
3666
|
+
glAttachShader(program, vShaderId);
|
|
3667
|
+
glAttachShader(program, fShaderId);
|
|
3668
|
+
|
|
3669
|
+
// NOTE: Default attribute shader locations must be binded before linking
|
|
3670
|
+
glBindAttribLocation(program, 0, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
|
|
3671
|
+
glBindAttribLocation(program, 1, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD);
|
|
3672
|
+
glBindAttribLocation(program, 2, RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL);
|
|
3673
|
+
glBindAttribLocation(program, 3, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
|
3674
|
+
glBindAttribLocation(program, 4, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
|
3675
|
+
glBindAttribLocation(program, 5, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
|
3676
|
+
|
|
3677
|
+
// NOTE: If some attrib name is no found on the shader, it locations becomes -1
|
|
3678
|
+
|
|
3679
|
+
glLinkProgram(program);
|
|
3680
|
+
|
|
3681
|
+
// NOTE: All uniform variables are intitialised to 0 when a program links
|
|
3682
|
+
|
|
3683
|
+
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
|
3684
|
+
|
|
3685
|
+
if (success == GL_FALSE)
|
|
3686
|
+
{
|
|
3687
|
+
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to link shader program", program);
|
|
3688
|
+
|
|
3689
|
+
int maxLength = 0;
|
|
3690
|
+
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
|
|
3691
|
+
|
|
3692
|
+
if (maxLength > 0)
|
|
3693
|
+
{
|
|
3694
|
+
int length = 0;
|
|
3695
|
+
char *log = RL_CALLOC(maxLength, sizeof(char));
|
|
3696
|
+
glGetProgramInfoLog(program, maxLength, &length, log);
|
|
3697
|
+
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Link error: %s", program, log);
|
|
3698
|
+
RL_FREE(log);
|
|
3699
|
+
}
|
|
3700
|
+
|
|
3701
|
+
glDeleteProgram(program);
|
|
3702
|
+
|
|
3703
|
+
program = 0;
|
|
3704
|
+
}
|
|
3705
|
+
else
|
|
3706
|
+
{
|
|
3707
|
+
// Get the size of compiled shader program (not available on OpenGL ES 2.0)
|
|
3708
|
+
// NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
|
|
3709
|
+
//GLint binarySize = 0;
|
|
3710
|
+
//glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
|
|
3711
|
+
|
|
3712
|
+
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Program shader loaded successfully", program);
|
|
3713
|
+
}
|
|
3714
|
+
#endif
|
|
3715
|
+
return program;
|
|
3716
|
+
}
|
|
3717
|
+
|
|
3718
|
+
// Unload shader program
|
|
3719
|
+
void rlUnloadShaderProgram(unsigned int id)
|
|
3720
|
+
{
|
|
3721
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3722
|
+
glDeleteProgram(id);
|
|
3723
|
+
|
|
3724
|
+
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Unloaded shader program data from VRAM (GPU)", id);
|
|
3725
|
+
#endif
|
|
3726
|
+
}
|
|
3727
|
+
|
|
3728
|
+
// Get shader location uniform
|
|
3729
|
+
int rlGetLocationUniform(unsigned int shaderId, const char *uniformName)
|
|
3730
|
+
{
|
|
3731
|
+
int location = -1;
|
|
3732
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3733
|
+
location = glGetUniformLocation(shaderId, uniformName);
|
|
3734
|
+
|
|
3735
|
+
if (location == -1) TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to find shader uniform: %s", shaderId, uniformName);
|
|
3736
|
+
else TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Shader uniform (%s) set at location: %i", shaderId, uniformName, location);
|
|
3737
|
+
#endif
|
|
3738
|
+
return location;
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3741
|
+
// Get shader location attribute
|
|
3742
|
+
int rlGetLocationAttrib(unsigned int shaderId, const char *attribName)
|
|
3743
|
+
{
|
|
3744
|
+
int location = -1;
|
|
3745
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3746
|
+
location = glGetAttribLocation(shaderId, attribName);
|
|
3747
|
+
|
|
3748
|
+
if (location == -1) TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to find shader attribute: %s", shaderId, attribName);
|
|
3749
|
+
else TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Shader attribute (%s) set at location: %i", shaderId, attribName, location);
|
|
3750
|
+
#endif
|
|
3751
|
+
return location;
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3754
|
+
// Set shader value uniform
|
|
3755
|
+
void rlSetUniform(int locIndex, const void *value, int uniformType, int count)
|
|
3756
|
+
{
|
|
3757
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3758
|
+
switch (uniformType)
|
|
3759
|
+
{
|
|
3760
|
+
case RL_SHADER_UNIFORM_FLOAT: glUniform1fv(locIndex, count, (float *)value); break;
|
|
3761
|
+
case RL_SHADER_UNIFORM_VEC2: glUniform2fv(locIndex, count, (float *)value); break;
|
|
3762
|
+
case RL_SHADER_UNIFORM_VEC3: glUniform3fv(locIndex, count, (float *)value); break;
|
|
3763
|
+
case RL_SHADER_UNIFORM_VEC4: glUniform4fv(locIndex, count, (float *)value); break;
|
|
3764
|
+
case RL_SHADER_UNIFORM_INT: glUniform1iv(locIndex, count, (int *)value); break;
|
|
3765
|
+
case RL_SHADER_UNIFORM_IVEC2: glUniform2iv(locIndex, count, (int *)value); break;
|
|
3766
|
+
case RL_SHADER_UNIFORM_IVEC3: glUniform3iv(locIndex, count, (int *)value); break;
|
|
3767
|
+
case RL_SHADER_UNIFORM_IVEC4: glUniform4iv(locIndex, count, (int *)value); break;
|
|
3768
|
+
case RL_SHADER_UNIFORM_SAMPLER2D: glUniform1iv(locIndex, count, (int *)value); break;
|
|
3769
|
+
default: TRACELOG(RL_LOG_WARNING, "SHADER: Failed to set uniform value, data type not recognized");
|
|
3770
|
+
}
|
|
3771
|
+
#endif
|
|
3772
|
+
}
|
|
3773
|
+
|
|
3774
|
+
// Set shader value attribute
|
|
3775
|
+
void rlSetVertexAttributeDefault(int locIndex, const void *value, int attribType, int count)
|
|
3776
|
+
{
|
|
3777
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3778
|
+
switch (attribType)
|
|
3779
|
+
{
|
|
3780
|
+
case RL_SHADER_ATTRIB_FLOAT: if (count == 1) glVertexAttrib1fv(locIndex, (float *)value); break;
|
|
3781
|
+
case RL_SHADER_ATTRIB_VEC2: if (count == 2) glVertexAttrib2fv(locIndex, (float *)value); break;
|
|
3782
|
+
case RL_SHADER_ATTRIB_VEC3: if (count == 3) glVertexAttrib3fv(locIndex, (float *)value); break;
|
|
3783
|
+
case RL_SHADER_ATTRIB_VEC4: if (count == 4) glVertexAttrib4fv(locIndex, (float *)value); break;
|
|
3784
|
+
default: TRACELOG(RL_LOG_WARNING, "SHADER: Failed to set attrib default value, data type not recognized");
|
|
3785
|
+
}
|
|
3786
|
+
#endif
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
// Set shader value uniform matrix
|
|
3790
|
+
void rlSetUniformMatrix(int locIndex, Matrix mat)
|
|
3791
|
+
{
|
|
3792
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3793
|
+
float matfloat[16] = {
|
|
3794
|
+
mat.m0, mat.m1, mat.m2, mat.m3,
|
|
3795
|
+
mat.m4, mat.m5, mat.m6, mat.m7,
|
|
3796
|
+
mat.m8, mat.m9, mat.m10, mat.m11,
|
|
3797
|
+
mat.m12, mat.m13, mat.m14, mat.m15
|
|
3798
|
+
};
|
|
3799
|
+
glUniformMatrix4fv(locIndex, 1, false, matfloat);
|
|
3800
|
+
#endif
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
// Set shader value uniform sampler
|
|
3804
|
+
void rlSetUniformSampler(int locIndex, unsigned int textureId)
|
|
3805
|
+
{
|
|
3806
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3807
|
+
// Check if texture is already active
|
|
3808
|
+
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++) if (RLGL.State.activeTextureId[i] == textureId) return;
|
|
3809
|
+
|
|
3810
|
+
// Register a new active texture for the internal batch system
|
|
3811
|
+
// NOTE: Default texture is always activated as GL_TEXTURE0
|
|
3812
|
+
for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++)
|
|
3813
|
+
{
|
|
3814
|
+
if (RLGL.State.activeTextureId[i] == 0)
|
|
3815
|
+
{
|
|
3816
|
+
glUniform1i(locIndex, 1 + i); // Activate new texture unit
|
|
3817
|
+
RLGL.State.activeTextureId[i] = textureId; // Save texture id for binding on drawing
|
|
3818
|
+
break;
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
#endif
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
// Set shader currently active (id and locations)
|
|
3825
|
+
void rlSetShader(unsigned int id, int *locs)
|
|
3826
|
+
{
|
|
3827
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
3828
|
+
if (RLGL.State.currentShaderId != id)
|
|
3829
|
+
{
|
|
3830
|
+
rlDrawRenderBatch(RLGL.currentBatch);
|
|
3831
|
+
RLGL.State.currentShaderId = id;
|
|
3832
|
+
RLGL.State.currentShaderLocs = locs;
|
|
3833
|
+
}
|
|
3834
|
+
#endif
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
// Load compute shader program
|
|
3838
|
+
unsigned int rlLoadComputeShaderProgram(unsigned int shaderId)
|
|
3839
|
+
{
|
|
3840
|
+
unsigned int program = 0;
|
|
3841
|
+
|
|
3842
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3843
|
+
GLint success = 0;
|
|
3844
|
+
program = glCreateProgram();
|
|
3845
|
+
glAttachShader(program, shaderId);
|
|
3846
|
+
glLinkProgram(program);
|
|
3847
|
+
|
|
3848
|
+
// NOTE: All uniform variables are intitialised to 0 when a program links
|
|
3849
|
+
|
|
3850
|
+
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
|
3851
|
+
|
|
3852
|
+
if (success == GL_FALSE)
|
|
3853
|
+
{
|
|
3854
|
+
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to link compute shader program", program);
|
|
3855
|
+
|
|
3856
|
+
int maxLength = 0;
|
|
3857
|
+
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
|
|
3858
|
+
|
|
3859
|
+
if (maxLength > 0)
|
|
3860
|
+
{
|
|
3861
|
+
int length = 0;
|
|
3862
|
+
char *log = RL_CALLOC(maxLength, sizeof(char));
|
|
3863
|
+
glGetProgramInfoLog(program, maxLength, &length, log);
|
|
3864
|
+
TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Link error: %s", program, log);
|
|
3865
|
+
RL_FREE(log);
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
glDeleteProgram(program);
|
|
3869
|
+
|
|
3870
|
+
program = 0;
|
|
3871
|
+
}
|
|
3872
|
+
else
|
|
3873
|
+
{
|
|
3874
|
+
// Get the size of compiled shader program (not available on OpenGL ES 2.0)
|
|
3875
|
+
// NOTE: If GL_LINK_STATUS is GL_FALSE, program binary length is zero.
|
|
3876
|
+
//GLint binarySize = 0;
|
|
3877
|
+
//glGetProgramiv(id, GL_PROGRAM_BINARY_LENGTH, &binarySize);
|
|
3878
|
+
|
|
3879
|
+
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Compute shader program loaded successfully", program);
|
|
3880
|
+
}
|
|
3881
|
+
#endif
|
|
3882
|
+
|
|
3883
|
+
return program;
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
// Dispatch compute shader (equivalent to *draw* for graphics pilepine)
|
|
3887
|
+
void rlComputeShaderDispatch(unsigned int groupX, unsigned int groupY, unsigned int groupZ)
|
|
3888
|
+
{
|
|
3889
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3890
|
+
glDispatchCompute(groupX, groupY, groupZ);
|
|
3891
|
+
#endif
|
|
3892
|
+
}
|
|
3893
|
+
|
|
3894
|
+
// Load shader storage buffer object (SSBO)
|
|
3895
|
+
unsigned int rlLoadShaderBuffer(unsigned long long size, const void *data, int usageHint)
|
|
3896
|
+
{
|
|
3897
|
+
unsigned int ssbo = 0;
|
|
3898
|
+
|
|
3899
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3900
|
+
glGenBuffers(1, &ssbo);
|
|
3901
|
+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
|
|
3902
|
+
glBufferData(GL_SHADER_STORAGE_BUFFER, size, data, usageHint? usageHint : RL_STREAM_COPY);
|
|
3903
|
+
#endif
|
|
3904
|
+
|
|
3905
|
+
return ssbo;
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
// Unload shader storage buffer object (SSBO)
|
|
3909
|
+
void rlUnloadShaderBuffer(unsigned int ssboId)
|
|
3910
|
+
{
|
|
3911
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3912
|
+
glDeleteBuffers(1, &ssboId);
|
|
3913
|
+
#endif
|
|
3914
|
+
}
|
|
3915
|
+
|
|
3916
|
+
// Update SSBO buffer data
|
|
3917
|
+
void rlUpdateShaderBufferElements(unsigned int id, const void *data, unsigned long long dataSize, unsigned long long offset)
|
|
3918
|
+
{
|
|
3919
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3920
|
+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
|
|
3921
|
+
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, dataSize, data);
|
|
3922
|
+
#endif
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
// Get SSBO buffer size
|
|
3926
|
+
unsigned long long rlGetShaderBufferSize(unsigned int id)
|
|
3927
|
+
{
|
|
3928
|
+
long long size = 0;
|
|
3929
|
+
|
|
3930
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3931
|
+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
|
|
3932
|
+
glGetInteger64v(GL_SHADER_STORAGE_BUFFER_SIZE, &size);
|
|
3933
|
+
#endif
|
|
3934
|
+
|
|
3935
|
+
return (size > 0)? size : 0;
|
|
3936
|
+
}
|
|
3937
|
+
|
|
3938
|
+
// Read SSBO buffer data
|
|
3939
|
+
void rlReadShaderBufferElements(unsigned int id, void *dest, unsigned long long count, unsigned long long offset)
|
|
3940
|
+
{
|
|
3941
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3942
|
+
glBindBuffer(GL_SHADER_STORAGE_BUFFER, id);
|
|
3943
|
+
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, count, dest);
|
|
3944
|
+
#endif
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
// Bind SSBO buffer
|
|
3948
|
+
void rlBindShaderBuffer(unsigned int id, unsigned int index)
|
|
3949
|
+
{
|
|
3950
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3951
|
+
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, id);
|
|
3952
|
+
#endif
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
// Copy SSBO buffer data
|
|
3956
|
+
void rlCopyBuffersElements(unsigned int destId, unsigned int srcId, unsigned long long destOffset, unsigned long long srcOffset, unsigned long long count)
|
|
3957
|
+
{
|
|
3958
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3959
|
+
glBindBuffer(GL_COPY_READ_BUFFER, srcId);
|
|
3960
|
+
glBindBuffer(GL_COPY_WRITE_BUFFER, destId);
|
|
3961
|
+
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, srcOffset, destOffset, count);
|
|
3962
|
+
#endif
|
|
3963
|
+
}
|
|
3964
|
+
|
|
3965
|
+
// Bind image texture
|
|
3966
|
+
void rlBindImageTexture(unsigned int id, unsigned int index, unsigned int format, int readonly)
|
|
3967
|
+
{
|
|
3968
|
+
#if defined(GRAPHICS_API_OPENGL_43)
|
|
3969
|
+
int glInternalFormat = 0, glFormat = 0, glType = 0;
|
|
3970
|
+
|
|
3971
|
+
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
|
3972
|
+
glBindImageTexture(index, id, 0, 0, 0, readonly ? GL_READ_ONLY : GL_READ_WRITE, glInternalFormat);
|
|
3973
|
+
#endif
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3976
|
+
// Matrix state management
|
|
3977
|
+
//-----------------------------------------------------------------------------------------
|
|
3978
|
+
// Get internal modelview matrix
|
|
3979
|
+
Matrix rlGetMatrixModelview(void)
|
|
3980
|
+
{
|
|
3981
|
+
Matrix matrix = rlMatrixIdentity();
|
|
3982
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
3983
|
+
float mat[16];
|
|
3984
|
+
glGetFloatv(GL_MODELVIEW_MATRIX, mat);
|
|
3985
|
+
matrix.m0 = mat[0];
|
|
3986
|
+
matrix.m1 = mat[1];
|
|
3987
|
+
matrix.m2 = mat[2];
|
|
3988
|
+
matrix.m3 = mat[3];
|
|
3989
|
+
matrix.m4 = mat[4];
|
|
3990
|
+
matrix.m5 = mat[5];
|
|
3991
|
+
matrix.m6 = mat[6];
|
|
3992
|
+
matrix.m7 = mat[7];
|
|
3993
|
+
matrix.m8 = mat[8];
|
|
3994
|
+
matrix.m9 = mat[9];
|
|
3995
|
+
matrix.m10 = mat[10];
|
|
3996
|
+
matrix.m11 = mat[11];
|
|
3997
|
+
matrix.m12 = mat[12];
|
|
3998
|
+
matrix.m13 = mat[13];
|
|
3999
|
+
matrix.m14 = mat[14];
|
|
4000
|
+
matrix.m15 = mat[15];
|
|
4001
|
+
#else
|
|
4002
|
+
matrix = RLGL.State.modelview;
|
|
4003
|
+
#endif
|
|
4004
|
+
return matrix;
|
|
4005
|
+
}
|
|
4006
|
+
|
|
4007
|
+
// Get internal projection matrix
|
|
4008
|
+
Matrix rlGetMatrixProjection(void)
|
|
4009
|
+
{
|
|
4010
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
4011
|
+
float mat[16];
|
|
4012
|
+
glGetFloatv(GL_PROJECTION_MATRIX,mat);
|
|
4013
|
+
Matrix m;
|
|
4014
|
+
m.m0 = mat[0];
|
|
4015
|
+
m.m1 = mat[1];
|
|
4016
|
+
m.m2 = mat[2];
|
|
4017
|
+
m.m3 = mat[3];
|
|
4018
|
+
m.m4 = mat[4];
|
|
4019
|
+
m.m5 = mat[5];
|
|
4020
|
+
m.m6 = mat[6];
|
|
4021
|
+
m.m7 = mat[7];
|
|
4022
|
+
m.m8 = mat[8];
|
|
4023
|
+
m.m9 = mat[9];
|
|
4024
|
+
m.m10 = mat[10];
|
|
4025
|
+
m.m11 = mat[11];
|
|
4026
|
+
m.m12 = mat[12];
|
|
4027
|
+
m.m13 = mat[13];
|
|
4028
|
+
m.m14 = mat[14];
|
|
4029
|
+
m.m15 = mat[15];
|
|
4030
|
+
return m;
|
|
4031
|
+
#else
|
|
4032
|
+
return RLGL.State.projection;
|
|
4033
|
+
#endif
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
// Get internal accumulated transform matrix
|
|
4037
|
+
Matrix rlGetMatrixTransform(void)
|
|
4038
|
+
{
|
|
4039
|
+
Matrix mat = rlMatrixIdentity();
|
|
4040
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4041
|
+
// TODO: Consider possible transform matrices in the RLGL.State.stack
|
|
4042
|
+
// Is this the right order? or should we start with the first stored matrix instead of the last one?
|
|
4043
|
+
//Matrix matStackTransform = rlMatrixIdentity();
|
|
4044
|
+
//for (int i = RLGL.State.stackCounter; i > 0; i--) matStackTransform = rlMatrixMultiply(RLGL.State.stack[i], matStackTransform);
|
|
4045
|
+
mat = RLGL.State.transform;
|
|
4046
|
+
#endif
|
|
4047
|
+
return mat;
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
// Get internal projection matrix for stereo render (selected eye)
|
|
4051
|
+
RLAPI Matrix rlGetMatrixProjectionStereo(int eye)
|
|
4052
|
+
{
|
|
4053
|
+
Matrix mat = rlMatrixIdentity();
|
|
4054
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4055
|
+
mat = RLGL.State.projectionStereo[eye];
|
|
4056
|
+
#endif
|
|
4057
|
+
return mat;
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4060
|
+
// Get internal view offset matrix for stereo render (selected eye)
|
|
4061
|
+
RLAPI Matrix rlGetMatrixViewOffsetStereo(int eye)
|
|
4062
|
+
{
|
|
4063
|
+
Matrix mat = rlMatrixIdentity();
|
|
4064
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4065
|
+
mat = RLGL.State.viewOffsetStereo[eye];
|
|
4066
|
+
#endif
|
|
4067
|
+
return mat;
|
|
4068
|
+
}
|
|
4069
|
+
|
|
4070
|
+
// Set a custom modelview matrix (replaces internal modelview matrix)
|
|
4071
|
+
void rlSetMatrixModelview(Matrix view)
|
|
4072
|
+
{
|
|
4073
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4074
|
+
RLGL.State.modelview = view;
|
|
4075
|
+
#endif
|
|
4076
|
+
}
|
|
4077
|
+
|
|
4078
|
+
// Set a custom projection matrix (replaces internal projection matrix)
|
|
4079
|
+
void rlSetMatrixProjection(Matrix projection)
|
|
4080
|
+
{
|
|
4081
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4082
|
+
RLGL.State.projection = projection;
|
|
4083
|
+
#endif
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
// Set eyes projection matrices for stereo rendering
|
|
4087
|
+
void rlSetMatrixProjectionStereo(Matrix right, Matrix left)
|
|
4088
|
+
{
|
|
4089
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4090
|
+
RLGL.State.projectionStereo[0] = right;
|
|
4091
|
+
RLGL.State.projectionStereo[1] = left;
|
|
4092
|
+
#endif
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
// Set eyes view offsets matrices for stereo rendering
|
|
4096
|
+
void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left)
|
|
4097
|
+
{
|
|
4098
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4099
|
+
RLGL.State.viewOffsetStereo[0] = right;
|
|
4100
|
+
RLGL.State.viewOffsetStereo[1] = left;
|
|
4101
|
+
#endif
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
// Load and draw a quad in NDC
|
|
4105
|
+
void rlLoadDrawQuad(void)
|
|
4106
|
+
{
|
|
4107
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4108
|
+
unsigned int quadVAO = 0;
|
|
4109
|
+
unsigned int quadVBO = 0;
|
|
4110
|
+
|
|
4111
|
+
float vertices[] = {
|
|
4112
|
+
// Positions Texcoords
|
|
4113
|
+
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
|
4114
|
+
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
|
4115
|
+
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
|
4116
|
+
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
4117
|
+
};
|
|
4118
|
+
|
|
4119
|
+
// Gen VAO to contain VBO
|
|
4120
|
+
glGenVertexArrays(1, &quadVAO);
|
|
4121
|
+
glBindVertexArray(quadVAO);
|
|
4122
|
+
|
|
4123
|
+
// Gen and fill vertex buffer (VBO)
|
|
4124
|
+
glGenBuffers(1, &quadVBO);
|
|
4125
|
+
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
|
4126
|
+
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
|
|
4127
|
+
|
|
4128
|
+
// Bind vertex attributes (position, texcoords)
|
|
4129
|
+
glEnableVertexAttribArray(0);
|
|
4130
|
+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0); // Positions
|
|
4131
|
+
glEnableVertexAttribArray(1);
|
|
4132
|
+
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float))); // Texcoords
|
|
4133
|
+
|
|
4134
|
+
// Draw quad
|
|
4135
|
+
glBindVertexArray(quadVAO);
|
|
4136
|
+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
4137
|
+
glBindVertexArray(0);
|
|
4138
|
+
|
|
4139
|
+
// Delete buffers (VBO and VAO)
|
|
4140
|
+
glDeleteBuffers(1, &quadVBO);
|
|
4141
|
+
glDeleteVertexArrays(1, &quadVAO);
|
|
4142
|
+
#endif
|
|
4143
|
+
}
|
|
4144
|
+
|
|
4145
|
+
// Load and draw a cube in NDC
|
|
4146
|
+
void rlLoadDrawCube(void)
|
|
4147
|
+
{
|
|
4148
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4149
|
+
unsigned int cubeVAO = 0;
|
|
4150
|
+
unsigned int cubeVBO = 0;
|
|
4151
|
+
|
|
4152
|
+
float vertices[] = {
|
|
4153
|
+
// Positions Normals Texcoords
|
|
4154
|
+
-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
|
4155
|
+
1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
|
4156
|
+
1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
|
|
4157
|
+
1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
|
4158
|
+
-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
|
4159
|
+
-1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
|
|
4160
|
+
-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
|
4161
|
+
1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
|
4162
|
+
1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
|
4163
|
+
1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
|
4164
|
+
-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
|
4165
|
+
-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
|
4166
|
+
-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
|
4167
|
+
-1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
|
4168
|
+
-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
|
4169
|
+
-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
|
4170
|
+
-1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
4171
|
+
-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
|
4172
|
+
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
|
4173
|
+
1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
|
4174
|
+
1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
|
|
4175
|
+
1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
|
|
4176
|
+
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
|
4177
|
+
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
4178
|
+
-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,
|
|
4179
|
+
1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f,
|
|
4180
|
+
1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
4181
|
+
1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
|
4182
|
+
-1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
|
4183
|
+
-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,
|
|
4184
|
+
-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
|
4185
|
+
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
|
4186
|
+
1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
|
4187
|
+
1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
|
4188
|
+
-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
|
4189
|
+
-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f
|
|
4190
|
+
};
|
|
4191
|
+
|
|
4192
|
+
// Gen VAO to contain VBO
|
|
4193
|
+
glGenVertexArrays(1, &cubeVAO);
|
|
4194
|
+
glBindVertexArray(cubeVAO);
|
|
4195
|
+
|
|
4196
|
+
// Gen and fill vertex buffer (VBO)
|
|
4197
|
+
glGenBuffers(1, &cubeVBO);
|
|
4198
|
+
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
|
|
4199
|
+
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
4200
|
+
|
|
4201
|
+
// Bind vertex attributes (position, normals, texcoords)
|
|
4202
|
+
glBindVertexArray(cubeVAO);
|
|
4203
|
+
glEnableVertexAttribArray(0);
|
|
4204
|
+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0); // Positions
|
|
4205
|
+
glEnableVertexAttribArray(1);
|
|
4206
|
+
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float))); // Normals
|
|
4207
|
+
glEnableVertexAttribArray(2);
|
|
4208
|
+
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float))); // Texcoords
|
|
4209
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
4210
|
+
glBindVertexArray(0);
|
|
4211
|
+
|
|
4212
|
+
// Draw cube
|
|
4213
|
+
glBindVertexArray(cubeVAO);
|
|
4214
|
+
glDrawArrays(GL_TRIANGLES, 0, 36);
|
|
4215
|
+
glBindVertexArray(0);
|
|
4216
|
+
|
|
4217
|
+
// Delete VBO and VAO
|
|
4218
|
+
glDeleteBuffers(1, &cubeVBO);
|
|
4219
|
+
glDeleteVertexArrays(1, &cubeVAO);
|
|
4220
|
+
#endif
|
|
4221
|
+
}
|
|
4222
|
+
|
|
4223
|
+
// Get name string for pixel format
|
|
4224
|
+
const char *rlGetPixelFormatName(unsigned int format)
|
|
4225
|
+
{
|
|
4226
|
+
switch (format)
|
|
4227
|
+
{
|
|
4228
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: return "GRAYSCALE"; break; // 8 bit per pixel (no alpha)
|
|
4229
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: return "GRAY_ALPHA"; break; // 8*2 bpp (2 channels)
|
|
4230
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5: return "R5G6B5"; break; // 16 bpp
|
|
4231
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8: return "R8G8B8"; break; // 24 bpp
|
|
4232
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: return "R5G5B5A1"; break; // 16 bpp (1 bit alpha)
|
|
4233
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: return "R4G4B4A4"; break; // 16 bpp (4 bit alpha)
|
|
4234
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: return "R8G8B8A8"; break; // 32 bpp
|
|
4235
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32: return "R32"; break; // 32 bpp (1 channel - float)
|
|
4236
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: return "R32G32B32"; break; // 32*3 bpp (3 channels - float)
|
|
4237
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: return "R32G32B32A32"; break; // 32*4 bpp (4 channels - float)
|
|
4238
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT1_RGB: return "DXT1_RGB"; break; // 4 bpp (no alpha)
|
|
4239
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA: return "DXT1_RGBA"; break; // 4 bpp (1 bit alpha)
|
|
4240
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA: return "DXT3_RGBA"; break; // 8 bpp
|
|
4241
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA: return "DXT5_RGBA"; break; // 8 bpp
|
|
4242
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC1_RGB: return "ETC1_RGB"; break; // 4 bpp
|
|
4243
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC2_RGB: return "ETC2_RGB"; break; // 4 bpp
|
|
4244
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA: return "ETC2_RGBA"; break; // 8 bpp
|
|
4245
|
+
case RL_PIXELFORMAT_COMPRESSED_PVRT_RGB: return "PVRT_RGB"; break; // 4 bpp
|
|
4246
|
+
case RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA: return "PVRT_RGBA"; break; // 4 bpp
|
|
4247
|
+
case RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: return "ASTC_4x4_RGBA"; break; // 8 bpp
|
|
4248
|
+
case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: return "ASTC_8x8_RGBA"; break; // 2 bpp
|
|
4249
|
+
default: return "UNKNOWN"; break;
|
|
4250
|
+
}
|
|
4251
|
+
}
|
|
4252
|
+
|
|
4253
|
+
//----------------------------------------------------------------------------------
|
|
4254
|
+
// Module specific Functions Definition
|
|
4255
|
+
//----------------------------------------------------------------------------------
|
|
4256
|
+
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
|
4257
|
+
// Load default shader (just vertex positioning and texture coloring)
|
|
4258
|
+
// NOTE: This shader program is used for internal buffers
|
|
4259
|
+
// NOTE: Loaded: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
|
|
4260
|
+
static void rlLoadShaderDefault(void)
|
|
4261
|
+
{
|
|
4262
|
+
RLGL.State.defaultShaderLocs = (int *)RL_CALLOC(RL_MAX_SHADER_LOCATIONS, sizeof(int));
|
|
4263
|
+
|
|
4264
|
+
// NOTE: All locations must be reseted to -1 (no location)
|
|
4265
|
+
for (int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++) RLGL.State.defaultShaderLocs[i] = -1;
|
|
4266
|
+
|
|
4267
|
+
// Vertex shader directly defined, no external file required
|
|
4268
|
+
const char *defaultVShaderCode =
|
|
4269
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
4270
|
+
"#version 120 \n"
|
|
4271
|
+
"attribute vec3 vertexPosition; \n"
|
|
4272
|
+
"attribute vec2 vertexTexCoord; \n"
|
|
4273
|
+
"attribute vec4 vertexColor; \n"
|
|
4274
|
+
"varying vec2 fragTexCoord; \n"
|
|
4275
|
+
"varying vec4 fragColor; \n"
|
|
4276
|
+
#elif defined(GRAPHICS_API_OPENGL_33)
|
|
4277
|
+
"#version 330 \n"
|
|
4278
|
+
"in vec3 vertexPosition; \n"
|
|
4279
|
+
"in vec2 vertexTexCoord; \n"
|
|
4280
|
+
"in vec4 vertexColor; \n"
|
|
4281
|
+
"out vec2 fragTexCoord; \n"
|
|
4282
|
+
"out vec4 fragColor; \n"
|
|
4283
|
+
#endif
|
|
4284
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
4285
|
+
"#version 100 \n"
|
|
4286
|
+
"attribute vec3 vertexPosition; \n"
|
|
4287
|
+
"attribute vec2 vertexTexCoord; \n"
|
|
4288
|
+
"attribute vec4 vertexColor; \n"
|
|
4289
|
+
"varying vec2 fragTexCoord; \n"
|
|
4290
|
+
"varying vec4 fragColor; \n"
|
|
4291
|
+
#endif
|
|
4292
|
+
"uniform mat4 mvp; \n"
|
|
4293
|
+
"void main() \n"
|
|
4294
|
+
"{ \n"
|
|
4295
|
+
" fragTexCoord = vertexTexCoord; \n"
|
|
4296
|
+
" fragColor = vertexColor; \n"
|
|
4297
|
+
" gl_Position = mvp*vec4(vertexPosition, 1.0); \n"
|
|
4298
|
+
"} \n";
|
|
4299
|
+
|
|
4300
|
+
// Fragment shader directly defined, no external file required
|
|
4301
|
+
const char *defaultFShaderCode =
|
|
4302
|
+
#if defined(GRAPHICS_API_OPENGL_21)
|
|
4303
|
+
"#version 120 \n"
|
|
4304
|
+
"varying vec2 fragTexCoord; \n"
|
|
4305
|
+
"varying vec4 fragColor; \n"
|
|
4306
|
+
"uniform sampler2D texture0; \n"
|
|
4307
|
+
"uniform vec4 colDiffuse; \n"
|
|
4308
|
+
"void main() \n"
|
|
4309
|
+
"{ \n"
|
|
4310
|
+
" vec4 texelColor = texture2D(texture0, fragTexCoord); \n"
|
|
4311
|
+
" gl_FragColor = texelColor*colDiffuse*fragColor; \n"
|
|
4312
|
+
"} \n";
|
|
4313
|
+
#elif defined(GRAPHICS_API_OPENGL_33)
|
|
4314
|
+
"#version 330 \n"
|
|
4315
|
+
"in vec2 fragTexCoord; \n"
|
|
4316
|
+
"in vec4 fragColor; \n"
|
|
4317
|
+
"out vec4 finalColor; \n"
|
|
4318
|
+
"uniform sampler2D texture0; \n"
|
|
4319
|
+
"uniform vec4 colDiffuse; \n"
|
|
4320
|
+
"void main() \n"
|
|
4321
|
+
"{ \n"
|
|
4322
|
+
" vec4 texelColor = texture(texture0, fragTexCoord); \n"
|
|
4323
|
+
" finalColor = texelColor*colDiffuse*fragColor; \n"
|
|
4324
|
+
"} \n";
|
|
4325
|
+
#endif
|
|
4326
|
+
#if defined(GRAPHICS_API_OPENGL_ES2)
|
|
4327
|
+
"#version 100 \n"
|
|
4328
|
+
"precision mediump float; \n" // Precision required for OpenGL ES2 (WebGL)
|
|
4329
|
+
"varying vec2 fragTexCoord; \n"
|
|
4330
|
+
"varying vec4 fragColor; \n"
|
|
4331
|
+
"uniform sampler2D texture0; \n"
|
|
4332
|
+
"uniform vec4 colDiffuse; \n"
|
|
4333
|
+
"void main() \n"
|
|
4334
|
+
"{ \n"
|
|
4335
|
+
" vec4 texelColor = texture2D(texture0, fragTexCoord); \n"
|
|
4336
|
+
" gl_FragColor = texelColor*colDiffuse*fragColor; \n"
|
|
4337
|
+
"} \n";
|
|
4338
|
+
#endif
|
|
4339
|
+
|
|
4340
|
+
// NOTE: Compiled vertex/fragment shaders are kept for re-use
|
|
4341
|
+
RLGL.State.defaultVShaderId = rlCompileShader(defaultVShaderCode, GL_VERTEX_SHADER); // Compile default vertex shader
|
|
4342
|
+
RLGL.State.defaultFShaderId = rlCompileShader(defaultFShaderCode, GL_FRAGMENT_SHADER); // Compile default fragment shader
|
|
4343
|
+
|
|
4344
|
+
RLGL.State.defaultShaderId = rlLoadShaderProgram(RLGL.State.defaultVShaderId, RLGL.State.defaultFShaderId);
|
|
4345
|
+
|
|
4346
|
+
if (RLGL.State.defaultShaderId > 0)
|
|
4347
|
+
{
|
|
4348
|
+
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Default shader loaded successfully", RLGL.State.defaultShaderId);
|
|
4349
|
+
|
|
4350
|
+
// Set default shader locations: attributes locations
|
|
4351
|
+
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_POSITION] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexPosition");
|
|
4352
|
+
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_TEXCOORD01] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexTexCoord");
|
|
4353
|
+
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_VERTEX_COLOR] = glGetAttribLocation(RLGL.State.defaultShaderId, "vertexColor");
|
|
4354
|
+
|
|
4355
|
+
// Set default shader locations: uniform locations
|
|
4356
|
+
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MATRIX_MVP] = glGetUniformLocation(RLGL.State.defaultShaderId, "mvp");
|
|
4357
|
+
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_COLOR_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, "colDiffuse");
|
|
4358
|
+
RLGL.State.defaultShaderLocs[RL_SHADER_LOC_MAP_DIFFUSE] = glGetUniformLocation(RLGL.State.defaultShaderId, "texture0");
|
|
4359
|
+
}
|
|
4360
|
+
else TRACELOG(RL_LOG_WARNING, "SHADER: [ID %i] Failed to load default shader", RLGL.State.defaultShaderId);
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4363
|
+
// Unload default shader
|
|
4364
|
+
// NOTE: Unloads: RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs
|
|
4365
|
+
static void rlUnloadShaderDefault(void)
|
|
4366
|
+
{
|
|
4367
|
+
glUseProgram(0);
|
|
4368
|
+
|
|
4369
|
+
glDetachShader(RLGL.State.defaultShaderId, RLGL.State.defaultVShaderId);
|
|
4370
|
+
glDetachShader(RLGL.State.defaultShaderId, RLGL.State.defaultFShaderId);
|
|
4371
|
+
glDeleteShader(RLGL.State.defaultVShaderId);
|
|
4372
|
+
glDeleteShader(RLGL.State.defaultFShaderId);
|
|
4373
|
+
|
|
4374
|
+
glDeleteProgram(RLGL.State.defaultShaderId);
|
|
4375
|
+
|
|
4376
|
+
RL_FREE(RLGL.State.defaultShaderLocs);
|
|
4377
|
+
|
|
4378
|
+
TRACELOG(RL_LOG_INFO, "SHADER: [ID %i] Default shader unloaded successfully", RLGL.State.defaultShaderId);
|
|
4379
|
+
}
|
|
4380
|
+
|
|
4381
|
+
#if defined(RLGL_SHOW_GL_DETAILS_INFO)
|
|
4382
|
+
// Get compressed format official GL identifier name
|
|
4383
|
+
static char *rlGetCompressedFormatName(int format)
|
|
4384
|
+
{
|
|
4385
|
+
static char compName[64] = { 0 };
|
|
4386
|
+
memset(compName, 0, 64);
|
|
4387
|
+
|
|
4388
|
+
switch (format)
|
|
4389
|
+
{
|
|
4390
|
+
// GL_EXT_texture_compression_s3tc
|
|
4391
|
+
case 0x83F0: strcpy(compName, "GL_COMPRESSED_RGB_S3TC_DXT1_EXT"); break;
|
|
4392
|
+
case 0x83F1: strcpy(compName, "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT"); break;
|
|
4393
|
+
case 0x83F2: strcpy(compName, "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT"); break;
|
|
4394
|
+
case 0x83F3: strcpy(compName, "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT"); break;
|
|
4395
|
+
// GL_3DFX_texture_compression_FXT1
|
|
4396
|
+
case 0x86B0: strcpy(compName, "GL_COMPRESSED_RGB_FXT1_3DFX"); break;
|
|
4397
|
+
case 0x86B1: strcpy(compName, "GL_COMPRESSED_RGBA_FXT1_3DFX"); break;
|
|
4398
|
+
// GL_IMG_texture_compression_pvrtc
|
|
4399
|
+
case 0x8C00: strcpy(compName, "GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG"); break;
|
|
4400
|
+
case 0x8C01: strcpy(compName, "GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG"); break;
|
|
4401
|
+
case 0x8C02: strcpy(compName, "GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG"); break;
|
|
4402
|
+
case 0x8C03: strcpy(compName, "GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG"); break;
|
|
4403
|
+
// GL_OES_compressed_ETC1_RGB8_texture
|
|
4404
|
+
case 0x8D64: strcpy(compName, "GL_ETC1_RGB8_OES"); break;
|
|
4405
|
+
// GL_ARB_texture_compression_rgtc
|
|
4406
|
+
case 0x8DBB: strcpy(compName, "GL_COMPRESSED_RED_RGTC1"); break;
|
|
4407
|
+
case 0x8DBC: strcpy(compName, "GL_COMPRESSED_SIGNED_RED_RGTC1"); break;
|
|
4408
|
+
case 0x8DBD: strcpy(compName, "GL_COMPRESSED_RG_RGTC2"); break;
|
|
4409
|
+
case 0x8DBE: strcpy(compName, "GL_COMPRESSED_SIGNED_RG_RGTC2"); break;
|
|
4410
|
+
// GL_ARB_texture_compression_bptc
|
|
4411
|
+
case 0x8E8C: strcpy(compName, "GL_COMPRESSED_RGBA_BPTC_UNORM_ARB"); break;
|
|
4412
|
+
case 0x8E8D: strcpy(compName, "GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB"); break;
|
|
4413
|
+
case 0x8E8E: strcpy(compName, "GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB"); break;
|
|
4414
|
+
case 0x8E8F: strcpy(compName, "GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB"); break;
|
|
4415
|
+
// GL_ARB_ES3_compatibility
|
|
4416
|
+
case 0x9274: strcpy(compName, "GL_COMPRESSED_RGB8_ETC2"); break;
|
|
4417
|
+
case 0x9275: strcpy(compName, "GL_COMPRESSED_SRGB8_ETC2"); break;
|
|
4418
|
+
case 0x9276: strcpy(compName, "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2"); break;
|
|
4419
|
+
case 0x9277: strcpy(compName, "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2"); break;
|
|
4420
|
+
case 0x9278: strcpy(compName, "GL_COMPRESSED_RGBA8_ETC2_EAC"); break;
|
|
4421
|
+
case 0x9279: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC"); break;
|
|
4422
|
+
case 0x9270: strcpy(compName, "GL_COMPRESSED_R11_EAC"); break;
|
|
4423
|
+
case 0x9271: strcpy(compName, "GL_COMPRESSED_SIGNED_R11_EAC"); break;
|
|
4424
|
+
case 0x9272: strcpy(compName, "GL_COMPRESSED_RG11_EAC"); break;
|
|
4425
|
+
case 0x9273: strcpy(compName, "GL_COMPRESSED_SIGNED_RG11_EAC"); break;
|
|
4426
|
+
// GL_KHR_texture_compression_astc_hdr
|
|
4427
|
+
case 0x93B0: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_4x4_KHR"); break;
|
|
4428
|
+
case 0x93B1: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_5x4_KHR"); break;
|
|
4429
|
+
case 0x93B2: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_5x5_KHR"); break;
|
|
4430
|
+
case 0x93B3: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_6x5_KHR"); break;
|
|
4431
|
+
case 0x93B4: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_6x6_KHR"); break;
|
|
4432
|
+
case 0x93B5: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_8x5_KHR"); break;
|
|
4433
|
+
case 0x93B6: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_8x6_KHR"); break;
|
|
4434
|
+
case 0x93B7: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_8x8_KHR"); break;
|
|
4435
|
+
case 0x93B8: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_10x5_KHR"); break;
|
|
4436
|
+
case 0x93B9: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_10x6_KHR"); break;
|
|
4437
|
+
case 0x93BA: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_10x8_KHR"); break;
|
|
4438
|
+
case 0x93BB: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_10x10_KHR"); break;
|
|
4439
|
+
case 0x93BC: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_12x10_KHR"); break;
|
|
4440
|
+
case 0x93BD: strcpy(compName, "GL_COMPRESSED_RGBA_ASTC_12x12_KHR"); break;
|
|
4441
|
+
case 0x93D0: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR"); break;
|
|
4442
|
+
case 0x93D1: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR"); break;
|
|
4443
|
+
case 0x93D2: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR"); break;
|
|
4444
|
+
case 0x93D3: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR"); break;
|
|
4445
|
+
case 0x93D4: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR"); break;
|
|
4446
|
+
case 0x93D5: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR"); break;
|
|
4447
|
+
case 0x93D6: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR"); break;
|
|
4448
|
+
case 0x93D7: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR"); break;
|
|
4449
|
+
case 0x93D8: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR"); break;
|
|
4450
|
+
case 0x93D9: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR"); break;
|
|
4451
|
+
case 0x93DA: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR"); break;
|
|
4452
|
+
case 0x93DB: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR"); break;
|
|
4453
|
+
case 0x93DC: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR"); break;
|
|
4454
|
+
case 0x93DD: strcpy(compName, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR"); break;
|
|
4455
|
+
default: strcpy(compName, "GL_COMPRESSED_UNKNOWN"); break;
|
|
4456
|
+
}
|
|
4457
|
+
|
|
4458
|
+
return compName;
|
|
4459
|
+
}
|
|
4460
|
+
#endif // RLGL_SHOW_GL_DETAILS_INFO
|
|
4461
|
+
|
|
4462
|
+
#endif // GRAPHICS_API_OPENGL_33 || GRAPHICS_API_OPENGL_ES2
|
|
4463
|
+
|
|
4464
|
+
#if defined(GRAPHICS_API_OPENGL_11)
|
|
4465
|
+
// Mipmaps data is generated after image data
|
|
4466
|
+
// NOTE: Only works with RGBA (4 bytes) data!
|
|
4467
|
+
static int rlGenTextureMipmapsData(unsigned char *data, int baseWidth, int baseHeight)
|
|
4468
|
+
{
|
|
4469
|
+
int mipmapCount = 1; // Required mipmap levels count (including base level)
|
|
4470
|
+
int width = baseWidth;
|
|
4471
|
+
int height = baseHeight;
|
|
4472
|
+
int size = baseWidth*baseHeight*4; // Size in bytes (will include mipmaps...), RGBA only
|
|
4473
|
+
|
|
4474
|
+
// Count mipmap levels required
|
|
4475
|
+
while ((width != 1) && (height != 1))
|
|
4476
|
+
{
|
|
4477
|
+
width /= 2;
|
|
4478
|
+
height /= 2;
|
|
4479
|
+
|
|
4480
|
+
TRACELOGD("TEXTURE: Next mipmap size: %i x %i", width, height);
|
|
4481
|
+
|
|
4482
|
+
mipmapCount++;
|
|
4483
|
+
|
|
4484
|
+
size += (width*height*4); // Add mipmap size (in bytes)
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
TRACELOGD("TEXTURE: Total mipmaps required: %i", mipmapCount);
|
|
4488
|
+
TRACELOGD("TEXTURE: Total size of data required: %i", size);
|
|
4489
|
+
|
|
4490
|
+
unsigned char *temp = RL_REALLOC(data, size);
|
|
4491
|
+
|
|
4492
|
+
if (temp != NULL) data = temp;
|
|
4493
|
+
else TRACELOG(RL_LOG_WARNING, "TEXTURE: Failed to re-allocate required mipmaps memory");
|
|
4494
|
+
|
|
4495
|
+
width = baseWidth;
|
|
4496
|
+
height = baseHeight;
|
|
4497
|
+
size = (width*height*4); // RGBA: 4 bytes
|
|
4498
|
+
|
|
4499
|
+
// Generate mipmaps
|
|
4500
|
+
// NOTE: Every mipmap data is stored after data (RGBA - 4 bytes)
|
|
4501
|
+
unsigned char *image = (unsigned char *)RL_MALLOC(width*height*4);
|
|
4502
|
+
unsigned char *mipmap = NULL;
|
|
4503
|
+
int offset = 0;
|
|
4504
|
+
|
|
4505
|
+
for (int i = 0; i < size; i += 4)
|
|
4506
|
+
{
|
|
4507
|
+
image[i] = data[i];
|
|
4508
|
+
image[i + 1] = data[i + 1];
|
|
4509
|
+
image[i + 2] = data[i + 2];
|
|
4510
|
+
image[i + 3] = data[i + 3];
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4513
|
+
TRACELOGD("TEXTURE: Mipmap base size (%ix%i)", width, height);
|
|
4514
|
+
|
|
4515
|
+
for (int mip = 1; mip < mipmapCount; mip++)
|
|
4516
|
+
{
|
|
4517
|
+
mipmap = rlGenNextMipmapData(image, width, height);
|
|
4518
|
+
|
|
4519
|
+
offset += (width*height*4); // Size of last mipmap
|
|
4520
|
+
|
|
4521
|
+
width /= 2;
|
|
4522
|
+
height /= 2;
|
|
4523
|
+
size = (width*height*4); // Mipmap size to store after offset
|
|
4524
|
+
|
|
4525
|
+
// Add mipmap to data
|
|
4526
|
+
for (int i = 0; i < size; i += 4)
|
|
4527
|
+
{
|
|
4528
|
+
data[offset + i] = mipmap[i];
|
|
4529
|
+
data[offset + i + 1] = mipmap[i + 1];
|
|
4530
|
+
data[offset + i + 2] = mipmap[i + 2];
|
|
4531
|
+
data[offset + i + 3] = mipmap[i + 3];
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
RL_FREE(image);
|
|
4535
|
+
|
|
4536
|
+
image = mipmap;
|
|
4537
|
+
mipmap = NULL;
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
RL_FREE(mipmap); // free mipmap data
|
|
4541
|
+
|
|
4542
|
+
return mipmapCount;
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
|
+
// Manual mipmap generation (basic scaling algorithm)
|
|
4546
|
+
static unsigned char *rlGenNextMipmapData(unsigned char *srcData, int srcWidth, int srcHeight)
|
|
4547
|
+
{
|
|
4548
|
+
int x2 = 0;
|
|
4549
|
+
int y2 = 0;
|
|
4550
|
+
unsigned char prow[4];
|
|
4551
|
+
unsigned char pcol[4];
|
|
4552
|
+
|
|
4553
|
+
int width = srcWidth/2;
|
|
4554
|
+
int height = srcHeight/2;
|
|
4555
|
+
|
|
4556
|
+
unsigned char *mipmap = (unsigned char *)RL_MALLOC(width*height*4);
|
|
4557
|
+
|
|
4558
|
+
// Scaling algorithm works perfectly (box-filter)
|
|
4559
|
+
for (int y = 0; y < height; y++)
|
|
4560
|
+
{
|
|
4561
|
+
y2 = 2*y;
|
|
4562
|
+
|
|
4563
|
+
for (int x = 0; x < width; x++)
|
|
4564
|
+
{
|
|
4565
|
+
x2 = 2*x;
|
|
4566
|
+
|
|
4567
|
+
prow[0] = (srcData[(y2*srcWidth + x2)*4 + 0] + srcData[(y2*srcWidth + x2 + 1)*4 + 0])/2;
|
|
4568
|
+
prow[1] = (srcData[(y2*srcWidth + x2)*4 + 1] + srcData[(y2*srcWidth + x2 + 1)*4 + 1])/2;
|
|
4569
|
+
prow[2] = (srcData[(y2*srcWidth + x2)*4 + 2] + srcData[(y2*srcWidth + x2 + 1)*4 + 2])/2;
|
|
4570
|
+
prow[3] = (srcData[(y2*srcWidth + x2)*4 + 3] + srcData[(y2*srcWidth + x2 + 1)*4 + 3])/2;
|
|
4571
|
+
|
|
4572
|
+
pcol[0] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 0] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 0])/2;
|
|
4573
|
+
pcol[1] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 1] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 1])/2;
|
|
4574
|
+
pcol[2] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 2] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 2])/2;
|
|
4575
|
+
pcol[3] = (srcData[((y2 + 1)*srcWidth + x2)*4 + 3] + srcData[((y2 + 1)*srcWidth + x2 + 1)*4 + 3])/2;
|
|
4576
|
+
|
|
4577
|
+
mipmap[(y*width + x)*4 + 0] = (prow[0] + pcol[0])/2;
|
|
4578
|
+
mipmap[(y*width + x)*4 + 1] = (prow[1] + pcol[1])/2;
|
|
4579
|
+
mipmap[(y*width + x)*4 + 2] = (prow[2] + pcol[2])/2;
|
|
4580
|
+
mipmap[(y*width + x)*4 + 3] = (prow[3] + pcol[3])/2;
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4583
|
+
|
|
4584
|
+
TRACELOGD("TEXTURE: Mipmap generated successfully (%ix%i)", width, height);
|
|
4585
|
+
|
|
4586
|
+
return mipmap;
|
|
4587
|
+
}
|
|
4588
|
+
#endif // GRAPHICS_API_OPENGL_11
|
|
4589
|
+
|
|
4590
|
+
// Get pixel data size in bytes (image or texture)
|
|
4591
|
+
// NOTE: Size depends on pixel format
|
|
4592
|
+
static int rlGetPixelDataSize(int width, int height, int format)
|
|
4593
|
+
{
|
|
4594
|
+
int dataSize = 0; // Size in bytes
|
|
4595
|
+
int bpp = 0; // Bits per pixel
|
|
4596
|
+
|
|
4597
|
+
switch (format)
|
|
4598
|
+
{
|
|
4599
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: bpp = 8; break;
|
|
4600
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
|
|
4601
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G6B5:
|
|
4602
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
|
|
4603
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: bpp = 16; break;
|
|
4604
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: bpp = 32; break;
|
|
4605
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8: bpp = 24; break;
|
|
4606
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32: bpp = 32; break;
|
|
4607
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32: bpp = 32*3; break;
|
|
4608
|
+
case RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: bpp = 32*4; break;
|
|
4609
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT1_RGB:
|
|
4610
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT1_RGBA:
|
|
4611
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC1_RGB:
|
|
4612
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC2_RGB:
|
|
4613
|
+
case RL_PIXELFORMAT_COMPRESSED_PVRT_RGB:
|
|
4614
|
+
case RL_PIXELFORMAT_COMPRESSED_PVRT_RGBA: bpp = 4; break;
|
|
4615
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA:
|
|
4616
|
+
case RL_PIXELFORMAT_COMPRESSED_DXT5_RGBA:
|
|
4617
|
+
case RL_PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA:
|
|
4618
|
+
case RL_PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: bpp = 8; break;
|
|
4619
|
+
case RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: bpp = 2; break;
|
|
4620
|
+
default: break;
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4623
|
+
dataSize = width*height*bpp/8; // Total data size in bytes
|
|
4624
|
+
|
|
4625
|
+
// Most compressed formats works on 4x4 blocks,
|
|
4626
|
+
// if texture is smaller, minimum dataSize is 8 or 16
|
|
4627
|
+
if ((width < 4) && (height < 4))
|
|
4628
|
+
{
|
|
4629
|
+
if ((format >= RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) && (format < RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA)) dataSize = 8;
|
|
4630
|
+
else if ((format >= RL_PIXELFORMAT_COMPRESSED_DXT3_RGBA) && (format < RL_PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA)) dataSize = 16;
|
|
4631
|
+
}
|
|
4632
|
+
|
|
4633
|
+
return dataSize;
|
|
4634
|
+
}
|
|
4635
|
+
|
|
4636
|
+
// Auxiliar math functions
|
|
4637
|
+
|
|
4638
|
+
// Get identity matrix
|
|
4639
|
+
static Matrix rlMatrixIdentity(void)
|
|
4640
|
+
{
|
|
4641
|
+
Matrix result = {
|
|
4642
|
+
1.0f, 0.0f, 0.0f, 0.0f,
|
|
4643
|
+
0.0f, 1.0f, 0.0f, 0.0f,
|
|
4644
|
+
0.0f, 0.0f, 1.0f, 0.0f,
|
|
4645
|
+
0.0f, 0.0f, 0.0f, 1.0f
|
|
4646
|
+
};
|
|
4647
|
+
|
|
4648
|
+
return result;
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
// Get two matrix multiplication
|
|
4652
|
+
// NOTE: When multiplying matrices... the order matters!
|
|
4653
|
+
static Matrix rlMatrixMultiply(Matrix left, Matrix right)
|
|
4654
|
+
{
|
|
4655
|
+
Matrix result = { 0 };
|
|
4656
|
+
|
|
4657
|
+
result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
|
|
4658
|
+
result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
|
|
4659
|
+
result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
|
|
4660
|
+
result.m3 = left.m0*right.m3 + left.m1*right.m7 + left.m2*right.m11 + left.m3*right.m15;
|
|
4661
|
+
result.m4 = left.m4*right.m0 + left.m5*right.m4 + left.m6*right.m8 + left.m7*right.m12;
|
|
4662
|
+
result.m5 = left.m4*right.m1 + left.m5*right.m5 + left.m6*right.m9 + left.m7*right.m13;
|
|
4663
|
+
result.m6 = left.m4*right.m2 + left.m5*right.m6 + left.m6*right.m10 + left.m7*right.m14;
|
|
4664
|
+
result.m7 = left.m4*right.m3 + left.m5*right.m7 + left.m6*right.m11 + left.m7*right.m15;
|
|
4665
|
+
result.m8 = left.m8*right.m0 + left.m9*right.m4 + left.m10*right.m8 + left.m11*right.m12;
|
|
4666
|
+
result.m9 = left.m8*right.m1 + left.m9*right.m5 + left.m10*right.m9 + left.m11*right.m13;
|
|
4667
|
+
result.m10 = left.m8*right.m2 + left.m9*right.m6 + left.m10*right.m10 + left.m11*right.m14;
|
|
4668
|
+
result.m11 = left.m8*right.m3 + left.m9*right.m7 + left.m10*right.m11 + left.m11*right.m15;
|
|
4669
|
+
result.m12 = left.m12*right.m0 + left.m13*right.m4 + left.m14*right.m8 + left.m15*right.m12;
|
|
4670
|
+
result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13;
|
|
4671
|
+
result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14;
|
|
4672
|
+
result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15;
|
|
4673
|
+
|
|
4674
|
+
return result;
|
|
4675
|
+
}
|
|
4676
|
+
|
|
4677
|
+
#endif // RLGL_IMPLEMENTATION
|