Commit graph

1755 commits

Author SHA1 Message Date
Yamagi
78ca79c602 Merge pull request #181 from DanielGibson/render_dll
Resurrect support for render / refresher loadable libraries and use them to implement  an experimental OpenGL 3.2 renderer. Please note that the new renderer interface is somewhat different from the original one, old render libraries will NOT work!
2017-04-18 17:12:40 +02:00
Daniel Gibson
6e7dc59622 GL3: Deactivate STUB_ONCE() messages 2017-04-18 17:08:42 +02:00
Daniel Gibson
7d53e6ebf2 Quirk map bug in waste3 (secret not counted)
there's a target_secret (with targetname "t117"), but no one triggers
it - that's why the help computer shows four secrets, but you can only
get three of them.
Now when you open the door in front of the hidden secret armor
(by shooting it), it'll trigger the target_secret and you can get all
four secrets.

fixes #182
2017-04-15 18:38:09 +02:00
Yamagi Burmeister
0608eed7c3 Fix order of the video menu items.
The internal order of the items is determined by Menu_AddItem() and
not the y position. Without this change the cursor didn't jump from
item to item, but from the mode list box to the aspect list box,
skipping the brightness slider.
2017-04-11 14:54:22 +02:00
Yamagi Burmeister
b48108cf37 Add the renderer selection back to the video menu.
Remove the 'viewsize' slider to free one row. Use this row for the new
renderer selection. While at it reorder the items.
2017-04-10 23:15:36 +02:00
Yamagi Burmeister
df86c46e57 Several adjustments to the visual impression.
- Bump vid_gamma to 1.2 in both GL1 and GL3. A default value of 1.0 is
  too dark.
- Lower gl3_overbrightbits to 1.3, the previous value of 1.5 was too
  bright. This can be seen in later units, for example on mine1 some
  textures blended into white.
- Lower gl3_particle_size to 40. A value of 60 may be okay, but with
  gl3_particle_fade_factor 1.2 the particles take up too much screen
  estate in close range combat.

With this changes GL3 looks (at least for me) nearly the same as GL1
rendered through the removed multitexturing path.
2017-04-10 19:28:46 +02:00
Yamagi Burmeister
8316dfe3d9 Change the dynamic light cuttoff from 64 to 52.
64 was the cutoff used by GL1. Testing showed that 52 is better suited
for GL3. Good levels to test this can be found in the Mines unit.
2017-04-10 19:28:46 +02:00
Yamagi Burmeister
0314eafdaa Cap dynamic light intensity / brightness to 3.
Without capping the brightness entity models may fade into pure white
which looks ugly. This can be seen when several flyer fire blaster
bolds onto the player or when multiple barrels are exploding. This
change was suggest by @DanielGibson, I'm just the messenger.
2017-04-10 19:28:46 +02:00
Yamagi Burmeister
b124d0cada Change the default screenshot binding to JPEG with Quality 90.
While here add a default binding for the power shield on w.
2017-04-10 19:22:23 +02:00
Yamagi Burmeister
8c665b826c Do not enforce the Vrect to have even width and heights.
I really don't see why this constraint was ever necessary. It leads to
one line of pixels not rendered either at the bottom or the right edge
of the screen. In GL1 for whatever reasons this line is just black, in
GL3 garbage is drawn.
2017-04-10 19:22:23 +02:00
Yamagi Burmeister
38e60005cb Add back the GLAD_INCLUDE variable, lost in 4bd263c. 2017-04-10 19:22:23 +02:00
Daniel Gibson
b916d11662 GL3: gl3_particle_fade_factor cvar to configure particle softness
the higher it is, the less soft (more like in GL1) the particles look

While at it, I removed lmOffset from uni3D, as it's not used.
2017-04-10 19:04:59 +02:00
Yamagi Burmeister
e510bfc281 Fix render artifacts around health points when the HUD is scaled.
In SCR_DrawFieldScaled() the HUD scale factor wasn't taken into account
when calculating the screen area affected by the change. Therefor wrong
coordinates were passed to SCR_AddDirtyPoint() and a part of the changed
area wasn't marked dirty, leading to render artifacts.

