summaryrefslogtreecommitdiff
path: root/cogl/cogl-gles2-context-private.h
Commit message (Collapse)AuthorAgeFilesLines
* This re-licenses Cogl 1.18 under the MIT licenseRobert Bragg2014-02-221-12/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
* Use the Wayland embedded linked list implementation instead of BSD'sNeil Roberts2013-06-131-9/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes cogl-queue.h and adds a copy of Wayland's embedded list implementation. The advantage of the Wayland model is that it is much simpler and so it is easier to follow. It also doesn't require defining a typedef for every list type. The downside is that there is only one list type which is a doubly-linked list where the head has a pointer to both the beginning and the end. The BSD implementation has many more combinations some of which we were taking advantage of to reduce the size of critical structs where we didn't need a pointer to the end of the list. The corresponding changes to uses of cogl-queue.h are: • COGL_STAILQ_* was used for onscreen the list of events and dirty notifications. This makes the size of the CoglContext grow by one pointer. • COGL_TAILQ_* was used for fences. • COGL_LIST_* for CoglClosures. In this case the list head now has an extra pointer which means CoglOnscreen will grow by the size of three pointers, but this doesn't seem like a particularly important struct to optimise for size anyway. • COGL_LIST_* was used for the list of foreign GLES2 offscreens. • COGL_TAILQ_* was used for the list of sub stacks in a CoglMemoryStack. • COGL_LIST_* was used to track the list of layers that haven't had code generated yet while generating a fragment shader for a pipeline. • COGL_LIST_* was used to track the pipeline hierarchy in CoglNode. The last part is a bit more controversial because it increases the size of CoglPipeline and CoglPipelineLayer by one pointer in order to have the redundant tail pointer for the list head. Normally we try to be very careful about the size of the CoglPipeline struct. Because CoglPipeline is slice-allocated, this effectively ends up adding two pointers to the size because GSlice rounds up to the size of two pointers. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 13abf613b15f571ba1fcf6d2eb831ffc6fa31324) Conflicts: cogl/cogl-context-private.h cogl/cogl-context.c cogl/driver/gl/cogl-pipeline-fragend-glsl.c doc/reference/cogl-2.0-experimental/Makefile.am
* cogl-gles2-context: Append wrapper shader to user shadersDaniel Stone2012-09-171-4/+0
| | | | | | | | | | | | | | | | | The SGX GLSL compiler refuses to accept shaders of the form: void foo(); void bar() { foo(); } where foo is undefined at glShaderSource() time, left for definition at link time. To work around this, simply append the wrapper shader to user shaders, rather than building a separate shader that's always linked with user shaders. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 96f02c445f763ace088be71dc32b3374b2cdbab2)
* cogl-gles2-context: Keep track of extra data per texture objectNeil Roberts2012-08-151-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds a hash table mapping texture object IDs to a struct so that we can keep track of some of the state for each texture object. Currently it will just track the width and height of the texture 2D target. Additionally it will now try to delete any texture objects that have data created for them by the GLES2 context so that it won't leak them. It only tracks objects that get data set on them, not all objects that are bound because it is possible to use the GLES2 context with foreign textures via cogl_gles2_texture_get_handle() and we don't want to delete those. In order to keep track of the currently bound texture object it also needs to track the active texture unit. Note that this state tracking will probably go wrong if GL throws an error for invalid state. For example if glActiveTexture is called with an invalid texture unit then GL will ignore the binding but Cogl will assume it is valid and the state tracking will get out of sync. Perhaps it would be good if Cogl could detect the errors but this is difficult to do without consuming them. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit d8c72bb56cf3598fc57d629edc618f1bfa79f125)
* cogl-gles2-context: Flip the rendering when framebuffer is offscreenNeil Roberts2012-08-141-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cogl has a different origin for texture coordinates than OpenGL so that the results of rendering to a texture should leave the top of the image at the texture coordinate 0,0 rather than the bottom. When a GLES2 context is used to render to a Cogl texture via a CoglOffscreen we don't really want the application to have to be aware of the mismatch and flip the texture coordinates. To get that to work, this patch now tracks all of the programs that the application generates using the context and sneaks in an extra vertex shader with an alternative main function. This main function multiplies the final calculated gl_Position by a vector uniform which we can use to flip the image. When the application uploads the source code for a vertex shader we now replace any occurrences of the token 'main' with '_c31' and this renamed function gets called from the replacement main function. The token has a weird name so that it will be unlikely to conflict with a variable name in the application's source but it also needs to have the same number of characters as the original token so that it won't affect column numbers in the error reporting. We are also wrapping glGetShaderSource so that we can try to revert the token name. The same goes for the error logs just in case the error report mentions function names. Both places that cause drawing to occur (glDrawElements and glDrawArrays) are now also wrapped so that we can update the uniform value whenever the program is used with a different type of framebuffer from last time. We additionally need to manually track the state for the viewport, the stencil box and the front face because all of these will be affected by whether we are flipping the image or not. Any attempts to change these states will be queued and instead flushed at the last minute before drawing. There are still some known issues with this patch: • glCopyTexImage2D and glCopyTexSubImage2D will do the wrong thing when copying data from a CoglOffscreen. This could be quite fiddly to solve. • Point sprites won't flip correctly. To make this work we would need to flip the gl_PointSprite builtin variable somehow. This is done in the fragment shader not the vertex shader so flipping the calculated gl_Position doesn't help here. • The patch doesn't attempt to flip rendering to framebuffers for textures created within the GLES2 context. This probably makes sense because those textures are likely to be used within the GLES2 context in which case we want to leave the texture coordinates as they are. However, if the texture is shared back out to Cogl with cogl_gles2_texture_2d_new_from_handle then the texture will be upside-down. • The application can discover our secret uniform that we added via glGetActiveUniform. It might be worth trying to disguise this by wrapping that function although that could be quite fiddly. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit d589bf19e51f22c3241b2a18db10f22131ac126a)
* cogl-gles2-context: Keep some extra data for shaders and programsNeil Roberts2012-08-141-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | All of the functions that create and destroy shaders are now wrapped in the CoglGLES2Context so that we can track some extra data for them. There are hash tables mapping object IDs to the corresponding data. The data is currently not used for anything but will be in later patches. The glUseProgram, glAttachShader and glDetachShader functions additionally need to be wrapped because GL does not delete shader objects that are in use. Therefore we need to have a reference count on the data so we can recognise when the last use has been removed. The IDs are assumed to be specific to an individual CoglGLES2Context. This is technically not the case because all of the CoglGLES2Contexts are in the same share list. However we don't really want this to be the case so currently we will assume sharing the object IDs between contexts is undefined behaviour. Eventually we may want to actually enforce this. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 05dc1e34785ae5f5484cd398ecc5464bd8bd3dcd)
* cogl-gles2-context: Fix the default viewport and scissor sizeNeil Roberts2012-08-141-0/+5
| | | | | | | | | | | | | In GL, the default viewport and scissor should be set to the size of the first surface that the context is bound to. If a CoglGLES2Context is first used with an offscreen framebuffer then this surface will actually be the dummy 1x1 window which will mess up the defaults. To fix that, this patch makes it just always override the viewport and scissor the first time the context is bound to something. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 02567b3e6b64e6849b9f7c6aa2137401be7ece8d)
* Adds initial GLES2 integration supportRobert Bragg2012-08-061-0/+69
This makes it possible to integrate existing GLES2 code with applications using Cogl as the rendering api. Currently all GLES2 usage is handled with separate GLES2 contexts to ensure that GLES2 api usage doesn't interfere with Cogl's own use of OpenGL[ES]. The api has been designed though so we can provide tighter integration later. The api would allow us to support GLES2 virtualized on top of an OpenGL/GLX driver as well as GLES2 virtualized on the core rendering api of Cogl itself. Virtualizing the GLES2 support on Cogl will allow us to take advantage of Cogl debugging facilities as well as let us optimize the cost of allocating multiple GLES2 contexts and switching between them which can both be very expensive with many drivers. As as a side effect of this patch Cogl can also now be used as a portable window system binding API for GLES2 as an alternative to EGL. Parts of this patch are based on work done by Tomeu Vizoso <tomeu.vizoso@collabora.com> who did the first iteration of adding GLES2 API support to Cogl so that WebGL support could be added to webkit-clutter. This patch adds a very minimal cogl-gles2-context example that shows how to create a gles2 context, clear the screen to a random color and also draw a triangle with the cogl api. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 4bb6eff3dbd50d8fef7d6bdbed55c5aaa70036a8)