Commit Graph

76 Commits (376ca5a9dfb6b51ad02253a429ef0bd935d85799)

Author SHA1 Message Date
Julius Michaelis 376ca5a9df Prevent using USE_CONSOLE in lib{misc,c4script} 2016-10-22 17:42:23 +02:00
Julius Michaelis 34a9a1de8d Twiddle with header organization: lib{misc,c4script} do no longer include GL/glew.h
(Yes, it is just that complicated.)
2016-10-20 18:46:32 +02:00
Nicolas Hake ad091fcfcf Fix shader code memory lifetime problem
I love StdBuf SO MUCH!
2016-06-27 12:40:35 +02:00
Nicolas Hake cc595ec58d GL Legacy: Survive skinning meshes with no bones 2016-06-27 01:05:18 +02:00
Nicolas Hake e9c5facf91 GL: Disable hardware-based skinning on old Intel devices
Our hardware-based skinning doesn't work on certain Intel graphics
devices. Fall back to software skinning on GPUs that return an OpenGL
3.1 context even though we explicitly request a 3.2 one.

Might fix #1459, #1689.
2016-06-19 13:45:12 +02:00
Nicolas Hake 9555bf737f GL: Bail earlier when encountering degenerate matrices 2016-06-19 11:22:04 +02:00
Nicolas Hake eabca223f5 Update all copyright notices for 2016 2016-04-03 20:24:42 +02:00
Nicolas Hake 493c276126 Rewrite header inclusions to #include "path/to/file.h" style 2016-04-03 20:24:42 +02:00
Nicolas Hake de1d00eb68 Meshes: Enable reload for custom material shaders 2016-04-03 13:37:03 +02:00
Nicolas Hake 33b8d404a5 GL: Add "frameCounter" uniform
Add the current frame counter as a uniform variable to the shaders, so
people can use it to do time-based animation.
2016-03-31 01:44:44 +02:00
Günther Brammer a6b1ee79e9 Fix assertion failure when rendering mesh with degenerate transform
It isn't enough to check the top-level mesh, because attached meshes also
get a transformation from script. At least cotton branches sometimes do
that.