This bug was present since HUD scaling was first introduced.
2017-04-10 15:50:48 +02:00
Yamagi Burmeister
7b5e13d4ff Add GL1 and GL3 refresh libraries to the CMakeLists.txt
I hope that I've referenced all headers required by the libraries. If
I missed some compilation will work but IDEs like Clion won't be able
to deduce all symbols.

Before this change cmake overlinked the q2ded binary and the game.so
game library. Now it is also the case with ref_gl1.so and ref_gl3. This
will be fixed in a later commit.
2017-04-10 15:50:25 +02:00
Yamagi Burmeister
4bd263c4d4 Some cleanup to the Makefile.
- Rename REFGL to REFGL1 for consistency with REFGL3.
- Fix some comments.
- There's no need to link flash.c and rand.c into both renderer libs.
2017-04-10 15:50:25 +02:00
Daniel Gibson
5d3f024f82 GL3: Fix GL3_Draw_Flash() for viewsize < 100 and odd resolutions
the flash should only be drawn in the part of the window where actual
3D rendering happens, not in the borders added if viewsize < 100
(and apparently also for with 1 pixel width if the resolution is odd).
2017-04-10 01:38:30 +02:00
Daniel Gibson
264df420e3 Rename vid_ref cvar to vid_renderer 2017-04-09 00:00:36 +02:00
Daniel Gibson
54b38176ef Fix Windows build (missing OSTYPE => YQ2_OSTYPE in Makefile) 2017-04-04 17:34:19 +02:00
Daniel Gibson
7fe6412d70 Fix crash if gamedata (pics/colormap.pcx) isn't found 2017-04-03 14:54:46 +02:00
Daniel Gibson
b91b244431 GL3: Cleanup (remove TODOs, STUBs and old commented out code, ...) 2017-04-03 00:23:56 +02:00
Daniel Gibson
85c8c83c4b GL3: Make sure HandmadeMath also works without SSE 2017-04-02 20:04:27 +02:00
Daniel Gibson
dbf0563565 GL3: Update HandMadeMath.h 2017-04-02 19:18:40 +02:00
Daniel Gibson
ca5dccb881 GL3: Render dynamic lights on all brush-based entities
The GL1 renderer can't do this :)
2017-04-02 18:28:19 +02:00
Daniel Gibson
35daa08c23 GL3: Split up transModelViewMat4 matrix 2017-04-02 18:21:32 +02:00
Daniel Gibson
ea6dacbc12 GL3: Rename some CVars to gl3_*, fix water brightness
* gl3_particle_size: in GL3 the particles should be a bit bigger because
  the particles fade out towards the edge, so I put it in a seperate
  CVar
* gl3_intensity: in GL3 the intensity can have any floating point value,
  in GL1 only integers, so it gets its own CVar
* gl3_overbrightbits: gl_overbrightbits had to be 1, 2 or 4, in GL3 it
  can have any floating point value.

Changed the particle scaling a bit so they look bigger.
2017-04-02 17:16:26 +02:00
Daniel Gibson
182948fecc Rename ref_gl.* to ref_gl1.* 2017-04-02 16:23:00 +02:00
Daniel Gibson
fcae894c1e Makefile: OSTYPE => YQ2_OSYTPE, ARCH => YQ2_ARCH, -std=gnu99
Hopefully this fixes the build on SUSE Linux.
2017-04-02 15:58:35 +02:00
Daniel Gibson
a9093fdf98 Make it work with SDL1.2 again
Some things broke when moving the renderer into a DLL, and the GL3
renderer needed some more work to work with it.
2017-04-02 05:20:24 +02:00
Daniel Gibson
9044eb1370 Load ref_* lib with absolute path, fall back to ref_gl
.. if initializing the other renderer failed.
2017-04-02 05:19:01 +02:00
Daniel Gibson
bd5b8d0aea Don't crash if re.InitContext() fails before creating context
One problem was that GL3_Shutdown() called several functions that use
that gl* function pointers - not a good idea if InitContext() failed
and the function pointers are all NULL. So check for that.
Similarly in GL3/R_ShutdownWindow() calling glClear() etc.

