Commit graph

1733 commits

Author SHA1 Message Date
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
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
Daniel Gibson
b6f68cd532 Allow setting png compression level in screenshot command
The level is between 0 and 10, use like
screenshot png 6
2017-03-13 00:50:57 +01:00
Daniel Gibson
bbf36746c8 stb_image_write.h: allow using custom zlib compress function
the one from zlib compresses better than the builtin one and might even
be faster.
2017-03-13 00:50:57 +01:00
Daniel Gibson
a1a634b95a stb_image_write.h: configurable png compress level 2017-03-12 22:33:59 +01:00
Daniel Gibson
9462063869 Screenshots can be tga, bmp, png, jpg now, using stb_image_write.h
the screenshot command now supports the filetype as optional argument
(just "screenshot" will use tga like before):
"screenshot png" will save the screenshot as PNG, same with jpg, png
and tga.
For jpg, you can even specify the quality, like "screenshot jpg 90"
(the Quality is between 1 and 100, like with libjpeg).

To reduce duplicated code, I addeed Vid_WriteScreenshot() to refimport_t
and implement most of it in the client (vid.c).
The renderer still fetches the raw image data from OpenGL or whatever
and then calls re.VidWriteScreenshot() which will write it to disk in
the format requested by the user.
2017-03-12 03:28:06 +01:00
Daniel Gibson
516c417d91 Render lightmaps together with corresponding faces; gl_overbrightbits
pass both normal texture and lightmap to shader instead of rendering the
level geometry again with the lightmap and GL_BLEND.

This is not done, some translucent surfaces are buggy now and it's only
static lightmaps. For this to work properly I'll need to add some more
shaders with and without lightmaps and use them accordingly.
For example, translucent surfaces (SURF_TRANS33/66) never have
lightmaps, neither to pertubed ones (SURF_DRAWTURB) like water and lava,
but scrolling surfaces (SURF_FLOWING) like elevators do use lightmaps
(as long as they're not also transulcent or perturbed)...
2017-03-12 03:11:29 +01:00
Daniel Gibson
13789554ba GL3: Dynamic Lightmaps (via blending)
well, seems to work, but once the lightmaps are rendered with the normal
textured faces, maybe the dynamic part can be done in shader?
(Might even look less blocky, because it's not limited to lightmap
 resolution then)
2017-03-05 17:34:53 +01:00
Daniel Gibson
2932d995fe GL3: Static Lightmaps (via blending)
not *that* cool, I wanna render them together with the normal texture..

and dynamic lightmaps are missing so most things look shitty anyway
2017-03-05 03:08:05 +01:00
Daniel Gibson
a3865db4bb GL3: rip out gl_flashblend 2017-03-04 16:38:08 +01:00
Daniel Gibson
18bfa35f9b Allow switching VSync on/off without vid_restart (for SDL2) 2017-03-04 16:31:34 +01:00
Daniel Gibson
6b21811af8 GL3: DrawNullModel()
this is used if a model can't be found/loaded
2017-02-26 20:47:37 +01:00
Daniel Gibson
613071078a GL3: render beams; common struct gl3_3D_vtx_t for vertex arrays
that struct can/should be used with gl3state.vao3D which expects data
as 7 floats (x,y,z, s,t, lms,lmt) - this is used for brushes, sprites,
the sky and more (not for models though).
(For rendering brushes the struct isn't used, the data already is in
 that format in float arrays)

beams are now rendered, they are used by the BFG and in some levels for
lasers etc
2017-02-26 05:22:39 +01:00
Daniel Gibson
977c81db5d GL3: Render sprites
and some cleanup/small stuff.

Damn, my productivity today scares me :-P
2017-02-26 04:37:22 +01:00
Daniel Gibson
15296ab5f8 GL3: Render Sky 2017-02-26 03:46:59 +01:00
Daniel Gibson
cf11473130 GL3: flashing screen (formerly R_Flash())
which just called R_PolyBlend().. no idea what that all was about..
and no idea why it happend in 3D mode, it's much  easier after
SetGL2D(), then it can share code with GL3_Draw_FadeScreen() and doesn't
need any additional messing with transformation matrices
2017-02-26 02:23:20 +01:00
Daniel Gibson
247a81c69b GL3: Render Particles, simplify GL3_ShutdownShaders()
* The particles look more fuzzy than in old renderer - I think it looks
  better this way ;)
