Commit graph

122 commits

Author SHA1 Message Date
Daniel Gibson
6dbcf6523e Shader Gamma: support "OUTPUT bla = result.color;" in frag. shaders
so far the code assumed that "result.color" is always used directly,
but the ARB shaders allow creating an alias with the aforementioned
syntax. So turn that into an variable-alias for dhewm3tmpres.
2021-07-19 05:26:22 +02:00
Daniel Gibson
5e4e1d61be Merge branch 'debugger' 2021-07-16 02:21:16 +02:00
Daniel Gibson
277dbf89f1 Make sure shaders are only loaded once at startup, fix #386
this *shouldn't* matter, but due to some Mesa bug is does:
If the shaders have been loaded already (with R_LoadARBProgram()),
then loading them again (like from the `reloadARBprograms` console cmd
or as it happens if the `r_gammaInShader` has been modified) will
cause glitches with the open source radeonsi driver (maybe also with
others? at least the open source intel driver seems unaffected).
As r_gammaInShader was marked as modified at startup (before the shaders
were even loaded) they were loaded twice: First as expected when OpenGL
is initialized, then again in R_CheckCvars() which is executed each
frame. Marking as at not modified in R_InitOpenGL() prevents this and
thus works around the bug.
However this means that changing r_gammaInShader at runtime will still
trigger this bug (while with non-broken drivers it switches seamlessly
between gamma in shader and gamma in hardware without a vid_restart).
2021-06-24 18:37:14 +02:00
Daniel Gibson
dc42bdc873 Do gamma correction (r_gamma, r_brightness) in shaders
by injecting code to do it into fragment shaders.

Can be disabled with r_gammaInShaders 0

refs #385
2021-06-20 03:36:39 +02:00
Daniel Gibson
0b644a1648 Fix crashes on shutdown
idCommonLocal::VPrintf() wanted to call session->UpdateScreen() even though
the renderer was in the process of being shut down and that caused crashes
2021-06-19 21:30:26 +02:00
Daniel Gibson
c212148d41 Remove R_LockSurfaceScene(), clean up temporary changes
R_LockSurfaceScene() isn't used anymore, surface locking is implemented
differently (so it actually works now :-p)
2021-06-15 03:27:52 +02:00
Daniel Gibson
a11b2d352c r_lockSurfaces: Make mirrors look only a bit broken
it's still not great, but at least they don't float around anymore
2021-06-15 03:27:52 +02:00
Daniel Gibson
633ce814ca r_lockSurfaces: Cleaner handling of view matrix creation etc 2021-06-15 03:27:52 +02:00
Daniel Gibson
907fc5771b Disable r_useScissor when r_lockSurfaces is active 2021-06-15 03:27:52 +02:00
Daniel Gibson
d17fa6b2b6 Fix rendering of ingame GUIs with r_lockSurfaces 1 2021-06-15 03:27:52 +02:00
Daniel Gibson
dcb933efb5 Fix rendering HUD with r_lockSurfaces 1
only override cmd->viewDef in RB_DrawView() if we're drawing the
primary view (which for several calculations before actual drawing
was set to the saved/locked render view)

Note that r_lockSurfaces is more useful with r_useScissor 0 (otherwise
there's black bars over the screen when moving) and r_shadows 0 (otherwise
areas that weren't visible when locking are black because the lights
there are skipped)

remaining bug: gui surfaces move around the screen when looking around
2021-06-15 03:27:52 +02:00
Daniel Gibson
1a6998781b Make r_locksurfaces kinda work
refs #357
2021-06-15 03:26:44 +02:00
Daniel Gibson
0b28322500 Fix loading .ASE models with no materials
The "A Place of Malice" custom map has such a model which caused a crash
(models/z13sp2/temple/pushable_collision_box.ASE), see #382
2021-05-19 02:48:31 +02:00
Daniel Gibson
b054261a0e Make MFC Tools work with MSAA enabled
The problem was that the editors called ChoosePixelFormat() instead of
wglChoosePixelFormatARB() - and the normal ChoosePixelFormat() has no
attribute for MSAA, so if MSAA is enabled (by SDL2 which calls the wgl
variant), ChoosePixelFormat() will return an incomaptible format and
the editors don't get a working OpenGL context.
So I wrote a wrapper around ChoosePixelFormat() that calls the wgl variant
if available, and all the necessary plumbing around that.