Another problem was that R_SetMode() would, if R_SetMode_impl() failed,
try again with a "safe" resolution (640x480 unless  we had another
working resolution before) - which is bad if we're already using that
"safe" resolution because then GLimp_InitGraphics() would check mode
and fullscreen and decide it hasn't changed and do nothing and return
true, which would make SetMode() believe everything is fine and
afterwards all hell breaks loose.
2017-04-02 05:18:44 +02:00
Daniel Gibson
3503f91234 GL3: Use dlightbits/lightflags in shader
This makes the fragment shader faster by skipping lights that haven't
marked this surface in GL3_MarkLights()

This seems to improve performance at least slightly everywhere, but
it really helps *a lot* on integrated intel GPUs like the one on their
Sandy Bridge, Ivy Bride and Haswell CPUs (those are the ones we tested).
2017-04-01 16:17:22 +02:00
Daniel Gibson
5656345d1f GL3: Dyn. Lights: Factor in angle, make it work on Win/AMD and OSX
adding dot(surfaceNormal, lightToPixelOnSurfaceNormal) to the equation,
should be Phong-y now? Looks good at least.

The Windows AMD legacy driver needed its usual manual padding..

OSX was totally weird.. There were no errors or warnings from OpenGL
at all, but the dynamic lights were just not visible.
After (too long) debugging the shader I figured out that
dynLights[i].lightIntensity was always 1, and thus
'dynLights[i].lightIntensity - distLightToPos - 64' was negative and set
to 0 with max(0, ...).
I still have no idea why that happens, but removing lightIntensity from
the struct, making lightColor a vec4 and using .a for intensity works...
2017-03-27 22:43:10 +02:00
Daniel Gibson
d5cf8c2852 GL3: Support dynamic lights (mostly) + changes for that
Dynamic lights on normal world brushes work, on brush-based entities
probably not yet properly. For this I need the model matrix in the
shader to transform vertex positions and normals to worldspace
(they already are for world brushes, but not entities that might rotate
 and move etc).
Furthermore, while they dynamic lights look nice and smooth they might
need some fine tuning in the shader..

For this to work there are two bigger changes:
* the vertex data for brushes (gl3_3D_vtx_t) now also contains the
  vertex normal
  - glpoly_t contains array of gl3_3D_vtx_t instead of 7 floats
* 3D shaders now have in vec3 normal, bound to GL3_ATTRIB_NORMAL
* There's a new UBO for light data: uniLights, containing an array of
  up to 32 dynamic lights, with data copied from gl3_newrefdef.dlights
2017-03-27 01:02:54 +02:00
Daniel Gibson
6547e08c1a GL3: Upload UBOs with glBufferData(), make it build+work on Windows..
..with Radeon 6950 using AMDs legacy driver.

For uploading UBOs it turned out that glBufferData() is faster,
sometimes a lot faster, with several drivers, especially Intel/OSX.
2017-03-25 18:19:28 +01:00
Daniel Gibson
35285a0fcd GL3: Render each Model in one draw call (as GL_TRIANGLES w/ EBO)
this increases performance a lot.

Using DG_dynarr.h for dynamic arrays collecting all the vertices and
indices of a model.
2017-03-25 17:25:17 +01:00
Daniel Gibson
4bc3a68699 GL3: Bigger, fewer Lightmap textures, cleanups
if the lightmap textures are 1024x512 instead of 128x128, all original
Q2 levels will only need one lightmap texture (instead of max 26 or so)
and even maps that needed all 127 (the 128th was the dynamic lightmap)
won't need more than 4.
This should result in less glBindTexture() calls.

(Note: When I wrote "1 lightmap texture" I meant 4, because where the
 old renderer dynamically blended the up to 4 lightmaps/surface, I put
 them in 4 textures that belong together and are alle passed to and
 blended in the fragment shader)
