Skip to content

Instantly share code, notes, and snippets.

@szdarkhack
szdarkhack / imgldst.cpp
Last active September 22, 2019 18:14
Here's the code sample, let me know if you need any clarifications.
// Description:
//
// A simple test program using the EXT_image_load_store extention (core in OpenGL 4.2 and above) to completely take over the fragment operations,
// in the hope of providing a method for accurate emulation of systems offering stencil/depth tests or blending operations that are impossible to
// implement using the standard OpenGL equivalents, such as the Sony PSP. This method also has the benefit of being single-pass, so it is pretty
// efficient and doesn't require any extra framebuffers.
//
// The rendering shader renders both to the framebuffer and to a few images (color, depth, stencil) such that it can subsequently use the data
// to perform depth/stencil testing and blending. Memory consistency is achieved by a combination of cache qualifiers, per-pixel mutexes and
// memory barriers where appropriate. Specifically, glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT) is required between draw calls with