Commit graph

137 commits

Author SHA1 Message Date
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
9bb51687c3
renderer/api: workaround for ASan false positive 2021-06-27 12:02:29 +03:00
Andrei Alexeyev
659ed15e43
Fix some issues found by clang static analysis 2021-06-18 16:11:00 +03:00
Andrei Alexeyev
88bec7008f
glcommon: ignore GL_EXT_texture_norm16 on WebGL
Works around a Chromium bug. See comment for details.

Related: #287
2021-05-07 00:25:08 +03:00
Andrei Alexeyev
97c3ccef87
glcommon: fix logging in glcommon_ext_flag 2021-04-30 03:34:36 +03:00
Andrei Alexeyev
491cbe353b
glcommon: shut up some warnings 2021-04-30 03:26:38 +03:00
Andrei Alexeyev
326e499f7e
shaderlib/cache: switch to zstd compression 2021-03-28 15:18:11 +03:00
Andrei Alexeyev
8706426ea2
rwops_zlib: various improvements:
* Add compression level parameter to writer wrappers
* Add APIs for raw deflate streams
* Add optional seeking emulation for reader wrappers
* Handle inflate/deflate init errors
2021-03-23 12:05:47 +02:00
Andrei Alexeyev
937cb3bea7
I have no idea why/how this ever worked
Now it doesn't. It's also not very useful anyway, since the static gles3
mode only works with emscripten, for which we manually specify GL
linking flags.
2021-02-25 08:55:39 +02:00
Andrei Alexeyev
0115c55f51
gl33: fix incorrect handling of uniform array offsets 2021-02-20 00:04:20 +02:00
Andrei Alexeyev
4580673839
add a PBR sprite shader 2021-02-18 21:39:14 +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
laochailan
5701269c6f models: add tangents to the static quad 2021-01-21 05:20:15 +02:00
Andrei Alexeyev
6072a72046
glcommon: remove unused variable 2021-01-19 06:04:37 +02:00
Andrei Alexeyev
50efbede34
glcommon: more robust texture format feature detection
Make less assumptions about support beyond the spec guarantees, and use
GL_ARB_internalformat_query2 to get the actual set of supported features
from the driver, if available.