* Not sure I keep the way they're rendered - instead of calculating and
  passing the distance in GL3_ShutdownShaders() I could set the player
  (camera) origin in a UBO and calculate distance (and based on that
  the size) in the vertex shader. I could also pass the basic point size
  via UBO, it's the same for all particles..
* Deleting shader programs is a lot shorter now and using a loop and
  the fact that consecutive fields of the same type in a struct have
  the same memory layout as an array of that type.
  Now I can just add a gl3ShaderInfo_t to gl3state, set it up in
  GL3_InitShaders() and don't have to add anything to
  GL3_ShutdownShaders() (this is good, I forgot that all the time and
  didn't notice, as it doesn't cause visible errors)
2017-02-26 00:47:27 +01:00
Daniel Gibson
f3e77e1123 GL3: Fix color-only rendering of models (+refactor GL3_UpdateUBO*)
* Of course the color attribute has 4 floats, not 2..
* I read that updating UBOs with glBufferData() is kinda slow.
  I didn't change that (yet), but at least all three GL3_UpdateUBO*()
  functions now call updateUBO() which can easily be changed to do
  whatever is best without touching the other three functions.
2017-02-26 00:20:32 +01:00
Daniel Gibson
b7bf822e6d GL1: Particle improvements
* When using gl_pointparameters, the particles always had the same size
  regardless of resolution, i.e. they look bigger (use bigger part of
  screen) at lower resolutions. Now I scale gl_particle_size according
  to the resolution, assuming the configured size looks good at 800x600
  (or generally 600px vertical)
* When not using gl_pointparameters, a textured triangle is rendered.
  The texture had a resolution of 8x8 pixels and looked like a cross,
  now it's 16x16 and has rounded ages, looking more like a circle.
  So particles with "gl_pointparameters 0" should look much better now.
2017-02-26 00:10:34 +01:00
Daniel Gibson
c4c21075a4 vid_listmodes command to show video modes, add 720p mode
the very unusual 1280x854 mode has been replaced with the more common
1280x720 ("720p").
2017-02-25 20:33:17 +01:00
Daniel Gibson
66e9c5f6db GL3: fix calculation of perspective matrix, some cleanups
turns out R_MYgluPerspective() was not the same as gluPerspective()
and thus not equivalent to HMM_Perspective() either. Because of this,
the weapon and corresponding arm looked different in GL3 vs GL1.
Created GL3_MYgluPerspective() to fix that.
Also tested optimized code in GL3_RotateForEntity() and
rotAroundAxisZYX(), use this code from now on and cleaned it all up by
removing commented out code.
2017-02-20 17:08:59 +01:00
Daniel Gibson
5511f44c99 GL3: Delete new shaders in GL3_ShutdownShaders()
also a small optimization in GL3_DrawAliasModel(), and adding that
function to local.h
2017-02-20 17:04:52 +01:00
Daniel Gibson
eadb607ac3 GL3: Support left-handed gun rendering (hand=1)
that was easy..
however, not related to this change or left vs right hand, the gun
seems to be drawn too far back, we should see more of the arm..
I wonder where that went wrong...
2017-02-20 02:16:34 +01:00
Daniel Gibson
de0197a8c0 GL3: Render models (weapons, items, monsters, projectiles etc)
introducing vertex color attributes GL3_ATTRIB_COLOR (it's used for
lighting models and to render models flat-colored, I think that's used
for quad damage effect and similar)
2017-02-20 02:03:31 +01:00