So check the matrix directly before using it and skip rendering.
2016-01-31 21:51:50 +01:00
Armin Burgmeier b698557163 Replace obsolete GL_MAX_TEXTURE_UNITS (#1641)
The replacement is GL_MAX_TEXTURE_IMAGE_UNITS.
2016-01-19 18:05:57 -08:00
Armin Burgmeier 4b98e71271 Fix GL state reset of wireframe mode (#1636)
Not sure why this broke, maybe glGetIntegerv does not return the current
polygon mode anymore. Either way, we don't need to remember the previous
setting but can just always reset it to GL_FILL afterwards.
2016-01-17 21:32:48 -08:00
Armin Burgmeier d387fdb270 Fix mesh rendering for meshes with more than one submesh
The buffer offset was encoded in the VAO which would be shared across all
submeshes. Instead, don't encode the buffer offset into the VAO but apply it
with glDrawElementsBaseVertex().
2016-01-17 11:37:17 -08:00
Armin Burgmeier 6bda0b4ec8 Use an element array buffer (IBO) for meshes
This is required for glDrawElements() with a core profile. Furthermore, for
meshes that have a fixed face ordering (non-transparent meshes at 100%
completion), this puts more static data on the GPU that we don't have to
upload every frame.

For meshes with non-fixed face ordering, we still have to upload faces every
frame, since the ordering might change if the mesh rotates. We could still
improve this by figuring out if the order actually changed after the sort
step, and only update to the GPU if it has. In many cases it hasn't, so there
is some potential for more optimization there. But that's for later.
2016-01-17 11:37:17 -08:00
Armin Burgmeier aef7538aa1 Switch shader code to OpenGL 3 style 2016-01-17 11:37:17 -08:00
Armin Burgmeier bc8db0589e Make the mesh material properties uniform variables
Instead of relying on the obsolete glMaterial call.
2016-01-17 11:37:17 -08:00
Armin Burgmeier 28aa1d1812 For each VBO, use a VAO to render it
For OpenGL 3.2 core compatibility, and to reduce the number of state
changes during rendering.
2016-01-17 11:37:17 -08:00
Armin Burgmeier 95774e0e8f Use generic vertex attributes for sprites, meshes, particles 2016-01-02 13:10:03 -08:00
Armin Burgmeier 26cfbdb059 Fix assertion failure when rendering mesh with degenerate transform (#1519)
The DynamiteBox sets the PictureTransformation to a degenerate matrix, to
prevent it from being rendered. Exit early in this case, since we are not
going to render anything anyway, and avoid the assertion when inverting the
matrix.
2016-01-01 11:34:04 -08:00
Armin Burgmeier c0844c10ff Add support for generic attributes to C4Shader
Replace the hardcoded VAI_ constants with that. The VAI constants are now
moved to C4DrawGL as C4SSA_ constants, similar to the C4SSU ones. This allows
to introduce other attributes to replace vertex positions, normals, colors
and texture coordinates with attributes in later commits. This, in turn, is
needed because the built-in attributes are no longer available in the OpenGL
core profile.

Also, while at it, cleanup C4Shader a bit. Use std::vector<> instead of
maintaining an own array of uniform names. Delete the vertex and fragment
objects after the full shader program has been linked. Make sure that
C4Shader::Init keeps the old program in place if the new one cannot be
compiled or linked.
2015-12-31 22:28:23 -08:00
Nicolas Hake 90293d019d C4FoWRegion: Make more private
Code outside of C4FoWRegion should not care about the internals of the
class. Therefore, we remove direct access to the backing surface (and
secondary buffer surface) and replace it instead with accessors that
return those few values that are required by outside code.
2015-12-28 21:45:21 +01:00
Nicolas Hake cbdeca56de Temporarily change to C locale before formatting shader floats
In the game initialization code, we're setting the thread locale to the
user's default locale. This is bad when generating shader code because
it may lead to floats being written with commas instead of dots for the
decimal separator, which in turn confuses the GLSL compiler (because it
parses the comma as the comma operator). So now we just temporarily set
the C locale while generating shader code.
2015-12-27 01:54:42 +01:00
Armin Burgmeier de3ed60aa8 Avoid built-in GL matrices for mesh rendering
Instead, compute the projection, modelview and normal matrices explictly
and upload them as shader uniforms.
2015-12-24 23:02:03 -08:00
Armin Burgmeier 379fac32ee Move alpha test into the fragment shader 2015-12-19 17:04:34 -08:00
Nicolas Hake 24b54211c5 Drop Min, Max, Swap for std::min, std::max, std::swap
The C++ standard library comes with perfectly fine implementations of
these functions, so there's no point in reimplementing them just for the
hell of it.
2015-11-15 13:53:01 +01:00
Armin Burgmeier fb68624686 Try to compile vertex shader before trying work-around (#1368)
It looks like sometimes graphics drivers don't report the correct number for
maximum uniforms, since the workaround was enabled even though Newton
confirmed disabling the workaround worked just fine on his GPU. Therefore,
don't listen to what the graphics driver is saying but just try to compile the
shader, and fall back to the workaround if the compilation fails.
2015-10-03 14:45:54 -04:00
Armin Burgmeier 061305c0c7 Don't enable textures in C4ShaderCall::AllocTexUnit
This was only necessary with the fixed function pipeline, but not when
using shaders.
2015-09-16 21:45:30 -04:00
Armin Burgmeier 9197acbb62 Generate mipmaps by default, and use them for mesh textures 2015-09-14 20:36:08 -04:00
Armin Burgmeier db29160fea Revert "revert workaround made for #1368, doesn't work on (certain) Intel chipsets. Instead, limit the maximum bone count to 64 so to meet the limit of 1024 uniform components by certain graphics cards (#1285)"
This reverts commit f57bfa089c.

This was committed by mistake. Fixes #1375.
2015-09-03 20:38:53 -04:00
Tobias Zwick f57bfa089c revert workaround made for #1368, doesn't work on (certain) Intel chipsets. Instead, limit the maximum bone count to 64 so to meet the limit of 1024 uniform components by certain graphics cards (#1285) 2015-08-31 19:28:00 +02:00
Peter Wortmann 30857e835e Shader gamma implementation
In comparison to the old system, this is a downgrade - instead of being
able to set a full color mapping by gamma ramp, we now get just a value
per colour channel.

Upside is that we do not need to play around with the global gamma ramps
any more, which was arguably the wrong way to do it.

This commit will likely break everything that has been using gamma so far.
2015-08-31 17:35:08 +01:00
Armin Burgmeier 0cdafc278b Transform all mesh data to Clonk reference frame on load
Instead of doing the transformation when drawing a mesh. This allows making
the OpenGL normal matrix more consistent, since it does not include the
Ogre-To-Clonk transformation, and so that the transformation does not need
to be inverted in the shader.

As a side effect, all Attach transformations were updated, since before
they were specified in the OGRE reference frame, not the Clonk reference
frame.
2015-08-18 20:30:20 -04:00
Armin Burgmeier 08aaf662a9 Add support for alpha_rejection in OGRE material scripts 2015-07-31 22:50:21 -04:00
Armin Burgmeier a172245c1e Illuminate materials with no backface culling from both sides
This might need adaptions in some materials, but is probably the right thing
to do.
2015-07-20 22:11:19 -04:00
Nicolas Hake 5562b09dc4 Remove a lot of disabled legacy code, round 2
Maybe at some point we'll be rid of all the commented-out code that
nobody has looked at in years.
2015-03-25 20:02:53 +01:00
Nicolas Hake d6f219a3df Use 3x4 bones on low MAX_VTX_UNIFORM_COMPS (#1285)
4x3 matrices use the same number of uniform components as 4x4 ones.
If we're short on uniform components, don't transpose the transformation
matrix before sending it to the shader, and transpose it in the shader
itself instead, saving 4 components per bone.
2015-03-18 23:38:20 +01:00
Nicolas Hake f0579f7f93 gl: Use fewer uniform components to upload bones (#1285)
The last row of the bone transformation matrix always is 0,0,0,1 so
there's no point in uploading it. Also reducing the max bone count to 80
which means the uniform array will fit into the available space on 6000
and 7000 series Geforce GPUs.
2015-03-17 22:55:12 +01:00
Nicolas Hake 179498984d Upload dummy bone for boneless meshes (#1278)
As long as we're not actually using a different shader for meshes
without bones, we need to upload an identity matrix so there's defined
data in the bone slot.
2015-03-05 13:09:40 +01:00
Nicolas Hake d13af4dadd Work around g++'s dislike of nonconstant offsetof 2015-02-28 13:42:33 +01:00
Nicolas Hake d2563fe345 Do skinning in hardware
Instead of transforming all vertices on the CPU every time an animation
progresses, we now only recalculate the skeleton, leaving the heavy
lifting for the GPU. This also means we no longer have to push all
vertices onto the bus every frame, because the mesh isn't changing and
can therefore be stored in a GL_STATIC_DRAW VBO when it's first loaded.
The downside of this approach is that there's only a limited number of
uniforms and vertex attributes we can pass to the shader. At the moment
these limits are a maximum of 128 bones per skeleton, and no vertex can
be influenced by more than 8 bones at once. So far this is no problem,
as the most complex skeleton in the base game uses less than 64 bones
and no more than 6 bone weights per vertex.
2015-02-27 21:51:58 +01:00
Nicolas Hake 517e4e6e85 Load default object vertex shader from Graphics.ocg
Instead of having the default vertex shader hard-coded into the engine,
allow to load it from Graphics.ocg. There's still a fall-back version
wired into the engine because we can't return an error from
GetVertexShaderCodeForPass.
2015-02-26 21:04:12 +01:00
Nicolas Hake c66833e2db GL: Render meshes out of a VBO
While we're still not doing skinning on the GPU, copying the vertex data
to a VBO immediately after updating the animation allows us to re-use
that data for unanimated meshes. It also allows us to store unanimated
data on the GPU, instead of transferring it over the bus for each frame.
2015-02-24 18:36:58 +01:00
Nicolas Hake 2ef2c637a7 Remove several instances of disabled legacy code 2015-01-18 22:59:45 +01:00
Nicolas Hake fef96eca9c Replace C4Surface::ppTex by a vector
This should improve cache coherency by having all surface tiles adjacent
instead of strewn across the heap. This will also remove an indirection
in the common case of only using one tile.
2015-01-18 22:59:44 +01:00
Armin Burgmeier e1d1d540c7 Allow independent viewport and light regions in C4FoWRegion (#1211)
With this change, an additional rectangle is stored in C4FoWRegion that
represents the area covered by the viewport in fractional floating point
coordinates. This allows the light texture to be created for an arbitrary
portion of the landscape, and the coordinate transformations for the
shaders will still work.

Also, since the additional rectangle uses floating point precision, the
computed coordinate transformations do now give the exact same result as for
the landscape pixel-by-pixel, and there should not be any offsets left.

I also hope that this change improves or fixes the single-pixel-lines of sky
that are sometimes seen at the edges of the viewport.
2015-01-07 19:44:31 +01:00
Armin Burgmeier a508fb38e7 Remove GL shade model changes
This gets rid of GL state changes for questionable gain. It also fixes drawing
of fade sky backgrounds in global viewports (where, for some reason, the shade
model was set to GL_FLAT instead of GL_SMOOTH).
2014-12-29 22:27:49 +01:00
Armin Burgmeier 8116a96ed4 Fix fragment coordinate transforms (#1192)
There were two problems with the previous transforms:
  1) For inverting the Y axis for the ambient map, the total height of the
     output window is needed, not only the viewport region.
  2) The Y offset to only use the part of the light texture that is being
     rendered to was not applied.

In order to keep the transformations more readable, a new lightweight class
C4FragTransform has been introduced which can only handle translations
and scales in x and y.
2014-12-26 16:16:09 +01:00
Armin Burgmeier 8686441d45 Make mesh shaders use the C4Shader slice machinery 2014-12-22 22:56:30 +01:00
Armin Burgmeier ab4de05b4f Fix light/ambient drawing offset when upperboard is active 2014-12-07 21:54:12 -05:00