Commit graph

146 commits

Author SHA1 Message Date
Alexander Akulich b6470e5a43 Use client 'six' data structs for client 'seven' data 2023-10-06 18:14:38 +03:00
Robert Müller 99cee23de4 Add assertion when double-freeing texture index
Simplify the handling of free texture indices by using `-1` only for indices which are currently in use, whereas the size of the vector is now used to indicate the last free index. Otherwise the assertions incorrectly detect the last texture index always being in use because `-1` was used for both states.
2023-09-24 22:24:51 +02:00
Robert Müller dde45f7a40 Add CImageInfo::PixelSize function, use enum EImageFormat
Use `enum EImageFormat` type for image format literals and variables.

Add `PixelSize` function to get the number of bytes/color channels per pixel for a specified image format.

Remove unused store format argument of texture loading functions. All textures are automatically being stored as RGBA, so the argument was unused. Also remove the therefore unused `FORMAT_AUTO`.

Rename variables consistently to `PixelSize` and use `size_t`, instead of mixing different names like `BPP` and `ColorChannelCount`.

Validate image format loaded from maps using `CImageInfo::ImageFormatFromInt`. Add `FORMAT_ERROR` to represent invalid formats.

Remove redundant `PixelSize` parameter from graphics backends and commands, which can be derived from the texture format.

Fix memory leak when RGB image data is being converted to RGBA format when saving map in editor.
2023-09-03 20:40:28 +02:00
Robert Müller 31a80c976b Remove gfx_finish config variable
This config variable does not have any use case right now and only causes the rendering to be slowed down.
2023-08-30 20:07:11 +02:00
Robert Müller 58927cdc8d Use size_t more in engine graphics 2023-07-20 21:58:17 +02:00
Robert Müller 78e23062c9 Add assertions for graphics command buffer allocation
When memory for a command or data in the command buffer cannot be allocated in `CGraphics_Threaded::AddCmd` and `CGraphics_Threaded::AllocCommandBufferData` the command buffer is cleared so it should always be possible to allocated memory successfully on the second try. Therefore assertions are added and the return values and inconsistent checks of the functions are removed.

The usage of `AddCmd` is simplified by automatically deriving an error message based on the type of the template parameter.
2023-07-20 21:58:17 +02:00
Robert Müller a96242b850 Extract CGraphics_Threaded::FindFreeTextureIndex function
To reduce duplicate code.
2023-07-20 21:58:16 +02:00
Robert Müller 3134d42ce6 Extract CGraphics_Threaded::FreeTextureIndex function
To reduce duplicate code.
2023-07-20 21:58:16 +02:00
heinrich5991 9c0c7550ba Don't support loading RGB images ingame
They're essentially unused and not supporting them ingame probably
allows to keep that part of the map format unused.

See https://github.com/ddnet/ddnet/pull/5737#issuecomment-1538284956 or
https://github.com/teeworlds/teeworlds/issues/2812.
2023-07-16 15:26:00 +02:00
Robert Müller abfafa314a Add IGraphics::GetScreenName
To get the screen name for each screen index.
2023-06-08 12:52:34 +02:00
Jupeyy 70d48140f0 Show GPU info (if available) in assert 2023-05-27 09:51:22 +02:00
Robert Müller c841c7ad05 Destroy window before showing popup if graphics initialized
Work around SDL bug that prevents message popup from being closed.
2023-05-07 21:20:47 +02:00
Robert Müller 1b1fc8de3e Save screenshot in separate thread to avoid lags
Encoding the image as PNG and saving it to a file comprises the majority of the time when taking a screenshot.

To avoid the client freezing while a screenshot is being saved, this task is moved to a separate background thread.
2023-03-11 13:19:57 +01:00
Robert Müller db4ec4a12d Replace usages of C math functions
Replacing the C standard headers with the C++ standard headers causes various `error: call to 'floor' promotes float to double [performance-type-promotion-in-math-fn,-warnings-as-errors]`, which are fixed by using the C++ std math functions or our own math functions instead of the C math functions.