While at it, removed the unused qwgl*PixelFormat function pointers and
supressed the "inconsistent dll linkage" warnings for the gl stubs
2021-05-11 00:39:00 +02:00
Daniel Gibson
409dd8e3d9 Fix crash if both image_useCache and image_downSize are 1
the commented out code clamped the loaded filesize of affected .dds
images (crash observed with dds/guis/assets/splash/pdtempa.dds) to
200KB - but then later tries to load it and skip the first mipmap,
resuling in reading invalid memory (> 200KB into the file).
No idea what this was supposed to achieve, but it's disabled now
and the crash (at startup) is gone.

fixes #374
2021-04-28 00:04:24 +02:00
Daniel Gibson
b0e0883f6e Replace libjpeg with stb_image.h
libjpeg is a pain in the ass, especially due to Ubuntu shipping
libjpeg-turbo in jpeg8 mode as their default libjpeg, while every other
distro I checked (including debian!) ships libjpeg-turbo in jpeg6.2 mode

Thankfully stb_image.h exists - just a single header and it even
has a (much!) friendlier API.

It's not like Doom3 (or any of the mods I checked) actually use JPEGs,
but I'm sure if I'd drop support completely, someone would complain
(perhaps rightfully so).
2021-04-27 20:08:59 +02:00
Daniel Gibson
bb7346579e GLimp_Init() Print actually received color/alpha/stencil/depth bits
to help debugging #368 and #348
2021-04-24 20:27:16 +02:00
Turo Lamminen
9c6b835f16 Fix uninitialized members of drawInteraction_t in RB_CreateSingleDrawInteractions 2021-04-12 19:13:39 +02:00
Turo Lamminen
7aee2af217 Silence misleading indentation warnings 2021-03-15 13:02:45 +02:00
Daniel Gibson
9a83b3def4 Add r_fullscreenDesktop CVar for "desktop"/windowed fullscreen mode
.. that doesn't switch the display resolution, but creates a borderless
fullscreen window at current desktop resolution.
SDL2-only (SDL_WINDOW_FULLSCREEN_DESKTOP).

Doing this with an additional CVar instead of r_fullscreen 2 or similar
has the advantage that it works properly with Alt-Enter
2021-01-15 18:24:48 +01:00
Daniel Gibson
d1b0073582 Try to enforce selected fullscreen resolution
SDL has a bug (at least on Windows) where SDL_CreateWindow() with
SDL_WINDOW_FULLSCREEN doesn't use the configured resolution (if it's
higher than the current desktop resolution).
Try to work around that - based on Yamagi Quake II code.

Also, if GLimp_Init() fails, the "safe mode" fallback is now in
windowed mode instead of fullscreen mode.
2021-01-15 18:24:48 +01:00
Tobias Frost
8c699cd030 s/referneces/references 2021-01-15 18:00:25 +01:00
Daniel Gibson
7297ebcaf6 Fix fonts on Big Endian systems, fixes #148
The code used #ifdef __ppc__, probably a leftover from old Mac support,
which apparently doesn't work on all PPC systems (maybe not 64bit PPC).

Now using the LittleFloat() function instead which exists for
exactly this purpose and already handles endianess properly.
2021-01-14 12:25:22 +01:00
Daniel Gibson
31e26856e0 (Hopefully) fix Editors messing up game viewport for good, fix #300
I worked around the issue for the particle editor, but now it turned out
it can also somehow happen when switching from the Radiant to the Engine
(with F2), so I implemented the "proper" fix of restoring
glConfig.vidWidth/Height, that are overwritten in
RenderSystemLocal::BeginFrame(), in RenderSystemLocal::EndFrame().
2020-07-20 05:01:51 +02:00
Daniel Gibson
f3a4d92d33 Remove C++11-isms
accidentally used nullptr instead of NULL, oops..
2020-07-13 05:34:13 +02:00
Daniel Gibson
aca8c24c3a Assertions in _alloca() and _alloca16() for too big stack allocations
not on Windows though, for some reason MSVC doesn't like my ugly
hack to add an assert() to the _alloca16() macro :-/
2020-01-11 16:14:43 +01:00
Daniel Gibson
bcf647cf71 Prevent stackoverflow in R_DeriveTangentsWithoutNormals()
turns out tri->numIndexes can be quite big so _alloca16() would be
called with >1MB - and the Win32 stack only is 1MB, so that overflows.
As a workaround, use Mem_Alloc16() if we need >600KB