Follow-up to #274
2021-01-19 05:42:24 +02:00
Andrei Alexeyev
212640c515
glcommon: don't assume that any RGB formats are color-renderable
fixes #274
2021-01-17 05:31:14 +02:00
Lukas Weber
6087e36198
models: raise max vertex limit 2020-12-26 02:11:24 +02:00
Tim Gates
2d259196f6
docs: fix simple typo, pendatic -> pedantic (#268) 2020-12-19 13:16:24 +02:00
Andrei Alexeyev
4ac5f346ca
Disable SPRITE_BATCH_STATS by default 2020-08-25 04:56:22 +03: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
059f9f4991
Expose transpiling info to shaders via macros
Fixes legacy GLSL compatibility code
2020-08-04 02:46:15 +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
Andrei Alexeyev
89ecc0c55e
Establish more-or-less consistent resource getter functions
Deprecate old ad-hoc stuff like get_sprite, r_texture_get, etc.
2020-06-09 04:33:22 +03:00
Andrei Alexeyev
ae8194ae78
Various fixes & improvements for concurrent loading (#235)
- RESF_UNSAFE is removed.
- Resources that don't have to be finalized on the main thread can load
completely asynchronously.
- A thread waiting for a concurrent task to complete can start executing
that task itself if it hasn't started yet.
- Refactor the resource loading interface, add support for load-time
dependencies.
- Main-thread finalization of asynchronously loaded resources is now
spread out across multiple frames to mitigate frametime spikes.
- Remove some archaisms from the resource management code.
- Fix potential hashtable synchronization issue.
- Fix some deadlock edge cases.
- Don't spawn more worker threads than there are CPU cores (degrades
performance).
- Add TAISEI_AGGRESSIVE_PRELOAD env variable to attempt to aggressively
discover and preload every possible resource.
- Make r_texture_fill{,_region} expect optimal pixmaps, so that it's
never forced to convert them on the main thread. The optimal format may
be queried with the new r_texture_optimal_pixmap_format_for_type API.
These functions will also no longer needlessly copy the entire image
into a staging buffer - previously they did this even if no conversion
was needed.
- Other random changes to facilitate the stuff above.

The overall effect is somewhat faster load times.

Of course it's still all terrible and full of lock contention because I
suck at concurrent programming, but it's not worse than it was.
Probably.
2020-06-09 03:01:53 +03:00
Andrei Alexeyev
fb3d8af3b7
fix vertex layout setup for static models 2020-06-07 08:37:20 +03:00
Andrei Alexeyev
ee3bec1c22
Replace .obj models with .iqm (#232)
http://sauerbraten.org/iqm/

The iqms were converted from the objs with the official iqm "compiler",
but can be also exported directly from Blender with a script from the
SDK.

In addition, indexed rendering was fixed (it's not useless anymore), and
the winding order convention changed from counter-clockwise to clockwise
to facilitate faster model loading.

A limited subset of IQM functionality is currently supported:
	- One mesh per model.
	- Only floating point data in vertex arrays.
	- Only standard vertex arrays: positions, UVs, normals,
	tangents.
	- No animations etc.

The "standard" shader interface now receives an additional vec4 tangent
attribute. This attribute is currently ignored by shaders. The bitangent
vector can be computed in a vertex shader as:
	vec3 bitangent = cross(normal, tangent.xyz) * tangent.w;

* iqm: remove axis scrambling and re-export models

* remove debug stuff
2020-06-06 18:27:08 +03:00
Andrei Alexeyev
54ca97587c
Rename cmplx32 into cmplxf for better consistency 2020-05-09 09:31:20 +03:00
Andrei Alexeyev
f5f8f9fb49
Get rid of custom min() and max() functions
Use the standard fmin() and fmax() for floating point values, and ours
imin(), imax(), umin(), umax() for integers.
2020-05-09 09:16:07 +03:00
Andrei Alexeyev
7d7f1b157f
Migrate OpenGL loader to glad2 (#217)
* Migrate to glad2

* basic OpenGL 2.1+ fallback support
2020-04-26 04:10:00 +03:00
Andrei Alexeyev
a9775c065b
Store sprite texture coords in normalized form 2020-04-25 05:36:48 +03:00
Andrei Alexeyev
0cbc86c66e
Add generic type-safe facility for dynamic arrays (#207)
Replace most ad-hoc opencoded dynamic arrays across the codebase
2020-04-05 05:51:00 +03:00
Andrei Alexeyev
07b6e0950c
Add r_framebuffer_get_size; abstract away SDL_GL_GetDrawableSize 2020-03-30 01:41:29 +03:00
Alice D
77246397c3
Video resolution improvements/high-DPI quirks (#204) 2020-03-30 00:03:38 +03:00
Andrei Alexeyev
b56f3eeb54
fix broken logic 2020-03-21 04:26:18 +02:00
Andrei Alexeyev
5435971a08
bunch of emscripten crap 2020-03-19 08:58:51 +02:00
Andrei Alexeyev
02eb72608e
Fix various warnings 2020-03-19 05:04:11 +02:00
Andrei Alexeyev
c6f75c07ea
fix r_shader_uniform 2020-03-18 05:23:25 +02:00
Andrei Alexeyev
0fdea86be1
Implement Robin Hood hashing (#200)
* Implement Robin Hood hashing

This replaces the previous separate chaining implementation. This
approach is more memory-efficient, cache-friendly, and puts much less
stress on the memory allocator.

* Replace crc32 with fnva1

Also attempt to make the compiler pre-hash as much stuff as possible at
build time.
2020-03-17 10:09:49 +02:00
Andrei Alexeyev
38d21bbb1f
fix some bad function pointer casts 2020-03-08 18:55:46 +02:00
Andrei Alexeyev
a8bf8012f6
shut up some anal-retentive warnings 2020-03-07 18:47:02 +02:00
Andrei Alexeyev
d756790b6e
show num. of context swiches/frame in coroutine stats 2020-03-04 22:26:48 +02:00
Andrei Alexeyev
3d1c0eee4e
WIP proj draw rule revamp; YoumuB revamp; misc changes; giant mess
cursed commit
2020-03-04 22:26:45 +02:00
Andrei Alexeyev
9868fbcaa4
display number of active/allocated tasks 2020-03-04 22:26:44 +02:00
Andrei Alexeyev
50348191d4
shut up some debug spam 2020-03-04 22:26:40 +02:00
Andrei Alexeyev
fadd6de76d
refactor some aspects of path config, ANGLE libs in particular 2020-02-21 00:36:40 +02:00