Commit graph

111 commits

Author SHA1 Message Date
Andrei Alexeyev
7c82cbba9b
gl33: remove avoid_sampler_uniform_updates workaround and make it the default 2024-10-04 16:27:28 +02:00
Andrei Alexeyev
5274cec283
gl33: use glTexStorage* and glInvalidateTexImage* when available
glTexStorage is mostly intended to work around a regression in ANGLE's
Metal backend; see https://issues.chromium.org/issues/355605685

Potentially fixes #386
2024-10-01 04:22:30 +02:00
Andrei Alexeyev
fda8556a39
src: deprecate strdup(), use mem_strdup() explicitly
This fixes a nasty bug that manifests on windows when building without
precompiled headers. util/stringops.h used to silently replace strdup
with a macro that's compatible with mem_free(). This header would
typically be included everywhere due to PCH, but without it the strdup
from libc would sometimes be in scope. On most platforms mem_free() is
equivalent to free(), but not on windows, because we have to use
_aligned_free() there. Attempting to mem_free() the result of a libc
strdup() would segfault in such a configuration.

Avoid the footgun by banning strdup() entirely. Maybe redefining libc
names isn't such a great idea, who knew?
2024-09-10 14:31:55 +02:00
Andrei Alexeyev
c150f4cd13
gl33: fix gl33_framebuffer_finalize_read_requests() 2024-09-03 01:52:50 +02:00
Andrei Alexeyev
49bcbac838
renderer: remove PRIM_LINE_LOOP 2024-08-30 11:52:47 +02:00
Andrei Alexeyev
47c8f5bee3
gl33: don't try to fall back to r_shader_standard() if active shader is deleted
This prevents clean shutdown in tests that don't bring up the whole
resource system, and is not really a sane fallback anyway.
2024-08-30 11:52:47 +02:00
Andrei Alexeyev
043f09c668
gl33: remove magic _SIZE uniform handling
Only FXAA ever used this, and it's trivial to implement in client code
2024-08-30 11:52:47 +02:00
Andrei Alexeyev
7cd47e9404
renderer: move magic uniform definitions to common 2024-08-30 11:52:47 +02:00
Andrei Alexeyev
4ebd7ba14b
gl33: remove trailing [0] from array uniform names 2024-08-30 11:52:47 +02:00
Andrei Alexeyev
50056eb41a
renderer: decouple models and sprite_batch init/shutdown from main render system 2024-08-30 11:52:47 +02:00
Andrei Alexeyev
8b37d1cbf2
src: the great #include massacre of 2024 2024-05-17 14:11:48 +02:00
Andrei Alexeyev
be7905d6a3
src: run upkeep 2024-05-17 04:58:47 +02:00
Andrei Alexeyev
8d5ffe4b91
renderer: remove old r_screenshot() API 2024-05-01 01:07:18 +02:00
Andrei Alexeyev
f11a09649d
gl33: implement sync fallback for framebuffer async read 2024-05-01 01:01:09 +02:00
Andrei Alexeyev
783172861a
renderer: simplify async readback API; use glMapBufferRange
glGetBufferSubData is not available on GLES
2024-05-01 00:19:07 +02:00
Andrei Alexeyev
c6d92f7407
renderer: add asynchronous framebuffer readback API
Used to download rendered images from the GPU with minimal (if any)
pipeline stalling. Implemented with PBOs in OpenGL.
2024-04-29 01:15:15 +02:00
Andrei Alexeyev
e54b144973
gl33: fix scissor test 2024-04-11 18:04:22 +02:00
Andrei Alexeyev
cc01be15fe
all: use the clamp() macro 2023-09-28 17:43:14 +02:00
Andrei Alexeyev
8f8ca2beca
all: use min/max macros; avoid some unnecessary conversions 2023-09-28 17:43:14 +02:00
Andrei Alexeyev
cab432f843
gles: create angle context in webgl mode on windows
Cubemaps are broken in ANGLE's D3D11 backend, except in WebGL mode for
some reason. This is a terrible workaround, but it beats fucked up
rendering in stage backgrounds.
2023-08-28 19:15:40 +02:00
Andrei Alexeyev
6cc8bf2d47
gl33: shut up -Wunreachable-code on emscripten builds 2023-07-30 03:01:58 +02:00
Andrei Alexeyev
190da85628
gl33,glescommon: fix screenshots
Broken by b50b57803e
2023-04-18 12:47:19 +02:00
Andrei Alexeyev
b50b57803e
renderer: add r_framebuffer_copy 2023-04-10 06:47:55 +02:00
Andrei Alexeyev
3dc0faec9e
renderer/api: rename ClearBufferFlags to BufferKindFlags 2023-04-10 06:47:55 +02:00
Andrei Alexeyev
711edc218f
util/assert: add optional message to assert, assume, and static_assert
Removed static_assert_nomsg, since static_assert's message argument is
optional now. In C2X mode this uses the native _Static_assert
functionality, otherwise it falls back to a macro-based overload.