was reported in #265
2020-01-11 15:39:34 +01:00
Daniel Gibson
f24f18a61e Use OpenGL2 glStencilOpSeparate() for shadows, if available
can be enabled/disabled with the r_useStencilOpSeparate for comparisons

(like Z-Fail, this doesn't really seem to make a difference on my main
 machine, neither on my RPi4)

Partly based on Pat Raynor's Code:
2933cb5545/neo/renderer/draw_stencilshadow.cpp
2019-11-03 03:13:21 +01:00
Daniel Gibson
aeb03cc4e4 Allow switching off "Carmacks Reverse" via CVar r_useCarmacksReverse
mainly useful for comparisons

The Z-Fail code is based on Leith Bade's code by the way:
d4de024341
2019-11-03 03:13:21 +01:00
Leith Bade
b6b5827aff Put back the old patented "Carmack's Reverse" depth fail stencil shadow technique. 2019-11-03 00:19:03 +01:00
Daniel Gibson
3a763fc685 Merge branch 'tools'
Bringing back support for the (MFC-based Windows-only) editing tools.
Only tested 32bit (not sure if the code is 64bit-clean), needs a
"proper" (non-Express) version of Visual Studio *including* MFC support,
tested the free "Community" Editions of VS 2013 and 2017.
(For VS2013 I needed to install the "Visual C++ MFC MBCS Library for
Visual Studio 2013" because it either didn't include MFC support at all
or only the wrong version, don't remember, you'll need that one anyway)
2019-03-11 01:30:26 +01:00
Daniel Gibson
5c1e1d7708 Fix ParticleEditor's Materialpicker screwing up ViewPort
In short, it uses a idGLDrawableMaterial widget that calls
renderSystem->BeginFrame(w, h); (with w and h being small for the texture
preview window) and BeginFrame() sets glConfig.vidWidth and vidHeight to
w/h and that never got reset to the original value (window width/height).
This breaks everything because for some reason
renderSystem->GetSCreenWidth()/Height() return glConfig.vidWidth/Height
so it will just continue to render everything at that resolution (in a
small rectangle on the lower left corner of the window).
This bug has already existed in Doom3 1.3.1 (but was less noticable because
apparently  when switching away from Doom3 and back to the window it reset
vidWidth/Height to the window resolution)
I only implemented a workaround (restore glConfig.vid* after rendering the
texture preview), it's possible that the same issue exists in other
(probably editor-) code - but a "proper fix" might also break code (and I'm
not super-familiar with the editor code or even just using them)
2019-03-10 05:23:06 +01:00
Daniel Gibson
b0d022f559 Fix crash when selecting nonexistant texture in D3Radiant
When selecting a texture in Inspectors -> Media -> Textures that doesn't
really exist (.mtr defines it, but referenced image files are missing),
the game/editor used to crash.
The problem was that somehow people thought the best way to communicate
that a file wasn't found was by setting the timestamp to 0xFFFFFFFF
and then checking for that - sometimes (incorrectly) by comparing it to -1.
That worked for 32bit ID_TIME_T (typedefed to time_t), but not with 64bit
time_t, which now seems to be the default for Win32 in VS.
So I replaced a few -1 and 0xFF... with FILE_NOT_FOUND_TIMESTAMP and now it
works.
FILE_NOT_FOUND_TIMESTAMP is still defined as 0xFFFFFFFF, maybe I should
change that, unsure if that'd break anything though..
When changing it one should keep in mind that time_t might still be 32bit
on some platforms (Linux x86?) so that should still work.. (-1 could work)
2019-03-10 05:11:33 +01:00
Dmitry Marakasov
17c10d40a5 Fix build on powerpc but not mac
...by including `vecLib/vecLib.h` only on `__APPLE__`, and not just any `__ppc__`