- Use `absolute` instead of `abs` and `fabs`.
- Use `std::floor` instead of `floor` and `floorf`.
- Use `std::ceil` instead of `ceil`, `ceilf` and `round_ceil`.
- Use `std::round` instead of `round` and `roundf`.
- Use `std::sin` instead of `sin` and `sinf`.
- Use `std::asin` instead of `asin` and `asinf`.
- Use `std::cos` instead of `cos` and `cosf`.
- Use `std::acos` instead of `acos` and `acosf`.
- Use `std::tan` instead of `tan` and `tanf`.
- Use `std::atan` instead of `atan` and `atanf`.
- Use `std::pow` instead of `pow` and `powf`.
- Use `std::log` instead of `log` and `logf`.
- Use `std::log2` instead of `log2` and `log2f`.
- Use `std::log10` instead of `log10` and `log10f`.
- Use `std::pow` instead of `pow` and `powf`.
- Use `std::sqrt` instead of `sqrt` and `sqrtf`.
- Use `std::fmod` instead of `fmod` and `fmodf`.
- Use `direction(Angle)` instead of `vec2(std::cos(Angle), std::sin(Angle))`.
- Use `length(vec2(x, y))` instead of `std::sqrt(x * x + y * y)`.
- Remove unused `NormalizeAngular` and `AngularDistance` functions.
2023-03-01 19:26:53 +01:00
Jupeyy 9530077588 Only call onresize events if actual size changed
clearify difference between resize and window property change for resolution list
2023-02-25 16:02:38 +01:00
Robert Müller 3280f1824f Reset graphics container indices after deletion
Reduce duplicate code and improve correctness by passing indices of quad, buffer and text containers by reference and always setting them to `-1` after they are deleted.

Also check if index is `-1` before trying to delete it to reduce duplicate code when calling the methods.
2023-02-15 21:05:15 +01:00
Jupeyy 870ea8566e Improve error handling in vulkan
so it doesn't assert & shows a message box with the error and some tips
2022-12-13 18:11:26 +01:00
Rafael Fontenelle cd14660307 Fix misspellings 2022-10-25 13:51:56 -03:00
Robert Müller 3b1ef5642b Refactor DrawRect* methods:
- use `CORNER_*` constants and add missing constants
- fix array variable names
- use `size_t`
- extract duplicate computation into constant
- use `ColorRGBA` instead of `vec4`
2022-08-12 17:42:05 +02:00
Robert Müller 2a21cd6eab Move all DrawRect* methods from CRenderTools to IGraphics
As the methods do not depend on any game components they are moved to the engine graphics interface.
2022-08-12 17:42:05 +02:00
Robert Müller 9ad097da4d Refactor DrawCircle:
- improve argument names
- remove duplicate computation by adding `SegmentsAngle`
- rename variable `Array` to `aItems`
- use `std::size` and `size_t`
- remove unnecessary temporary variables
2022-08-12 17:42:03 +02:00
Robert Müller 237fdc76db Move CRenderTools::DrawCircle to IGraphics::DrawCircle
As this method does not depend on any game components it is be moved to the engine graphics interface.
2022-08-12 17:42:03 +02:00
heinrich5991 994324b059 Warn about pnglite-incompatible PNGs on load
This allows a larger range of PNGs to be loaded while still maintaining
backward compatibility with older clients by annoying the user.

This warning can be enabled by the `warn-pnglite-incompatible-images`
key in the https://info2.ddnet.tw/info JSON, if the key is not there or
the JSON hasn't been obtained yet, the warning is disabled. Since the
JSON is cached across restarts, it'll be effective for initially loaded
images from the second start.
2022-07-14 18:22:46 +02:00
heinrich5991 4292c9ed77 Convert preprocessor #define to constexpr int 2022-07-14 18:22:46 +02:00
Chairn a69dc599a9 Huge variable naming format
Fix pointer and pointer array variable naming