Additionally, rewrote the assert macro so it correctly marks the failing
branch as a dead end.
2023-03-26 01:52:41 +01:00
Andrei Alexeyev
b6978178b1
memory: use custom memory allocation wrappers
Introduces wrappers around memory allocation functions in `memory.h`
that should be used instead of the standard C ones.

These never return NULL and, with the exception of `mem_realloc()`,
zero-initialize the allocated memory like `calloc()` does.

All allocations made with the memory.h API must be deallocated with
`mem_free()`. Although standard `free()` will work on some platforms,
it's not portable (currently it won't work on Windows). Likewise,
`mem_free()` must not be used to free foreign allocations.

The standard C allocation functions are now diagnosed as deprecated.
They are, however, available with the `libc_` prefix in case interfacing
with foreign APIs is required. So far they are only used to implement
`memory.h`.

Perhaps the most important change is the introduction of the `ALLOC()`,
`ALLOC_ARRAY()`, and `ALLOC_FLEX()` macros. They take a type as a
parameter, and allocate enough memory with the correct alignment for
that type. That includes overaligned types as well. In most
circumstances you should prefer to use these macros. See the `memory.h`
header for some usage examples.
2023-01-18 13:23:22 +01:00
Andrei Alexeyev
3fd3c33371
gl33: fix inverted logic in gl33_framebuffer_attach 2022-09-05 06:23:35 +02:00
Andrei Alexeyev
7d9603f0da
gl33: index buffer fixes
* Allow updates before VAO association happens
* Fix array out of bounds on destroy
2022-02-09 05:51:41 +02:00
Andrei Alexeyev
fb18c3b7cd
renderer: add r_index_buffer_invalidate() 2022-02-09 05:51:41 +02:00
Andrei Alexeyev
de09759d31
renderer: support specifying index size for index buffers
Sizes of 2 (uint16_t) and 4 (uint32_t) are supported.

Moved most of the logic for appending indices into renderer/api.c
2022-02-09 05:51:41 +02:00
Andrei Alexeyev
a82b63045c
renderer: add scissor test API 2022-02-09 05:51:41 +02:00
Andrei Alexeyev
b39c9ba78e
resource: partial support for resource reloading 2022-01-02 08:28:02 +02:00
Andrei Alexeyev
dc52836af7
gl33: enable sRGB conversion when rendering to sRGB textures
This matches the gles30 behavior, which can not be changed without
relying on extensions. It also lets us simplify the texture_post_load
shader.
2021-12-22 22:46:59 +02:00
Andrei Alexeyev
630929a4a5
gl33: dynamically grow buffers when running out of space
Prevents crashes from loading too many models (happens in normal
gameplay!)
2021-10-25 14:03:35 +03:00
Andrei Alexeyev
8d2ee76710
replace include guards with #pragma once 2021-08-31 23:34:46 +03:00
Andrei Alexeyev
61d2d18731
gl33: only regen auto mipmaps if texture is to be used in the next draw 2021-07-20 14:16:15 +03:00
Andrei Alexeyev
7e58ebe8b9
gl33: fix linear-to-nearest filter remapping for unfilterable textures 2021-07-19 15:10:35 +03:00
Andrei Alexeyev
9666bae1bc
Fix gcc11 warnings 2021-07-18 19:09:12 +03:00
Andrei Alexeyev
d10c5d0e7e
renderer: fix gles30/webgl breakage 2021-07-18 11:16:16 +03:00
Andrei Alexeyev
cbbaa3eb7f
renderer: Add API to dump texture data into a pixmap 2021-07-18 10:39:05 +03:00
Andrei Alexeyev
20ec3e62e9
gl33: fix even more texture management issues
We still can't have two incompatible samplers bound to the same
texturing unit, even if there is no texture bound to it.
2021-07-13 00:24:46 +03:00
Andrei Alexeyev
b45b2c22ce
renderer,gl33: fix texture management issues
Previously we assumed that we generally do not need to unbind textures
from shader samplers: if a sampler had no Taisei-level texture binding,
we would simply not update its OpenGL-level binding. This assumption is
no longer valid after introduction of cubemap textures. Shader samplers
always have an OpenGL-level binding to a texturing unit (0 by default).
If the sampler type is not compatible with the type of texture bound to
its texturing unit (e.g. 2D texture with a cube sampler), the draw call
will raise an error, even if the shader does not actually use the
invalid sampler.

For that reason, we now make sure that all samplers without a
Taisei-level texture binding are assigned a texturing unit with no
OpenGL-level texture binding. The texunit juggling logic had to be fixed
quite a bit to correctly handle unbinding textures.

Additionally, some assertions have been added to prevent assigning
incompatible textures to samplers via the renderer API, and the number
of minimum required texturing units has been raised to 8 (we sometimes
need more than 4 bound textures at a time).
2021-07-13 00:21:03 +03:00
Andrei Alexeyev
087f1ab0d9
renderer,texture_loader: Add support for cubemap textures
On the renderer side, the concept of a "texture class" has been
introduced. There are currently two texture classes: 2D and Cubemap.
These map to `sampler2D` and `samplerCube` in shaders, respectively.
Textures now also have an additional `layers` property. Its meaning
depends on the texture class. For simple 2D textures, there is always
only 1 layer. Cubemaps always have 6 layers, one for each face. In the
future, layers could be used to represent depth in 3D textures and
individual images in array textures.

