Commit Graph

240 Commits (aef7538aa1e4d58eaa806f57bb0b4cb82eb308e1)

Author SHA1 Message Date
Armin Burgmeier aef7538aa1 Switch shader code to OpenGL 3 style 2016-01-17 11:37:17 -08:00
Armin Burgmeier 16d2eb5cb1 Use the core api for shaders instead of the ARB one 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 fabb4cbdbf Implement a mechanism that allows using VAOs across contexts
Basically add another layer of indirection around accessing VAOs. The problem
is that VAOs are not shared between OpenGL contexts. This mechanism allows to
treat them mostly as if they were shared if they are only accessed through
the API defined in CStdGL.

This is accomplished by caching all existing VAOs per context. If a VAO is
being accessed, it is checked whether that VAO exists in the currently
selected context. If yes, return it, otherwise create a new VAO and return it,
together with a flag that indicates that the VAO needs to be initialized.
2016-01-17 11:37:17 -08:00
Armin Burgmeier fa9f4c6356 Replace GL_GENERATE_MIPMAP flag by glGenerateMipmap call
The former is not available in a OpenGL 3 core profile, but glGenerateMipmap
is available since OpenGL 3.0, and so is always available when we have a
core profile.
2016-01-17 11:37:17 -08:00
Armin Burgmeier bb8b933417 Revert "Revert "Replace 3D texture in landscape shader by a 2D texture array""
This reverts commit 4a02d3c77b.