From https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235668:

> On powerpc* platforms vecLib/vecLib.h is included by default.
> This header is only available on Mac OS X, so remove it. It
> doesn't seem to be actually needed to compile this port.
2019-02-14 16:53:38 +01:00
Daniel Gibson
9a95a2a1cf Building with editor support (on Win w/ VS2017) works \o/
Editor also seems to start, didn't test much further.

Only tested 32bit Windows, I fear the editor code isn't 64bit clean..

I hope I haven't broken anything elsewhere..
2019-01-13 22:52:28 +01:00
Daniel Gibson
e41bf2b147 Scale "Menu" GUIs (incl. PDA + fullscreen vids) to 4:3
So stuff doesn't look so distorted in widescreen resolutions.
Implies that there are black bars on the left/right then..

Can be disabled with "r_scaleMenusTo43 0"

Does *not* affect the HUD (incl. crosshair) - scaling it automagically
would be very hard (or impossible), because it doesn't only render
the crosshair, healthpoints etc, but also fullscreen effects like the
screen turning red when the player is hit - and fullscreen effects
would look very shitty if they didn't cover the whole screen but had
"empty" bars on left/right.

(Mostly) fixes #188 and #189
2018-10-28 05:29:11 +01:00
Daniel Gibson
7a8f0e9fdb Allow injecting video mode list into Mod menus
Mods that have their own video settings menu can tell dhewm3 to replace
the "choices" and "values" entries in their choiceDef with the
resolutions supported by dhewm3 (and corresponding modes).
So if we add new video modes to dhewm3, they'll automatically appear in
the menu without changing the .gui
To enable this, the mod authors only need to add a "injectResolutions 1"
entry to their resolution choiceDef. By default, the first entry will
be "r_custom*" for r_mode -1, which means "custom resolution, use
r_customWidth and r_customHeight".
If that entry shoud be disabled for the mod, just add another entry:
"injectCustomResolutionMode 0"
2018-10-21 23:56:38 +02:00
Daniel Gibson
519cc68b0e idCommon::SetCallback() and GetAdditionalFunction() - for Mods
This is an ugly hack that allows both exporting additional functions
(incl. methods via static function + void* userArg) to Game DLLs
and setting callback functions from the Game DLL that the Engine will
call, without breaking the Game API (again after this change).
This is mostly meant for replacing ugly hacks with SourceHook and
similar and mods (yes, this is still an ugly hack, but less ugly).

See the huge comment in Common.h for more information.

Right now the only thing implemented is a Callback for when images
are reloaded (via reloadImages or vid_restart) - Ruiner needs that.

Also increased GAME_API_VERSION to 9, because this breaks the A[PB]I
(hopefully after the next release it won't be broken in the foreseeable
 future)
2018-09-30 05:06:20 +02:00
Andre Heider
83b358ddbe Fix color glitches on cinematics for selected archs
These two casts assumed char is signed, which is not a valid assumption.
Be explicit.

Fixes idlogo.roq on e.g. aarch64.
2018-02-23 13:40:11 +01:00
Kalamatee
f83e270cdb revert changes committed in error 2017-04-02 00:42:28 +01:00
Kalamatee
46279bf11f import AROS changes 2017-04-02 00:42:28 +01:00
Turo Lamminen
d535e54c90 Add 2560x1440 screen mode 2017-04-02 00:48:40 +02:00
Daniel Gibson
3d57e99e0a Hopefully fix built on OSX El Capitan with libjpeg9 2017-02-27 20:19:20 +01:00
Daniel Gibson
9950a5721f Fix heap corruption when loading (broken?) .ma models
On FreeBSD, the game used to crash when loading the last level of RoE
(d3xp), while loading models/david/hell_h7.ma.
The problem could be reproduced on Linux whith #define USE_LIBC_MALLOC 1
and clang's AddressSanitizer.
Turns out that this file specifies a vertex transform for a non-existent
vertex (index 31, while we only have 0-30) and thus the bounds of
pMesh->vertexes[] are violated.
I added a check to ensure the index is within the bounds and a Warning
if it isn't.
It should work now. If however it turns out that more files have this
problem, maybe .ma is parsed incorrectly and we need a differently fix.