Huge renaming to match our rules

Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)[^a]\w+\[
            (?!(return|delete)\b)\b\w+ (?!(m_|ms_|g_|gs_|s_))[^a]\w+\[

Further format static variables

Format almost all pointer names accordingly

Used regex: (?!(return)\b)\b\w+
\*(?!(m_p|p|s_p|m_ap|s_ap|g_p|g_ap|ap|gs_ap|ms_ap|gs_p|ms_p))\w+\b[^:\(p]

clang-format

Fix CI fail

Fix misnamed non pointer as pointer and non array as array

Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)p\w+\b
            (?!return\b)\b\w+ (ms_|m_|g_|gs_|s_)a\w+\b[^\[]

clang-format

Revert to SCREAMING_SNAKE_CASE and reinstate dead code
2022-07-08 18:01:29 +02:00
Chairn 2e8c5b3914 Split screen pos in independent variable. Format function declaration 2022-07-07 04:51:17 +02:00
Chairn 32318a7c90 Reworked color system
Removed duplicate structs. Replaced 4 floats array with appropriate
struct where applicable
2022-07-06 11:39:51 +02:00
Chairn 27da8391dc Replace 2 floats array with vec2 where it makes sense 2022-07-06 11:39:43 +02:00
Chairn 01edaec628 Format vector variables names (fixes #5209) 2022-06-11 21:38:49 +02:00
Jupeyy 1e6df0c7a9 Lower max allowed FSAA on OpenGL 2022-05-22 14:42:21 +02:00
Jupeyy b8da817716 Return the quad offset of the first added quad, when adding new quads 2022-04-28 16:50:18 +02:00
Jupeyy b23e60c077 Allow onfly FSAA change under Vulkan 2022-04-26 21:09:55 +02:00
Jupeyy 50f9aa88d3 Prepare graphics for dynamic viewport changes 2022-04-18 09:50:19 +02:00
Chairn 3778e0ff6b Format member variable's name correctly 2022-03-24 19:30:26 +01:00
Jupeyy fbeba9eb5f Add Vulkan backend 2022-03-21 12:39:51 +01:00
Jupeyy e54da1b396 Cleanup backend a bit for vulkan 2022-03-20 18:03:25 +01:00
Chairn c0d398df38 CheckImageFormatRGBA --> IsImageFormatRGBA 2022-02-23 00:39:31 +01:00
Chairn 76064bd1c8 Drop non RGBA images 2022-02-22 20:21:34 +01:00
Jupeyy 338b6b2238 Add windowed fullscreen ( a special case for Windows ) 2022-02-04 11:14:10 +01:00
Jupeyy 55a1406641 Further android build fixes 2022-01-20 11:04:47 +01:00
Jupeyy 69202fdc22 Fix windows macro and split the resize events 2022-01-15 16:55:32 +01:00
def ac094b5378 Fix text selection cursor position (fixes #4444)
after moving window to a screen with different dimensions than the
initial one
2021-12-13 19:12:37 +01:00
Jupeyy 0d17665137 Revert "Add new mouse state"
This reverts commit e4cb348db2.
2021-10-23 13:48:21 +02:00
Jupeyy e4cb348db2 Add new mouse state 2021-10-07 16:48:25 +02:00
bors[bot] 43e69905bc
Merge #4157
4157: invalidate texture when unloading a texture. r=heinrich5991 a=ChillerDragon

Closes https://github.com/teeworlds/teeworlds/issues/1450

(cherry picked from commit 23a1b80f60)

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: oy <Tom_Adams@web.de>
Co-authored-by: ChillerDragon <ChillerDragon@gmail.com>
2021-10-06 15:16:00 +00:00
Chairn 635485de90 Fixed typo in variable name 2021-09-18 20:41:01 +02:00
ChillerDragon de4e1ea644 Merge UnloadTexture with UnloadTextureNew 2021-09-15 13:19:54 +02:00
Jupeyy 7f5ca0ffe1 Small graphic refactoring 2021-09-14 00:21:17 +02:00
ChillerDragon d60e330085 Pointer naming convention in UnloadTexture 2021-09-13 14:55:21 +02:00
oy 9e17281573 invalidate texture when unloading a texture.
Closes https://github.com/teeworlds/teeworlds/issues/1450

(cherry picked from commit 23a1b80f60)
2021-09-13 13:23:00 +02:00