summaryrefslogtreecommitdiff
path: root/cogl/cogl-context.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove cogl-internal.hRobert Bragg2013-01-211-1/+1
| | | | | | | | | | | | This remove cogl-internal.h in favour of using cogl-private.h. Some things in cogl-internal.h were moved to driver/gl/cogl-util-gl-private.h and the _cogl_gl_error_to_string function whose prototype was moved from cogl-internal.h to cogl-util-gl-private.h has had its implementation moved from cogl.c to cogl-util-gl.c Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 01cc82ece091aa3bec4c07fdd6bc9e5135fca573)
* build: Hide cogl_pipeline_cache_{new,free}()Damien Lespiau2013-01-211-2/+2
| | | | | | | Those symbols should not be public and were exported as they started with cogl_. (cherry picked from commit 68a55f1dc70ea60fcccbe226029e585886feddc2)
* matrix-stack: make CoglMatrixStack publicRobert Bragg2013-01-211-6/+6
| | | | | | | | | | | | We have found several times now when writing code using Cogl that it would really help if Cogl's matrix stack api was public as a utility api. In Rig for example we want to avoid redundant arithmetic when deriving the matrices of entities used to render and we aren't able to simply use the framebuffer's matrix stack to achieve this. Also when implementing cairo-cogl we found that it would be really useful if we could have a matrix stack utility api. (cherry picked from commit d17a01fd935d88fab96fe6cc0b906c84026c0067)
* Adds back tex_coord array for CoglShader compatibilityRobert Bragg2013-01-211-0/+1
| | | | | | | | | This adds back compatibility for CoglShaders that reference the cogl_tex_coord_in[] or cogl_tex_coord_out[] varyings. Unlike the previous way this was done this patch maintains the use of layer numbers for attributes and maintains forwards compatibility by letting shaders alternatively access the per-layer tex_coord varyings via cogl_tex_coord%i_in/out defines that index into the array.
* clip-stack: workaround intel gen6 viewport clip bugRobert Bragg2013-01-201-0/+17
| | | | | | | | The Intel Mesa gen6 driver doesn't currently handle scissoring offset viewports correctly, so this implements a workaround to intersect the current viewport bounds with the scissor rectangle. (cherry picked from commit afc5daab85e5faca99d6d6866658cb82c3954830)
* Add a GL 3 driverNeil Roberts2013-01-201-53/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new CoglDriver for GL 3 called COGL_DRIVER_GL3. When requested, the GLX, EGL and SDL2 winsyss will set the necessary attributes to request a forward-compatible core profile 3.1 context. That means it will have no deprecated features. To simplify the explosion of checks for specific combinations of context->driver, many of these conditionals have now been replaced with private feature flags that are checked instead. The GL and GLES drivers now initialise these private feature flags depending on which driver is used. The fixed function backends now explicitly check whether the fixed function private feature is available which means the GL3 driver will fall back to always using the GLSL progend. Since Rob's latest patches the GLSL progend no longer uses any fixed function API anyway so it should just work. The driver is currently lower priority than COGL_DRIVER_GL so it will not be used unless it is specificly requested. We may want to change this priority at some point because apparently Mesa can make some memory savings if a core profile context is used. In GL 3, getting the combined extensions string with glGetString is deprecated so this patch changes it to use glGetStringi to build up an array of extensions instead. _cogl_context_get_gl_extensions now returns this array instead of trying to return a const string. The caller is expected to free the array. Some issues with this patch: • GL 3 does not support GL_ALPHA format textures. We should probably make this a feature flag or something. Cogl uses this to render text which currently just throws a GL error and breaks so it's pretty important to do something about this before considering the GL3 driver to be stable. • GL 3 doesn't support client side vertex buffers. This probably doesn't matter because CoglBuffer won't normally use malloc'd buffers if VBOs are available, but it might but worth making malloc'd buffers a private feature and forcing it not to use them. • GL 3 doesn't support the default vertex array object. This patch just makes it create and bind a single non-default vertex array object which gets used just like the normal default object. Ideally it would be good to use vertex array objects properly and attach them to a CoglPrimitive to cache the state. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 66c9db993595b3a22e63f4c201ea468bc9b88cb6)
* Adds a NOP driverRobert Bragg2013-01-201-5/+11
| | | | | | | | | | | | | | | | This adds a new "nop" driver that does nothing. This can be selected at runtime either with the COGL_DRIVER=nop environment variable or by passing COGL_DRIVER_NOP to cogl_renderer_set_driver() Adding the nop driver gives us a way to test workloads without any driver and hardware overheads which can help us understand how Cogl's state tracking performs in isolation. Having a nop driver can also serve as an shell/outline for creating other drivers later. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 90587418233b6438290741d80aedf193ae660cad)
* Adds CoglError apiRobert Bragg2013-01-201-8/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although we use GLib internally in Cogl we would rather not leak GLib api through Cogl's own api, except through explicitly namespaced cogl_glib_ / cogl_gtype_ feature apis. One of the benefits we see to not leaking GLib through Cogl's public API is that documentation for Cogl won't need to first introduce the Glib API to newcomers, thus hopefully lowering the barrier to learning Cogl. This patch provides a Cogl specific typedef for reporting runtime errors which by no coincidence matches the typedef for GError exactly. If Cogl is built with --enable-glib (default) then developers can even safely assume that a CoglError is a GError under the hood. This patch also enforces a consistent policy for when NULL is passed as an error argument and an error is thrown. In this case we log the error and abort the application, instead of silently ignoring it. In common cases where nothing has been implemented to handle a particular error and/or where applications are just printing the error and aborting themselves then this saves some typing. This also seems more consistent with language based exceptions which usually cause a program to abort if they are not explicitly caught (which passing a non-NULL error signifies in this case) Since this policy for NULL error pointers is stricter than the standard GError convention, there is a clear note in the documentation to warn developers that are used to using the GError api. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit b068d5ea09ab32c37e8c965fc8582c85d1b2db46) Note: Since we can't change the Cogl 1.x api the patch was changed to not rename _error_quark() functions to be _error_domain() functions and although it's a bit ugly, instead of providing our own CoglError type that's compatible with GError we simply #define CoglError to GError unless Cogl is built with glib disabled. Note: this patch does technically introduce an API break since it drops the cogl_error_get_type() symbol generated by glib-mkenum (Since the CoglError enum was replaced by a CoglSystemError enum) but for now we are assuming that this will not affect anyone currently using the Cogl API. If this does turn out to be a problem in practice then we would be able to fix this my manually copying an implementation of cogl_error_get_type() generated by glib-mkenum into a compatibility source file and we could also define the original COGL_ERROR_ enums for compatibility too. Note: another minor concern with cherry-picking this patch to the 1.14 branch is that an api scanner would be lead to believe that some APIs have changed, and for example the gobject-introspection parser which understands the semantics of GError will not understand the semantics of CoglError. We expect most people that have tried to use gobject-introspection with Cogl already understand though that it is not well suited to generating bindings of the Cogl api anyway and we aren't aware or anyone depending on such bindings for apis involving GErrors. (GnomeShell only makes very-very minimal use of Cogl via the gjs bindings for the cogl_rectangle and cogl_color apis.) The main reason we have cherry-picked this patch to the 1.14 branch even given the above concerns is that without it it would become very awkward for us to cherry-pick other beneficial patches from master.
* framebuffer: split GL code out from cogl-framebuffer.cRobert Bragg2013-01-181-29/+4
| | | | | | | | | | | | | | This splits out most of the OpenGL specific code from cogl-framebuffer.c into cogl-framebuffer-gl.c and extends the CoglDriverVtable interface for cogl-framebuffer.c to use. There are hopes to support several different backends for Cogl eventually to hopefully get us closer to the metal so this makes some progress in organizing which parts of Cogl are OpenGL specific so these parts can potentially be switched out later. The only remaining use of OpenGL still in cogl-framebuffer.c is to handle cogl_framebuffer_read_pixels.
* Avoid referencing file scope context in _context_new()Robert Bragg2012-09-171-20/+20
| | | | | | | | | | | | cogl_context_new() had a mixture of references to the file scope context variable (_context) and the local (context) variable. This renames the file scope variable to _cogl_context to catch unnecessary references to the old name and fixes the code accordingly to reference the local variable instead. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 33a9397ee1ae1729200be2e5084cf43cebb64289)
* Add conf vars to trick Cogl to think extensions are disabledNeil Roberts2012-08-061-0/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds two new configuration environment variables: COGL_DISABLE_GL_EXTENSIONS and COGL_OVERRIDE_GL_VERSION The variables can also be set in the cogl.conf file using the same names. The first one is a list of GL extension names separated by commas. When set Cogl will assume any extension listed here is not available by removing it from the string returned from glGetString(GL_EXTENSIONS). If the string is set in both the config file and the environment variable then the union of the two lists will be used. The second overrides the value returned from glGetString(GL_VERSION). If the string is set in both places the version from the environment variable will take priority. These are sometimes useful for debugging Cogl to test the various combinations of extensions. It could also be useful to work around driver bugs where an extension is badly supported and it would be better not to use it. The variables in cogl-config that just set a global char * variable have been put together in an array instead of having a separate blob of code for each one in order to make it simpler to add new variables. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit ec69c2dc576c78664e0b73879365cb7414ecf441)
* Adds initial GLES2 integration supportRobert Bragg2012-08-061-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* Workaround drisw bug where clipped redraws don't workRobert Bragg2012-08-061-2/+0
| | | | | | | | | | | | | | | | | | This detects when we are running on any of Mesa's software rasterizer backends and disables use of glBlitFramebuffer and glXCopySubBuffer. Both of these currently result in full-screen copies so there's little point in using these to optimize how much of the screen we present. To help ensure we re-evaluate this workaround periodically we have added a comment marker of "ONGOING BUG" above the workaround and added a note to our RELEASING document that says we should grep for this marker and write a NEWS section about ongoing bug workarounds. https://bugzilla.gnome.org/show_bug.cgi?id=674208 Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 11f2f6ebb42398978ec8dd92b3c332ae8140a728)
* Re-design the matrix stack using a graph of opsRobert Bragg2012-08-061-23/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This re-designs the matrix stack so we now keep track of each separate operation such as rotating, scaling, translating and multiplying as immutable, ref-counted nodes in a graph. Being a "graph" here means that different transformations composed of a sequence of linked operation nodes may share nodes. The first node in a matrix-stack is always a LOAD_IDENTITY operation. As an example consider if an application where to draw three rectangles A, B and C something like this: cogl_framebuffer_scale (fb, 2, 2, 2); cogl_framebuffer_push_matrix(fb); cogl_framebuffer_translate (fb, 10, 0, 0); cogl_framebuffer_push_matrix(fb); cogl_framebuffer_rotate (fb, 45, 0, 0, 1); cogl_framebuffer_draw_rectangle (...); /* A */ cogl_framebuffer_pop_matrix(fb); cogl_framebuffer_draw_rectangle (...); /* B */ cogl_framebuffer_pop_matrix(fb); cogl_framebuffer_push_matrix(fb); cogl_framebuffer_set_modelview_matrix (fb, &mv); cogl_framebuffer_draw_rectangle (...); /* C */ cogl_framebuffer_pop_matrix(fb); That would result in a graph of nodes like this: LOAD_IDENTITY | SCALE / \ SAVE LOAD | | TRANSLATE RECTANGLE(C) | \ SAVE RECTANGLE(B) | ROTATE | RECTANGLE(A) Each push adds a SAVE operation which serves as a marker to rewind too when a corresponding pop is issued and also each SAVE node may also store a cached matrix representing the composition of all its ancestor nodes. This means if we repeatedly need to resolve a real CoglMatrix for a given node then we don't need to repeat the composition. Some advantages of this design are: - A single pointer to any node in the graph can now represent a complete, immutable transformation that can be logged for example into a journal. Previously we were storing a full CoglMatrix in each journal entry which is 16 floats for the matrix itself as well as space for flags and another 16 floats for possibly storing a cache of the inverse. This means that we significantly reduce the size of the journal when drawing lots of primitives and we also avoid copying over 128 bytes per entry. - It becomes much cheaper to check for equality. In cases where some (unlikely) false negatives are allowed simply comparing the pointers of two matrix stack graph entries is enough. Previously we would use memcmp() to compare matrices. - It becomes easier to do comparisons of transformations. By looking for the common ancestry between nodes we can determine the operations that differentiate the transforms and use those to gain a high level understanding of the differences. For example we use this in the journal to be able to efficiently determine when two rectangle transforms only differ by some translation so that we can perform software clipping. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f75aee93f6b293ca7a7babbd8fcc326ee6bf7aef)
* Switch use of primitive glib types to c99 equivalentsRobert Bragg2012-08-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The coding style has for a long time said to avoid using redundant glib data types such as gint or gchar etc because we feel that they make the code look unnecessarily foreign to developers coming from outside of the Gnome developer community. Note: When we tried to find the historical rationale for the types we just found that they were apparently only added for consistent syntax highlighting which didn't seem that compelling. Up until now we have been continuing to use some of the platform specific type such as gint{8,16,32,64} and gsize but this patch switches us over to using the standard c99 equivalents instead so we can further ensure that our code looks familiar to the widest range of C developers who might potentially contribute to Cogl. So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this switches all Cogl code to instead use the int{8,16,32,64}_t and uint{8,16,32,64}_t c99 types instead. Instead of gsize we now use size_t For now we are not going to use the c99 _Bool type and instead we have introduced a new CoglBool type to use instead of gboolean. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
* Removes all remaining use of CoglHandleRobert Bragg2012-08-061-16/+14
| | | | | | | | | | | | | | | | | | | Removing CoglHandle has been an on going goal for quite a long time now and finally this patch removes the last remaining uses of the CoglHandle type and the cogl_handle_ apis. Since the big remaining users of CoglHandle were the cogl_program_ and cogl_shader_ apis which have replaced with the CoglSnippets api this patch removes both of these apis. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 6ed3aaf4be21d605a1ed3176b3ea825933f85cf0) Since the original patch was done after removing deprecated API this back ported patch doesn't affect deprecated API and so actually this cherry-pick doesn't remove all remaining use of CoglHandle as it did for the master branch of Cogl.
* fix cogl_context_new crash if fail to connect rendererRobert Bragg2012-04-111-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | If a NULL display is passed to cogl_context_new() then it has to implicitly create a CoglRenderer and CoglDisplay and propagate any resulting errors back to the user. Previously the implementation relied on passing a NULL renderer to cogl_display_new() as the means for implicitly connecting to a renderer. The problem with this though is that cogl_display_new() isn't designed to ever return NULL but if it failed to connect to a renderer automatically it would do and then cogl_context_new would pass NULL to cogl_display_setup() leading to a crash. This patch changes the implementation of cogl_context_new() to now explicitly create a CoglRenderer and connect to it if a NULL display is given. This way we can easily propagate any errors. In addition cogl_display_new has been changed to abort if it fails to implicitly connect to a renderer due to a NULL renderer argument. An application needing to gracefully handle problems connecting to a renderer at runtime should manually instantiate and connect a renderer passing a GError argument to cogl_renderer_connect. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* Add a mechanism for determining GPU driver detailsNeil Roberts2012-04-051-0/+3
| | | | | | | | | | | | | This adds a CoglGpuInfo struct to the CoglContext which contains some enums describing the GL driver in use. This currently includes the driver package (ie, is it Mesa) the version number of the package and the vendor of the GPU (ie, is it by Intel). There is also a bitmask which will contain the workarounds that we should do for that particular driver configuration. The struct is initialised on context creation by using a series of string comparisons on the strings returned from glGetString. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Use GL_ARB_sampler_objectsNeil Roberts2012-04-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GL_ARB_sampler_objects provides a GL object which overrides the sampler state part of a texture object with different values. The sampler state that Cogl currently exposes is the wrap modes and filters. Cogl exposes the state as part of the pipeline layer state but without this extension GL only exposes it as part of the texture object state. This means that it won't work to use a single texture multiple times in one primitive with different sampler states. It also makes switching between different sampler states with a single texture not terribly efficient because it has to change the texture object state every time. This patch adds a cache for sampler states in a shared hash table attached to the CoglContext. The entire set of parameters for the sampler state is used as the key for the hash table. When a unique state is encountered the sampler cache will create a new entry, otherwise it will return a const pointer to an existing entry. That means we can have a single pointer to represent any combination of sampler state. Pipeline layers now just store this single pointer rather than storing all of the sampler state. The two separate state flags for wrap modes and filters have now been combined into one. It should be faster to compare the sampler state now because instead of comparing each value it can just compare the pointers to the cached sampler entries. The hash table of cached sampler states should only need to perform its more expensive hash on the state when a property is changed on a pipeline, not every time it is flushed. When the sampler objects extension is available each cached sampler state will also get a sampler object to represent it. The common code to flush the GL state will now simply bind this object to a unit instead of flushing the state though the CoglTexture when possible. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Add constructors which take a CoglBitmap to all primitive texturesNeil Roberts2012-04-051-13/+12
| | | | | | | | | | | | | | | | | | | This adds public constructors which take a CoglBitmap to all primitive texture types. This constructor should be considered the canonical constructor for initializing the texture with data because it should be possible to wrap any type of data in a CoglBitmap. Having at least this single constructor avoids the need to have an explosion of constructors such as new_from_data, new_from_pixel_buffer and new_from_file etc. The already available internal bitmap constructor for CoglTexture2D has had its flags parameter removed under the assumption that flags do not make sense for primitive textures. The meta constructor cogl_texture_new_from_bitmap now just explicitly calls set_auto_mipmap after constructing the texture depending on the value of the COGL_TEXTURE_NO_AUTO_MIPMAP flag. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* bitmap: Store a pointer to the contextNeil Roberts2012-04-041-2/+1
| | | | | | | | | | | | This adds a context member to CoglBitmap which stores the context it was created with. That way it can be used in texture constructors which use a bitmap. There is also an internal private function to get the context out of the bitmap which all of the texture constructors now use. _cogl_texture_3d_new_from_bitmap has had its context parameter removed so that it more closely matches the other bitmap constructors. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Add a vtable for the driverNeil Roberts2012-03-231-18/+13
| | | | | | | | | | | | | | Cogl already had a vtable for the texture driver. This ended up being used for some things that are not strictly related to texturing such as converting between pixel formats and GL enums. Some other functions that are driver dependent such as updating the features were not indirected through a vtable but instead switched directly by looking at the ctx->driver enum value. This patch normalises to the two uses by adding a separate vtable for driver functions not related to texturing and moves the pixel format conversion functions to it from the texture driver vtable. It also adds a context parameter to all of the functions in the new driver vtable so that they won't have to rely on the global context.
* Add a public cogl_bitmap_new_for_dataNeil Roberts2012-03-141-7/+11
| | | | | | | | | | | | | | | | This creates a CoglBitmap which points into an existing buffer in system memory. That way it can be used to create a texture or to read pixel data into. The function replaces the existing internal function _cogl_bitmap_new_from_data but removes the destroy notify call back. If the application wants notification of destruction it can just use the cogl_object_set_user_data function as normal. Internally there is now a convenience function to create a bitmap for system memory and automatically free the buffer using that mechanism. The name of the function is inspired by cairo_image_surface_create_for_data which has similar semantics. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Remove the point size cache on the contextNeil Roberts2012-03-071-2/+0
| | | | | | | | | | | I don't think there's really any point in this cache because the pipeline code completely owns the point size state. Pipelines are already compared for whether their point size state is different before setting it so it shouldn't result in any extra calls to glPointSize apart from maybe when the first pipeline is initially flushed. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Adds a context arg to cogl_pipeline_new()Robert Bragg2012-02-211-4/+4
| | | | | | | | | As we move towards Cogl 2.0 we are aiming to remove the need for a default global CoglContext and so everything should be explicitly related to a context somehow. CoglPipelines are top level objects and so this patch adds a context argument to cogl_pipeline_new(). Reviewed-by: Neil Roberts <neil@linux.intel.com>
* texture-3d: remove _EXP defines + CoglHandle and pass contextRobert Bragg2012-02-211-2/+2
| | | | | | | | | | | | | | | | | We are in the process of removing all _EXP suffix mangling for experimental APIs (Ref: c6528c4b6c3c34) and adding missing gtk-doc comments so that we can instead rely on the "Stability: unstable" markers in the gtk-doc comments. This patch tackles the cogl-texture-3d api symbols. This patch also replaces use of CoglHandle with a CoglTexture3D type instead. Finally this patch also ensures the CoglTexture3D constructors take an explicit CoglContext pointer but not a CoglTextureFlags argument, consistent with other CoglTexture constructors. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* Remove all internal includes of cogl.hRobert Bragg2012-02-201-1/+0
| | | | | | | | | | | The cogl.h header is meant to be the public header for including the 1.x api used by Clutter so we should stop using that as a convenient way to include all likely prototypes and typedefs. Actually we already do a good job of listing the specific headers we depend on in each of the .c files we have so mostly this patch just strip out the redundant includes for cogl.h with a few fixups where that broke the build. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* Move all types/prototypes from cogl.h -> cogl[1]-context.hRobert Bragg2012-02-201-0/+1
| | | | | | | | | | | | So we can get to the point where cogl.h is merely an aggregation of header includes for the 1.x api this moves all the function prototypes and type definitions into a cogl-context.h and a new cogl1-context.h. Ideally no code internally should ever need to include cogl.h as it just represents the public facing header for accessing the 1.x api which should only be used by Clutter. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* cogl-pipeline-layer: Use CoglTextureType instead of GL target enumNeil Roberts2012-02-131-16/+34
| | | | | | | | | | | | | | | | | | | | | | | | | Instead of storing the GLenum for the target of the last used texture for a layer it now stores the CoglTextureType instead. The state name has been renamed to 'texture type' instead of 'texture target'. Previously the default pipeline layer would store 0 here to represent that there is no texture. This has been changed to store COGL_TEXTURE_TYPE_2D instead which means that all pipeline layers always have a valid value for the texture type. Any places that were previously fetching the texture from a layer to determine the target (for example when generating shaders or when enabling a particular texture target) now use the texture type instead. This means they will work even for layers that don't have a texture. This also changes it so that when binding a fallback texture instead of always using a 2D texture it will now use the default texture corresponding to the texture type of the layer. That way when the generated shader tries to do a texture lookup for that type of texture it will get a valid texture object. To make this work the patch adds a default texture for 3D textures to the context and also makes the default rectangle texture actually be a rectangle texture instead of using a 2D texture. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Flush matrices in the progend and flip with a vectorNeil Roberts2011-12-061-10/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously flushing the matrices was performed as part of the framebuffer state. When on GLES2 this matrix flushing is actually diverted so that it only keeps a reference to the intended matrix stack. This is necessary because on GLES2 there are no builtin uniforms so it can't actually flush the matrices until the program for the pipeline is generated. When the matrices are flushed it would store the age of modifications on the matrix stack so that it could detect when the matrix hasn't changed and avoid flushing it. This patch changes it so that the pipeline is responsible for flushing the matrices even when we are using the GL builtins. The same mechanism for detecting unmodified matrix stacks is used in all cases. There is a new CoglMatrixStackCache type which is used to store a reference to the intended matrix stack along with its last flushed age. There are now two of these attached to the CoglContext to track the flushed state for the global matrix builtins and also two for each glsl progend program state to track the flushed state for a program. The framebuffer matrix flush now just updates the intended matrix stacks without actually trying to flush. When a vertex snippet is attached to the pipeline, the GLSL vertend will now avoid using the projection matrix to flip the rendering. This is necessary because any vertex snippet may cause the projection matrix not to be used. Instead the flip is done as a forced final step by multiplying cogl_position_out by a vec4 uniform. This uniform is updated as part of the progend pre_paint depending on whether the framebuffer is offscreen or not. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* rework enabling of attributes, removing _cogl_enable()Robert Bragg2011-12-061-9/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes the limited caching of enabled attributes done by _cogl_enable() and replaces it with a more generalized set of bitmasks associated with the context that allow us to efficiently compare the set of attribute locations that are currently enabled vs the new locations that need enabling so we only have to inform OpenGL of the changes in which locations are enabled/disabled. This also adds a per-context hash table for mapping attribute names to global name-state structs which includes a unique name-index for any name as well as pre-validated information about builtin "cogl_" attribute names including whether the attribute is normalized and what texture unit a texture attribute corresponds too. The name-state hash table means that cogl_attribute_new() now only needs to validate names the first time they are seen. CoglAttributes now reference a name-state structure instead of just the attribute name, so now we can efficiently get the name-index for any attribute and we can use that to index into a per-glsl-program cache that maps name indices to real GL attribute locations so when we get asked to draw a set of attributes we can very quickly determine what GL attributes need to be setup and enabled. If we don't have a cached location though we can still quickly access the string name so we can query OpenGL. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* framebuffer: Optimize _cogl_framebuffer_flush_state()Robert Bragg2011-12-061-3/+4
| | | | | | | | | | | | | | | | | | | | Previously the cost of _cogl_framebuffer_state_flush() would always scale by the total amount of state tracked by CoglFramebuffer even in cases where we knew up-front that we only wanted to flush a subset of the state or in cases where we requested to flush the same framebuffer multiple times with no changes being made to the framebuffer. We now track a set of state changed flags with each framebuffer and track the current read/draw buffers as part of the CoglContext so that we can quickly bail out when asked to flush the same framebuffer multiple times with no changes. _cogl_framebuffer_flush_state() now takes a mask of the state that we want to flush and the implementation has been redesigned so that the cost of checking what needs to be flushed and flushing those changes now scales by how much state we actually plan to update. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* cogl-pipeline: Use a hash table for faster uniform name lookupNeil Roberts2011-11-161-3/+5
| | | | | | | | The uniform names are now stored in a GPtrArray instead of a linked list. There is also a hash table to speed up converting names to locations. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* cogl-pipeline: Add support for setting uniform valuesNeil Roberts2011-11-161-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the following new public experimental functions to set uniform values on a CoglPipeline: void cogl_pipeline_set_uniform_1f (CoglPipeline *pipeline, int uniform_location, float value); void cogl_pipeline_set_uniform_1i (CoglPipeline *pipeline, int uniform_location, int value); void cogl_pipeline_set_uniform_float (CoglPipeline *pipeline, int uniform_location, int n_components, int count, const float *value); void cogl_pipeline_set_uniform_int (CoglPipeline *pipeline, int uniform_location, int n_components, int count, const int *value); void cogl_pipeline_set_uniform_matrix (CoglPipeline *pipeline, int uniform_location, int dimensions, int count, gboolean transpose, const float *value); These are similar to the old functions used to set uniforms on a CoglProgram. To get a value to pass in as the uniform_location there is also: int cogl_pipeline_get_uniform_location (CoglPipeline *pipeline, const char *uniform_name); Conceptually the uniform locations are tied to the pipeline so that whenever setting a value for a new pipeline the application is expected to call this function. However in practice the uniform locations are global to the CoglContext. The names are stored in a linked list where the position in the list is the uniform location. The global indices are used so that each pipeline can store a mask of which uniforms it overrides. That way it is quicker to detect which uniforms are different from the last pipeline that used the same CoglProgramState so it can avoid flushing uniforms that haven't changed. Currently the values are not actually compared which means that it will only avoid flushing a uniform if there is a common ancestor that sets the value (or if the same pipeline is being flushed again - in which case the pipeline and its common ancestor are the same thing). The uniform values are stored in the big state of the pipeline as a sparse linked list. A bitmask stores which values have been overridden and only overridden values are stored in the linked list. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Don't take a reference to the last used onscreen framebufferNeil Roberts2011-11-141-6/+0
| | | | | | | | | | | | | | Cogl keeps a pointer to the last used onscreen framebuffer from the context to implement the deprecated cogl_set_draw_buffer function which can take COGL_WINDOW_BUFFER as the target to use the last onscreen buffer. Previously this would also take a reference to that pointer. However that was causing a circular reference between the framebuffer and the context which makes it impossible to clean up resources properly when onscreen buffers are used. This patch instead changes it to just store the pointer and then clear the pointer during _cogl_onscreen_free as a kind of cheap weak reference. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* cogl-context: Destroy texture units later onNeil Roberts2011-11-041-2/+2
| | | | | | | | | | This patch moves the call to _cogl_destroy_texture_units() from _cogl_context_free() to later on. When destroying a GL texture the texture units are checked. This would end up accessing invalid memory so we need to try to destroy the texture units only after everything that might be referencing a texture has been destroyed. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Start to reduce dependence on glibRobert Bragg2011-11-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | Since we've had several developers from admirable projects say they would like to use Cogl but would really prefer not to pull in gobject,gmodule and glib as extra dependencies we are investigating if we can get to the point where glib is only an optional dependency. Actually we feel like we only make minimal use of glib anyway, so it may well be quite straightforward to achieve this. This adds a --disable-glib configure option that can be used to disable features that depend on glib. Actually --disable-glib doesn't strictly disable glib at this point because it's more helpful if cogl continues to build as we make incremental progress towards this. The first use of glib that this patch tackles is the use of g_return_val_if_fail and g_return_if_fail which have been replaced with equivalent _COGL_RETURN_VAL_IF_FAIL and _COGL_RETURN_IF_FAIL macros. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* framebuffer: split out CoglOnscreen codeRobert Bragg2011-11-011-0/+1
| | | | | | | | | | This factors out the CoglOnscreen code from cogl-framebuffer.c so we now have cogl-onscreen.c, cogl-onscreen.h and cogl-onscreen-private.h. Notably some of the functions pulled out are currently namespaced as cogl_framebuffer but we know we are planning on renaming them to be in the cogl_onscreen namespace; such as cogl_framebuffer_swap_buffers(). Reviewed-by: Neil Roberts <neil@linux.intel.com>
* features: Support more than 32 features!Robert Bragg2011-11-011-7/+23
| | | | | | | | | | | | | | | | | | | | | | | | Currently features are represented as bits in a 32bit mask so we obviously can't have more than 32 features with that approach. The new approach is to use the COGL_FLAGS_ macros which lets us handle bitmasks without a size limit and we change the public api to accept individual feature enums instead of a mask. This way there is no limit on the number of features we can add to Cogl. Instead of using cogl_features_available() there is a new cogl_has_feature() function and for checking multiple features there is cogl_has_features() which takes a zero terminated vararg list of features. In addition to being able to check for individual features this also adds a way to query all the features currently available via cogl_foreach_feature() which will call a callback for each feature. Since the new functions take an explicit context pointer there is also no longer any ambiguity over when users can first start to query features. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* make COGL_FEATURE_VBOS a private featureRobert Bragg2011-11-011-1/+1
| | | | | | | | | | | | Cogl provides a consistent public interface regardless of whether the underlying GL driver supports VBOs so it doesn't make much sense to have this feature as part of the public api. We can't break the api by removing the enum but at least we no longer ever set the feature flag. We now have a replacement private feature flag COGL_PRIVATE_FEATURE_VBOS which cogl now checks for internally. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* make COGL_FEATURE_PBOS a private featureRobert Bragg2011-11-011-1/+1
| | | | | | | | | | | | Cogl provides a consistent public interface regardless of whether the underlying GL driver supports PBOs so it doesn't make much sense to have this feature as part of the public api. We can't break the api by removing the enum but at least we no longer ever set the feature flag. We now have a replacement private feature flag COGL_PRIVATE_FEATURE_PBOS which cogl now checks for internally. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* pipeline: optimize _compare_differences functionsRobert Bragg2011-09-211-5/+0
| | | | | | | | | | | | | | | | This optimizes the layer and pipeline _compare_differences functions so neither of them use the GArray api since building up the list of ancestors by appending to a shared GArray was showing quite high on profiles due to how frequently pipeline comparisons are made. Instead we now build up a transient, singly linked list by allocating GList nodes via alloca to build up the parallel lists of ancestors. This tweaked approach actually ends up being a bit more concise than before, we avoid the overhead of the GArray api and now avoid making any function calls while comparing (assuming the _get_parent() calls always inline), we avoiding needing to get the default cogl context. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* Add a strong CoglTexture type to replace CoglHandleRobert Bragg2011-09-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As part of the on going, incremental effort to purge the non type safe CoglHandle type from the Cogl API this patch tackles most of the CoglHandle uses relating to textures. We'd postponed making this change for quite a while because we wanted to have a clearer understanding of how we wanted to evolve the texture APIs towards Cogl 2.0 before exposing type safety here which would be difficult to change later since it would imply breaking APIs. The basic idea that we are steering towards now is that CoglTexture can be considered to be the most primitive interface we have for any object representing a texture. The texture interface would provide roughly these methods: cogl_texture_get_width cogl_texture_get_height cogl_texture_can_repeat cogl_texture_can_mipmap cogl_texture_generate_mipmap; cogl_texture_get_format cogl_texture_set_region cogl_texture_get_region Besides the texture interface we will then start to expose types corresponding to specific texture types: CoglTexture2D, CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and CoglTexturePixmapX11. We will then also expose an interface for the high-level texture types we have (such as CoglTexture2DSlice, CoglSubTexture and CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an additional interface that lets you iterate a virtual region of a meta texture and get mappings of primitive textures to sub-regions of that virtual region. Internally we already have this kind of abstraction for dealing with sliced texture, sub-textures and atlas textures in a consistent way, so this will just make that abstraction public. The aim here is to clarify that there is a difference between primitive textures (CoglTexture2D/3D) and some of the other high-level textures, and also enable developers to implement primitives that can support meta textures since they can only be used with the cogl_rectangle API currently. The thing that's not so clean-cut with this are the texture constructors we have currently; such as cogl_texture_new_from_file which no longer make sense when CoglTexture is considered to be an interface. These will basically just become convenient factory functions and it's just a bit unusual that they are within the cogl_texture namespace. It's worth noting here that all the texture type APIs will also have their own type specific constructors so these functions will only be used for the convenience of being able to create a texture without really wanting to know the details of what type of texture you need. Longer term for 2.0 we may come up with replacement names for these factory functions or the other thing we are considering is designing some asynchronous factory functions instead since it's so often detrimental to application performance to be blocked waiting for a texture to be uploaded to the GPU. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* Make backface culling be part of the legacy stateNeil Roberts2011-09-191-3/+1
| | | | | | | | | | | | | | | | | | | | This adds an internal function to set the backface culling state on a pipeline. This includes properties to set the culling mode (front, back or both) and also to set which face is considered the front (COGL_WINDING_CLOCKWISE or COGL_WINDING_COUNTER_CLOCKWISE). The actual front face flushed to GL depends on whether we are rendering to an offscreen buffer or not. This means that when changing between on- and off- screen framebuffers it now checks whether the last flushed pipeline has backface culling enabled and forces a reflush of the cull face state if so. The backface culling is now set on a pipeline as part of the legacy state. This is important because some code in Cogl assumes it can flush a temporary pipeline to revert to a known state, but previously this wouldn't disable backface culling so things such as flushing the clip stack could get confused. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* cogl-framebuffer: Force flushing the color mask when changing fbsNeil Roberts2011-09-191-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | When changing between two framebuffers that have different color masks it now forces the pipeline to flush the mask by setting current_pipeline_changes_since_flush. For this to work there needs to be a common bit of code that gets called when the framebuffers are changed that has access to both the old framebuffer and the new framebuffer. _cogl_set_framebuffers_real can't be used for this because when it is called from cogl_pop_framebuffer the stack entries have already changed so it can't know the old framebuffer. This patch adds a new function called notify_buffers_changed which should get called whenever the buffers are changed and it explicitly gets passed pointers to the old and new buffers. cogl_pop_framebuffer now calls this instead of trying to use _cogl_set_framebuffers_real to force a flush. This patch also fixes the ctx->window_buffer pointer. Previously this was implemented by searching in the framebuffer stack for an onscreen framebuffer whenever the current buffers are changed. However it does this after the stack has already changed so it won't usually find the right buffer. Reviewed-by: Robert Bragg <robert@linux.intel.com>
* context: Add an accessor to get display associated with the contextDamien Lespiau2011-09-051-0/+6
| | | | | | https://bugzilla.gnome.org/show_bug.cgi?id=657347 Reviewed-by: Robert Bragg <robert@linux.intel.com>
* pipeline: Remove unsused get_max_texture_image_units()Damien Lespiau2011-09-051-1/+0
| | | | | | | | | | | This function was not used in the opengl pipeline, probably because of the more precise get_max_activable_texture_units(). Remove it then. https://bugzilla.gnome.org/show_bug.cgi?id=657347 Reviewed-by: Robert Bragg <robert@linux.intel.com>
* Fixed uninitialized data (current_clip_stack_valid) in context creationKirk A. Baker2011-07-271-2/+2
| | | | Reviewed-By: Robert Bragg <robert@linux.intel.com>
* Adds ColorMask support to CoglRobert Bragg2011-07-191-0/+1
| | | | | | | | | | | | | This adds CoglPipeline and CoglFramebuffer support for setting a color mask which is a bit mask defining which color channels should be written to the current framebuffer. The final color mask is the intersection of the framebuffer color mask and the pipeline color mask. The framebuffer mask affects all rendering to the framebuffer while the pipeline masks can be used to affect individual primitives. Reviewed-by: Neil Roberts <neil@linux.intel.com>
* Combine _cogl_context_check_gl_version and update_features into oneNeil Roberts2011-07-181-23/+4
| | | | | | | | | | | | | | The _cogl_context_check_gl_version function is meant to be called once Cogl has a GL context so that it can check whether the context found is supported by Cogl. However, only the stub winsys was calling this and it was doing it before Cogl had a chance to retrieve the function pointer for glString so it would just crash. This patch combines the two functions into one so that _cogl_context_update_features returns a gboolean and a GError. Then it can just check the context itself. https://bugzilla.gnome.org/show_bug.cgi?id=654440 Reviewed-by: Robert Bragg <robert@linux.intel.com>