This was merged into master even though I only wanted it in stable-7.0.
Oh well, let's just revert it again.
2016-01-17 11:37:17 -08:00
Armin Burgmeier 2935f9622c mac: fix mousewheel event handling (#1575)
Some sort of smooth scroll information was passed down to the engine which
didn't handle it properly, or the units with which they were reported to us
were different from what the engine expected.  For now, just use fixed scroll
offsets until we implement proper delta-y-aware scrolling in C4MouseControl.

The fix for #1574 might have also helped with this in recognizing when Control
is pressed and when it isn't.
2016-01-10 20:01:45 -08:00
Armin Burgmeier ef63aa0975 mac: send keydown events for modifier flags change (#1574)
For example, keydown events when pressing/releasing the shift, alt, or control
keys. With this version this is needed ingame e.g. to pick up objects with
Shift.
2016-01-10 18:11:29 -08:00
Clonkonaut 962b178663 Merge remote-tracking branch 'remotes/origin/revert-opengl-2.1' 2016-01-10 17:27:56 +01:00
Armin Burgmeier 25a19f9922 StdPNG: Fix crash when saving a screenshot on Linux/Mac 64bit
"unsigned long" is 8 bytes on 64-bit Linux and Mac, so we write 4 bytes
past the end of the allocated memory region.
2016-01-05 20:23:15 -08:00
Armin Burgmeier 4a02d3c77b Revert "Replace 3D texture in landscape shader by a 2D texture array"
This reverts commit 790219ac7e.

This commit broke support for Mac OS X since Apple only supports OpenGL 3.0
with a core profile, not a compatibility profile. Revert this commit
temporarily for the 7.0 release, until we port all OpenGL usage to the core
profile with 8.0.

This fixes #1495.
2016-01-04 18:27:44 -08:00
Armin Burgmeier d72b8cc385 Use generic vertex attributes for FoW rendering 2016-01-02 19:11:41 -08:00
Armin Burgmeier 96c8b51eac Use generic vertex attributes for landscape rendering 2016-01-02 17:20:24 -08:00
Armin Burgmeier 95774e0e8f Use generic vertex attributes for sprites, meshes, particles 2016-01-02 13:10:03 -08:00
Armin Burgmeier 988fe15e29 Use VBOs to draw sprite graphics
I don't expect much of a performance benefit from this, but it works toward
removal of legacy OpenGL usage. Note that we are already using VBOs for
meshes, so this does not require any functionality that we don't require
already.
2016-01-01 22:26:41 -08:00
Armin Burgmeier 795740c6ee C4Surface: fix texture restore on IntUnlock (#1526) 2016-01-01 14:48:33 -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
Armin Burgmeier c043795552 Fix memory leak in FoW surfaces
Surfaces are initially created in locked state, and only when unlocked the
memory buffer with the surface data is uploaded to the GPU. The FoW code
however never unlocks the surface but instead operates on the OpenGL texture
directly. To fix this, introduce a new flag for C4Surface to create it in an
unlocked state.

This is not a memory leak in the traditional sense as a pointer to the buffer
is still available and is being freed when the surface is being destructed
at the end of the game. However, during the game there might be several
megabytes allocated that are never used.

I'm not really sold by this Lock/Unlock mechanism. Instead, there should
simply be a function to obtain the current texture data, and a function to
upload new texture data. That's for another time though...
2015-12-31 18:40:38 -08:00
Armin Burgmeier fc4679e3ea Don't upload all texture data twice
For some reason, the C4TexRef constructor first uploaded a set of nulled
texture data, just to be replaced by the actual image data when Unlock()
is called. Skip the unnecessary step and instead just reserve the video
memory in the constructor.
2015-12-31 17:58:22 -08:00
Armin Burgmeier 8766f5123b Remove other usages of built-in GL matrices
Primarily for the FoW rendering, which now also uses (simple) shaders
without ftransform() everywhere. This also removes all GLU calls.
2015-12-31 17:30:21 -08:00
Nicolas Hake 9b34bf2634 Remove arbitrary inline forward declarations of StdBuf (and derivatives) 2015-12-29 21:42:46 +01: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
Nicolas Hake b36a9ec5b5 C4Draw: Remove C4Draw::IsShaderific()
In a surprising touch, using shaders to affect pretty much every pixel
that gets drawn on screen means there is little reason for code to ask
the renderer if it knows about shaders.
2015-12-27 01:54:41 +01:00
Nicolas Hake 73c26114cb C4Draw: Remove C4Draw::IsOpenGL()
Nobody was interested in testing whether the renderer was GL or something
else, so the function is superfluous.
2015-12-27 01:54:06 +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 a487457563 Add a 4x4 matrix class (StdProjectionMatrix)
This makes it easier to convert the projection and modelview matrices
to GLSL uniforms.
2015-12-24 23:01:52 -08:00
Armin Burgmeier 43e50f9320 Drop usage of gluErrorString
There are only a couple of error values worth considering, so we can just
write out own function for it. Disable error checking in C4FoWRegion.cpp as
well, since we have the --debug-opengl flag now.

This should allow us to get rid of the GLU dependency soon.
2015-12-24 16:26:52 -08:00
Armin Burgmeier a1f7a7c0e8 Fix conversion of C4BltTransform to StdMeshMatrix (#1508)
This was introduced by a9967e7.
2015-12-20 09:55:41 -08:00
Armin Burgmeier 10f98d1e3b Fix Windows build (hopefully) 2015-12-20 09:48:17 -08:00
Armin Burgmeier a9967e7b16 Avoid built-in GL matrices for sprite rendering
Instead, compute the projection, modelview and normal matrices explictly
and upload them as shader uniforms. This is one step towards using the
OpenGL 3 core profile.
2015-12-19 22:37:36 -08:00
Armin Burgmeier 609840fda0 Fix internalFormat parameter of glTexImage* calls 2015-12-19 17:20:11 -08:00
Armin Burgmeier 379fac32ee Move alpha test into the fragment shader 2015-12-19 17:04:34 -08:00
Nicolas Hake f0eeb3f6b3 Make headless build compile again 2015-12-15 19:45:32 +01: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
Nicolas Hake 8fc57b69c3 Don't ZeroMem non-POD types
Using memset to initialize non-POD types doesn't work. Or rather, it may
work right now, but will fail when somebody adds a member that relies on
its constructor doing something (like for example any STL container).
Either way it's undefined behavior and needs to go. Furthermore, using
it to reinitialize an object also prevents any dtors from doing their
work when needed.

A new helper function InplaceReconstruct will take an object of nothrow-
default-constructible type, and call the dtor to properly clean up
before placement-new reconstructing the object in the same location.
This is still bad design, but unfortunately removing the Default/Clear
functions from every object currently using them is a herculean task.
2015-11-14 16:43:19 +01:00
Armin Burgmeier 12ae83cfe4 Re-initialize shaders after changing anti-alias setting (#1286) 2015-10-31 21:12:45 -06:00
Tupone Alfredo 67558a8511 Build with jpeg-9
Gentoo bug #520884 by flameeyes@gentoo.org
2015-10-21 11:55:20 +02:00
Armin Burgmeier 70fd6d20bf Keep parallax objects fixed on full map screenshots (#1042) 2015-10-17 17:38:50 -04:00
Peter Wortmann 86679d2fb0 Allow all shaders to refresh
The solution is slightly hacky and not entirely stable, but for fine-
tuning this functionality is essential.

While I was at it, also reduced refresh interval so it doesn't have a
chance to lag the game.
2015-10-04 14:25:56 +01:00
Peter Wortmann beef0369e7 Fix OC_SKY definition
Lost in the merge...
2015-10-04 14:24:49 +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 745683c860 Small shader preprocessor fixes 2015-10-03 11:18:47 -04:00
Peter Wortmann cf4ed1b0b7 Shiny materials, shader reorganisation
This implements the proposal made in the forum for "shiny" materials -
material can now determine the angle at which the most light is reflected.
Shiny materials might set this lower to approximate a "reflection" effect,
and increase the "spottiness" at the same time. To compensate for the
lack of brightness without light, "emittance" can be used.

Not sure this is the most elegant way to model this - the "proper" way
here would be to have emittance, shading and specular as three separate
light parameters instead of molding one into the other and using the third
to compensate.

Furthermore, this reorganises shaders in a major way: We reduce the
number of shader files down to three, pushing a number of possible
configurations into preprocessor. I believe this should be easier to
understand, which for the moment trumps theoretical extensibility
benefits.
2015-10-03 15:32:39 +01:00
Peter Wortmann f0030e33e0 Warning fixes
Actually pretty sure a few of them were bugs. Hopefully no new
ones were introduced here.
2015-10-03 15:32:39 +01:00
Sven Eberhardt fc7d16b2aa Fix mac build (I hope). 2015-09-29 21:31:13 -04:00
Sven Eberhardt 737b1fd8fd Save screenshots in background thread (#998, #1104).
Also ensure music keeps streaming while collecting data for full map screenshot.
2015-09-29 20:48:34 -04:00
Sven Eberhardt 59d7c761fc Screenshot fixes and optimizations.
* There was an off-by-one-error causing a blank line at the screen upper screen border.
* Remove ApplyGamma. It is always applied because Gamma is just part of the drawing shaders now.
* Save by copying rows instead of pixels for whole map screenshots.
2015-09-28 18:54:34 -04:00