Much of the texture loading code has been refactored, as it wasn't
adequate for loading multiple images for a single texture. Both Basis
Universal cubemaps and traditional image-based cubemaps are supported,
although no runtime preprocessing is implemented for cubemaps. The Basis
Universal format is strongly recommended.

The mkbasis utility can now convert 2:1 equirectangular panoramas into
`.basis` cubemaps with the --equirect-cubemap map.

A `vec3 fixCubeCoord(vec3 v)` function has been added to `utils.glslh`,
to convert a vector into the suitable coordinate system for sampling a
cubemap. The vector doesn't need to be normalized.
2021-07-11 18:08:00 +03:00
Andrei Alexeyev
4bebd1ab5d
gl33: don't try to create context if SDL_CreateWindow fails 2021-07-11 18:07:37 +03:00
Andrei Alexeyev
659ed15e43
Fix some issues found by clang static analysis 2021-06-18 16:11:00 +03:00
Andrei Alexeyev
0115c55f51
gl33: fix incorrect handling of uniform array offsets 2021-02-20 00:04:20 +02:00
Andrei Alexeyev
a5d0deec0f
renderer,gl33: expose new magic uniforms; see render_context.glslh
Also optimize access to all magic uniforms slightly.
2021-02-04 01:50:10 +02:00
Tim Gates
2d259196f6
docs: fix simple typo, pendatic -> pedantic (#268) 2020-12-19 13:16:24 +02:00
Andrei Alexeyev
a5fd6fe5d9
Texturing overhaul: GPU compression, sRGB sampling, swizzles, etc. (#240)
* WIP compressed textures, swizzles, sRGB sampling, ...

* refactor texture type info & fix random bugs

* fix preprocessing of sRGB textures

* handle y-flipped basis textures

* glcommon: better WebGL compat for compressed format detection

* missed WEBGL_compressed_texture_pvrtc

* implement compressed texture xcoding and uploading

* Add basis_universal submodule

* Reorganize texture loader code

Clean up some code
Isolate Basis Universal loader into a separate module

* Add wrapper script for encoding .basis textures

* basisu: honor custom metadata written by the mkbasis.py script

* mkbasis.py: add --incredibly-slow and --dry-run

* Move pixmap code from util/ to pixmap/

* Add an on-disk transcode cache for basis textures to speed up loads

* Compress texture cache with zlib

* Use readable format names for basisu cache filenames

* basisu: mip bias test code

* basisu: small caching cleanup

* add TAISEI_BASISU_MIP_BIAS env variable

* Improve OpenGL format matching heuristics

* Document considerations for compressed format priority

* Remove dead code

* Enable two forgotten formats, BC3_RGBA and ATC_RGBA

Also prefer BC7 over BC1/BC3

* Recognize GL_ANGLE_compressed_texture_etc for ETC2 textures

* Default depth buffers to 24-bit; remove ANGLE hack

* Fix glcommon_check_extension for GLES2/legacy gl

* Add renderer feature bit for texture swizzle masks

* glcommon: Fixup internal formats for GLES2

Sized internal formats are not allowed in GLES2

* Fix emscripten compile errors

* Update basis_universal

* remove more dead code

* revert irrelevant stage4 change

* shut up UBSan

* basisu: shut up some debug spam

* Add normalmap sampling helper to util.glslh

* basisu: add a gray-alpha mode

* mkbasis.py: Abort if image dimansions aren't multiples of 4

* Add basic Basis Universal encoding documentation (WIP)

* doc/basisu: Add paragraph about modes; minor tweaks

* basisu: workarounds for GL texture size requirements

* gles20: fix uncompressed sRGB formats

* Partial workaround for missing swizzles in gles2 and webgl

* remove invalid assertion

* New renderer API to expose glDrawBuffers-like functionality

* stagedraw: disable all color outputs for copy_depth pass

required for WebGL compatibility

* support GL_ANGLE_request_extension

* emscripten: include *.basis in gfx package

Also fix a potential problem when more than one .pkgdir is used to
construct emscripten packages

* Don't rely on emscripten runtime to enable webgl extensions
2020-08-15 14:51:12 +03:00
Andrei Alexeyev
46bd7244a9
Remove glDrawElementsInstancedBaseInstance support
This extension is unimportant, and actually severely degrades ANGLE
performance over Direct3D to unacceptable levels. This also removes the
alternative sprite batching codepath making use of this functionality.
The renderer API hasn't changed yet; attempting to use the extension
will trigger an assertion failure.

This commit also regenerates glad with a new version. Apparently the old
one had a bug and ended up pulling a lot of unrequested functionality,
which is now removed.
2020-07-31 17:19:39 +03:00