2017-03-25 17:22:54 +01:00
Yamagi Burmeister
e229008b72 Another try to make this utterly piece of crap portable. 2017-03-22 18:03:44 +01:00
Daniel Gibson
2e31ae0ec5 Remove/Replace unprintable characters for printing to stdout/log
some chars draw lines etc in Q2's font (conchars.pcx), but aren't
printable in ASCII.
Now they're replaced with equivalent real chars or just spaces.
2017-03-19 19:17:20 +01:00
Daniel Gibson
6b3195e942 GL3: Remove some unused variables 2017-03-19 05:56:08 +01:00
Daniel Gibson
2dc7b6e6eb GL3: Multiple lightmaps/surface with lightstyles works
not sure if this is the very best solution..
Every surface can have up to 4 lightmaps.
I now always create 4 lightmaps (in separate textures, so the
corresponding texture coordinates are identical), the "fillers" are
set to 0, so in the shader they won't make a visible difference.
(The shader always adds up lightmaps from 4 textures, but how much
 they're actually visible depends on lmScales which also will be set to
 0 if "unused")

If all this turns out to be (too) slow, there could be a special case
for surfaces with only one lightmap, I /think/ that's the most common
case by far.
2017-03-19 05:45:10 +01:00
Daniel Gibson
5abf60de89 GL3: Reintroduce RenderLightmappedPoly from old multitexturing Code
adjusted to new GL3 stuff, of course.
Also, more code for light style/lightmap scale support.
Should probably (maybe) work once we have really have 4 textures
per lightmap id.

(And then of course dynamic lights are still missing)
2017-03-19 05:45:01 +01:00
Daniel Gibson
d034362809 R_RenderBrushPoly: Don't overflow msurface_t::styles
maps could be 4 at that point.
2017-03-18 20:05:07 +01:00
Daniel Gibson
f3c78fb1c5 GL3: Theoretically support 4 lightmaps with styles (in shaders)
practically those lightmaps must be created and uploaded as textures
etc
2017-03-18 20:02:31 +01:00
Daniel Gibson
e6a534aef2 Extra shaders for rendering with lightmaps vs transparent surfaces 2017-03-18 15:41:11 +01:00
Yamagi Burmeister
4d299e26d7 Don't write stdout.txt and stderr.txt when portable.
To be able to test if the game is running portable all checks of the
portable cvar must be done after Cvar_Init(). Instead of redirecting
stdout and stderr as early as possible, delay the redirection right
after Cvar_Init(). After this change the printf() in WinMain() aren't
printed into stdout.txt, but I guess that it isn't a big problem. All
interessting stuff like the search pathes is still there.

Rename fs_portable to portable. It's no longer filesystem specific.
2017-03-13 16:24:26 +01:00
Yamagi Burmeister
3032698f95 Put console_history.txt in the binary dir when fs_portable is 1. 2017-03-13 15:41:41 +01:00
Yamagi Burmeister
00758277f1 Add a missing sanity check. attacker->classname may be NULL.
This was reported by maraakate in issue #170.
2017-03-13 14:17:51 +01:00
Yamagi Burmeister
692b64ad38 Add a cvar fs_portable. When set to 1 the game is 'portable'.
Normally Q2 writes all persistent data (the configurations, saves, etc.)
into a subdirectory in the users $HOME. That can be a problem when the
game is installed onto an thumb drive or something like that. Therefor
provide a cvar fs_portable. When set to 1 the games uses it binary dir
as it's persistent storage location.

Examples:

./quake2 +set fs_portable 1
./quake2 +set basedir ~/games/quake2 +set fs_portable 1

fs_portable is _not_ saved into the config file. It must be set at
every start!

This closed issue #158.
2017-03-13 14:12:33 +01:00
Yamagi Burmeister
4a54fdd0ed Ensure that '+set game baseq2' doesn't break the search pathes.
This is the first step to fix issue #158, consistent behavior for all
cases. This problem was also reported by @lonkamikaze through IRC.
2017-03-13 13:52:11 +01:00
Yamagi Burmeister
45cc75d2d9 Add an undocumented option for forcing busy waits.
Some people complained about the usage of non busy waits:

  * I was told that there's an input lag with nanosleep(). I still doubt
    that, but since the problem is easy to solve...
  * Some Intel CPUs throttle the GPU if the selected CPU pstate is too
    low. This is especially a problem on Haswell mobile CPUs. Keeping
    a core busy works around that.
2017-03-13 13:39:03 +01:00