Mikko Rasa [Mon, 5 Dec 2016 16:35:22 +0000 (18:35 +0200)]
Store Renderables as non-const pointers or references
It's irked me for a while how some renderables (mostly effects) need to
do internal updates in setup_frame, but it's const so I end up with a ton
of mutables. Since almost all of my use cases actually pass in non-const
Renderables anyway, I'm just going to change this.
Mikko Rasa [Mon, 5 Dec 2016 16:10:52 +0000 (18:10 +0200)]
Remove the Renderer-less overload of Renderable::render
It's been sort-of deprecated for a long time even though it wasn't marked
as such. None of my code code uses it with anything else than Pipeline
(and that code path is being replaced with View).
Mikko Rasa [Sat, 3 Dec 2016 16:37:53 +0000 (18:37 +0200)]
Refactor postprocessor uniform usage
A lot of the values are shared between processing passes, so it doesn't
make sense to keep multiple copies. ProgramData will take care of only
setting the required uniforms.
Mikko Rasa [Sat, 3 Dec 2016 16:03:12 +0000 (18:03 +0200)]
Add a RenderTarget class to manage and annotate FBOs
I want to have deferred lighting support at some point, and it requires
multiple outputs from the geometry rasterization stage. There needs to
be some way to annotate which buffer holds which information.
Mikko Rasa [Sat, 3 Dec 2016 15:53:19 +0000 (17:53 +0200)]
Remove dynamic allocation from VertexFormat
On 64-bit systems the pointer takes eight bytes, and a typical malloc
implementation will have two pointers worth of overhead. Vertex formats
hardly ever reach even eight components, so it's cheaper to just store
a fixed-size array in the class itself.
Mikko Rasa [Fri, 2 Dec 2016 20:17:50 +0000 (22:17 +0200)]
Ensure that program syntax nodes get deep-copied properly
The changes in 57c1139 prevented copies happening even when they should,
so the shared section got inserted into shader stages by reference. This
caused some funny business with the variable resolver and unused variable
locator.
Containers of nodes must have RefPtrs inside them, since insertions will
create some temporary copies of the element and with NodePtr that would
trigger copying the node as well. So the cloning of nodes is performed
when the container itself is copied.
Mikko Rasa [Fri, 2 Dec 2016 10:26:12 +0000 (12:26 +0200)]
Reorder declarations in shaders
So that structs appear before variables and variables appear before
functions. This ensures that the declarations stay visible if an
expression is moved to an earlier point while inlining functions.
Mikko Rasa [Thu, 1 Dec 2016 11:29:29 +0000 (13:29 +0200)]
Upgrade NodePtr to RefPtr
Allows Nodes to be moved from one Block to another without copying them.
When targeting GLSL 1.30 LegacyConverter has a sequence where it flattens
an interface block and later checks the type of those variables through
their declaration pointer. This caused memory errors because the
original nodes were destroyed in the flatten operation.
Mikko Rasa [Sat, 26 Nov 2016 04:56:54 +0000 (06:56 +0200)]
Make the camera part of changeable Renderer state
I'd like to move to a single, persistent renderer at some point and this
is a necessary step towards that. Some effects want to use their own
camera to render into an FBO.
Mikko Rasa [Fri, 18 Nov 2016 22:01:40 +0000 (00:01 +0200)]
Allow redeclarations to override the type of a variable
This can be used to e.g. change the sampler type of the diffuse map. At
the moment the appropriate sampling function also needs to be overridden
since texcoord dimensions are not handled automatically.
Mikko Rasa [Tue, 15 Nov 2016 17:09:50 +0000 (19:09 +0200)]
Add a builtin module for standard shaders
It doesn't support multiple lights as generating the necessary array
interfaces through a geometry shader turned out to be rather non-trivial.
I plan to add deferred rendering modules with multi-light support later.
Mikko Rasa [Mon, 14 Nov 2016 13:33:45 +0000 (15:33 +0200)]
Remove conditionals and loops that can be determined to never run
This is the other major step required for standard shader generation.
Currently the constant condition eliminator is pretty conservative and
will only consider the initialization values of variables. Globals are
only considered if they are declared const.
Mikko Rasa [Mon, 14 Nov 2016 12:22:02 +0000 (14:22 +0200)]
Implement an import system
This is the first of two major steps required to replicate the core
functionality of the old ProgramBuilder system, namely generating
standard shaders. The other is conditionally including pieces of code,
which will be added soon.
Mikko Rasa [Sat, 12 Nov 2016 00:00:09 +0000 (02:00 +0200)]
Process existing inputs in passthrough
Vertex shader inputs are not linked to any outputs so they weren't being
recognized for passthrough. Also, some inputs might have already been
declared either explicitly or implicitly so those declarations should be
preferred over creating new ones.
Mikko Rasa [Fri, 11 Nov 2016 16:39:57 +0000 (18:39 +0200)]
Refactor module and stage management
Originally I envisioned that ProgramParser would handle imports, but it's
non-trivial to make re-entrant. The parser will now only hold one module
at a time and ProgramCompiler will handle combining them.
Mikko Rasa [Fri, 11 Nov 2016 09:05:15 +0000 (11:05 +0200)]
Streamline interface declarations
Out variables can now be declared inside functions and will be exported
to global scope. In variables don't need to be declared at all; they are
pulled in from the previous stage. There's a new passthrough statement
to copy all inputs to outputs.
Mikko Rasa [Mon, 7 Nov 2016 21:10:51 +0000 (23:10 +0200)]
Begin implementing a new shader program generator system
ProgramBuilder is good enough when working within its standard features,
but it's difficult to expand. Custom variables are overly sensitive to
declration order. Adding loops or conditionals (other than the operator
flavor) requires using an additional shader. It's not possible to modify
a variable's expression without replicating it in its entirety.
All of the internal processing with coordinate spaces, interfaces and
indices can also be difficult to understand. Not to mention the reverse
processing order which starts from the goal variables and works backwards
to figure out how they can be computed.
The new ProgramCompiler system, as its name implies, works more like a
compiler. It's designed to take GLSL as input, apply transformations to
it and produce different GLSL as output. Storing the progrem as an
abstract syntax tree allows much more comprehensive processing than the
old system which barely understood what an identifier is.
At the moment it doesn't do much yet. The only transformation is to
split a single source file into vertex, geometry and fragment parts and
add a common section at the beginning of each of them. More will be
added soon.
Mikko Rasa [Sat, 5 Nov 2016 23:37:55 +0000 (01:37 +0200)]
Detect deprecation versions for extensions
If the core profile is in use, deprecated extensions will be made
unavailable unless the driver explicitly advertises them. In particular,
MSP_legacy_features is made unavailable so code that tries to access
legacy features with a core profile context will throw an exception.
Additionally no enable/disable calls will be generated for textures, as
they are only used for legacy texture units.
Mikko Rasa [Thu, 3 Nov 2016 11:12:06 +0000 (13:12 +0200)]
Prefer RG pixelformats over LUMINANCE
LUMINANCE formats were deprecated in OpenGL 3.0. ARB_texture_swizzle
was not promoted to core until 3.3, so it's possible this won't work on
some transition period hardware.
SLUMINANCE formats are marked as deprecated in mspgl since it's not
possible to properly emulate them through swizzling.
Mikko Rasa [Thu, 3 Nov 2016 10:50:35 +0000 (12:50 +0200)]
Expand the PixelFormat conversion API
Get_sized_pixelformat now takes an explicit size parameter. The decision
between 16-bit and 32-bit depth component formats has been moved to
Texture::set_internal_format.
Get_unsized_pixelformat was added as an intermediate step for
get_base_pixelformat. It preserves sRGB information.
Mikko Rasa [Wed, 26 Oct 2016 18:33:21 +0000 (21:33 +0300)]
Be smarter about detecting backport extensions
Sometimes a more recent and completely unrelated extension reuses some
tokens with their core names, causing them to seem like backport
extensions to the script.