(Should) fix #138
2015-12-17 18:07:35 +01:00
Daniel Gibson
1680603d8c Sort vidmodes in menu, add 2880x1800
it's the native resolution of "Macbook Pro retina 15-inch mid 2014"
2015-10-30 21:41:18 +01:00
Daniel Gibson
6ba1b71fb1 Change default values for some video and sound (EAX) CVars
* r_mode defaults to 5 (1024x768), I think that's more sane than 640x480
* r_fullscreen defaults to 0 (=> windowed mode) because fullscreen in
  the wrong resolution sucks.. let people do their initial configuration
  in windowed mode
* r_swapInterval defaults to 1 (=> VSync active by default) because that
  makes the game feel more smooth and most PCs should be able to 60fps
  in this 11years old game anyway

* s_useEAXReverb defaults to 1 (=> use EAX/EFX effects by default),
  because OpenAL-soft supports them on all platforms/hardware and if
  for some reason the used OpenAL implementation doesn't support it,
  it's deactivated automatically anyway.

All these things can be configured in the Options Menu.
2015-09-29 21:14:45 +02:00
Daniel Gibson
c0e8e20628 Nasty hack to show more default resolutions in menu
the resolutions are really hardcoded in an ugly combination of the
values r_mode supports, a string in strings/*.lang ("#str_04222")
describing the resolutions r_mode supports
("640x480;800x600;1024x768;1152x864;1280x1024;1600x1200")
and a string in mainmenu.gui with the corresponding r_mode values
("3;4;5;6;7;8").. as neither the strings nor mainmenu.gui are GPL'ed
I can't really redistribute a changed version of them.

So I added lots of resolutions to r_vidModes and wrote two functions
that generate the resolutions list string and r_mode value
string for the GUI.
Then I added a hack in the code that detects when the "window" for the
system options ("choiceDef OS2Primary") is created and overwrites the
hardcoded strings with custom ones from my new functions.

This is tested with both the main game and the official d3xp
(Resurrection of Evil) Addon.
No idea if it works with other mods, depends on whether they just copied
that part of the menu or wrote their own.
2015-09-28 16:01:18 +02:00
Daniel Gibson
657ad99bf1 Remove jpeg_memory_src hack that worked around old libjpeg versions
Because Debian Squeeze's libjpeg6 didn't have jpeg_mem_src(), we added
jpeg_memory_src() to provide the functionality.
This shouldn't be needed anymore and without it we can drop libjpeg code
from our repo.

Fixes #110
2015-03-22 16:49:26 +01:00
Daniel Gibson
3202f0aa0f Get rid of some compiler warnings
GCC had shitloads of superfluous warnings wherever List.h and Str.h were
included.. get rid of them by using #pragma GCC diagnostic at some places
in List.h and Str.h.
Also add some casts, initialize some variables for other warnings
2012-11-13 23:24:13 +01:00
Daniel Gibson
105fdb0624 Fix dedicated server for Windows
* the OpenAL function definitions mustn't include __declspec(dllimport)
  => fixed by pretending to compile OpenAL statically
* glimp.cpp shouldn't be used in dedicated-only mode (as it was already
  the case on Linux and OSX)
  => No special handling for ID_DEDICATED needed in glimp.cpp, as it's not
   used anyway
* add APIENTRY to every gl function in stub_gl.cpp for compatibility
  with windows headers and MSVC
* remove GL/gl.h #include from win_local.h as it's not needed
* in qgl.h, when building dedicated server for windows, redefine WINGDIAPI
  to nothing for SDL_opengl.h #include to get rid off __declspec(dllimport)
  by using #pragma push_macro and pop_macro, because our stub is no dll.

Fixes https://github.com/dhewm/dhewm3/issues/39
2012-11-12 20:18:00 +01:00