Merge lp:~amaranth/compiz-core/gles into lp:compiz-core/0.9.5

Proposed by Travis Watkins
Status: Superseded
Proposed branch: lp:~amaranth/compiz-core/gles
Merge into: lp:compiz-core/0.9.5
Diff against target: 6779 lines (+2760/-2251)
50 files modified
CMakeLists.txt (+13/-0)
cmake/CMakeLists.txt (+2/-0)
cmake/CompizCommon.cmake (+12/-0)
cmake/CompizPlugin.cmake (+14/-10)
cmake/FindOpenGLES2.cmake (+51/-0)
cmake/base.cmake (+3/-1)
cmake/plugin_extensions/CompizOpenGLFixups.cmake (+22/-0)
include/core/rect.h (+2/-0)
plugins/annotate/src/annotate.cpp (+133/-77)
plugins/clone/src/clone.cpp (+0/-5)
plugins/compiztoolbox/src/compiztoolbox.cpp (+14/-28)
plugins/copytex/src/copytex.cpp (+9/-0)
plugins/cube/src/cube.cpp (+0/-4)
plugins/decor/src/decor.cpp (+17/-15)
plugins/decor/src/decor.h (+1/-1)
plugins/imgsvg/src/imgsvg.cpp (+12/-9)
plugins/imgsvg/src/imgsvg.h (+2/-1)
plugins/obs/src/obs.cpp (+9/-8)
plugins/obs/src/obs.h (+1/-1)
plugins/opengl/CMakeLists.txt (+9/-4)
plugins/opengl/compiz-opengl.pc.in (+2/-2)
plugins/opengl/include/opengl/fragment.h (+0/-124)
plugins/opengl/include/opengl/matrix.h (+2/-0)
plugins/opengl/include/opengl/opengl.h (+126/-65)
plugins/opengl/include/opengl/program.h (+68/-0)
plugins/opengl/include/opengl/programcache.h (+51/-0)
plugins/opengl/include/opengl/texture.h (+4/-0)
plugins/opengl/include/opengl/vertexbuffer.h (+83/-0)
plugins/opengl/opengl.xml.in (+1/-1)
plugins/opengl/src/fragment.cpp (+0/-1145)
plugins/opengl/src/matrix.cpp (+54/-0)
plugins/opengl/src/paint.cpp (+291/-418)
plugins/opengl/src/privatefragment.h (+0/-54)
plugins/opengl/src/privates.h (+22/-10)
plugins/opengl/src/privatetexture.h (+32/-0)
plugins/opengl/src/privatevertexbuffer.h (+71/-0)
plugins/opengl/src/program.cpp (+225/-0)
plugins/opengl/src/programcache.cpp (+175/-0)
plugins/opengl/src/screen.cpp (+316/-27)
plugins/opengl/src/shaders.h (+130/-0)
plugins/opengl/src/texture.cpp (+126/-3)
plugins/opengl/src/vertexbuffer.cpp (+414/-0)
plugins/opengl/src/window.cpp (+29/-84)
plugins/resize/src/resize.cpp (+56/-37)
plugins/scale/src/scale.cpp (+12/-24)
plugins/screenshot/src/screenshot.cpp (+50/-25)
plugins/switcher/src/switcher.cpp (+41/-48)
plugins/zoom/src/zoom.cpp (+41/-19)
src/event.cpp (+11/-0)
src/plugin.cpp (+1/-1)
To merge this branch: bzr merge lp:~amaranth/compiz-core/gles
Reviewer Review Type Date Requested Status
Sam Spilsbury Pending
Review via email: mp+71084@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-23.

Description of the change

This branch contains the code to make compiz work on GLES. This includes several changes to the compiz API.

* GLVertexBuffer class added for managing vertices, normals, texture coordinates, and colors
* GLProgram class added for managing GLSL programs
* GLProgramCache class added for managing per-plugin GLSL programs efficiently, uses an LRU cache
  to avoid recompiling recently used GLSL programs all the time
* GLFragment class removed as fragment programs are no longer used (replaced with GLSL programs)
* GL_BLEND now always enabled when rendering as almost everything was enabling it anyway
* EGL context setup added
* EglTexture class added to use EGL_image extension instead of GLX_EXT_texture_from_pixmap for GLES

Things left to do for a complete port:

  * properly check for GLSL support on desktop, currently assumes if you have VBO support you
    have GLSL support
  * port blur, wobbly, rotate, cube, and water plugins
    * wobbly, cube, and rotate should be fairly straightforward, water and blur need updated to
      use GLSL instead of fragment programs

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :
Download full text (8.3 KiB)

1682 + int render (const GLMatrix &modelview,
1683 + const GLWindowPaintAttrib &attrib);
1684 +
1685 + int render (const GLMatrix &projection,
1686 + const GLMatrix &modelview,
1687 + const GLWindowPaintAttrib &attrib);

Probably for the sake of API confusion, it might be worth swapping the order of projection and modelview in this case, so you have

1685 + int render (const GLMatrix &modelview,
1686 + const GLMatrix &projection,
1687 + const GLWindowPaintAttrib &attrib);

--

1586 + GLProgram* operator () (std::list<GLShaderData*>);

Can that take a const std::list <GLShaderData *> & ?

1116 +#if !defined(GL_BGRA)
1117 + #if !defined(GL_BGRA_EXT)
1118 + #error GL_BGRA support is required
1119 + #else
1120 + #define GL_BGRA GL_BGRA_EXT
1121 + #endif
1122 +#endif

This can probably be detected in CMake by using try_compile () [1]

1703 - <default>true</default>
1704 + <default>false</default>

Does this need to be off by default?

1678 + void setProgram (GLProgram *program);
1679 +
1680 + int render (const GLMatrix &modelview);
1681 +
1682 + int render (const GLMatrix &modelview,
1683 + const GLWindowPaintAttrib &attrib);
1684 +
1685 + int render (const GLMatrix &projection,
1686 + const GLMatrix &modelview,
1687 + const GLWindowPaintAttrib &attrib);

The semantics of this are odd. Is GLVertexBuffer meant to be a stateful object which holds on to the state of what its rendering? In that case, it might be more appropriate to have a:

void setProjection ();
void setModelView ();
void setAttrib ();

However, on another though, perhaps all of these arguments are redundant. If glPushMatrix, glLoadMatrixf and glPopMatrix are all parts of the deprecated API, and PrivateGLVertexBuffer::render is really doing this:

+ GLfloat params[4] = {0, 0, 0, 0};
+ GLfloat attribs[3] = {1, 1, 1};
+ GLint index = 0;
+

+ program->setUniform ("projection", projection);
+ program->setUniform ("modelview", modelview);

+ //convert paint attribs to 0-1 range
+ attribs[0] = attrib.opacity / 65535.0f;
+ attribs[1] = attrib.brightness / 65535.0f;
+ attribs[2] = attrib.saturation / 65535.0f;
+ program->setUniform3f ("paintAttrib", attribs[0], attribs[1], attribs[2]);
+

Then it might make more sense to have helper objects in the OpenGL plugin to handle that so that you don't need to pass matrices or paint attributes to the GLVertexBuffer at render time and we don't need to continue to expand the ::render () function argument list should we add more things to the core profile.

The helper object might just server to build a GLProgram with that stuff built in so that it can be passed directly to GLVertexBuffer at render time. Just a thought.

+ #ifdef USE_GLES
+ Display *xdpy = screen->dpy ();
+
+ glFlush ();
+ if (mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK)
+ {
+ eglSwapBuffers (eglGetDisplay (xdpy), surface);
+ }
+ else
+ {
+ #warning use proper extension for this
+ eglSwapBuffers (eglGetDisplay (xdpy), surface);
+ }
+ eglW...

Read more...

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Is there a reason nothing has happened here since Aug/Sep 2011?

Unmerged revisions

2782. By Travis Watkins

merge in gles git branch

2781. By Ville Syrjala <email address hidden>

[PATCH] Don't unredirect overlay windows until we have set the new
bounding shape for the output window.

Unredirecting them before this time meant that they were stacked
underneath the overlay window and changing the bounding shape of
the output window would cause an expose event to be sent to
the overlay window causing a breif flicker as it redraws.

Unredirecting after this means that no expose event is sent because
the backing store is only set again after the bounding shape of the
output window has been changed

2780. By Sam Spilsbury

Merge trunk

2779. By Sam Spilsbury

Merge in doc for decor

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2011-07-29 15:08:52 +0000
+++ CMakeLists.txt 2011-08-10 17:09:44 +0000
@@ -103,6 +103,13 @@
103 DESTINATION ${COMPIZ_DESTDIR}${libdir}/pkgconfig103 DESTINATION ${COMPIZ_DESTDIR}${libdir}/pkgconfig
104)104)
105105
106# temporarily disable plugins that aren't ported yed
107set (COMPIZ_DISABLE_PLUGIN_BLUR ON)
108set (COMPIZ_DISABLE_PLUGIN_CUBE ON)
109set (COMPIZ_DISABLE_PLUGIN_ROTATE ON)
110set (COMPIZ_DISABLE_PLUGIN_WATER ON)
111set (COMPIZ_DISABLE_PLUGIN_WOBBLY ON)
112
106add_subdirectory (cmake)113add_subdirectory (cmake)
107add_subdirectory (include)114add_subdirectory (include)
108add_subdirectory (images)115add_subdirectory (images)
@@ -131,4 +138,10 @@
131138
132_check_compiz_cmake_macro (${CMAKE_MODULE_PATH_ORIG})139_check_compiz_cmake_macro (${CMAKE_MODULE_PATH_ORIG})
133140
141# temporarily disable plugins that aren't ported yed
142SET(COMPIZ_DISABLE_PLUGIN_BLUR "ON")
143SET(COMPIZ_DISABLE_PLUGIN_CUBE "ON")
144SET(COMPIZ_DISABLE_PLUGIN_ROTATE "ON")
145SET(COMPIZ_DISABLE_PLUGIN_WATER "ON")
146SET(COMPIZ_DISABLE_PLUGIN_WOBBLY "ON")
134147
135148
=== modified file 'cmake/CMakeLists.txt'
--- cmake/CMakeLists.txt 2011-07-27 16:13:28 +0000
+++ cmake/CMakeLists.txt 2011-08-10 17:09:44 +0000
@@ -15,6 +15,8 @@
15 plugin_extensions/CompizGenInstallData.cmake)15 plugin_extensions/CompizGenInstallData.cmake)
16list (APPEND _PluginExtensionFiles16list (APPEND _PluginExtensionFiles
17 plugin_extensions/CompizGenInstallImages.cmake)17 plugin_extensions/CompizGenInstallImages.cmake)
18list (APPEND _PluginExtensionFiles
19 plugin_extensions/CompizOpenGLFixups.cmake)
1820
19if (USE_GCONF)21if (USE_GCONF)
20 list (APPEND _files CompizGconf.cmake)22 list (APPEND _files CompizGconf.cmake)
2123
=== modified file 'cmake/CompizCommon.cmake'
--- cmake/CompizCommon.cmake 2011-07-27 16:13:28 +0000
+++ cmake/CompizCommon.cmake 2011-08-10 17:09:44 +0000
@@ -18,6 +18,7 @@
1818
19set (CMAKE_SKIP_RPATH FALSE)19set (CMAKE_SKIP_RPATH FALSE)
2020
21option (BUILD_GLES "Build against GLESv2 instead of GL" OFF)
21option (COMPIZ_BUILD_WITH_RPATH "Leave as ON unless building packages" ON)22option (COMPIZ_BUILD_WITH_RPATH "Leave as ON unless building packages" ON)
22option (COMPIZ_RUN_LDCONFIG "Leave OFF unless you need to run ldconfig after install")23option (COMPIZ_RUN_LDCONFIG "Leave OFF unless you need to run ldconfig after install")
23option (COMPIZ_PACKAGING_ENABLED "Enable to manually set prefix, exec_prefix, libdir, includedir, datadir" OFF)24option (COMPIZ_PACKAGING_ENABLED "Enable to manually set prefix, exec_prefix, libdir, includedir, datadir" OFF)
@@ -70,6 +71,17 @@
70 set(IS_BZR_REPO 0)71 set(IS_BZR_REPO 0)
71endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.bzr)72endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.bzr)
7273
74set (USE_GLES ${BUILD_GLES})
75
76if (USE_GLES)
77 find_package(OpenGLES2)
78
79 if (NOT OPENGLES2_FOUND)
80 set (USE_GLES 0)
81 message (SEND_ERROR "OpenGLESv2 not found")
82 endif (NOT OPENGLES2_FOUND)
83endif (USE_GLES)
84
73function (compiz_ensure_linkage)85function (compiz_ensure_linkage)
74 find_program (LDCONFIG_EXECUTABLE ldconfig)86 find_program (LDCONFIG_EXECUTABLE ldconfig)
75 mark_as_advanced (FORCE LDCONFIG_EXECUTABLE)87 mark_as_advanced (FORCE LDCONFIG_EXECUTABLE)
7688
=== modified file 'cmake/CompizPlugin.cmake'
--- cmake/CompizPlugin.cmake 2011-07-13 17:29:00 +0000
+++ cmake/CompizPlugin.cmake 2011-08-10 17:09:44 +0000
@@ -304,6 +304,16 @@
304 NO_DEFAULT_PATH304 NO_DEFAULT_PATH
305 )305 )
306306
307 set (COMPIZ_CURRENT_PLUGIN ${plugin})
308 set (COMPIZ_CURRENT_XML_FILE ${_translated_xml})
309
310 # find extension files
311 file (GLOB _extension_files "${COMPIZ_CMAKE_MODULE_PATH}/plugin_extensions/*.cmake")
312
313 foreach (_file ${_extension_files})
314 include (${_file})
315 endforeach ()
316
307 # generate pkgconfig file and install it and the plugin header file317 # generate pkgconfig file and install it and the plugin header file
308 if (_${plugin}_pkg AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin})318 if (_${plugin}_pkg AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin})
309 if ("${PLUGIN_BUILDTYPE}" STREQUAL "local")319 if ("${PLUGIN_BUILDTYPE}" STREQUAL "local")
@@ -316,11 +326,15 @@
316 set (VERSION 0.0.1-git)326 set (VERSION 0.0.1-git)
317 endif (NOT VERSION)327 endif (NOT VERSION)
318328
329 #add CFLAGSADD so pkg-config file has correct flags
330 set (COMPIZ_CFLAGS ${COMPIZ_CFLAGS} ${${_PLUGIN}_CFLAGSADD})
331
319 compiz_configure_file (332 compiz_configure_file (
320 ${_${plugin}_pkg}333 ${_${plugin}_pkg}
321 ${CMAKE_BINARY_DIR}/generated/compiz-${plugin}.pc334 ${CMAKE_BINARY_DIR}/generated/compiz-${plugin}.pc
322 COMPIZ_REQUIRES335 COMPIZ_REQUIRES
323 COMPIZ_CFLAGS336 COMPIZ_CFLAGS
337 PKGCONFIG_LIBS
324 )338 )
325339
326 install (340 install (
@@ -334,16 +348,6 @@
334 endif ()348 endif ()
335 endif ()349 endif ()
336350
337 set (COMPIZ_CURRENT_PLUGIN ${plugin})
338 set (COMPIZ_CURRENT_XML_FILE ${_translated_xml})
339
340 # find extension files
341 file (GLOB _extension_files "${COMPIZ_CMAKE_MODULE_PATH}/plugin_extensions/*.cmake")
342
343 foreach (_file ${_extension_files})
344 include (${_file})
345 endforeach ()
346
347 # find files for build351 # find files for build
348 file (GLOB _h_files "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")352 file (GLOB _h_files "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
349 file (GLOB _h_ins_files "${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin}/*.h")353 file (GLOB _h_ins_files "${CMAKE_CURRENT_SOURCE_DIR}/include/${plugin}/*.h")
350354
=== added file 'cmake/FindOpenGLES2.cmake'
--- cmake/FindOpenGLES2.cmake 1970-01-01 00:00:00 +0000
+++ cmake/FindOpenGLES2.cmake 2011-08-10 17:09:44 +0000
@@ -0,0 +1,51 @@
1# - Try to find OpenGLES
2# Once done this will define
3#
4# OPENGLES2_FOUND - system has OpenGLES
5# OPENGLES2_INCLUDE_DIR - the GLES include directory
6# OPENGLES2_LIBRARY - the GLES library
7# OPENGLES2_LIBRARIES - Link this to use OpenGLES
8#
9
10FIND_PATH(OPENGLES2_INCLUDE_DIR GLES2/gl2.h
11 /usr/openwin/share/include
12 /opt/graphics/OpenGL/include /usr/X11R6/include
13 /usr/include
14)
15
16FIND_LIBRARY(OPENGLES2_LIBRARY
17 NAMES GLESv2
18 PATHS /opt/graphics/OpenGL/lib
19 /usr/openwin/lib
20 /usr/shlib /usr/X11R6/lib
21 /usr/lib
22)
23
24FIND_LIBRARY(OPENGLES2_EGL_LIBRARY
25 NAMES EGL
26 PATHS /usr/shlib /usr/X11R6/lib
27 /usr/lib
28)
29
30# On Unix OpenGL most certainly always requires X11.
31# Feel free to tighten up these conditions if you don't
32# think this is always true.
33# It's not true on OSX.
34
35IF (OPENGLES2_LIBRARY)
36 IF(NOT X11_FOUND)
37 INCLUDE(FindX11)
38 ENDIF(NOT X11_FOUND)
39 IF (X11_FOUND)
40 IF (NOT APPLE)
41 SET (OPENGLES2_LIBRARIES ${X11_LIBRARIES})
42 ENDIF (NOT APPLE)
43 ENDIF (X11_FOUND)
44ENDIF(OPENGLES2_LIBRARY)
45
46SET( OPENGLES2_FOUND "NO" )
47IF(OPENGLES2_LIBRARY AND OPENGLES2_EGL_LIBRARY)
48 SET( OPENGLES2_LIBRARIES ${OPENGLES2_LIBRARY} ${OPENGLES2_EGL_LIBRARY} ${OPENGLES2_LIBRARIES})
49 SET( OPENGLES2_FOUND "YES" )
50ENDIF(OPENGLES2_LIBRARY AND OPENGLES2_EGL_LIBRARY)
51
052
=== modified file 'cmake/base.cmake'
--- cmake/base.cmake 2011-07-27 16:13:28 +0000
+++ cmake/base.cmake 2011-08-10 17:09:44 +0000
@@ -24,6 +24,7 @@
24 compiz_print_configure_header ("Compiz")24 compiz_print_configure_header ("Compiz")
25 compiz_color_message ("\n${_escape}[4mOptional features:${_escape}[0m\n")25 compiz_color_message ("\n${_escape}[4mOptional features:${_escape}[0m\n")
2626
27 compiz_print_result_message ("GLESv2" USE_GLES)
27 compiz_print_result_message ("gtk window decorator" USE_GTK)28 compiz_print_result_message ("gtk window decorator" USE_GTK)
28 compiz_print_result_message ("metacity theme support" USE_METACITY)29 compiz_print_result_message ("metacity theme support" USE_METACITY)
29 compiz_print_result_message ("gconf schemas" USE_GCONF)30 compiz_print_result_message ("gconf schemas" USE_GCONF)
@@ -46,7 +47,8 @@
46 endif ()47 endif ()
47 add_custom_target (findcompiz_install48 add_custom_target (findcompiz_install
48 ${CMAKE_COMMAND} -E make_directory ${COMPIZ_DESTDIR}${CMAKE_ROOT}/Modules &&49 ${CMAKE_COMMAND} -E make_directory ${COMPIZ_DESTDIR}${CMAKE_ROOT}/Modules &&
49 ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/FindCompiz.cmake ${COMPIZ_DESTDIR}${CMAKE_ROOT}/Modules50 ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/FindCompiz.cmake ${COMPIZ_DESTDIR}${CMAKE_ROOT}/Modules &&
51 ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/FindOpenGLES2.cmake ${COMPIZ_DESTDIR}${CMAKE_ROOT}/Modules
50 )52 )
51endfunction ()53endfunction ()
5254
5355
=== added file 'cmake/plugin_extensions/CompizOpenGLFixups.cmake'
--- cmake/plugin_extensions/CompizOpenGLFixups.cmake 1970-01-01 00:00:00 +0000
+++ cmake/plugin_extensions/CompizOpenGLFixups.cmake 2011-08-10 17:09:44 +0000
@@ -0,0 +1,22 @@
1
2# modify pkg-config libs for opengl based on if we found GLES or not
3if (${COMPIZ_CURRENT_PLUGIN} STREQUAL "opengl")
4 if (USE_GLES)
5 set (PKGCONFIG_LIBS "-lGLESv2 -lEGL")
6 else (USE_GLES)
7 set (PKGCONFIG_LIBS "-lGL")
8 endif (USE_GLES)
9endif (${COMPIZ_CURRENT_PLUGIN} STREQUAL "opengl")
10
11# if plugin is using opengl plugin check for GLES library and set correct define
12if (NOT "${${_PLUGIN}_PLUGINDEPS}" STREQUAL "")
13 string (REGEX MATCH "opengl" opengl_found ${${_PLUGIN}_PLUGINDEPS})
14
15 if (opengl_found STREQUAL "opengl")
16 if (USE_GLES)
17 set (${_PLUGIN}_CFLAGSADD ${${_PLUGIN}_CFLAGSADD} " -DUSE_GLES")
18 string (REPLACE ";" " " ${_PLUGIN}_CFLAGSADD ${${_PLUGIN}_CFLAGSADD})
19 endif (USE_GLES)
20 endif (opengl_found STREQUAL "opengl")
21endif (NOT "${${_PLUGIN}_PLUGINDEPS}" STREQUAL "")
22
023
=== modified file 'include/core/rect.h'
--- include/core/rect.h 2011-03-16 19:39:09 +0000
+++ include/core/rect.h 2011-08-10 17:09:44 +0000
@@ -26,6 +26,8 @@
26#ifndef _COMPRECT_H26#ifndef _COMPRECT_H
27#define _COMPRECT_H27#define _COMPRECT_H
2828
29#include <core/point.h>
30
29/**31/**
30 * A 2D rectangle, which is likely in screen space. It's data is32 * A 2D rectangle, which is likely in screen space. It's data is
31 * isolated and can only be mutated with set() methods.33 * isolated and can only be mutated with set() methods.
3234
=== modified file 'plugins/annotate/src/annotate.cpp'
--- plugins/annotate/src/annotate.cpp 2010-07-02 03:00:14 +0000
+++ plugins/annotate/src/annotate.cpp 2011-08-10 17:09:44 +0000
@@ -627,11 +627,14 @@
627627
628 if (status)628 if (status)
629 {629 {
630 GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
631 GLfloat vertexData[18];
632 GLfloat textureData[8];
630 CompRect rect;633 CompRect rect;
631 GLMatrix sTransform = transform;634 GLMatrix sTransform = transform;
632 int numRect;635 int numRect;
633 int pos = 0;636 int pos = 0;
634 float vectorX, vectorY, offset;637 float offset;
635 int angle;638 int angle;
636639
637 offset = optionGetStrokeWidth () / 2;640 offset = optionGetStrokeWidth () / 2;
@@ -639,12 +642,6 @@
639 /* This replaced prepareXCoords (s, output, -DEFAULT_Z_CAMERA) */642 /* This replaced prepareXCoords (s, output, -DEFAULT_Z_CAMERA) */
640 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);643 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
641644
642 glPushMatrix ();
643 glLoadMatrixf (sTransform.getMatrix ());
644
645 glDisableClientState (GL_TEXTURE_COORD_ARRAY);
646 glEnable (GL_BLEND);
647
648 if (content && !region.isEmpty ())645 if (content && !region.isEmpty ())
649 {646 {
650 foreach (GLTexture *tex, texture)647 foreach (GLTexture *tex, texture)
@@ -654,34 +651,48 @@
654651
655 tex->enable (GLTexture::Fast);652 tex->enable (GLTexture::Fast);
656653
657 glBegin (GL_QUADS);654 streamingBuffer->begin (GL_TRIANGLE_STRIP);
658655
659 while (numRect--)656 while (numRect--)
660 {657 {
661 glTexCoord2f (658 vertexData[0] = rect.at (pos).x1 ();
662 COMP_TEX_COORD_X (tex->matrix (), rect.at (pos).x1 ()),659 vertexData[1] = rect.at (pos).y1 ();
663 COMP_TEX_COORD_Y (tex->matrix (), rect.at (pos).y2 ()));660 vertexData[2] = 0.0f;
664 glVertex2i (rect.at (pos).x1 (), rect.at (pos).y2 ());661 vertexData[3] = rect.at (pos).x1 ();
665662 vertexData[4] = rect.at (pos).y2 ();
666 glTexCoord2f (663 vertexData[5] = 0.0f;
667 COMP_TEX_COORD_X (tex->matrix (), rect.at (pos).x2 ()),664 vertexData[6] = rect.at (pos).x2 ();
668 COMP_TEX_COORD_Y (tex->matrix (), rect.at (pos).y2 ()));665 vertexData[7] = rect.at (pos).y1 ();
669 glVertex2i (rect.at (pos).x2 (), rect.at (pos).y2 ());666 vertexData[8] = 0.0f;
670667 vertexData[9] = rect.at (pos).x2 ();
671 glTexCoord2f (668 vertexData[10] = rect.at (pos).y2 ();
672 COMP_TEX_COORD_X (tex->matrix (), rect.at (pos).x2 ()),669 vertexData[11] = 0.0f;
673 COMP_TEX_COORD_Y (tex->matrix (), rect.at (pos).y1 ()));670
674 glVertex2i (rect.at (pos).x2 (), rect.at (pos).y1 ());671 textureData[0] = COMP_TEX_COORD_X (tex->matrix (),
675672 rect.at (pos).x1 ());
676 glTexCoord2f (673 textureData[1] = COMP_TEX_COORD_Y (tex->matrix (),
677 COMP_TEX_COORD_X (tex->matrix (), rect.at (pos).x1 ()),674 rect.at (pos).y1 ());
678 COMP_TEX_COORD_Y (tex->matrix (), rect.at (pos).y1 ()));675 textureData[2] = COMP_TEX_COORD_X (tex->matrix (),
679 glVertex2i (rect.at (pos).x1 (), rect.at (pos).y1 ());676 rect.at (pos).x1 ());
680677 textureData[3] = COMP_TEX_COORD_Y (tex->matrix (),
678 rect.at (pos).y2 ());
679 textureData[4] = COMP_TEX_COORD_X (tex->matrix (),
680 rect.at (pos).x2 ());
681 textureData[5] = COMP_TEX_COORD_Y (tex->matrix (),
682 rect.at (pos).y1 ());
683 textureData[6] = COMP_TEX_COORD_X (tex->matrix (),
684 rect.at (pos).x2 ());
685 textureData[7] = COMP_TEX_COORD_Y (tex->matrix (),
686 rect.at (pos).y2 ());
687
688 streamingBuffer->addVertices (4, vertexData);
689 streamingBuffer->addTexCoords (0, 4, textureData);
681 pos++;690 pos++;
682 }691 }
683692
684 glEnd ();693 streamingBuffer->end ();
694 streamingBuffer->render (sTransform);
695
685 tex->disable ();696 tex->disable ();
686 }697 }
687 }698 }
@@ -689,85 +700,130 @@
689 switch (drawMode)700 switch (drawMode)
690 {701 {
691 case LineMode:702 case LineMode:
692 glColor4usv (optionGetStrokeColor ());
693 glLineWidth (optionGetStrokeWidth ());703 glLineWidth (optionGetStrokeWidth ());
694 glBegin (GL_LINES);704
695 glVertex2i (initialPointerX, initialPointerY);705 streamingBuffer->begin (GL_LINES);
696 glVertex2i (lineVector.x (), lineVector.y ());706
697 glEnd ();707 streamingBuffer->addColors (1, optionGetStrokeColor ());
708
709 vertexData[0] = initialPointerX;
710 vertexData[1] = initialPointerY;
711 vertexData[2] = 0.0f;
712 vertexData[3] = lineVector.x ();
713 vertexData[4] = lineVector.y ();
714 vertexData[5] = 0.0f;
715 streamingBuffer->addVertices (2, vertexData);
716
717 streamingBuffer->end ();
718 streamingBuffer->render (sTransform);
698 break;719 break;
699720
700 case RectangleMode:721 case RectangleMode:
722 vertexData[0] = rectangle.x1 ();
723 vertexData[1] = rectangle.y1 ();
724 vertexData[2] = 0.0f;
725 vertexData[3] = rectangle.x1 ();
726 vertexData[4] = rectangle.y2 ();
727 vertexData[5] = 0.0f;
728 vertexData[6] = rectangle.x2 ();
729 vertexData[7] = rectangle.y1 ();
730 vertexData[8] = 0.0f;
731 vertexData[9] = rectangle.x2 ();
732 vertexData[10] = rectangle.y2 ();
733 vertexData[11] = 0.0f;
734
701 /* fill rectangle */735 /* fill rectangle */
702 glColor4usv (optionGetFillColor ());736 streamingBuffer->begin (GL_TRIANGLE_STRIP);
703 glRecti (rectangle.x1 (), rectangle.y2 (),737
704 rectangle.x2 (), rectangle.y1 ());738 streamingBuffer->addColors (1, optionGetFillColor ());
739 streamingBuffer->addVertices (4, vertexData);
740
741 streamingBuffer->end ();
742 streamingBuffer->render (sTransform);
705743
706 /* draw rectangle outline */744 /* draw rectangle outline */
707 glColor4usv (optionGetStrokeColor ());745/* streamingBuffer->begin ();
708 glRecti (rectangle.x1 () - offset, rectangle.y2 (),746
709 rectangle.x1 () + offset, rectangle.y1 ());747 streamingBuffer->addColors (1, optionGetStrokeColor ());
748
749 vertexData[0] = rectangle.x1 () - offset;
750 vertexData[3] = rectangle.x1 () - offset;
751 streamingBuffer->addVertices (4, vertexData);
752
710 glRecti (rectangle.x2 () - offset, rectangle.y2 (),753 glRecti (rectangle.x2 () - offset, rectangle.y2 (),
711 rectangle.x2 () + offset, rectangle.y1 ());754 rectangle.x2 () + offset, rectangle.y1 ());
712 glRecti (rectangle.x1 () - offset, rectangle.y1 () + offset,755 glRecti (rectangle.x1 () - offset, rectangle.y1 () + offset,
713 rectangle.x2 () + offset, rectangle.y1 () - offset);756 rectangle.x2 () + offset, rectangle.y1 () - offset);
714 glRecti (rectangle.x1 () - offset, rectangle.y2 () + offset,757 glRecti (rectangle.x1 () - offset, rectangle.y2 () + offset,
715 rectangle.x2 () + offset, rectangle.y2 () - offset);758 rectangle.x2 () + offset, rectangle.y2 () - offset);*/
716 break;759 break;
717760
718 case EllipseMode:761 case EllipseMode:
719 /* fill ellipse */762 /* fill ellipse */
720 glColor4usv (optionGetFillColor ());763 streamingBuffer->begin (GL_TRIANGLE_FAN);
721764
722 glBegin (GL_TRIANGLE_FAN);765 streamingBuffer->addColors (1, optionGetFillColor ());
723 glVertex2d (ellipse.center.x (), ellipse.center.y ());766
767 vertexData[0] = ellipse.center.x ();
768 vertexData[1] = ellipse.center.y ();
769 vertexData[2] = 0.0f;
770 streamingBuffer->addVertices (1, vertexData);
771
724 for (angle = 0; angle <= 360; angle += 1)772 for (angle = 0; angle <= 360; angle += 1)
725 {773 {
726 vectorX = ellipse.center.x () +774 vertexData[0] = ellipse.center.x () +
727 (ellipse.radiusX * sinf (angle * DEG2RAD));775 (ellipse.radiusX * sinf (angle * DEG2RAD));
728 vectorY = ellipse.center.y () +776 vertexData[1] = ellipse.center.y () +
729 (ellipse.radiusY * cosf (angle * DEG2RAD));777 (ellipse.radiusY * cosf (angle * DEG2RAD));
730 glVertex2d (vectorX, vectorY);778 streamingBuffer->addVertices (1, vertexData);
731 }779 }
732 glVertex2d (ellipse.center.x (), ellipse.center.y () +780
733 ellipse.radiusY);781 vertexData[0] = ellipse.center.x ();
734 glEnd();782 vertexData[1] = ellipse.center.y () + ellipse.radiusY;
783 streamingBuffer->addVertices (1, vertexData);
784
785 streamingBuffer->end ();
786 streamingBuffer->render (sTransform);
735787
736 /* draw ellipse outline */788 /* draw ellipse outline */
737 glColor4usv (optionGetStrokeColor ());
738 glLineWidth (optionGetStrokeWidth ());789 glLineWidth (optionGetStrokeWidth ());
739790
740 glBegin (GL_TRIANGLE_STRIP);791 streamingBuffer->begin (GL_TRIANGLE_STRIP);
741 glVertex2d (ellipse.center.x (), ellipse.center.y () +792
742 ellipse.radiusY - offset);793 streamingBuffer->addColors (1, optionGetStrokeColor ());
794
795
796 vertexData[0] = ellipse.center.x ();
797 vertexData[1] = ellipse.center.y () + ellipse.radiusY - offset;
798 vertexData[2] = 0.0f;
799 streamingBuffer->addVertices (1, vertexData);
800
743 for (angle = 360; angle >= 0; angle -= 1)801 for (angle = 360; angle >= 0; angle -= 1)
744 {802 {
745 vectorX = ellipse.center.x () + ((ellipse.radiusX -803 vertexData[0] = ellipse.center.x () + ((ellipse.radiusX -
746 offset) * sinf (angle * DEG2RAD));804 offset) * sinf (angle * DEG2RAD));
747 vectorY = ellipse.center.y () + ((ellipse.radiusY -805 vertexData[1] = ellipse.center.y () + ((ellipse.radiusY -
748 offset) * cosf (angle * DEG2RAD));806 offset) * cosf (angle * DEG2RAD));
749 glVertex2d (vectorX, vectorY);807 vertexData[2] = 0.0f;
750 vectorX = ellipse.center.x () + ((ellipse.radiusX +808 vertexData[3] = ellipse.center.x () + ((ellipse.radiusX +
751 offset) * sinf (angle * DEG2RAD));809 offset) * sinf (angle * DEG2RAD));
752 vectorY = ellipse.center.y () + ((ellipse.radiusY +810 vertexData[4] = ellipse.center.y () + ((ellipse.radiusY +
753 offset) * cosf (angle * DEG2RAD));811 offset) * cosf (angle * DEG2RAD));
754 glVertex2d (vectorX, vectorY);812 vertexData[5] = 0.0f;
813 streamingBuffer->addVertices (2, vertexData);
755 }814 }
756 glVertex2d (ellipse.center.x (), ellipse.center.y () +815
757 ellipse.radiusY + offset);816 vertexData[0] = ellipse.center.x ();
758 glEnd();817 vertexData[1] = ellipse.center.y () + ellipse.radiusY + offset;
818 streamingBuffer->addVertices (1, vertexData);
819
820 streamingBuffer->end ();
821 streamingBuffer->render (sTransform);
759 break;822 break;
760823
761 default:824 default:
762 break;825 break;
763 }826 }
764
765 /* clean up */
766 glColor4usv (defaultColor);
767 glDisable (GL_BLEND);
768 glEnableClientState (GL_TEXTURE_COORD_ARRAY);
769
770 glPopMatrix ();
771 }827 }
772828
773 return status;829 return status;
774830
=== modified file 'plugins/clone/src/clone.cpp'
--- plugins/clone/src/clone.cpp 2010-02-04 17:16:02 +0000
+++ plugins/clone/src/clone.cpp 2011-08-10 17:09:44 +0000
@@ -295,9 +295,6 @@
295 0.0f);295 0.0f);
296 sTransform.scale (zoomX, zoomY, 1.0f);296 sTransform.scale (zoomX, zoomY, 1.0f);
297297
298 glPushMatrix ();
299 glLoadMatrixf (sTransform.getMatrix ());
300
301 filter = gScreen->textureFilter ();298 filter = gScreen->textureFilter ();
302299
303 if (offset == 0.0f)300 if (offset == 0.0f)
@@ -325,8 +322,6 @@
325 }322 }
326323
327 gScreen->setTextureFilter (filter);324 gScreen->setTextureFilter (filter);
328
329 glPopMatrix ();
330 }325 }
331326
332 return status;327 return status;
333328
=== modified file 'plugins/compiztoolbox/src/compiztoolbox.cpp'
--- plugins/compiztoolbox/src/compiztoolbox.cpp 2011-03-14 16:12:45 +0000
+++ plugins/compiztoolbox/src/compiztoolbox.cpp 2011-08-10 17:09:44 +0000
@@ -459,9 +459,7 @@
459 sAttrib.yTranslate = wy - g.y () +459 sAttrib.yTranslate = wy - g.y () +
460 window->border ().top * sAttrib.yScale;460 window->border ().top * sAttrib.yScale;
461461
462 GLFragment::Attrib fragment (sAttrib);462 if (window->alpha () || sAttrib.opacity != OPAQUE)
463
464 if (window->alpha () || fragment.getOpacity () != OPAQUE)
465 mask |= PAINT_WINDOW_TRANSLUCENT_MASK;463 mask |= PAINT_WINDOW_TRANSLUCENT_MASK;
466464
467 wTransform.translate (g.x (), g.y (), 0.0f);465 wTransform.translate (g.x (), g.y (), 0.0f);
@@ -470,9 +468,6 @@
470 sAttrib.yTranslate / sAttrib.yScale - g.y (),468 sAttrib.yTranslate / sAttrib.yScale - g.y (),
471 0.0f);469 0.0f);
472470
473 glPushMatrix ();
474 glLoadMatrixf (wTransform.getMatrix ());
475
476 filter = gScreen->textureFilter ();471 filter = gScreen->textureFilter ();
477472
478 if (baseScreen->getMipmap ())473 if (baseScreen->getMipmap ())
@@ -482,13 +477,11 @@
482 very ugly but necessary until the vertex stage has been made477 very ugly but necessary until the vertex stage has been made
483 fully pluggable. */478 fully pluggable. */
484 gWindow->glAddGeometrySetCurrentIndex (MAXSHORT);479 gWindow->glAddGeometrySetCurrentIndex (MAXSHORT);
485 gWindow->glDraw (wTransform, fragment, infiniteRegion, mask);480 gWindow->glDraw (wTransform, sAttrib, infiniteRegion, mask);
486 gWindow->glAddGeometrySetCurrentIndex (addWindowGeometryIndex);481 gWindow->glAddGeometrySetCurrentIndex (addWindowGeometryIndex);
487482
488 gScreen->setTextureFilter (filter);483 gScreen->setTextureFilter (filter);
489484
490 glPopMatrix ();
491
492 if (iconMode != HideIcon)485 if (iconMode != HideIcon)
493 {486 {
494 icon = gWindow->getIcon (MAX_ICON_SIZE, MAX_ICON_SIZE);487 icon = gWindow->getIcon (MAX_ICON_SIZE, MAX_ICON_SIZE);
@@ -529,30 +522,23 @@
529 sAttrib.xTranslate = wx - g.x ();522 sAttrib.xTranslate = wx - g.x ();
530 sAttrib.yTranslate = wy - g.y ();523 sAttrib.yTranslate = wy - g.y ();
531524
532 gWindow->geometry ().reset ();525 gWindow->vertexBuffer ()->begin ();
533526
534 gWindow->glAddGeometrySetCurrentIndex (MAXSHORT);527 gWindow->glAddGeometrySetCurrentIndex (MAXSHORT);
535 gWindow->glAddGeometry (matrix, iconReg, infiniteRegion);528 gWindow->glAddGeometry (matrix, iconReg, infiniteRegion);
536 gWindow->glAddGeometrySetCurrentIndex (addWindowGeometryIndex);529 gWindow->glAddGeometrySetCurrentIndex (addWindowGeometryIndex);
537530
538 if (gWindow->geometry ().vCount)531 gWindow->vertexBuffer ()->end ();
539 {532
540 GLFragment::Attrib fragment (sAttrib);533 GLMatrix wTransform (transform);
541 GLMatrix wTransform (transform);534
542535 wTransform.translate (g.x (), g.y (), 0.0f);
543 wTransform.translate (g.x (), g.y (), 0.0f);536 wTransform.scale (sAttrib.xScale, sAttrib.yScale, 1.0f);
544 wTransform.scale (sAttrib.xScale, sAttrib.yScale, 1.0f);537 wTransform.translate (sAttrib.xTranslate / sAttrib.xScale - g.x (),
545 wTransform.translate (sAttrib.xTranslate / sAttrib.xScale - g.x (),538 sAttrib.yTranslate / sAttrib.yScale - g.y (),
546 sAttrib.yTranslate / sAttrib.yScale - g.y (),539 0.0f);
547 0.0f);540
548541 gWindow->glDrawTexture (icon, wTransform, sAttrib, mask);
549 glPushMatrix ();
550 glLoadMatrixf (wTransform.getMatrix ());
551
552 gWindow->glDrawTexture (icon, fragment, mask);
553
554 glPopMatrix ();
555 }
556 }542 }
557}543}
558544
559545
=== modified file 'plugins/copytex/src/copytex.cpp'
--- plugins/copytex/src/copytex.cpp 2011-06-01 03:33:04 +0000
+++ plugins/copytex/src/copytex.cpp 2011-08-10 17:09:44 +0000
@@ -112,6 +112,14 @@
112 GLenum target;112 GLenum target;
113 GLTexture::Matrix matrix = _identity_matrix;113 GLTexture::Matrix matrix = _identity_matrix;
114114
115#ifdef USE_GLES
116 target = GL_TEXTURE_2D;
117 matrix.xx = 1.0f / dim.width ();
118 matrix.yy = 1.0f / dim.height ();
119 matrix.x0 = -dim.x () * matrix.xx;
120 matrix.y0 = -dim.y () * matrix.yy;
121#else
122
115 if (GL::textureNonPowerOfTwo ||123 if (GL::textureNonPowerOfTwo ||
116 (POWER_OF_TWO (dim.width ()) && POWER_OF_TWO (dim.height ())))124 (POWER_OF_TWO (dim.width ()) && POWER_OF_TWO (dim.height ())))
117 {125 {
@@ -129,6 +137,7 @@
129 matrix.x0 = -dim.x ();137 matrix.x0 = -dim.x ();
130 matrix.y0 = -dim.y ();138 matrix.y0 = -dim.y ();
131 }139 }
140#endif
132141
133 setData (target, matrix, false);142 setData (target, matrix, false);
134 setGeometry (dim.x1 (), dim.y1 (), dim.x2 () - dim.x1 (), dim.y2 () - dim.y1 ());143 setGeometry (dim.x1 (), dim.y1 (), dim.x2 () - dim.x1 (), dim.y2 () - dim.y1 ());
135144
=== modified file 'plugins/cube/src/cube.cpp'
--- plugins/cube/src/cube.cpp 2011-02-24 07:52:09 +0000
+++ plugins/cube/src/cube.cpp 2011-08-10 17:09:44 +0000
@@ -1123,7 +1123,6 @@
1123 if ((priv->mDesktopOpacity != OPAQUE) || (color[3] != OPAQUE))1123 if ((priv->mDesktopOpacity != OPAQUE) || (color[3] != OPAQUE))
1124 {1124 {
1125 priv->gScreen->setTexEnvMode (GL_MODULATE);1125 priv->gScreen->setTexEnvMode (GL_MODULATE);
1126 glEnable (GL_BLEND);
1127 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);1126 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1128 }1127 }
11291128
@@ -1149,7 +1148,6 @@
1149 glEnableClientState (GL_TEXTURE_COORD_ARRAY);1148 glEnableClientState (GL_TEXTURE_COORD_ARRAY);
11501149
1151 priv->gScreen->setTexEnvMode (GL_REPLACE);1150 priv->gScreen->setTexEnvMode (GL_REPLACE);
1152 glDisable (GL_BLEND);
1153 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);1151 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1154}1152}
11551153
@@ -1190,7 +1188,6 @@
1190 if ((priv->mDesktopOpacity != OPAQUE) || (color[3] != OPAQUE))1188 if ((priv->mDesktopOpacity != OPAQUE) || (color[3] != OPAQUE))
1191 {1189 {
1192 priv->gScreen->setTexEnvMode (GL_MODULATE);1190 priv->gScreen->setTexEnvMode (GL_MODULATE);
1193 glEnable (GL_BLEND);
1194 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);1191 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1195 }1192 }
11961193
@@ -1206,7 +1203,6 @@
1206 glEnableClientState (GL_TEXTURE_COORD_ARRAY);1203 glEnableClientState (GL_TEXTURE_COORD_ARRAY);
12071204
1208 priv->gScreen->setTexEnvMode (GL_REPLACE);1205 priv->gScreen->setTexEnvMode (GL_REPLACE);
1209 glDisable (GL_BLEND);
1210 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);1206 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1211}1207}
12121208
12131209
=== modified file 'plugins/decor/src/decor.cpp'
--- plugins/decor/src/decor.cpp 2011-06-18 06:54:05 +0000
+++ plugins/decor/src/decor.cpp 2011-08-10 17:09:44 +0000
@@ -236,10 +236,10 @@
236 */236 */
237237
238bool238bool
239DecorWindow::glDraw (const GLMatrix &transform,239DecorWindow::glDraw (const GLMatrix &transform,
240 GLFragment::Attrib &attrib,240 const GLWindowPaintAttrib &attrib,
241 const CompRegion &region,241 const CompRegion &region,
242 unsigned int mask)242 unsigned int mask)
243{243{
244 bool status;244 bool status;
245245
@@ -255,7 +255,7 @@
255 GLTexture::MatrixList ml (1);255 GLTexture::MatrixList ml (1);
256 mask |= PAINT_WINDOW_BLEND_MASK;256 mask |= PAINT_WINDOW_BLEND_MASK;
257257
258 gWindow->geometry ().reset ();258 gWindow->vertexBuffer ()->begin ();
259259
260 for (int i = 0; i < wd->nQuad; i++)260 for (int i = 0; i < wd->nQuad; i++)
261 {261 {
@@ -271,9 +271,10 @@
271 }271 }
272 }272 }
273273
274 if (gWindow->geometry ().vCount)274 gWindow->vertexBuffer ()->end ();
275 gWindow->glDrawTexture (wd->decor->texture->textures[0],275
276 attrib, mask);276 gWindow->glDrawTexture (wd->decor->texture->textures[0], transform,
277 attrib, mask);
277 }278 }
278 else if (wd && !reg.isEmpty () &&279 else if (wd && !reg.isEmpty () &&
279 wd->decor->type == WINDOW_DECORATION_TYPE_WINDOW)280 wd->decor->type == WINDOW_DECORATION_TYPE_WINDOW)
@@ -288,11 +289,12 @@
288 if (gWindow->textures ().size () == 1)289 if (gWindow->textures ().size () == 1)
289 {290 {
290 ml[0] = gWindow->matrices ()[0];291 ml[0] = gWindow->matrices ()[0];
291 gWindow->geometry ().reset ();292 gWindow->vertexBuffer ()->begin ();
292 gWindow->glAddGeometry (ml, window->frameRegion (), reg);293 gWindow->glAddGeometry (ml, window->frameRegion (), reg);
294 gWindow->vertexBuffer ()->end ();
293295
294 if (gWindow->geometry ().vCount)296 gWindow->glDrawTexture (gWindow->textures ()[0], transform,
295 gWindow->glDrawTexture (gWindow->textures ()[0], attrib, mask);297 attrib, mask);
296 }298 }
297 else299 else
298 {300 {
@@ -301,12 +303,12 @@
301 for (unsigned int i = 0; i < gWindow->textures ().size (); i++)303 for (unsigned int i = 0; i < gWindow->textures ().size (); i++)
302 {304 {
303 ml[0] = gWindow->matrices ()[i];305 ml[0] = gWindow->matrices ()[i];
304 gWindow->geometry ().reset ();306 gWindow->vertexBuffer ()->begin ();
305 gWindow->glAddGeometry (ml, regions[i], reg);307 gWindow->glAddGeometry (ml, regions[i], reg);
308 gWindow->vertexBuffer ()->end ();
306309
307 if (gWindow->geometry ().vCount)310 gWindow->glDrawTexture (gWindow->textures ()[i], transform,
308 gWindow->glDrawTexture (gWindow->textures ()[i], attrib,311 attrib, mask);
309 mask);
310 }312 }
311 }313 }
312 }314 }
313315
=== modified file 'plugins/decor/src/decor.h'
--- plugins/decor/src/decor.h 2011-05-08 13:44:52 +0000
+++ plugins/decor/src/decor.h 2011-08-10 17:09:44 +0000
@@ -203,7 +203,7 @@
203203
204 void computeShadowRegion ();204 void computeShadowRegion ();
205205
206 bool glDraw (const GLMatrix &, GLFragment::Attrib &,206 bool glDraw (const GLMatrix &, const GLWindowPaintAttrib &,
207 const CompRegion &, unsigned int);207 const CompRegion &, unsigned int);
208208
209 void windowNotify (CompWindowNotify n);209 void windowNotify (CompWindowNotify n);
210210
=== modified file 'plugins/imgsvg/src/imgsvg.cpp'
--- plugins/imgsvg/src/imgsvg.cpp 2010-02-04 17:16:02 +0000
+++ plugins/imgsvg/src/imgsvg.cpp 2011-08-10 17:09:44 +0000
@@ -218,12 +218,12 @@
218}218}
219219
220bool220bool
221SvgWindow::glDraw (const GLMatrix &transform,221SvgWindow::glDraw (const GLMatrix &transform,
222 GLFragment::Attrib &fragment,222 const GLWindowPaintAttrib &attrib,
223 const CompRegion &region,223 const CompRegion &region,
224 unsigned int mask)224 unsigned int mask)
225{225{
226 bool status = gWindow->glDraw (transform, fragment, region, mask);226 bool status = gWindow->glDraw (transform, attrib, region, mask);
227227
228 if (!status)228 if (!status)
229 return status;229 return status;
@@ -249,13 +249,15 @@
249 {249 {
250 matrix[0] = context->texture[0].matrices[i];250 matrix[0] = context->texture[0].matrices[i];
251251
252 gWindow->geometry ().reset ();252 gWindow->vertexBuffer ()->begin ();
253 gWindow->glAddGeometry (matrix, context->box, reg);253 gWindow->glAddGeometry (matrix, context->box, reg);
254 gWindow->vertexBuffer ()->end ();
254255
255 if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)256 if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)
256 mask |= PAINT_WINDOW_BLEND_MASK;257 mask |= PAINT_WINDOW_BLEND_MASK;
257258
258 gWindow->glDrawTexture (context->texture[0].textures[i], fragment, mask);259 gWindow->glDrawTexture (context->texture[0].textures[i], transform,
260 attrib, mask);
259261
260 if (rect.width () > 0 && rect.height () > 0)262 if (rect.width () > 0 && rect.height () > 0)
261 {263 {
@@ -319,11 +321,12 @@
319 saveFilter = gScreen->filter (SCREEN_TRANS_FILTER);321 saveFilter = gScreen->filter (SCREEN_TRANS_FILTER);
320 gScreen->setFilter (SCREEN_TRANS_FILTER, GLTexture::Good);322 gScreen->setFilter (SCREEN_TRANS_FILTER, GLTexture::Good);
321323
322 gWindow->geometry ().reset ();324 gWindow->vertexBuffer ()->begin ();
323 gWindow->glAddGeometry (matrix, r, reg);325 gWindow->glAddGeometry (matrix, r, reg);
326 gWindow->vertexBuffer ()->end ();
324327
325 gWindow->glDrawTexture (context->texture[1].textures[j],328 gWindow->glDrawTexture (context->texture[1].textures[j],
326 fragment, mask);329 transform, attrib, mask);
327330
328 gScreen->setFilter (SCREEN_TRANS_FILTER, saveFilter);331 gScreen->setFilter (SCREEN_TRANS_FILTER, saveFilter);
329 }332 }
330333
=== modified file 'plugins/imgsvg/src/imgsvg.h'
--- plugins/imgsvg/src/imgsvg.h 2009-03-15 17:58:48 +0000
+++ plugins/imgsvg/src/imgsvg.h 2011-08-10 17:09:44 +0000
@@ -76,7 +76,8 @@
76 SvgWindow (CompWindow *window);76 SvgWindow (CompWindow *window);
77 ~SvgWindow ();77 ~SvgWindow ();
7878
79 bool glDraw (const GLMatrix &transform, GLFragment::Attrib &fragment,79 bool glDraw (const GLMatrix &transform,
80 const GLWindowPaintAttrib &attrib,
80 const CompRegion &region, unsigned int mask);81 const CompRegion &region, unsigned int mask);
81 void moveNotify (int dx, int dy, bool immediate);82 void moveNotify (int dx, int dy, bool immediate);
82 void resizeNotify (int dx, int dy, int dwidth, int dheight);83 void resizeNotify (int dx, int dy, int dwidth, int dheight);
8384
=== modified file 'plugins/obs/src/obs.cpp'
--- plugins/obs/src/obs.cpp 2010-07-02 02:49:24 +0000
+++ plugins/obs/src/obs.cpp 2011-08-10 17:09:44 +0000
@@ -151,29 +151,30 @@
151 we wrap into glDrawWindow here */151 we wrap into glDrawWindow here */
152152
153bool153bool
154ObsWindow::glDraw (const GLMatrix& transform,154ObsWindow::glDraw (const GLMatrix &transform,
155 GLFragment::Attrib& attrib,155 const GLWindowPaintAttrib &attrib,
156 const CompRegion& region,156 const CompRegion &region,
157 unsigned int mask)157 unsigned int mask)
158{158{
159 GLWindowPaintAttrib wAttrib (attrib);
159 int factor;160 int factor;
160161
161 factor = customFactor[MODIFIER_OPACITY];162 factor = customFactor[MODIFIER_OPACITY];
162 if (factor != 100)163 if (factor != 100)
163 {164 {
164 attrib.setOpacity (factor * attrib.getOpacity () / 100);165 wAttrib.opacity = factor * wAttrib.opacity / 100;
165 mask |= PAINT_WINDOW_TRANSLUCENT_MASK;166 mask |= PAINT_WINDOW_TRANSLUCENT_MASK;
166 }167 }
167168
168 factor = customFactor[MODIFIER_BRIGHTNESS];169 factor = customFactor[MODIFIER_BRIGHTNESS];
169 if (factor != 100)170 if (factor != 100)
170 attrib.setBrightness (factor * attrib.getBrightness () / 100);171 wAttrib.brightness = factor * wAttrib.brightness / 100;
171172
172 factor = customFactor[MODIFIER_SATURATION];173 factor = customFactor[MODIFIER_SATURATION];
173 if (factor != 100)174 if (factor != 100)
174 attrib.setSaturation (factor * attrib.getSaturation () / 100);175 wAttrib.saturation = factor * wAttrib.saturation / 100;
175176
176 return gWindow->glDraw (transform, attrib, region, mask);177 return gWindow->glDraw (transform, wAttrib, region, mask);
177}178}
178179
179void180void
180181
=== modified file 'plugins/obs/src/obs.h'
--- plugins/obs/src/obs.h 2010-06-12 07:43:36 +0000
+++ plugins/obs/src/obs.h 2011-08-10 17:09:44 +0000
@@ -66,7 +66,7 @@
6666
67 bool glPaint (const GLWindowPaintAttrib &, const GLMatrix &,67 bool glPaint (const GLWindowPaintAttrib &, const GLMatrix &,
68 const CompRegion &, unsigned int);68 const CompRegion &, unsigned int);
69 bool glDraw (const GLMatrix &, GLFragment::Attrib &,69 bool glDraw (const GLMatrix &, const GLWindowPaintAttrib &,
70 const CompRegion &, unsigned int);70 const CompRegion &, unsigned int);
7171
72 void changePaintModifier (unsigned int, int);72 void changePaintModifier (unsigned int, int);
7373
=== modified file 'plugins/opengl/CMakeLists.txt'
--- plugins/opengl/CMakeLists.txt 2009-03-15 05:09:18 +0000
+++ plugins/opengl/CMakeLists.txt 2011-08-10 17:09:44 +0000
@@ -2,7 +2,12 @@
22
3include (CompizPlugin)3include (CompizPlugin)
44
5find_package (OpenGL)
6if (OPENGL_FOUND)
7 compiz_plugin(opengl PLUGINDEPS composite LIBRARIES ${OPENGL_gl_LIBRARY} INCDIRS ${OPENGL_INCLUDE_DIR})
8endif ()
9\ No newline at end of file5\ No newline at end of file
6if (USE_GLES)
7 compiz_plugin(opengl PLUGINDEPS composite CFLAGSADD -DUSE_GLES LIBRARIES ${OPENGLES2_LIBRARIES} INCDIRS ${OPENGLES2_INCLUDE_DIR})
8else (USE_GLES)
9 find_package (OpenGL)
10 if (OPENGL_FOUND)
11 compiz_plugin(opengl PLUGINDEPS composite LIBRARIES ${OPENGL_gl_LIBRARY} INCDIRS ${OPENGL_INCLUDE_DIR})
12 endif (OPENGL_FOUND)
13endif (USE_GLES)
14
1015
=== modified file 'plugins/opengl/compiz-opengl.pc.in'
--- plugins/opengl/compiz-opengl.pc.in 2009-03-15 05:09:18 +0000
+++ plugins/opengl/compiz-opengl.pc.in 2011-08-10 17:09:44 +0000
@@ -8,5 +8,5 @@
8Version: @VERSION@8Version: @VERSION@
99
10Requires: compiz compiz-composite10Requires: compiz compiz-composite
11Libs: -lGL -L${libdir} -lopengl
12Cflags: @COMPIZ_CFLAGS@ -I${includedir}/compiz
13\ No newline at end of file11\ No newline at end of file
12Libs: @PKGCONFIG_LIBS@ -L${libdir} -lopengl
13Cflags: @COMPIZ_CFLAGS@ -I${includedir}/compiz
1414
=== removed file 'plugins/opengl/include/opengl/fragment.h'
--- plugins/opengl/include/opengl/fragment.h 2010-04-03 16:24:05 +0000
+++ plugins/opengl/include/opengl/fragment.h 1970-01-01 00:00:00 +0000
@@ -1,124 +0,0 @@
1/*
2 * Copyright © 2008 Dennis Kasprzyk
3 * Copyright © 2007 Novell, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior permission.
12 * Dennis Kasprzyk makes no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without express or
14 * implied warranty.
15 *
16 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
22 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 *
24 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
25 * David Reveman <davidr@novell.com>
26 */
27
28#ifndef _GLFRAGMENT_H
29#define _GLFRAGMENT_H
30
31#define MAX_FRAGMENT_FUNCTIONS 16
32
33#define COMP_FETCH_TARGET_2D 0
34#define COMP_FETCH_TARGET_RECT 1
35#define COMP_FETCH_TARGET_NUM 2
36
37struct GLWindowPaintAttrib;
38class GLScreen;
39
40/**
41 * Describes a texture modification fragment program
42 * for a texture
43 */
44namespace GLFragment {
45
46 class Storage;
47
48 typedef unsigned int FunctionId;
49
50 class PrivateFunctionData;
51 class PrivateAttrib;
52
53 class FunctionData {
54 public:
55 FunctionData ();
56 ~FunctionData ();
57
58 /**
59 * Returns the status of this fragment program
60 * (valid or invalid)
61 */
62 bool status ();
63
64 void addTempHeaderOp (const char *name);
65
66 void addParamHeaderOp (const char *name);
67
68 void addAttribHeaderOp (const char *name);
69
70
71 void addFetchOp (const char *dst, const char *offset, int target);
72
73 void addColorOp (const char *dst, const char *src);
74
75 void addDataOp (const char *str, ...);
76
77 void addBlendOp (const char *str, ...);
78
79 FunctionId createFragmentFunction (const char *name);
80
81 private:
82 PrivateFunctionData *priv;
83 };
84
85 class Attrib {
86 public:
87 Attrib (const GLWindowPaintAttrib &paint);
88 Attrib (const Attrib&);
89 ~Attrib ();
90
91 Attrib &operator= (const Attrib &rhs);
92
93 unsigned int allocTextureUnits (unsigned int nTexture);
94
95 unsigned int allocParameters (unsigned int nParam);
96
97 void addFunction (FunctionId function);
98
99 bool enable (bool *blending);
100 void disable ();
101
102 unsigned short getSaturation ();
103 unsigned short getBrightness ();
104 unsigned short getOpacity ();
105
106 void setSaturation (unsigned short);
107 void setBrightness (unsigned short);
108 void setOpacity (unsigned short);
109
110 bool hasFunctions ();
111
112 private:
113 PrivateAttrib *priv;
114 };
115
116 void destroyFragmentFunction (FunctionId id);
117
118 FunctionId getSaturateFragmentFunction (GLTexture *texture,
119 int param);
120};
121
122
123
124#endif
1250
=== modified file 'plugins/opengl/include/opengl/matrix.h'
--- plugins/opengl/include/opengl/matrix.h 2009-03-15 05:09:18 +0000
+++ plugins/opengl/include/opengl/matrix.h 2011-08-10 17:09:44 +0000
@@ -44,6 +44,8 @@
44 void reset ();44 void reset ();
45 void toScreenSpace (const CompOutput *output, float z);45 void toScreenSpace (const CompOutput *output, float z);
4646
47 bool invert ();
48
47 void rotate (const float angle, const float x,49 void rotate (const float angle, const float x,
48 const float y, const float z);50 const float y, const float z);
49 void rotate (const float angle, const GLVector& vector);51 void rotate (const float angle, const GLVector& vector);
5052
=== modified file 'plugins/opengl/include/opengl/opengl.h'
--- plugins/opengl/include/opengl/opengl.h 2011-02-24 07:52:09 +0000
+++ plugins/opengl/include/opengl/opengl.h 2011-08-10 17:09:44 +0000
@@ -28,17 +28,35 @@
28#ifndef _COMPIZ_OPENGL_H28#ifndef _COMPIZ_OPENGL_H
29#define _COMPIZ_OPENGL_H29#define _COMPIZ_OPENGL_H
3030
31#ifdef USE_GLES
32#define SUPPORT_X11
33#include <GLES2/gl2.h>
34#include <GLES2/gl2ext.h>
35#include <EGL/egl.h>
36#include <EGL/eglext.h>
37#else
31#include <GL/gl.h>38#include <GL/gl.h>
32#include <GL/glx.h>39#include <GL/glx.h>
40#endif
3341
34#include <opengl/matrix.h>42#include <opengl/matrix.h>
35#include <opengl/texture.h>43#include <opengl/texture.h>
36#include <opengl/fragment.h>44#include <opengl/vertexbuffer.h>
45#include <opengl/program.h>
46#include <opengl/programcache.h>
3747
38#define COMPIZ_OPENGL_ABI 348#define COMPIZ_OPENGL_ABI 3
3949
40#include <core/pluginclasshandler.h>50#include <core/pluginclasshandler.h>
4151
52#if !defined(GL_BGRA)
53 #if !defined(GL_BGRA_EXT)
54 #error GL_BGRA support is required
55 #else
56 #define GL_BGRA GL_BGRA_EXT
57 #endif
58#endif
59
42/**60/**
43 * camera distance from screen, 0.5 * tan (FOV)61 * camera distance from screen, 0.5 * tan (FOV)
44 */62 */
@@ -75,8 +93,21 @@
75#endif93#endif
7694
77namespace GL {95namespace GL {
7896 #ifdef USE_GLES
97 typedef EGLImageKHR (*EGLCreateImageKHRProc) (EGLDisplay dpy,
98 EGLContext ctx,
99 EGLenum target,
100 EGLClientBuffer buffer,
101 const EGLint *attrib_list);
102 typedef EGLBoolean (*EGLDestroyImageKHRProc) (EGLDisplay dpy,
103 EGLImageKHR image);
104
105 typedef void (*GLEGLImageTargetTexture2DOESProc) (GLenum target,
106 GLeglImageOES image);
107
108 #else
79 typedef void (*FuncPtr) (void);109 typedef void (*FuncPtr) (void);
110
80 typedef FuncPtr (*GLXGetProcAddressProc) (const GLubyte *procName);111 typedef FuncPtr (*GLXGetProcAddressProc) (const GLubyte *procName);
81112
82 typedef void (*GLXBindTexImageProc) (Display *display,113 typedef void (*GLXBindTexImageProc) (Display *display,
@@ -121,10 +152,6 @@
121 typedef void (*GLXDestroyPixmapProc) (Display *display,152 typedef void (*GLXDestroyPixmapProc) (Display *display,
122 GLXPixmap pixmap);153 GLXPixmap pixmap);
123154
124 typedef void (*GLActiveTextureProc) (GLenum texture);
125 typedef void (*GLClientActiveTextureProc) (GLenum texture);
126 typedef void (*GLMultiTexCoord2fProc) (GLenum, GLfloat, GLfloat);
127
128 typedef void (*GLGenProgramsProc) (GLsizei n,155 typedef void (*GLGenProgramsProc) (GLsizei n,
129 GLuint *programs);156 GLuint *programs);
130 typedef void (*GLDeleteProgramsProc) (GLsizei n,157 typedef void (*GLDeleteProgramsProc) (GLsizei n,
@@ -144,11 +171,16 @@
144 typedef void (*GLGetProgramivProc) (GLenum target,171 typedef void (*GLGetProgramivProc) (GLenum target,
145 GLenum pname,172 GLenum pname,
146 int *params);173 int *params);
174 #endif
175
176 typedef void (*GLActiveTextureProc) (GLenum texture);
177 typedef void (*GLClientActiveTextureProc) (GLenum texture);
178 typedef void (*GLMultiTexCoord2fProc) (GLenum, GLfloat, GLfloat);
147179
148 typedef void (*GLGenFramebuffersProc) (GLsizei n,180 typedef void (*GLGenFramebuffersProc) (GLsizei n,
149 GLuint *framebuffers);181 GLuint *framebuffers);
150 typedef void (*GLDeleteFramebuffersProc) (GLsizei n,182 typedef void (*GLDeleteFramebuffersProc) (GLsizei n,
151 GLuint *framebuffers);183 const GLuint *framebuffers);
152 typedef void (*GLBindFramebufferProc) (GLenum target,184 typedef void (*GLBindFramebufferProc) (GLenum target,
153 GLuint framebuffer);185 GLuint framebuffer);
154 typedef GLenum (*GLCheckFramebufferStatusProc) (GLenum target);186 typedef GLenum (*GLCheckFramebufferStatusProc) (GLenum target);
@@ -159,6 +191,28 @@
159 GLint level);191 GLint level);
160 typedef void (*GLGenerateMipmapProc) (GLenum target);192 typedef void (*GLGenerateMipmapProc) (GLenum target);
161193
194 typedef void (*GLBindBufferProc) (GLenum target,
195 GLuint buffer);
196 typedef void (*GLDeleteBuffersProc) (GLsizei n,
197 const GLuint *buffers);
198 typedef void (*GLGenBuffersProc) (GLsizei n,
199 GLuint *buffers);
200 typedef void (*GLBufferDataProc) (GLenum target,
201 GLsizeiptr size,
202 const GLvoid *data,
203 GLenum usage);
204 typedef void (*GLBufferSubDataProc) (GLenum target,
205 GLintptr offset,
206 GLsizeiptr size,
207 const GLvoid *data);
208
209 #ifdef USE_GLES
210 extern EGLCreateImageKHRProc createImage;
211 extern EGLDestroyImageKHRProc destroyImage;
212
213 extern GLEGLImageTargetTexture2DOESProc eglImageTargetTexture;
214
215 #else
162 extern GLXBindTexImageProc bindTexImage;216 extern GLXBindTexImageProc bindTexImage;
163 extern GLXReleaseTexImageProc releaseTexImage;217 extern GLXReleaseTexImageProc releaseTexImage;
164 extern GLXQueryDrawableProc queryDrawable;218 extern GLXQueryDrawableProc queryDrawable;
@@ -170,10 +224,6 @@
170 extern GLXCreatePixmapProc createPixmap;224 extern GLXCreatePixmapProc createPixmap;
171 extern GLXDestroyPixmapProc destroyPixmap;225 extern GLXDestroyPixmapProc destroyPixmap;
172226
173 extern GLActiveTextureProc activeTexture;
174 extern GLClientActiveTextureProc clientActiveTexture;
175 extern GLMultiTexCoord2fProc multiTexCoord2f;
176
177 extern GLGenProgramsProc genPrograms;227 extern GLGenProgramsProc genPrograms;
178 extern GLDeleteProgramsProc deletePrograms;228 extern GLDeleteProgramsProc deletePrograms;
179 extern GLBindProgramProc bindProgram;229 extern GLBindProgramProc bindProgram;
@@ -181,6 +231,11 @@
181 extern GLProgramParameter4fProc programEnvParameter4f;231 extern GLProgramParameter4fProc programEnvParameter4f;
182 extern GLProgramParameter4fProc programLocalParameter4f;232 extern GLProgramParameter4fProc programLocalParameter4f;
183 extern GLGetProgramivProc getProgramiv;233 extern GLGetProgramivProc getProgramiv;
234 #endif
235
236 extern GLActiveTextureProc activeTexture;
237 extern GLClientActiveTextureProc clientActiveTexture;
238 extern GLMultiTexCoord2fProc multiTexCoord2f;
184239
185 extern GLGenFramebuffersProc genFramebuffers;240 extern GLGenFramebuffersProc genFramebuffers;
186 extern GLDeleteFramebuffersProc deleteFramebuffers;241 extern GLDeleteFramebuffersProc deleteFramebuffers;
@@ -189,6 +244,12 @@
189 extern GLFramebufferTexture2DProc framebufferTexture2D;244 extern GLFramebufferTexture2DProc framebufferTexture2D;
190 extern GLGenerateMipmapProc generateMipmap;245 extern GLGenerateMipmapProc generateMipmap;
191246
247 extern GLBindBufferProc bindBuffer;
248 extern GLDeleteBuffersProc deleteBuffers;
249 extern GLGenBuffersProc genBuffers;
250 extern GLBufferDataProc bufferData;
251 extern GLBufferSubDataProc bufferSubData;
252
192 extern bool textureFromPixmap;253 extern bool textureFromPixmap;
193 extern bool textureRectangle;254 extern bool textureRectangle;
194 extern bool textureNonPowerOfTwo;255 extern bool textureNonPowerOfTwo;
@@ -198,6 +259,7 @@
198 extern bool textureCompression;259 extern bool textureCompression;
199 extern GLint maxTextureSize;260 extern GLint maxTextureSize;
200 extern bool fbo;261 extern bool fbo;
262 extern bool vbo;
201 extern bool fragmentProgram;263 extern bool fragmentProgram;
202 extern GLint maxTextureUnits;264 extern GLint maxTextureUnits;
203265
@@ -217,6 +279,7 @@
217279
218#define MAX_DEPTH 32280#define MAX_DEPTH 32
219281
282#ifndef USE_GLES
220struct GLFBConfig {283struct GLFBConfig {
221 GLXFBConfig fbConfig;284 GLXFBConfig fbConfig;
222 int yInverted;285 int yInverted;
@@ -224,6 +287,14 @@
224 int textureFormat;287 int textureFormat;
225 int textureTargets;288 int textureTargets;
226};289};
290#endif
291
292struct GLShaderData
293{
294 std::string name;
295 std::string vertex_shader;
296 std::string fragment_shader;
297};
227298
228#define NOTHING_TRANS_FILTER 0299#define NOTHING_TRANS_FILTER 0
229#define SCREEN_TRANS_FILTER 1300#define SCREEN_TRANS_FILTER 1
@@ -299,6 +370,8 @@
299 CompOutput *);370 CompOutput *);
300 virtual void glDisableOutputClipping ();371 virtual void glDisableOutputClipping ();
301372
373 virtual GLMatrix *projectionMatrix ();
374
302};375};
303376
304377
@@ -329,7 +402,9 @@
329 /**402 /**
330 * Gets the libGL address of a particular openGL functor403 * Gets the libGL address of a particular openGL functor
331 */404 */
405 #ifndef USE_GLES
332 GL::FuncPtr getProcAddress (const char *name);406 GL::FuncPtr getProcAddress (const char *name);
407 #endif
333408
334 void updateBackground ();409 void updateBackground ();
335410
@@ -343,8 +418,6 @@
343 */418 */
344 void setFilter (int, GLTexture::Filter);419 void setFilter (int, GLTexture::Filter);
345420
346 GLFragment::Storage * fragmentStorage ();
347
348 /**421 /**
349 * Sets a new compiz-wid openGL texture environment mode422 * Sets a new compiz-wid openGL texture environment mode
350 */423 */
@@ -368,7 +441,19 @@
368 GLTexture::BindPixmapHandle registerBindPixmap (GLTexture::BindPixmapProc);441 GLTexture::BindPixmapHandle registerBindPixmap (GLTexture::BindPixmapProc);
369 void unregisterBindPixmap (GLTexture::BindPixmapHandle);442 void unregisterBindPixmap (GLTexture::BindPixmapHandle);
370443
444 #ifndef USE_GLES
371 GLFBConfig * glxPixmapFBConfig (unsigned int depth);445 GLFBConfig * glxPixmapFBConfig (unsigned int depth);
446 #endif
447
448
449 #ifdef USE_GLES
450 EGLContext getEGLContext ();
451 #endif
452
453 /**
454 * Returns a GLProgram from the cache or creates one and caches it
455 */
456 GLProgram *getProgram (std::list<GLShaderData*>);
372457
373 /**458 /**
374 * Returns a default icon texture459 * Returns a default icon texture
@@ -377,12 +462,6 @@
377462
378 void resetRasterPos ();463 void resetRasterPos ();
379464
380 /**
381 * Returns a 4x4 const float array which
382 * represents the current projection matrix
383 */
384 const float * projectionMatrix ();
385
386 WRAPABLE_HND (0, GLScreenInterface, bool, glPaintOutput,465 WRAPABLE_HND (0, GLScreenInterface, bool, glPaintOutput,
387 const GLScreenPaintAttrib &, const GLMatrix &,466 const GLScreenPaintAttrib &, const GLMatrix &,
388 const CompRegion &, CompOutput *, unsigned int);467 const CompRegion &, CompOutput *, unsigned int);
@@ -397,6 +476,8 @@
397 const GLMatrix &, const CompRegion &, CompOutput *);476 const GLMatrix &, const CompRegion &, CompOutput *);
398 WRAPABLE_HND (4, GLScreenInterface, void, glDisableOutputClipping);477 WRAPABLE_HND (4, GLScreenInterface, void, glDisableOutputClipping);
399478
479 WRAPABLE_HND (5, GLScreenInterface, GLMatrix *, projectionMatrix);
480
400 friend class GLTexture;481 friend class GLTexture;
401482
402 private:483 private:
@@ -448,10 +529,10 @@
448 * @param region Describes which region will be drawn529 * @param region Describes which region will be drawn
449 * @param mask Bitmask which describes how this window is drawn530 * @param mask Bitmask which describes how this window is drawn
450 */531 */
451 virtual bool glDraw (const GLMatrix &matrix,532 virtual bool glDraw (const GLMatrix &matrix,
452 GLFragment::Attrib &attrib,533 const GLWindowPaintAttrib &attrib,
453 const CompRegion &region,534 const CompRegion &region,
454 unsigned int mask);535 unsigned int mask);
455536
456 /**537 /**
457 * Hookable function to add points to a window538 * Hookable function to add points to a window
@@ -474,9 +555,8 @@
474 const CompRegion &clipRegion,555 const CompRegion &clipRegion,
475 unsigned int min = MAXSHORT,556 unsigned int min = MAXSHORT,
476 unsigned int max = MAXSHORT);557 unsigned int max = MAXSHORT);
477 virtual void glDrawTexture (GLTexture *texture, GLFragment::Attrib &,558 virtual void glDrawTexture (GLTexture *texture, const GLMatrix &,
478 unsigned int);559 const GLWindowPaintAttrib &, unsigned int);
479 virtual void glDrawGeometry ();
480};560};
481561
482class GLWindow :562class GLWindow :
@@ -485,40 +565,8 @@
485{565{
486 public:566 public:
487567
488 /**
489 * Class which describes the texture geometry and transformation points
490 * of a window
491 */
492 class Geometry {
493 public:
494 Geometry ();
495 ~Geometry ();
496
497 void reset ();
498
499 /**
500 * Set the number of vertices in the texture geometry
501 */
502 bool moreVertices (int newSize);
503
504 /**
505 * Set the number of indices in the texture geometry
506 */
507 bool moreIndices (int newSize);
508
509 public:
510 GLfloat *vertices;
511 int vertexSize;
512 int vertexStride;
513 GLushort *indices;
514 int indexSize;
515 int vCount;
516 int texUnits;
517 int texCoordSize;
518 int indexCount;
519 };
520
521 static GLWindowPaintAttrib defaultPaintAttrib;568 static GLWindowPaintAttrib defaultPaintAttrib;
569
522 public:570 public:
523571
524 GLWindow (CompWindow *w);572 GLWindow (CompWindow *w);
@@ -561,9 +609,20 @@
561 void updatePaintAttribs ();609 void updatePaintAttribs ();
562610
563 /**611 /**
564 * Returns the window texture geometry612 * Returns the window vertex buffer object
565 */613 */
566 Geometry & geometry ();614 GLVertexBuffer * vertexBuffer ();
615
616 /**
617 * Add a vertex and/or fragment shader function to the pipeline.
618 *
619 * @param name Name of the plugin adding the functions
620 * @param vertex_shader Function to add to the vertex shader
621 * @param fragment_shader Function to add to the fragment shader
622 */
623 void addShaders (std::string name,
624 std::string vertex_shader,
625 std::string fragment_shader);
567626
568 GLTexture *getIcon (int width, int height);627 GLTexture *getIcon (int width, int height);
569628
@@ -571,14 +630,15 @@
571 const GLWindowPaintAttrib &, const GLMatrix &,630 const GLWindowPaintAttrib &, const GLMatrix &,
572 const CompRegion &, unsigned int);631 const CompRegion &, unsigned int);
573 WRAPABLE_HND (1, GLWindowInterface, bool, glDraw, const GLMatrix &,632 WRAPABLE_HND (1, GLWindowInterface, bool, glDraw, const GLMatrix &,
574 GLFragment::Attrib &, const CompRegion &, unsigned int);633 const GLWindowPaintAttrib &, const CompRegion &,
634 unsigned int);
575 WRAPABLE_HND (2, GLWindowInterface, void, glAddGeometry,635 WRAPABLE_HND (2, GLWindowInterface, void, glAddGeometry,
576 const GLTexture::MatrixList &, const CompRegion &,636 const GLTexture::MatrixList &, const CompRegion &,
577 const CompRegion &,637 const CompRegion &,
578 unsigned int = MAXSHORT, unsigned int = MAXSHORT);638 unsigned int = MAXSHORT, unsigned int = MAXSHORT);
579 WRAPABLE_HND (3, GLWindowInterface, void, glDrawTexture,639 WRAPABLE_HND (3, GLWindowInterface, void, glDrawTexture,
580 GLTexture *texture, GLFragment::Attrib &, unsigned int);640 GLTexture *texture, const GLMatrix &,
581 WRAPABLE_HND (4, GLWindowInterface, void, glDrawGeometry);641 const GLWindowPaintAttrib &, unsigned int);
582642
583 friend class GLScreen;643 friend class GLScreen;
584 friend class PrivateGLScreen;644 friend class PrivateGLScreen;
@@ -588,3 +648,4 @@
588};648};
589649
590#endif650#endif
651
591652
=== added file 'plugins/opengl/include/opengl/program.h'
--- plugins/opengl/include/opengl/program.h 1970-01-01 00:00:00 +0000
+++ plugins/opengl/include/opengl/program.h 2011-08-10 17:09:44 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright © 2011 Linaro Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Linaro Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Linaro Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Travis Watkins <travis.watkins@linaro.org>
24 */
25
26#ifndef _COMPIZ_GLPROGRAM_H
27#define _COMPIZ_GLPROGRAM_H
28
29#ifdef USE_GLES
30#include <GLES2/gl2.h>
31#else
32#include <GL/gl.h>
33#endif
34
35#include <core/core.h>
36#include <opengl/matrix.h>
37
38class PrivateProgram;
39
40class GLProgram
41{
42 public:
43 GLProgram (CompString &vertexShader, CompString &fragmentShader);
44 ~GLProgram ();
45
46 bool valid ();
47 void bind ();
48 void unbind ();
49
50 bool setUniform (const char *name, GLfloat value);
51 bool setUniform (const char *name, GLint value);
52 bool setUniform (const char *name, const GLMatrix &value);
53 bool setUniform2f (const char *name, GLfloat x, GLfloat y);
54 bool setUniform3f (const char *name, GLfloat x, GLfloat y, GLfloat z);
55 bool setUniform4f (const char *name,
56 GLfloat x,
57 GLfloat y,
58 GLfloat z,
59 GLfloat w);
60
61 GLuint attributeLocation (const char *name);
62
63 private:
64 PrivateProgram *priv;
65};
66
67#endif // _COMPIZ_GLPROGRAM_H
68
069
=== added file 'plugins/opengl/include/opengl/programcache.h'
--- plugins/opengl/include/opengl/programcache.h 1970-01-01 00:00:00 +0000
+++ plugins/opengl/include/opengl/programcache.h 2011-08-10 17:09:44 +0000
@@ -0,0 +1,51 @@
1/*
2 * Copyright © 2011 Linaro Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Linaro Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Linaro Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Travis Watkins <travis.watkins@linaro.org>
24 */
25
26#ifndef _COMPIZ_GLPROGRAMCACHE_H
27#define _COMPIZ_GLPROGRAMCACHE_H
28
29#include <string>
30#include <list>
31#include <map>
32#include <boost/bind.hpp>
33#include <opengl/program.h>
34
35class PrivateProgramCache;
36struct GLShaderData;
37
38class GLProgramCache
39{
40 private:
41 PrivateProgramCache *priv;
42
43 public:
44 GLProgramCache (size_t);
45 ~GLProgramCache ();
46
47 GLProgram* operator () (std::list<GLShaderData*>);
48};
49
50#endif // _COMPIZ_GLPROGRAMCACHE_H
51
052
=== modified file 'plugins/opengl/include/opengl/texture.h'
--- plugins/opengl/include/opengl/texture.h 2011-02-24 07:52:09 +0000
+++ plugins/opengl/include/opengl/texture.h 2011-08-10 17:09:44 +0000
@@ -30,7 +30,11 @@
3030
31#include <X11/Xlib-xcb.h>31#include <X11/Xlib-xcb.h>
3232
33#ifdef USE_GLES
34#include <GLES2/gl2.h>
35#else
33#include <GL/gl.h>36#include <GL/gl.h>
37#endif
3438
35#include <vector>39#include <vector>
3640
3741
=== added file 'plugins/opengl/include/opengl/vertexbuffer.h'
--- plugins/opengl/include/opengl/vertexbuffer.h 1970-01-01 00:00:00 +0000
+++ plugins/opengl/include/opengl/vertexbuffer.h 2011-08-10 17:09:44 +0000
@@ -0,0 +1,83 @@
1/*
2 * Copyright © 2011 Linaro Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Linaro Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Linaro Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Travis Watkins <travis.watkins@linaro.org>
24 */
25
26#ifndef _COMPIZ_GLVERTEXBUFFER_H
27#define _COMPIZ_GLVERTEXBUFFER_H
28
29#ifdef USE_GLES
30#include <GLES2/gl2.h>
31#else
32#include <GL/gl.h>
33#endif
34
35#include <core/core.h>
36#include <opengl/program.h>
37
38class PrivateVertexBuffer;
39struct GLWindowPaintAttrib;
40
41class GLVertexBuffer
42{
43 public:
44 GLVertexBuffer ();
45 GLVertexBuffer (GLenum usage);
46 ~GLVertexBuffer ();
47
48 static GLVertexBuffer *streamingBuffer ();
49
50 void begin (GLenum primitiveType);
51 // default primitiveType is GL_TRIANGLE_STRIP
52 void begin ();
53 int end ();
54
55 // vertices and normals are 3 parts, count is number of xyz groups
56 void addVertices (GLuint nVertices, GLfloat *vertices);
57 void addNormals (GLuint nNormals, GLfloat *normals);
58
59 // color is always RGBA (4 parts), count is number of rgba groups
60 void addColors (GLuint nColors, GLushort *colors);
61
62 // texture is index, texcoords are 2 parts, count is number of pairs
63 void addTexCoords (GLuint texture,
64 GLuint nTexcoords,
65 GLfloat *texcoords);
66
67 void setProgram (GLProgram *program);
68
69 int render (const GLMatrix &modelview);
70
71 int render (const GLMatrix &modelview,
72 const GLWindowPaintAttrib &attrib);
73
74 int render (const GLMatrix &projection,
75 const GLMatrix &modelview,
76 const GLWindowPaintAttrib &attrib);
77
78 private:
79 PrivateVertexBuffer *priv;
80};
81
82#endif // _COMPIZ_GLVERTEXBUFFER_H
83
084
=== modified file 'plugins/opengl/opengl.xml.in'
--- plugins/opengl/opengl.xml.in 2010-02-03 03:24:09 +0000
+++ plugins/opengl/opengl.xml.in 2011-08-10 17:09:44 +0000
@@ -36,7 +36,7 @@
36 <option name="sync_to_vblank" type="bool">36 <option name="sync_to_vblank" type="bool">
37 <_short>Sync To VBlank</_short>37 <_short>Sync To VBlank</_short>
38 <_long>Only perform screen updates during vertical blanking period</_long>38 <_long>Only perform screen updates during vertical blanking period</_long>
39 <default>true</default>39 <default>false</default>
40 </option>40 </option>
41 <option name="texture_compression" type="bool">41 <option name="texture_compression" type="bool">
42 <_short>Texture Compression</_short>42 <_short>Texture Compression</_short>
4343
=== removed file 'plugins/opengl/src/fragment.cpp'
--- plugins/opengl/src/fragment.cpp 2010-10-26 03:29:56 +0000
+++ plugins/opengl/src/fragment.cpp 1970-01-01 00:00:00 +0000
@@ -1,1145 +0,0 @@
1/*
2 * Copyright © 2007 Novell, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Novell, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Novell, Inc. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Author: David Reveman <davidr@novell.com>
24 */
25
26#include <boost/function.hpp>
27#include <boost/bind.hpp>
28#include <boost/foreach.hpp>
29#define foreach BOOST_FOREACH
30
31#include <core/core.h>
32#include <opengl/texture.h>
33#include <opengl/fragment.h>
34#include "privatefragment.h"
35#include "privates.h"
36
37#include <string.h>
38#include <stdlib.h>
39#include <stdarg.h>
40
41#define COMP_FUNCTION_TYPE_ARB 0
42#define COMP_FUNCTION_TYPE_NUM 1
43
44#define COMP_FUNCTION_ARB_MASK (1 << 0)
45#define COMP_FUNCTION_MASK (COMP_FUNCTION_ARB_MASK)
46
47namespace GLFragment {
48
49 class Program {
50 public:
51 Program () :
52 signature (0),
53 blending (false),
54 name (0),
55 type (GL_FRAGMENT_PROGRAM_ARB)
56 {};
57 ~Program ()
58 {
59 if (name)
60 (*GL::deletePrograms) (1, &name);
61 };
62
63 public:
64 std::vector<FunctionId> signature;
65
66 bool blending;
67
68 GLuint name;
69 GLenum type;
70 };
71
72 typedef enum {
73 OpTypeData,
74 OpTypeDataStore,
75 OpTypeDataOffset,
76 OpTypeDataBlend,
77 OpTypeHeaderTemp,
78 OpTypeHeaderParam,
79 OpTypeHeaderAttrib,
80 OpTypeColor,
81 OpTypeFetch,
82 OpTypeLoad
83 } OpType;
84
85 class HeaderOp {
86 public:
87 HeaderOp () : type (OpTypeHeaderTemp), name ("") {};
88 public:
89 OpType type;
90 CompString name;
91 };
92
93 class BodyOp {
94 public:
95 BodyOp () :
96 type (OpTypeData),
97 data (""),
98 dst (""),
99 src (""),
100 target (0)
101 {
102 foreach (CompString &str, noOffset)
103 str = "";
104 foreach (CompString &str, offset)
105 str = "";
106 };
107
108 public:
109 OpType type;
110 CompString data;
111 CompString dst;
112 CompString src;
113 unsigned int target;
114 CompString noOffset[COMP_FETCH_TARGET_NUM];
115 CompString offset[COMP_FETCH_TARGET_NUM];
116
117 };
118
119 class PrivateFunctionData {
120 public:
121 PrivateFunctionData () : header (0), body (0), status (true) {};
122 PrivateFunctionData (const PrivateFunctionData&, CompString);
123
124 public:
125 std::vector<HeaderOp> header;
126 std::vector<BodyOp> body;
127 bool status;
128 };
129
130 class Function {
131 public:
132 Function ():
133 id (0),
134 name (""),
135 mask (0)
136 {};
137
138 public:
139 FunctionId id;
140 CompString name;
141 PrivateFunctionData data[COMP_FUNCTION_TYPE_NUM];
142 unsigned int mask;
143 };
144
145 class PrivateAttrib {
146 public:
147 PrivateAttrib () :
148 opacity (0xffff),
149 brightness (0xffff),
150 saturation (0xffff),
151 nTexture (0),
152 nFunction (0),
153 nParam (0)
154 {}
155
156 PrivateAttrib (const PrivateAttrib &pa) :
157 opacity (pa.opacity),
158 brightness (pa.brightness),
159 saturation (pa.saturation),
160 nTexture (pa.nTexture),
161 nFunction (pa.nFunction),
162 nParam (pa.nParam)
163 {
164 for (int i = 0; i < MAX_FRAGMENT_FUNCTIONS; i++)
165 function[i] = pa.function[i];
166 }
167
168 public:
169 GLushort opacity;
170 GLushort brightness;
171 GLushort saturation;
172 int nTexture;
173 FunctionId function[MAX_FRAGMENT_FUNCTIONS];
174 int nFunction;
175 int nParam;
176 };
177
178 typedef boost::function<void (BodyOp *, int)> DataOpCallBack;
179
180 class InitialLoadFunction : public Function {
181 public:
182 InitialLoadFunction ()
183 {
184 id = 0;
185 name = "__core_load";
186 mask = COMP_FUNCTION_MASK;
187
188 BodyOp b;
189 b.type = OpTypeLoad;
190 b.noOffset[0] = "TEX output, fragment.texcoord[0], texture[0], 2D;";
191 b.noOffset[1] = "TEX output, fragment.texcoord[0], texture[0], RECT;";
192 b.offset[0] = "TEX output, __tmp_texcoord0, texture[0], 2D;";
193 b.offset[1] = "TEX output, __tmp_texcoord0, texture[0], RECT;";
194 data[0].body.push_back (b);
195 };
196 };
197
198 static InitialLoadFunction initialLoadFunction;
199
200 static Function *
201 findFragmentFunction (GLScreen *s,
202 FunctionId id)
203 {
204 foreach (Function *f, s->fragmentStorage ()->functions)
205 if (f->id == id)
206 return f;
207 return NULL;
208 }
209
210 static Function *
211 findFragmentFunctionWithName (GLScreen *s,
212 CompString name)
213 {
214 foreach (Function *f, s->fragmentStorage ()->functions)
215 if (f->name.compare (name) == 0)
216 return f;
217 return NULL;
218 }
219
220 static Program *
221 findFragmentProgram (GLScreen *s,
222 FunctionId *signature,
223 unsigned int nSignature)
224 {
225 unsigned int i;
226
227 foreach (Program *p, s->fragmentStorage ()->programs)
228 {
229 if (p->signature.size () != nSignature)
230 continue;
231
232 for (i = 0; i < nSignature; i++)
233 if (signature[i] != p->signature[i])
234 break;
235
236 if (i == nSignature)
237 return p;
238 }
239 return NULL;
240 }
241
242 static unsigned int
243 functionMaskToType (int mask)
244 {
245 static struct {
246 unsigned int type;
247 unsigned int mask;
248 } maskToType[] = {
249 { COMP_FUNCTION_TYPE_ARB, COMP_FUNCTION_ARB_MASK }
250 };
251
252 unsigned int i;
253
254 for (i = 0; i < sizeof (maskToType) / sizeof (maskToType[0]); i++)
255 if (mask & maskToType[i].mask)
256 return maskToType[i].type;
257
258 return 0;
259 }
260
261 static void
262 forEachDataOpInFunction (std::vector<Function *> list,
263 int index,
264 int type,
265 int loadTarget,
266 CompString loadOffset,
267 bool *color,
268 bool *blend,
269 DataOpCallBack callBack)
270 {
271 Function *f = list[index];
272 BodyOp dataOp;
273 bool colorDone = false;
274 bool blendDone = false;
275
276 *color = false;
277 *blend = false;
278
279 foreach (BodyOp &bodyOp, f->data[type].body)
280 {
281 switch (bodyOp.type) {
282 case OpTypeFetch: {
283 CompString offset = loadOffset;
284
285 /* add offset */
286 if (bodyOp.data.size ())
287 {
288 if (loadOffset.size ())
289 {
290 dataOp.type = OpTypeDataOffset;
291 dataOp.data =
292 compPrintf ("ADD __tmp_texcoord%d, %s, %s;",
293 index, loadOffset.c_str (),
294 bodyOp.data.c_str ());
295
296 callBack (&dataOp, index);
297
298 offset = compPrintf ("__tmp_texcoord%d", index);
299 }
300 else
301 {
302 offset = bodyOp.data;
303 }
304 }
305
306 forEachDataOpInFunction (list, index - 1, type,
307 bodyOp.target,
308 offset, &colorDone, &blendDone,
309 callBack);
310
311 if (bodyOp.dst.compare ("output"))
312 {
313 dataOp.type = OpTypeDataStore;
314 dataOp.data =
315 compPrintf ("MOV %s, output;", bodyOp.dst.c_str ());
316
317 /* move to destination */
318 callBack (&dataOp, index);
319 }
320 } break;
321 case OpTypeLoad:
322 if (loadOffset.size ())
323 {
324 dataOp.type = OpTypeDataOffset;
325 dataOp.data =
326 compPrintf ("ADD __tmp_texcoord0, fragment.texcoord[0], %s;",
327 loadOffset.c_str ());
328
329 callBack (&dataOp, index);
330
331 dataOp.data = bodyOp.offset[loadTarget];
332 }
333 else
334 {
335 dataOp.data = bodyOp.noOffset[loadTarget];
336 }
337
338 dataOp.type = OpTypeData;
339
340 callBack (&dataOp, index);
341
342 break;
343 case OpTypeColor:
344 if (!colorDone)
345 {
346 dataOp.type = OpTypeData;
347 dataOp.data =
348 compPrintf ("MUL %s, fragment.color, %s;",
349 bodyOp.dst.c_str (),
350 bodyOp.src.c_str ());
351
352 callBack (&dataOp, index);
353 }
354 else if (bodyOp.dst.compare (bodyOp.src))
355 {
356 dataOp.type = OpTypeData;
357 dataOp.data =
358 compPrintf ("MOV %s, %s;",
359 bodyOp.dst.c_str (),
360 bodyOp.src.c_str ());
361
362 callBack (&dataOp, index);
363 }
364 *color = true;
365 break;
366 case OpTypeDataBlend:
367 *blend = true;
368 /* fall-through */
369 case OpTypeData:
370 callBack (&bodyOp, index);
371 break;
372 case OpTypeDataStore:
373 case OpTypeDataOffset:
374 case OpTypeHeaderTemp:
375 case OpTypeHeaderParam:
376 case OpTypeHeaderAttrib:
377 break;
378 }
379 }
380
381 if (colorDone)
382 *color = true;
383
384 if (blendDone)
385 *blend = true;
386 }
387
388 static int
389 forEachHeaderOpWithType (std::vector<HeaderOp> list,
390 int index,
391 OpType type,
392 CompString prefix,
393 CompString functionPrefix,
394 int count,
395 DataOpCallBack callBack)
396 {
397 BodyOp dataOp;
398
399 dataOp.type = OpTypeData;
400
401 foreach (HeaderOp &header, list)
402 {
403 if (header.type == type)
404 {
405 if (count)
406 {
407 dataOp.data = ", ";
408 }
409 else
410 {
411 dataOp.data = prefix;
412 }
413
414 dataOp.data += functionPrefix;
415 dataOp.data += "_";
416 dataOp.data += header.name;
417
418 callBack (&dataOp, index);
419
420 count++;
421 }
422 }
423
424 return count;
425 }
426
427 static bool
428 forEachDataOp (std::vector<Function *> list,
429 int type,
430 DataOpCallBack callBack)
431 {
432 BodyOp dataOp;
433 bool colorDone;
434 bool blendDone;
435 int count, nList = list.size ();
436
437 dataOp.type = OpTypeData;
438
439 count = 1;
440
441 dataOp.data = "TEMP output";
442
443 callBack (&dataOp, nList);
444
445 foreach (Function *f, list)
446 count = forEachHeaderOpWithType (f->data[type].header,
447 nList, OpTypeHeaderTemp,
448 "", f->name, count, callBack);
449
450 dataOp.data = ";";
451
452 callBack (&dataOp, nList);
453
454 count = 0;
455
456 foreach (Function *f, list)
457 count = forEachHeaderOpWithType (f->data[type].header,
458 nList, OpTypeHeaderParam,
459 "PARAM ", f->name, count,
460 callBack);
461
462 if (count)
463 {
464 dataOp.data = ";";
465
466 callBack (&dataOp, nList);
467 }
468
469 count = 0;
470
471 foreach (Function *f, list)
472 count = forEachHeaderOpWithType (f->data[type].header,
473 nList, OpTypeHeaderAttrib,
474 "ATTRIB ", f->name, count,
475 callBack);
476
477 if (count)
478 {
479 dataOp.data = ";";
480
481 callBack (&dataOp, nList);
482 }
483
484 forEachDataOpInFunction (list, nList - 1, type, 0, "",
485 &colorDone, &blendDone,
486 callBack);
487
488 if (colorDone)
489 dataOp.data = "MOV result.color, output;END";
490 else
491 dataOp.data = "MUL result.color, fragment.color, output;END";
492
493 callBack (&dataOp, nList);
494
495 return blendDone;
496 }
497
498 static void
499 addFetchOffsetVariables (BodyOp *op,
500 int index,
501 bool *indices,
502 CompString *data)
503 {
504 if (op->type == OpTypeDataOffset)
505 {
506 if (!indices[index])
507 {
508 data->append (compPrintf ("TEMP __tmp_texcoord%d;", index));
509 indices[index] = true;
510 }
511 }
512 }
513
514 static void
515 addData (BodyOp *op,
516 CompString *data)
517 {
518 data->append (op->data);
519 }
520
521 static Program *
522 buildFragmentProgram (GLScreen *s,
523 PrivateAttrib *attrib)
524 {
525 Program *program;
526 std::vector<Function *> functionList (1);
527 int mask = COMP_FUNCTION_MASK;
528 int type;
529 GLint errorPos;
530 GLenum errorType;
531 CompString fetchData;
532 bool indices[MAX_FRAGMENT_FUNCTIONS];
533 int i;
534
535 program = new Program ();
536 if (!program)
537 return NULL;
538
539 functionList[0] = &initialLoadFunction;
540
541 for (i = 0; i < attrib->nFunction; i++)
542 {
543 Function *f = findFragmentFunction (s, attrib->function[i]);
544
545 if (f)
546 functionList.push_back (f);
547 }
548
549 foreach (Function *f, functionList)
550 mask &= f->mask;
551
552 if (!mask)
553 {
554 compLogMessage ("opengl", CompLogLevelWarn,
555 "fragment functions can't be linked together "
556 "because a common type doesn't exist");
557 }
558
559 if (!mask || functionList.size () == 1)
560 {
561 delete program;
562 return NULL;
563 }
564
565 for (i = 0; i < attrib->nFunction; i++)
566 program->signature.push_back (attrib->function[i]);
567
568 type = functionMaskToType (mask);
569
570 fetchData = "!!ARBfp1.0";
571
572 foreach (bool &val, indices)
573 val = false;
574
575 forEachDataOp (functionList, type,
576 boost::bind (addFetchOffsetVariables, _1, _2, indices, &fetchData));
577
578 program->blending = forEachDataOp (functionList, type,
579 boost::bind (addData, _1, &fetchData));
580
581 program->type = GL_FRAGMENT_PROGRAM_ARB;
582
583 glGetError ();
584
585 (*GL::genPrograms) (1, &program->name);
586 (*GL::bindProgram) (GL_FRAGMENT_PROGRAM_ARB, program->name);
587 (*GL::programString) (GL_FRAGMENT_PROGRAM_ARB,
588 GL_PROGRAM_FORMAT_ASCII_ARB,
589 fetchData.size (), fetchData.c_str ());
590
591 glGetIntegerv (GL_PROGRAM_ERROR_POSITION_ARB, &errorPos);
592 errorType = glGetError ();
593 if (errorType != GL_NO_ERROR || errorPos != -1)
594 {
595 compLogMessage ("opengl", CompLogLevelError,
596 "failed to load fragment program");
597
598 (*GL::deletePrograms) (1, &program->name);
599
600 program->name = 0;
601 program->type = 0;
602 }
603
604 return program;
605 }
606
607 static GLuint
608 getFragmentProgram (GLScreen *s,
609 PrivateAttrib *attrib,
610 GLenum *type,
611 bool *blending)
612 {
613 Program *program;
614
615 if (!attrib->nFunction)
616 return 0;
617
618 program = findFragmentProgram (s, attrib->function, attrib->nFunction);
619 if (!program)
620 {
621 program = buildFragmentProgram (s, attrib);
622 if (program)
623 {
624 s->fragmentStorage ()->programs.push_back (program);
625 }
626 }
627
628 if (program)
629 {
630 *type = program->type;
631 *blending = program->blending;
632
633 return program->name;
634 }
635
636 return 0;
637 }
638
639
640 /* performs simple variable substitution */
641 static CompString
642 copyData (std::vector<HeaderOp> header,
643 const CompString prefix,
644 CompString data)
645 {
646 CompString inPrefix (prefix);
647 inPrefix += "_";
648
649 foreach (HeaderOp &h, header)
650 {
651 size_t pos = data.find (h.name);
652 while (pos != std::string::npos)
653 {
654 bool prependPrefix = false;
655 /* It is possible to match parts of words here, so
656 * make sure that we have found the next chunk in the
657 * string and not just a header which matches
658 * part of another word */
659 if (data.size () > pos + h.name.size ())
660 {
661 const CompString &token = data.substr (pos + h.name.size (), 1);
662 if (token == "," ||
663 token == "." ||
664 token == ";")
665 {
666 prependPrefix = true;
667 }
668 else
669 {
670 /* We matched part of another word as our
671 * token so search for the next whole
672 * header op */
673 pos = data.find (h.name, pos + 1);
674 }
675 }
676 else
677 {
678 /* If this is the last word in the string, then it must
679 * have matched exactly our header op, so it is ok
680 * to prepend a prefix here and go straight to
681 * std::string::npos */
682 prependPrefix = true;
683 }
684
685 if (prependPrefix)
686 {
687 /* prepend the header op prefix to the header op
688 * and seek past this word to the next instance
689 * of the unprepended header op */
690 data.insert (pos, inPrefix);
691 pos += inPrefix.size () + h.name.size ();
692 pos = data.find (h.name, pos);
693 }
694 }
695 }
696
697 return data;
698 }
699
700 PrivateFunctionData::PrivateFunctionData (const PrivateFunctionData& src,
701 CompString dstPrefix) :
702 header (src.header),
703 body (0),
704 status (src.status)
705 {
706
707 foreach (BodyOp b, src.body)
708 {
709 BodyOp dst;
710 dst.type = b.type;
711
712 switch (b.type) {
713 case OpTypeFetch:
714 dst.dst = copyData (header, dstPrefix, b.dst);
715 if (b.data.size ())
716 dst.data = copyData (header, dstPrefix, b.data);
717 else
718 dst.data = "";
719
720 dst.target = b.target;
721 break;
722 case OpTypeLoad:
723 case OpTypeHeaderTemp:
724 case OpTypeHeaderParam:
725 case OpTypeHeaderAttrib:
726 break;
727 case OpTypeData:
728 case OpTypeDataBlend:
729 case OpTypeDataStore:
730 case OpTypeDataOffset:
731 dst.data = copyData (header, dstPrefix, b.data);
732 break;
733 case OpTypeColor:
734 dst.dst = copyData (header, dstPrefix, b.dst);
735 dst.src = copyData (header, dstPrefix, b.src);
736 break;
737 }
738 body.push_back (dst);
739 }
740 }
741
742 static bool
743 addHeaderOpToFunctionData (PrivateFunctionData *data,
744 const char *name,
745 OpType type)
746 {
747 static const char *reserved[] = {
748 "output",
749 "__tmp_texcoord",
750 "fragment",
751 "program",
752 "result",
753 "state",
754 "texture"
755 };
756 HeaderOp header;
757 CompString n (name);
758
759 foreach (const char *word, reserved)
760 {
761 if (n.find (word) != std::string::npos)
762 {
763 compLogMessage ("opengl", CompLogLevelWarn,
764 "%s is a reserved word", word);
765 return false;
766 }
767 }
768
769
770 header.type = type;
771 header.name = n;
772 data->header.push_back (header);
773
774 return true;
775 }
776
777 FunctionData::FunctionData () :
778 priv (new PrivateFunctionData ())
779 {
780 }
781
782 FunctionData::~FunctionData ()
783 {
784 delete priv;
785 }
786
787 bool
788 FunctionData::status ()
789 {
790 return priv->status;
791 }
792
793 void
794 FunctionData::addTempHeaderOp (const char *name)
795 {
796 priv->status &=
797 addHeaderOpToFunctionData (priv, name, OpTypeHeaderTemp);
798 }
799
800 void
801 FunctionData::addParamHeaderOp (const char *name)
802 {
803 priv->status &=
804 addHeaderOpToFunctionData (priv, name, OpTypeHeaderParam);
805 }
806
807 void
808 FunctionData::addAttribHeaderOp (const char *name)
809 {
810 priv->status &=
811 addHeaderOpToFunctionData (priv, name, OpTypeHeaderAttrib);
812 }
813
814
815 void
816 FunctionData::addFetchOp (const char *dst, const char *offset, int target)
817 {
818 BodyOp b;
819
820 b.type = OpTypeFetch;
821 b.dst = CompString (dst);
822 b.target = target;
823
824 if (offset)
825 b.data = CompString (offset);
826 else
827 b.data = CompString ("");
828
829 priv->body.push_back (b);
830 }
831
832 void
833 FunctionData::addColorOp (const char *dst, const char *src)
834 {
835 BodyOp b;
836
837 b.type = OpTypeColor;
838 b.dst = CompString (dst);
839 b.src = CompString (src);
840
841 priv->body.push_back (b);
842 }
843
844 void
845 FunctionData::addDataOp (const char *str, ...)
846 {
847 BodyOp b;
848 va_list ap;
849
850 b.type = OpTypeData;
851 va_start (ap, str);
852 b.data = compPrintf (str, ap);
853 va_end (ap);
854
855 priv->body.push_back (b);
856 }
857
858 void
859 FunctionData::addBlendOp (const char *str, ...)
860 {
861 BodyOp b;
862 va_list ap;
863
864 b.type = OpTypeDataBlend;
865 va_start (ap, str);
866 b.data = compPrintf (str, ap);
867 va_end (ap);
868
869 priv->body.push_back (b);
870 }
871
872 FunctionId
873 FunctionData::createFragmentFunction (const char *name)
874 {
875 GLScreen *s = GLScreen::get (screen);
876 Function *function = new Function ();
877 CompString validName = name;
878 unsigned int i = 0;
879
880 while (findFragmentFunctionWithName (s, validName))
881 {
882 validName = compPrintf ("%s%d", name, i++);
883 }
884
885 function->data[COMP_FUNCTION_TYPE_ARB] =
886 PrivateFunctionData (*priv, validName);
887
888 function->name = validName;
889 function->mask = COMP_FUNCTION_ARB_MASK;
890 function->id = s->fragmentStorage ()->lastFunctionId++;
891
892 s->fragmentStorage ()->functions.push_back (function);
893
894 return function->id;
895 }
896
897 Attrib::Attrib (const GLWindowPaintAttrib &paint) :
898 priv (new PrivateAttrib ())
899 {
900 priv->opacity = paint.opacity;
901 priv->brightness = paint.brightness;
902 priv->saturation = paint.saturation;
903 priv->nTexture = 0;
904 priv->nFunction = 0;
905 priv->nParam = 0;
906
907 foreach (FunctionId &f, priv->function)
908 f = 0;
909 }
910
911 Attrib::Attrib (const Attrib &fa) :
912 priv (new PrivateAttrib (*fa.priv))
913 {
914 }
915
916 Attrib::~Attrib ()
917 {
918 delete priv;
919 }
920
921 Attrib &
922 Attrib::operator= (const Attrib &rhs)
923 {
924 if (this == &rhs) // Check for self-assignment
925 return *this;
926
927 delete priv;
928 priv = new PrivateAttrib (*rhs.priv);
929
930 return *this;
931 }
932
933 unsigned int
934 Attrib::allocTextureUnits (unsigned int nTexture)
935 {
936 unsigned int first = priv->nTexture;
937
938 priv->nTexture += nTexture;
939
940 /* 0 is reserved for source texture */
941 return 1 + first;
942 }
943
944 unsigned int
945 Attrib::allocParameters (unsigned int nParam)
946 {
947 unsigned int first = priv->nParam;
948
949 priv->nParam += nParam;
950
951 return first;
952 }
953
954 void
955 Attrib::addFunction (FunctionId function)
956 {
957 if (priv->nFunction < MAX_FRAGMENT_FUNCTIONS)
958 priv->function[priv->nFunction++] = function;
959 }
960
961 bool
962 Attrib::enable (bool *blending)
963 {
964 GLuint name;
965 GLenum type;
966 bool programBlending;
967
968 if (!GL::fragmentProgram)
969 return false;
970
971 name = getFragmentProgram (GLScreen::get (screen), priv, &type,
972 &programBlending);
973 if (!name)
974 return false;
975
976 *blending = !programBlending;
977
978 glEnable (GL_FRAGMENT_PROGRAM_ARB);
979
980 (*GL::bindProgram) (type, name);
981
982 return true;
983 }
984
985 void
986 Attrib::disable ()
987 {
988 glDisable (GL_FRAGMENT_PROGRAM_ARB);
989 }
990
991 unsigned short
992 Attrib::getSaturation ()
993 {
994 return priv->saturation;
995 }
996
997 unsigned short
998 Attrib::getBrightness ()
999 {
1000 return priv->brightness;
1001 }
1002
1003 unsigned short
1004 Attrib::getOpacity ()
1005 {
1006 return priv->opacity;
1007 }
1008
1009 void
1010 Attrib::setSaturation (unsigned short value)
1011 {
1012 priv->saturation = value;
1013 }
1014
1015 void
1016 Attrib::setBrightness (unsigned short value)
1017 {
1018 priv->brightness = value;
1019 }
1020
1021
1022 void
1023 Attrib::setOpacity (unsigned short value)
1024 {
1025 priv->opacity = value;
1026 }
1027
1028 bool
1029 Attrib::hasFunctions ()
1030 {
1031 return priv->nFunction > 0;
1032 }
1033
1034 void destroyFragmentFunction (FunctionId id)
1035 {
1036 GLScreen *s = GLScreen::get (screen);
1037 Function *function;
1038 Program *program;
1039
1040 function = findFragmentFunction (s, id);
1041
1042 if (!function)
1043 return;
1044
1045 std::vector<Program *>::iterator it;
1046
1047 do {
1048 program = NULL;
1049
1050 it = s->fragmentStorage ()->programs.begin ();
1051
1052 for (; it != s->fragmentStorage ()->programs.end (); it++)
1053 {
1054 foreach (FunctionId i, (*it)->signature)
1055 if (i == id)
1056 {
1057 program = (*it);
1058 break;
1059 }
1060
1061 if (program)
1062 break;
1063 }
1064
1065 if (program)
1066 {
1067 delete program;
1068 s->fragmentStorage ()->programs.erase (it);
1069 }
1070
1071 } while (program);
1072
1073 std::vector<Function *>::iterator fi =
1074 std::find (s->fragmentStorage ()->functions.begin (),
1075 s->fragmentStorage ()->functions.end (),
1076 function);
1077 if (fi != s->fragmentStorage ()->functions.end ())
1078 s->fragmentStorage ()->functions.erase (fi);
1079
1080 delete (function);
1081 }
1082
1083 FunctionId
1084 getSaturateFragmentFunction (GLTexture *texture,
1085 int param)
1086 {
1087 int target;
1088 GLScreen *s = GLScreen::get (screen);
1089
1090 if (param >= 64)
1091 return 0;
1092
1093 if (texture->target () == GL_TEXTURE_2D)
1094 target = COMP_FETCH_TARGET_2D;
1095 else
1096 target = COMP_FETCH_TARGET_RECT;
1097
1098 if (!s->fragmentStorage ()->saturateFunction [target][param])
1099 {
1100 static const char *saturateData =
1101 "MUL temp, output, { 1.0, 1.0, 1.0, 0.0 };"
1102 "DP3 temp, temp, program.env[%d];"
1103 "LRP output.xyz, program.env[%d].w, output, temp;";
1104 FunctionData data;
1105
1106 data.addTempHeaderOp ("temp");
1107 data.addFetchOp ("output", NULL, target);
1108 data.addColorOp ("output", "output");
1109
1110 data.addDataOp (saturateData, param, param);
1111
1112 if (!data.status ())
1113 return 0;
1114
1115 s->fragmentStorage ()->saturateFunction [target][param] =
1116 data.createFragmentFunction ("__core_saturate");
1117
1118 }
1119
1120 return s->fragmentStorage ()->saturateFunction [target][param];
1121 }
1122
1123 Storage::Storage () :
1124 lastFunctionId (1),
1125 functions (0),
1126 programs (0)
1127 {
1128 for (int i = 0; i < 64; i++)
1129 {
1130 saturateFunction[0][i] = 0;
1131 saturateFunction[1][i] = 0;
1132 }
1133 }
1134
1135 Storage::~Storage ()
1136 {
1137 foreach (Program *p, programs)
1138 delete p;
1139 programs.clear ();
1140 foreach (Function *f, functions)
1141 delete f;
1142 functions.clear ();
1143 }
1144
1145};
11460
=== modified file 'plugins/opengl/src/matrix.cpp'
--- plugins/opengl/src/matrix.cpp 2010-10-24 14:42:07 +0000
+++ plugins/opengl/src/matrix.cpp 2011-08-10 17:09:44 +0000
@@ -159,6 +159,60 @@
159#undef B159#undef B
160#undef P160#undef P
161161
162/*
163** Invert 4x4 matrix.
164** Contributed by David Moore (See Mesa bug #6748)
165*/
166bool GLMatrix::invert ()
167{
168 float inv[16], det;
169 int i;
170
171 inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15]
172 + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10];
173 inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15]
174 - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10];
175 inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15]
176 + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9];
177 inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14]
178 - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9];
179 inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15]
180 - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10];
181 inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15]
182 + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10];
183 inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15]
184 - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9];
185 inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14]
186 + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9];
187 inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15]
188 + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6];
189 inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15]
190 - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6];
191 inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15]
192 + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5];
193 inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14]
194 - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5];
195 inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11]
196 - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6];
197 inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11]
198 + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6];
199 inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11]
200 - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5];
201 inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10]
202 + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5];
203
204 det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12];
205 if (det == 0)
206 return false;
207
208 det = 1.0f / det;
209
210 for (i = 0; i < 16; i++)
211 m[i] = inv[i] * det;
212
213 return true;
214}
215
162/**216/**
163 * Generate a 4x4 transformation matrix from glRotate parameters, and217 * Generate a 4x4 transformation matrix from glRotate parameters, and
164 * post-multiply the input matrix by it.218 * post-multiply the input matrix by it.
165219
=== modified file 'plugins/opengl/src/paint.cpp'
--- plugins/opengl/src/paint.cpp 2011-05-07 08:58:54 +0000
+++ plugins/opengl/src/paint.cpp 2011-08-10 17:09:44 +0000
@@ -1,5 +1,6 @@
1/*1/*
2 * Copyright © 2005 Novell, Inc.2 * Copyright © 2005 Novell, Inc.
3 * Copyright © 2011 Linaro, Ltd.
3 *4 *
4 * Permission to use, copy, modify, distribute, and sell this software5 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without6 * and its documentation for any purpose is hereby granted without
@@ -20,7 +21,8 @@
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.22 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *23 *
23 * Author: David Reveman <davidr@novell.com>24 * Authors: David Reveman <davidr@novell.com>
25 * Travis Watkins <travis.watkins@linaro.org>
24 */26 */
2527
26#include <stdlib.h>28#include <stdlib.h>
@@ -34,6 +36,7 @@
34#include <opengl/opengl.h>36#include <opengl/opengl.h>
3537
36#include "privates.h"38#include "privates.h"
39#include "shaders.h"
3740
3841
39GLScreenPaintAttrib defaultScreenPaintAttrib = {42GLScreenPaintAttrib defaultScreenPaintAttrib = {
@@ -63,12 +66,16 @@
63}66}
6467
65void68void
66PrivateGLScreen::paintBackground (const CompRegion &region,69PrivateGLScreen::paintBackground (const GLMatrix &transform,
67 bool transformed)70 const CompRegion &region,
71 bool transformed)
68{72{
73 GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
74 GLfloat vertexData[16];
75 GLushort colorData[4];
76
69 BoxPtr pBox = const_cast <Region> (region.handle ())->rects;77 BoxPtr pBox = const_cast <Region> (region.handle ())->rects;
70 int n, nBox = const_cast <Region> (region.handle ())->numRects;78 int n, nBox = const_cast <Region> (region.handle ())->numRects;
71 GLfloat *d, *data;
7279
73 if (!nBox)80 if (!nBox)
74 return;81 return;
@@ -92,81 +99,83 @@
92 backgroundLoaded = true;99 backgroundLoaded = true;
93 }100 }
94101
95 data = new GLfloat [nBox * 16];
96 if (!data)
97 return;
98
99 d = data;
100 n = nBox;102 n = nBox;
101103
102 if (backgroundTextures.empty ())104 if (backgroundTextures.empty ())
103 {105 {
106 streamingBuffer->begin (GL_TRIANGLE_STRIP);
107
104 while (n--)108 while (n--)
105 {109 {
106 *d++ = pBox->x1;110 vertexData[0] = pBox->x1;
107 *d++ = pBox->y2;111 vertexData[1] = pBox->y1;
108112 vertexData[2] = 0.0f;
109 *d++ = pBox->x2;113 vertexData[3] = pBox->x1;
110 *d++ = pBox->y2;114 vertexData[4] = pBox->y2;
111115 vertexData[5] = 0.0f;
112 *d++ = pBox->x2;116 vertexData[6] = pBox->x2;
113 *d++ = pBox->y1;117 vertexData[7] = pBox->y1;
114118 vertexData[8] = 0.0f;
115 *d++ = pBox->x1;119 vertexData[9] = pBox->x2;
116 *d++ = pBox->y1;120 vertexData[10] = pBox->y2;
121 vertexData[11] = 0.0f;
122
123 streamingBuffer->addVertices (4, vertexData);
117124
118 pBox++;125 pBox++;
119 }126 }
120127
121 glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 2, data + 2);128 colorData[0] = colorData[1] = colorData[2] = colorData[3] = 0;
129 streamingBuffer->addColors (1, colorData);
122130
123 glColor4us (0, 0, 0, 0);131 streamingBuffer->end ();
124 glDrawArrays (GL_QUADS, 0, nBox * 4);132 streamingBuffer->render (transform);
125 glColor4usv (defaultColor);
126 }133 }
127 else134 else
128 {135 {
129 for (unsigned int i = 0; i < backgroundTextures.size (); i++)136 for (unsigned int i = 0; i < backgroundTextures.size (); i++)
130 {137 {
138 GLfloat textureData[8];
131 GLTexture *bg = backgroundTextures[i];139 GLTexture *bg = backgroundTextures[i];
132 CompRegion r = region & *bg;140 CompRegion r = region & *bg;
133141
134 pBox = const_cast <Region> (r.handle ())->rects;142 pBox = const_cast <Region> (r.handle ())->rects;
135 nBox = const_cast <Region> (r.handle ())->numRects;143 nBox = const_cast <Region> (r.handle ())->numRects;
136 d = data;
137 n = nBox;144 n = nBox;
138145
146 streamingBuffer->begin (GL_TRIANGLE_STRIP);
147
139 while (n--)148 while (n--)
140 {149 {
141 *d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);150 vertexData[0] = pBox->x1;
142 *d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);151 vertexData[1] = pBox->y1;
143152 vertexData[2] = 0.0f;
144 *d++ = pBox->x1;153 vertexData[3] = pBox->x1;
145 *d++ = pBox->y2;154 vertexData[4] = pBox->y2;
146155 vertexData[5] = 0.0f;
147 *d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);156 vertexData[6] = pBox->x2;
148 *d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);157 vertexData[7] = pBox->y1;
149158 vertexData[8] = 0.0f;
150 *d++ = pBox->x2;159 vertexData[9] = pBox->x2;
151 *d++ = pBox->y2;160 vertexData[10] = pBox->y2;
152161 vertexData[11] = 0.0f;
153 *d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);162
154 *d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);163 textureData[0] = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
155164 textureData[1] = COMP_TEX_COORD_X (bg->matrix (), pBox->y1);
156 *d++ = pBox->x2;165 textureData[2] = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
157 *d++ = pBox->y1;166 textureData[3] = COMP_TEX_COORD_X (bg->matrix (), pBox->y2);
158167 textureData[4] = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
159 *d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);168 textureData[5] = COMP_TEX_COORD_X (bg->matrix (), pBox->y1);
160 *d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);169 textureData[6] = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
161170 textureData[7] = COMP_TEX_COORD_X (bg->matrix (), pBox->y2);
162 *d++ = pBox->x1;171
163 *d++ = pBox->y1;172 streamingBuffer->addVertices (4, vertexData);
173 streamingBuffer->addTexCoords (0, 4, textureData);
164174
165 pBox++;175 pBox++;
166 }176 }
167177
168 glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data);178 streamingBuffer->end ();
169 glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data + 2);
170179
171 if (bg->name ())180 if (bg->name ())
172 {181 {
@@ -175,14 +184,12 @@
175 else184 else
176 bg->enable (GLTexture::Fast);185 bg->enable (GLTexture::Fast);
177186
178 glDrawArrays (GL_QUADS, 0, nBox * 4);187 streamingBuffer->render (transform);
179188
180 bg->disable ();189 bg->disable ();
181 }190 }
182 }191 }
183 }192 }
184
185 delete [] data;
186}193}
187194
188195
@@ -309,7 +316,9 @@
309 CompositeWindow::get (fullscreenWindow)->unredirect ();316 CompositeWindow::get (fullscreenWindow)->unredirect ();
310317
311 if (!(mask & PAINT_SCREEN_NO_BACKGROUND_MASK))318 if (!(mask & PAINT_SCREEN_NO_BACKGROUND_MASK))
312 paintBackground (tmpRegion, (mask & PAINT_SCREEN_TRANSFORMED_MASK));319 paintBackground (transform,
320 tmpRegion,
321 (mask & PAINT_SCREEN_TRANSFORMED_MASK));
313322
314 /* paint all windows from bottom to top */323 /* paint all windows from bottom to top */
315 foreach (w, pl)324 foreach (w, pl)
@@ -358,6 +367,7 @@
358{367{
359 WRAPABLE_HND_FUNC (3, glEnableOutputClipping, transform, region, output)368 WRAPABLE_HND_FUNC (3, glEnableOutputClipping, transform, region, output)
360369
370 #ifndef USE_GLES
361 GLdouble h = screen->height ();371 GLdouble h = screen->height ();
362372
363 GLdouble p1[2] = { static_cast<GLdouble> (region.handle ()->extents.x1),373 GLdouble p1[2] = { static_cast<GLdouble> (region.handle ()->extents.x1),
@@ -390,6 +400,7 @@
390 glEnable (GL_CLIP_PLANE3);400 glEnable (GL_CLIP_PLANE3);
391401
392 glPopMatrix ();402 glPopMatrix ();
403 #endif
393}404}
394405
395void406void
@@ -397,10 +408,12 @@
397{408{
398 WRAPABLE_HND_FUNC (4, glDisableOutputClipping)409 WRAPABLE_HND_FUNC (4, glDisableOutputClipping)
399410
411 #ifndef USE_GLES
400 glDisable (GL_CLIP_PLANE0);412 glDisable (GL_CLIP_PLANE0);
401 glDisable (GL_CLIP_PLANE1);413 glDisable (GL_CLIP_PLANE1);
402 glDisable (GL_CLIP_PLANE2);414 glDisable (GL_CLIP_PLANE2);
403 glDisable (GL_CLIP_PLANE3);415 glDisable (GL_CLIP_PLANE3);
416 #endif
404}417}
405418
406#define CLIP_PLANE_MASK (PAINT_SCREEN_TRANSFORMED_MASK | \419#define CLIP_PLANE_MASK (PAINT_SCREEN_TRANSFORMED_MASK | \
@@ -430,26 +443,14 @@
430 glEnableOutputClipping (sTransform, region, output);443 glEnableOutputClipping (sTransform, region, output);
431444
432 sTransform.toScreenSpace (output, -sAttrib.zTranslate);445 sTransform.toScreenSpace (output, -sAttrib.zTranslate);
433
434 glPushMatrix ();
435 glLoadMatrixf (sTransform.getMatrix ());
436
437 priv->paintOutputRegion (sTransform, region, output, mask);446 priv->paintOutputRegion (sTransform, region, output, mask);
438447
439 glPopMatrix ();
440
441 glDisableOutputClipping ();448 glDisableOutputClipping ();
442 }449 }
443 else450 else
444 {451 {
445 sTransform.toScreenSpace (output, -sAttrib.zTranslate);452 sTransform.toScreenSpace (output, -sAttrib.zTranslate);
446
447 glPushMatrix ();
448 glLoadMatrixf (sTransform.getMatrix ());
449
450 priv->paintOutputRegion (sTransform, region, output, mask);453 priv->paintOutputRegion (sTransform, region, output, mask);
451
452 glPopMatrix ();
453 }454 }
454}455}
455456
@@ -484,13 +485,8 @@
484485
485 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);486 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
486487
487 glPushMatrix ();
488 glLoadMatrixf (sTransform.getMatrix ());
489
490 priv->paintOutputRegion (sTransform, region, output, mask);488 priv->paintOutputRegion (sTransform, region, output, mask);
491489
492 glPopMatrix ();
493
494 return true;490 return true;
495 }491 }
496 else if (mask & PAINT_SCREEN_FULL_MASK)492 else if (mask & PAINT_SCREEN_FULL_MASK)
@@ -506,182 +502,172 @@
506 }502 }
507}503}
508504
509#define ADD_RECT(data, m, n, x1, y1, x2, y2) \505#define ADD_RECT(vertexBuffer, m, n, x1, y1, x2, y2) \
510 for (it = 0; it < n; it++) \506 GLfloat vertexData[18] = { \
511 { \507 x1, y1, 0.0, \
512 const GLTexture::Matrix &mat = m[it]; \508 x1, y2, 0.0, \
513 *(data)++ = COMP_TEX_COORD_X (mat, x1); \509 x2, y1, 0.0, \
514 *(data)++ = COMP_TEX_COORD_Y (mat, y1); \510 x2, y1, 0.0, \
515 } \511 x1, y2, 0.0, \
516 *(data)++ = (x1); \512 x2, y2, 0.0 \
517 *(data)++ = (y1); \513 }; \
518 *(data)++ = 0.0; \514 vertexBuffer->addVertices (6, vertexData); \
519 for (it = 0; it < n; it++) \515 \
520 { \516 for (it = 0; it < n; it++) \
521 const GLTexture::Matrix &mat = m[it]; \517 { \
522 *(data)++ = COMP_TEX_COORD_X (mat, x1); \518 GLfloat data[2]; \
523 *(data)++ = COMP_TEX_COORD_Y (mat, y2); \519 const GLTexture::Matrix &mat = m[it]; \
524 } \520 data[0] = COMP_TEX_COORD_X (mat, x1); \
525 *(data)++ = (x1); \521 data[1] = COMP_TEX_COORD_Y (mat, y1); \
526 *(data)++ = (y2); \522 vertexBuffer->addTexCoords (it, 1, data); \
527 *(data)++ = 0.0; \523 } \
528 for (it = 0; it < n; it++) \524 for (it = 0; it < n; it++) \
529 { \525 { \
530 const GLTexture::Matrix &mat = m[it]; \526 GLfloat data[2]; \
531 *(data)++ = COMP_TEX_COORD_X (mat, x2); \527 const GLTexture::Matrix &mat = m[it]; \
532 *(data)++ = COMP_TEX_COORD_Y (mat, y2); \528 data[0] = COMP_TEX_COORD_X (mat, x1); \
533 } \529 data[1] = COMP_TEX_COORD_Y (mat, y2); \
534 *(data)++ = (x2); \530 vertexBuffer->addTexCoords (it, 1, data); \
535 *(data)++ = (y2); \531 } \
536 *(data)++ = 0.0; \532 for (it = 0; it < n; it++) \
537 for (it = 0; it < n; it++) \533 { \
538 { \534 GLfloat data[2]; \
539 const GLTexture::Matrix &mat = m[it]; \535 const GLTexture::Matrix &mat = m[it]; \
540 *(data)++ = COMP_TEX_COORD_X (mat, x2); \536 data[0] = COMP_TEX_COORD_X (mat, x2); \
541 *(data)++ = COMP_TEX_COORD_Y (mat, y1); \537 data[1] = COMP_TEX_COORD_Y (mat, y1); \
542 } \538 vertexBuffer->addTexCoords (it, 1, data); \
543 *(data)++ = (x2); \539 } \
544 *(data)++ = (y1); \540 for (it = 0; it < n; it++) \
545 *(data)++ = 0.0541 { \
546542 GLfloat data[2]; \
547#define ADD_QUAD(data, m, n, x1, y1, x2, y2) \543 const GLTexture::Matrix &mat = m[it]; \
548 for (it = 0; it < n; it++) \544 data[0] = COMP_TEX_COORD_X (mat, x2); \
549 { \545 data[1] = COMP_TEX_COORD_Y (mat, y1); \
550 const GLTexture::Matrix &mat = m[it]; \546 vertexBuffer->addTexCoords (it, 1, data); \
551 *(data)++ = COMP_TEX_COORD_XY (mat, x1, y1); \547 } \
552 *(data)++ = COMP_TEX_COORD_YX (mat, x1, y1); \548 for (it = 0; it < n; it++) \
553 } \549 { \
554 *(data)++ = (x1); \550 GLfloat data[2]; \
555 *(data)++ = (y1); \551 const GLTexture::Matrix &mat = m[it]; \
556 *(data)++ = 0.0; \552 data[0] = COMP_TEX_COORD_X (mat, x1); \
557 for (it = 0; it < n; it++) \553 data[1] = COMP_TEX_COORD_Y (mat, y2); \
558 { \554 vertexBuffer->addTexCoords (it, 1, data); \
559 const GLTexture::Matrix &mat = m[it]; \555 } \
560 *(data)++ = COMP_TEX_COORD_XY (mat, x1, y2); \556 for (it = 0; it < n; it++) \
561 *(data)++ = COMP_TEX_COORD_YX (mat, x1, y2); \557 { \
562 } \558 GLfloat data[2]; \
563 *(data)++ = (x1); \559 const GLTexture::Matrix &mat = m[it]; \
564 *(data)++ = (y2); \560 data[0] = COMP_TEX_COORD_X (mat, x2); \
565 *(data)++ = 0.0; \561 data[1] = COMP_TEX_COORD_Y (mat, y2); \
566 for (it = 0; it < n; it++) \562 vertexBuffer->addTexCoords (it, 1, data); \
567 { \563 }
568 const GLTexture::Matrix &mat = m[it]; \564
569 *(data)++ = COMP_TEX_COORD_XY (mat, x2, y2); \565#define ADD_QUAD(vertexBuffer, m, n, x1, y1, x2, y2) \
570 *(data)++ = COMP_TEX_COORD_YX (mat, x2, y2); \566 GLfloat vertexData[18] = { \
571 } \567 x1, y1, 0.0, \
572 *(data)++ = (x2); \568 x1, y2, 0.0, \
573 *(data)++ = (y2); \569 x2, y1, 0.0, \
574 *(data)++ = 0.0; \570 x2, y1, 0.0, \
575 for (it = 0; it < n; it++) \571 x1, y2, 0.0, \
576 { \572 x2, y2, 0.0 \
577 const GLTexture::Matrix &mat = m[it]; \573 }; \
578 *(data)++ = COMP_TEX_COORD_XY (mat, x2, y1); \574 vertexBuffer->addVertices (6, vertexData); \
579 *(data)++ = COMP_TEX_COORD_YX (mat, x2, y1); \575 \
580 } \576 for (it = 0; it < n; it++) \
581 *(data)++ = (x2); \577 { \
582 *(data)++ = (y1); \578 GLfloat data[2]; \
583 *(data)++ = 0.0;579 const GLTexture::Matrix &mat = m[it]; \
584580 data[0] = COMP_TEX_COORD_XY (mat, x1, y1); \
585void581 data[1] = COMP_TEX_COORD_YX (mat, x1, y1); \
586GLWindow::glDrawGeometry ()582 vertexBuffer->addTexCoords (it, 1, data); \
587{583 } \
588 WRAPABLE_HND_FUNC (4, glDrawGeometry)584 for (it = 0; it < n; it++) \
589585 { \
590 int texUnit = priv->geometry.texUnits;586 GLfloat data[2]; \
591 int currentTexUnit = 0;587 const GLTexture::Matrix &mat = m[it]; \
592 int stride = priv->geometry.vertexStride;588 data[0] = COMP_TEX_COORD_XY (mat, x1, y2); \
593 GLfloat *vertices = priv->geometry.vertices + (stride - 3);589 data[1] = COMP_TEX_COORD_YX (mat, x1, y2); \
594590 vertexBuffer->addTexCoords (it, 1, data); \
595 stride *= sizeof (GLfloat);591 } \
596592 for (it = 0; it < n; it++) \
597 glVertexPointer (3, GL_FLOAT, stride, vertices);593 { \
598594 GLfloat data[2]; \
599 while (texUnit--)595 const GLTexture::Matrix &mat = m[it]; \
600 {596 data[0] = COMP_TEX_COORD_XY (mat, x2, y1); \
601 if (texUnit != currentTexUnit)597 data[1] = COMP_TEX_COORD_YX (mat, x2, y1); \
602 {598 vertexBuffer->addTexCoords (it, 1, data); \
603 (*GL::clientActiveTexture) (GL_TEXTURE0_ARB + texUnit);599 } \
604 glEnableClientState (GL_TEXTURE_COORD_ARRAY);600 for (it = 0; it < n; it++) \
605 currentTexUnit = texUnit;601 { \
606 }602 GLfloat data[2]; \
607 vertices -= priv->geometry.texCoordSize;603 const GLTexture::Matrix &mat = m[it]; \
608 glTexCoordPointer (priv->geometry.texCoordSize,604 data[0] = COMP_TEX_COORD_XY (mat, x2, y1); \
609 GL_FLOAT, stride, vertices);605 data[1] = COMP_TEX_COORD_YX (mat, x2, y1); \
610 }606 vertexBuffer->addTexCoords (it, 1, data); \
611607 } \
612 glDrawArrays (GL_QUADS, 0, priv->geometry.vCount);608 for (it = 0; it < n; it++) \
613609 { \
614 /* disable all texture coordinate arrays except 0 */610 GLfloat data[2]; \
615 texUnit = priv->geometry.texUnits;611 const GLTexture::Matrix &mat = m[it]; \
616 if (texUnit > 1)612 data[0] = COMP_TEX_COORD_XY (mat, x1, y2); \
617 {613 data[1] = COMP_TEX_COORD_YX (mat, x1, y2); \
618 while (--texUnit)614 vertexBuffer->addTexCoords (it, 1, data); \
619 {615 } \
620 (*GL::clientActiveTexture) (GL_TEXTURE0_ARB + texUnit);616 for (it = 0; it < n; it++) \
621 glDisableClientState (GL_TEXTURE_COORD_ARRAY);617 { \
622 }618 GLfloat data[2]; \
623619 const GLTexture::Matrix &mat = m[it]; \
624 (*GL::clientActiveTexture) (GL_TEXTURE0_ARB);620 data[0] = COMP_TEX_COORD_XY (mat, x2, y2); \
625 }621 data[1] = COMP_TEX_COORD_YX (mat, x2, y2); \
626}622 vertexBuffer->addTexCoords (it, 1, data); \
623 }
624
627625
628static inline void626static inline void
629addSingleQuad (GLfloat *&d,627addSingleQuad (GLVertexBuffer *vertexBuffer,
630 const GLTexture::MatrixList &matrix,628 const GLTexture::MatrixList &matrix,
631 unsigned int nMatrix,629 unsigned int nMatrix,
632 int x1,630 int x1,
633 int y1,631 int y1,
634 int x2,632 int x2,
635 int y2,633 int y2,
636 int &n,634 int &n,
637 bool rect)635 bool rect)
638{636{
639 unsigned int it;637 unsigned int it;
640638
641 if (rect)639 if (rect)
642 {640 {
643 ADD_RECT (d, matrix, nMatrix, x1, y1, x2, y2);641 ADD_RECT (vertexBuffer, matrix, nMatrix, x1, y1, x2, y2);
644 }642 }
645 else643 else
646 {644 {
647 ADD_QUAD (d, matrix, nMatrix, x1, y1, x2, y2);645 ADD_QUAD (vertexBuffer, matrix, nMatrix, x1, y1, x2, y2);
648 }646 }
649 n++;647 n++;
650}648}
651649
652static inline void650static inline void
653addQuads (GLfloat *&d,651addQuads (GLVertexBuffer *vertexBuffer,
654 const GLTexture::MatrixList &matrix,652 const GLTexture::MatrixList &matrix,
655 unsigned int nMatrix,653 unsigned int nMatrix,
656 int x1,654 int x1,
657 int y1,655 int y1,
658 int x2,656 int x2,
659 int y2,657 int y2,
660 int &n,658 int &n,
661 int vSize,659 bool rect,
662 bool rect,660 unsigned int maxGridWidth,
663 GLWindow::Geometry &geometry,661 unsigned int maxGridHeight)
664 unsigned int maxGridWidth,
665 unsigned int maxGridHeight)
666{662{
667 int nQuadsX = (maxGridWidth == MAXSHORT) ? 1 :663 int nQuadsX = (maxGridWidth == MAXSHORT) ? 1 :
668 1 + (x2 - x1 - 1) / (int) maxGridWidth; // ceil. division664 1 + (x2 - x1 - 1) / (int) maxGridWidth; // ceil. division
669 int nQuadsY = (maxGridHeight == MAXSHORT) ? 1 :665 int nQuadsY = (maxGridHeight == MAXSHORT) ? 1 :
670 1 + (y2 - y1 - 1) / (int) maxGridHeight;666 1 + (y2 - y1 - 1) / (int) maxGridHeight;
671 int newVertexSize = (n + nQuadsX * nQuadsY) * vSize * 4;
672
673 // Make sure enough vertices are allocated for nQuadsX * nQuadsY more quads
674 if (newVertexSize > geometry.vertexSize)
675 {
676 if (!geometry.moreVertices (newVertexSize))
677 return;
678
679 d = geometry.vertices + (n * vSize * 4);
680 }
681667
682 if (nQuadsX == 1 && nQuadsY == 1)668 if (nQuadsX == 1 && nQuadsY == 1)
683 {669 {
684 addSingleQuad (d, matrix, nMatrix, x1, y1, x2, y2, n, rect);670 addSingleQuad (vertexBuffer, matrix, nMatrix, x1, y1, x2, y2, n, rect);
685 }671 }
686 else672 else
687 {673 {
@@ -697,7 +683,8 @@
697 {683 {
698 nx2 = MIN (nx1 + (int) quadWidth, x2);684 nx2 = MIN (nx1 + (int) quadWidth, x2);
699685
700 addSingleQuad (d, matrix, nMatrix, nx1, ny1, nx2, ny2, n, rect);686 addSingleQuad (vertexBuffer, matrix, nMatrix,
687 nx1, ny1, nx2, ny2, n, rect);
701 }688 }
702 }689 }
703 }690 }
@@ -715,8 +702,6 @@
715 BoxRec full;702 BoxRec full;
716 int nMatrix = matrix.size ();703 int nMatrix = matrix.size ();
717704
718 priv->geometry.texUnits = nMatrix;
719
720 full = clip.handle ()->extents;705 full = clip.handle ()->extents;
721 if (region.handle ()->extents.x1 > full.x1)706 if (region.handle ()->extents.x1 > full.x1)
722 full.x1 = region.handle ()->extents.x1;707 full.x1 = region.handle ()->extents.x1;
@@ -734,9 +719,7 @@
734 BoxPtr pClip;719 BoxPtr pClip;
735 int nClip;720 int nClip;
736 BoxRec cbox;721 BoxRec cbox;
737 int vSize;
738 int n, it, x1, y1, x2, y2;722 int n, it, x1, y1, x2, y2;
739 GLfloat *d;
740 bool rect = true;723 bool rect = true;
741724
742 for (it = 0; it < nMatrix; it++)725 for (it = 0; it < nMatrix; it++)
@@ -751,18 +734,6 @@
751 pBox = const_cast <Region> (region.handle ())->rects;734 pBox = const_cast <Region> (region.handle ())->rects;
752 nBox = const_cast <Region> (region.handle ())->numRects;735 nBox = const_cast <Region> (region.handle ())->numRects;
753736
754 vSize = 3 + nMatrix * 2;
755
756 n = priv->geometry.vCount / 4;
757
758 if ((n + nBox) * vSize * 4 > priv->geometry.vertexSize)
759 {
760 if (!priv->geometry.moreVertices ((n + nBox) * vSize * 4))
761 return;
762 }
763
764 d = priv->geometry.vertices + (priv->geometry.vCount * vSize);
765
766 while (nBox--)737 while (nBox--)
767 {738 {
768 x1 = pBox->x1;739 x1 = pBox->x1;
@@ -787,24 +758,15 @@
787758
788 if (nClip == 1)759 if (nClip == 1)
789 {760 {
790 addQuads (d, matrix, nMatrix,761 addQuads (priv->vertexBuffer, matrix, nMatrix,
791 x1, y1, x2, y2,762 x1, y1, x2, y2,
792 n, vSize, rect, priv->geometry,763 n, rect,
793 maxGridWidth, maxGridHeight);764 maxGridWidth, maxGridHeight);
794 }765 }
795 else766 else
796 {767 {
797 pClip = const_cast <Region> (clip.handle ())->rects;768 pClip = const_cast <Region> (clip.handle ())->rects;
798769
799 if (((n + nClip) * vSize * 4) > priv->geometry.vertexSize)
800 {
801 if (!priv->geometry.moreVertices ((n + nClip) *
802 vSize * 4))
803 return;
804
805 d = priv->geometry.vertices + (n * vSize * 4);
806 }
807
808 while (nClip--)770 while (nClip--)
809 {771 {
810 cbox = *pClip;772 cbox = *pClip;
@@ -822,120 +784,32 @@
822784
823 if (cbox.x1 < cbox.x2 && cbox.y1 < cbox.y2)785 if (cbox.x1 < cbox.x2 && cbox.y1 < cbox.y2)
824 {786 {
825 addQuads (d, matrix, nMatrix,787 addQuads (priv->vertexBuffer, matrix, nMatrix,
826 cbox.x1, cbox.y1, cbox.x2, cbox.y2,788 cbox.x1, cbox.y1, cbox.x2, cbox.y2,
827 n, vSize, rect, priv->geometry,789 n, rect,
828 maxGridWidth, maxGridHeight);790 maxGridWidth, maxGridHeight);
829 }791 }
830 }792 }
831 }793 }
832 }794 }
833 }795 }
834796 }
835 priv->geometry.vCount = n * 4;797}
836 priv->geometry.vertexStride = vSize;798
837 priv->geometry.texCoordSize = 2;799#ifndef USE_GLES
838 }
839}
840
841static bool
842enableFragmentProgramAndDrawGeometry (GLScreen *gs,
843 GLWindow *w,
844 GLTexture *texture,
845 GLFragment::Attrib &attrib,
846 GLTexture::Filter filter,
847 unsigned int mask)
848{
849 GLFragment::Attrib fa (attrib);
850 bool blending;
851
852 if (GL::canDoSaturated && attrib.getSaturation () != COLOR)
853 {
854 int param, function;
855
856 param = fa.allocParameters (1);
857 function =
858 GLFragment::getSaturateFragmentFunction (texture, param);
859
860 fa.addFunction (function);
861
862 (*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, param,
863 RED_SATURATION_WEIGHT,
864 GREEN_SATURATION_WEIGHT,
865 BLUE_SATURATION_WEIGHT,
866 attrib.getSaturation () / 65535.0f);
867 }
868
869 if (!fa.enable (&blending))
870 return false;
871
872 texture->enable (filter);
873
874 if (mask & PAINT_WINDOW_BLEND_MASK)
875 {
876 if (blending)
877 glEnable (GL_BLEND);
878
879 if (attrib.getOpacity () != OPAQUE || attrib.getBrightness () != BRIGHT)
880 {
881 GLushort color;
882
883 color = (attrib.getOpacity () * attrib.getBrightness ()) >> 16;
884
885 gs->setTexEnvMode (GL_MODULATE);
886 glColor4us (color, color, color, attrib.getOpacity ());
887
888 w->glDrawGeometry ();
889
890 glColor4usv (defaultColor);
891 gs->setTexEnvMode (GL_REPLACE);
892 }
893 else
894 {
895 w->glDrawGeometry ();
896 }
897
898 if (blending)
899 glDisable (GL_BLEND);
900 }
901 else if (attrib.getBrightness () != BRIGHT)
902 {
903 gs->setTexEnvMode (GL_MODULATE);
904 glColor4us (attrib.getBrightness (), attrib.getBrightness (),
905 attrib.getBrightness (), BRIGHT);
906
907 w->glDrawGeometry ();
908
909 glColor4usv (defaultColor);
910 gs->setTexEnvMode (GL_REPLACE);
911 }
912 else
913 {
914 w->glDrawGeometry ();
915 }
916
917 texture->disable ();
918
919 fa.disable ();
920
921 return true;
922}
923
924static void800static void
925enableFragmentOperationsAndDrawGeometry (GLScreen *gs,801enableLegacyOBSAndRender (GLScreen *gs,
926 GLWindow *w,802 GLWindow *w,
927 GLTexture *texture,803 GLTexture *texture,
928 GLFragment::Attrib &attrib,804 const GLMatrix &transform,
929 GLTexture::Filter filter,805 const GLWindowPaintAttrib &attrib,
930 unsigned int mask)806 GLTexture::Filter filter,
807 unsigned int mask)
931{808{
932 if (GL::canDoSaturated && attrib.getSaturation () != COLOR)809 if (GL::canDoSaturated && attrib.saturation != COLOR)
933 {810 {
934 GLfloat constant[4];811 GLfloat constant[4];
935812
936 if (mask & PAINT_WINDOW_BLEND_MASK)
937 glEnable (GL_BLEND);
938
939 texture->enable (filter);813 texture->enable (filter);
940814
941 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);815 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
@@ -966,7 +840,7 @@
966 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);840 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
967 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);841 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
968842
969 if (GL::canDoSlightlySaturated && attrib.getSaturation () > 0)843 if (GL::canDoSlightlySaturated && attrib.saturation > 0)
970 {844 {
971 glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);845 glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
972 glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);846 glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
@@ -997,20 +871,20 @@
997 glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);871 glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
998 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);872 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
999873
1000 constant[3] = attrib.getSaturation () / 65535.0f;874 constant[3] = attrib.saturation / 65535.0f;
1001875
1002 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);876 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
1003877
1004 if (attrib.getOpacity () < OPAQUE ||878 if (attrib.opacity < OPAQUE ||
1005 attrib.getBrightness () != BRIGHT)879 attrib.brightness != BRIGHT)
1006 {880 {
1007 GL::activeTexture (GL_TEXTURE3_ARB);881 GL::activeTexture (GL_TEXTURE3_ARB);
1008882
1009 texture->enable (filter);883 texture->enable (filter);
1010884
1011 constant[3] = attrib.getOpacity () / 65535.0f;885 constant[3] = attrib.opacity / 65535.0f;
1012 constant[0] = constant[1] = constant[2] = constant[3] *886 constant[0] = constant[1] = constant[2] = constant[3] *
1013 attrib.getBrightness () / 65535.0f;887 attrib.brightness / 65535.0f;
1014888
1015 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);889 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
1016890
@@ -1028,7 +902,7 @@
1028 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);902 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1029 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);903 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1030904
1031 w->glDrawGeometry ();905 w->vertexBuffer ()->render (transform, attrib);
1032906
1033 texture->disable ();907 texture->disable ();
1034908
@@ -1038,7 +912,7 @@
1038 }912 }
1039 else913 else
1040 {914 {
1041 w->glDrawGeometry ();915 w->vertexBuffer ()->render (transform, attrib);
1042 }916 }
1043917
1044 texture->disable ();918 texture->disable ();
@@ -1055,9 +929,9 @@
1055 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);929 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
1056 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);930 glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
1057931
1058 constant[3] = attrib.getOpacity () / 65535.0f;932 constant[3] = attrib.opacity / 65535.0f;
1059 constant[0] = constant[1] = constant[2] = constant[3] *933 constant[0] = constant[1] = constant[2] = constant[3] *
1060 attrib.getBrightness ()/ 65535.0f;934 attrib.brightness / 65535.0f;
1061935
1062 constant[0] = 0.5f + 0.5f * RED_SATURATION_WEIGHT * constant[0];936 constant[0] = 0.5f + 0.5f * RED_SATURATION_WEIGHT * constant[0];
1063 constant[1] = 0.5f + 0.5f * GREEN_SATURATION_WEIGHT * constant[1];937 constant[1] = 0.5f + 0.5f * GREEN_SATURATION_WEIGHT * constant[1];
@@ -1065,7 +939,7 @@
1065939
1066 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);940 glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
1067941
1068 w->glDrawGeometry ();942 w->vertexBuffer ()->render (transform, attrib);
1069 }943 }
1070944
1071 texture->disable ();945 texture->disable ();
@@ -1078,9 +952,6 @@
1078952
1079 glColor4usv (defaultColor);953 glColor4usv (defaultColor);
1080 gs->setTexEnvMode (GL_REPLACE);954 gs->setTexEnvMode (GL_REPLACE);
1081
1082 if (mask & PAINT_WINDOW_BLEND_MASK)
1083 glDisable (GL_BLEND);
1084 }955 }
1085 else956 else
1086 {957 {
@@ -1088,57 +959,57 @@
1088959
1089 if (mask & PAINT_WINDOW_BLEND_MASK)960 if (mask & PAINT_WINDOW_BLEND_MASK)
1090 {961 {
1091 glEnable (GL_BLEND);962 if (attrib.opacity != OPAQUE ||
1092 if (attrib.getOpacity ()!= OPAQUE ||963 attrib.brightness != BRIGHT)
1093 attrib.getBrightness () != BRIGHT)
1094 {964 {
1095 GLushort color;965 GLushort color;
1096966
1097 color = (attrib.getOpacity () * attrib.getBrightness ()) >> 16;967 color = (attrib.opacity * attrib.brightness) >> 16;
1098968
1099 gs->setTexEnvMode (GL_MODULATE);969 gs->setTexEnvMode (GL_MODULATE);
1100 glColor4us (color, color, color, attrib.getOpacity ());970 glColor4us (color, color, color, attrib.opacity);
1101971
1102 w->glDrawGeometry ();972 w->vertexBuffer ()->render (transform, attrib);
1103973
1104 glColor4usv (defaultColor);974 glColor4usv (defaultColor);
1105 gs->setTexEnvMode (GL_REPLACE);975 gs->setTexEnvMode (GL_REPLACE);
1106 }976 }
1107 else977 else
1108 {978 {
1109 w->glDrawGeometry ();979 w->vertexBuffer ()->render (transform, attrib);
1110 }980 }
1111
1112 glDisable (GL_BLEND);
1113 }981 }
1114 else if (attrib.getBrightness () != BRIGHT)982 else if (attrib.brightness != BRIGHT)
1115 {983 {
1116 gs->setTexEnvMode (GL_MODULATE);984 gs->setTexEnvMode (GL_MODULATE);
1117 glColor4us (attrib.getBrightness (), attrib.getBrightness (),985 glColor4us (attrib.brightness, attrib.brightness,
1118 attrib.getBrightness (), BRIGHT);986 attrib.brightness, BRIGHT);
1119987
1120 w->glDrawGeometry ();988 w->vertexBuffer ()->render (transform, attrib);
1121989
1122 glColor4usv (defaultColor);990 glColor4usv (defaultColor);
1123 gs->setTexEnvMode (GL_REPLACE);991 gs->setTexEnvMode (GL_REPLACE);
1124 }992 }
1125 else993 else
1126 {994 {
1127 w->glDrawGeometry ();995 w->vertexBuffer ()->render (transform, attrib);
1128 }996 }
1129997
1130 texture->disable ();998 texture->disable ();
1131 }999 }
1132}1000}
1001#endif
11331002
1134void1003void
1135GLWindow::glDrawTexture (GLTexture *texture,1004GLWindow::glDrawTexture (GLTexture *texture,
1136 GLFragment::Attrib &attrib,1005 const GLMatrix &transform,
1137 unsigned int mask)1006 const GLWindowPaintAttrib &attrib,
1007 unsigned int mask)
1138{1008{
1139 WRAPABLE_HND_FUNC (3, glDrawTexture, texture, attrib, mask)1009 WRAPABLE_HND_FUNC (3, glDrawTexture, texture, transform, attrib, mask)
11401010
1141 GLTexture::Filter filter;1011 GLTexture::Filter filter;
1012 GLProgram *program = NULL;
11421013
1143 if (mask & (PAINT_WINDOW_TRANSFORMED_MASK |1014 if (mask & (PAINT_WINDOW_TRANSFORMED_MASK |
1144 PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK))1015 PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK))
@@ -1146,24 +1017,36 @@
1146 else1017 else
1147 filter = priv->gScreen->filter (NOTHING_TRANS_FILTER);1018 filter = priv->gScreen->filter (NOTHING_TRANS_FILTER);
11481019
1149 if ((!attrib.hasFunctions () && (!priv->gScreen->lighting () ||1020 // add the opengl functions (main) to the shader list, use it, then clear it
1150 attrib.getSaturation () == COLOR || attrib.getSaturation () == 0)) ||1021 addShaders ("opengl", vertex_shader, fragment_shader);
1151 !enableFragmentProgramAndDrawGeometry (priv->gScreen, this, texture,1022 program = priv->gScreen->getProgram (priv->shaders);
1152 attrib, filter, mask))1023 priv->vertexBuffer->setProgram (program);
1153 {1024 priv->shaders.clear ();
1154 enableFragmentOperationsAndDrawGeometry (priv->gScreen, this, texture,1025
1155 attrib, filter, mask);1026 texture->enable (filter);
1156 }1027
1028 #ifdef USE_GLES
1029 priv->vertexBuffer->render (transform, attrib);
1030 #else
1031
1032 if (!GL::vbo)
1033 enableLegacyOBSAndRender (priv->gScreen, this, texture, transform,
1034 attrib, filter, mask);
1035 else
1036 priv->vertexBuffer->render (transform, attrib);
1037 #endif
1038
1039 texture->disable ();
1157}1040}
11581041
1159bool1042bool
1160GLWindow::glDraw (const GLMatrix &transform,1043GLWindow::glDraw (const GLMatrix &transform,
1161 GLFragment::Attrib &fragment,1044 const GLWindowPaintAttrib &attrib,
1162 const CompRegion &region,1045 const CompRegion &region,
1163 unsigned int mask)1046 unsigned int mask)
1164{1047{
1165 WRAPABLE_HND_FUNC_RETURN (1, bool, glDraw, transform,1048 WRAPABLE_HND_FUNC_RETURN (1, bool, glDraw, transform,
1166 fragment, region, mask)1049 attrib, region, mask)
11671050
1168 const CompRegion reg = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ?1051 const CompRegion reg = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ?
1169 infiniteRegion : region;1052 infiniteRegion : region;
@@ -1185,10 +1068,11 @@
1185 if (priv->textures.size () == 1)1068 if (priv->textures.size () == 1)
1186 {1069 {
1187 ml[0] = priv->matrices[0];1070 ml[0] = priv->matrices[0];
1188 priv->geometry.reset ();1071 priv->vertexBuffer->begin ();
1189 glAddGeometry (ml, priv->window->region (), reg);1072 glAddGeometry (ml, priv->window->region (), reg);
1190 if (priv->geometry.vCount)1073 priv->vertexBuffer->end ();
1191 glDrawTexture (priv->textures[0], fragment, mask);1074
1075 glDrawTexture (priv->textures[0], transform, attrib, mask);
1192 }1076 }
1193 else1077 else
1194 {1078 {
@@ -1197,10 +1081,11 @@
1197 for (unsigned int i = 0; i < priv->textures.size (); i++)1081 for (unsigned int i = 0; i < priv->textures.size (); i++)
1198 {1082 {
1199 ml[0] = priv->matrices[i];1083 ml[0] = priv->matrices[i];
1200 priv->geometry.reset ();1084 priv->vertexBuffer->begin ();
1201 glAddGeometry (ml, priv->regions[i], reg);1085 glAddGeometry (ml, priv->regions[i], reg);
1202 if (priv->geometry.vCount)1086 priv->vertexBuffer->end ();
1203 glDrawTexture (priv->textures[i], fragment, mask);1087
1088 glDrawTexture (priv->textures[i], transform, attrib, mask);
1204 }1089 }
1205 }1090 }
12061091
@@ -1215,7 +1100,6 @@
1215{1100{
1216 WRAPABLE_HND_FUNC_RETURN (0, bool, glPaint, attrib, transform, region, mask)1101 WRAPABLE_HND_FUNC_RETURN (0, bool, glPaint, attrib, transform, region, mask)
12171102
1218 GLFragment::Attrib fragment (attrib);
1219 bool status;1103 bool status;
12201104
1221 priv->lastPaint = attrib;1105 priv->lastPaint = attrib;
@@ -1245,18 +1129,7 @@
1245 if (mask & PAINT_WINDOW_NO_CORE_INSTANCE_MASK)1129 if (mask & PAINT_WINDOW_NO_CORE_INSTANCE_MASK)
1246 return true;1130 return true;
12471131
1248 if (mask & PAINT_WINDOW_TRANSFORMED_MASK ||1132 status = glDraw (transform, attrib, region, mask);
1249 mask & PAINT_WINDOW_WITH_OFFSET_MASK)
1250 {
1251 glPushMatrix ();
1252 glLoadMatrixf (transform.getMatrix ());
1253 }
1254
1255 status = glDraw (transform, fragment, region, mask);
1256
1257 if (mask & PAINT_WINDOW_TRANSFORMED_MASK ||
1258 mask & PAINT_WINDOW_WITH_OFFSET_MASK)
1259 glPopMatrix ();
12601133
1261 return status;1134 return status;
1262}1135}
12631136
=== removed file 'plugins/opengl/src/privatefragment.h'
--- plugins/opengl/src/privatefragment.h 2009-03-15 05:09:18 +0000
+++ plugins/opengl/src/privatefragment.h 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
1/*
2 * Copyright © 2008 Dennis Kasprzyk
3 * Copyright © 2007 Novell, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior permission.
12 * Dennis Kasprzyk makes no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without express or
14 * implied warranty.
15 *
16 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
22 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 *
24 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
25 * David Reveman <davidr@novell.com>
26 */
27
28#ifndef _PRIVATEFRAGMENT_H
29#define _PRIVATEFRAGMENT_H
30
31#include <vector>
32
33#include <opengl/fragment.h>
34
35namespace GLFragment {
36
37 class Function;
38 class Program;
39
40 class Storage {
41 public:
42 Storage ();
43 ~Storage ();
44
45 public:
46 int lastFunctionId;
47 std::vector<Function *> functions;
48 std::vector<Program *> programs;
49
50 FunctionId saturateFunction[2][64];
51 };
52};
53
54#endif
550
=== modified file 'plugins/opengl/src/privates.h'
--- plugins/opengl/src/privates.h 2009-03-16 09:18:16 +0000
+++ plugins/opengl/src/privates.h 2011-08-10 17:09:44 +0000
@@ -32,8 +32,8 @@
32#include <opengl/opengl.h>32#include <opengl/opengl.h>
33#include <core/atoms.h>33#include <core/atoms.h>
3434
35#include "privatefragment.h"
36#include "privatetexture.h"35#include "privatetexture.h"
36#include "privatevertexbuffer.h"
37#include "opengl_options.h"37#include "opengl_options.h"
3838
39extern CompOutput *targetOutput;39extern CompOutput *targetOutput;
@@ -72,8 +72,9 @@
7272
73 void waitForVideoSync ();73 void waitForVideoSync ();
7474
75 void paintBackground (const CompRegion &region,75 void paintBackground (const GLMatrix &transform,
76 bool transformed);76 const CompRegion &region,
77 bool transformed);
7778
78 void paintOutputRegion (const GLMatrix &transform,79 void paintOutputRegion (const GLMatrix &transform,
79 const CompRegion &region,80 const CompRegion &region,
@@ -91,7 +92,9 @@
9192
92 GLenum textureFilter;93 GLenum textureFilter;
9394
95 #ifndef USE_GLES
94 GLFBConfig glxPixmapFBConfigs[MAX_DEPTH + 1];96 GLFBConfig glxPixmapFBConfigs[MAX_DEPTH + 1];
97 #endif
9598
96 GLTexture::List backgroundTextures;99 GLTexture::List backgroundTextures;
97 bool backgroundLoaded;100 bool backgroundLoaded;
@@ -100,16 +103,19 @@
100103
101 CompPoint rasterPos;104 CompPoint rasterPos;
102105
103 GLFragment::Storage fragmentStorage;106 GLMatrix *projection;
104
105 GLfloat projection[16];
106107
107 bool clearBuffers;108 bool clearBuffers;
108 bool lighting;109 bool lighting;
109110
111 #ifdef USE_GLES
112 EGLContext ctx;
113 EGLSurface surface;
114 #else
115 GLXContext ctx;
116
110 GL::GLXGetProcAddressProc getProcAddress;117 GL::GLXGetProcAddressProc getProcAddress;
111118 #endif
112 GLXContext ctx;
113119
114 CompRegion outputRegion;120 CompRegion outputRegion;
115121
@@ -121,6 +127,8 @@
121 bool hasCompositing;127 bool hasCompositing;
122128
123 GLIcon defaultIcon;129 GLIcon defaultIcon;
130
131 GLProgramCache *programCache;
124};132};
125133
126class PrivateGLWindow :134class PrivateGLWindow :
@@ -163,10 +171,14 @@
163171
164 unsigned int lastMask;172 unsigned int lastMask;
165173
166 GLWindow::Geometry geometry;174 GLVertexBuffer *vertexBuffer;
175
176 // map of shaders, plugin name is key, pair of vertex and fragment
177 // shader source code is value
178 std::list<GLShaderData*> shaders;
167179
168 std::list<GLIcon> icons;180 std::list<GLIcon> icons;
169};181};
170182
171
172#endif183#endif
184
173185
=== modified file 'plugins/opengl/src/privatetexture.h'
--- plugins/opengl/src/privatetexture.h 2009-08-27 20:04:20 +0000
+++ plugins/opengl/src/privatetexture.h 2011-08-10 17:09:44 +0000
@@ -1,6 +1,7 @@
1/*1/*
2 * Copyright © 2008 Dennis Kasprzyk2 * Copyright © 2008 Dennis Kasprzyk
3 * Copyright © 2007 Novell, Inc.3 * Copyright © 2007 Novell, Inc.
4 * Copyright © 2011 Linaro Ltd.
4 *5 *
5 * Permission to use, copy, modify, distribute, and sell this software6 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without7 * and its documentation for any purpose is hereby granted without
@@ -23,6 +24,7 @@
23 *24 *
24 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>25 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
25 * David Reveman <davidr@novell.com>26 * David Reveman <davidr@novell.com>
27 * Travis Watkins <travis.watkins@linaro.org>
26 */28 */
2729
28#ifndef _PRIVATETEXTURE_H30#ifndef _PRIVATETEXTURE_H
@@ -30,8 +32,15 @@
3032
31#include <map>33#include <map>
3234
35#ifdef USE_GLES
36#define SUPPORT_X11
37#include <GLES2/gl2.h>
38#include <EGL/egl.h>
39#include <EGL/eglext.h>
40#else
33#include <GL/gl.h>41#include <GL/gl.h>
34#include <GL/glx.h>42#include <GL/glx.h>
43#endif
35#include <opengl/texture.h>44#include <opengl/texture.h>
3645
37class GLScreen;46class GLScreen;
@@ -61,6 +70,28 @@
61 int refCount;70 int refCount;
62};71};
6372
73#ifdef USE_GLES
74class EglTexture : public GLTexture {
75 public:
76 EglTexture ();
77 ~EglTexture ();
78
79 void enable (Filter filter);
80
81 static List bindPixmapToTexture (Pixmap pixmap,
82 int width,
83 int height,
84 int depth);
85
86 public:
87 bool damaged;
88 Damage damage;
89 bool updateMipMap;
90};
91
92extern std::map<Damage, EglTexture*> boundPixmapTex;
93#else
94
64class TfpTexture : public GLTexture {95class TfpTexture : public GLTexture {
65 public:96 public:
66 TfpTexture ();97 TfpTexture ();
@@ -81,5 +112,6 @@
81};112};
82113
83extern std::map<Damage, TfpTexture*> boundPixmapTex;114extern std::map<Damage, TfpTexture*> boundPixmapTex;
115#endif
84116
85#endif117#endif
86118
=== added file 'plugins/opengl/src/privatevertexbuffer.h'
--- plugins/opengl/src/privatevertexbuffer.h 1970-01-01 00:00:00 +0000
+++ plugins/opengl/src/privatevertexbuffer.h 2011-08-10 17:09:44 +0000
@@ -0,0 +1,71 @@
1/*
2 * Copyright © 2011 Linaro Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Linaro Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Linaro Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Travis Watkins <travis.watkins@linaro.org>
24 */
25
26#ifndef _VERTEXBUFFER_PRIVATE_H
27#define _VERTEXBUFFER_PRIVATE_H
28
29#ifdef USE_GLES
30#include <GLES2/gl2.h>
31#else
32#include <GL/gl.h>
33#endif
34
35#include <opengl/program.h>
36
37class GLVertexBuffer;
38
39class PrivateVertexBuffer
40{
41 public:
42 PrivateVertexBuffer ();
43 ~PrivateVertexBuffer ();
44
45 int render (const GLMatrix &projection,
46 const GLMatrix &modelview,
47 const GLWindowPaintAttrib &attrib);
48 int legacyRender (const GLMatrix &projection,
49 const GLMatrix &modelview,
50 const GLWindowPaintAttrib &attrib);
51
52 public:
53 static GLVertexBuffer *streamingBuffer;
54
55 std::vector<GLfloat> vertexData;
56 std::vector<GLfloat> normalData;
57 std::vector<GLfloat> colorData;
58 std::vector<std::vector<GLfloat> > textureData;
59
60 GLProgram *program;
61 GLenum primitiveType;
62 GLenum usage;
63
64 GLuint vertexBuffer;
65 GLuint normalBuffer;
66 GLuint colorBuffer;
67 std::vector<GLuint> textureBuffers;
68};
69
70#endif //_VERTEXBUFFER_PRIVATE_H
71
072
=== added file 'plugins/opengl/src/program.cpp'
--- plugins/opengl/src/program.cpp 1970-01-01 00:00:00 +0000
+++ plugins/opengl/src/program.cpp 2011-08-10 17:09:44 +0000
@@ -0,0 +1,225 @@
1/*
2 * Copyright © 2011 Linaro Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Linaro Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Linaro Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Travis Watkins <travis.watkins@linaro.org>
24 */
25
26#define GL_GLEXT_PROTOTYPES
27
28#include <iostream>
29#include <fstream>
30#include <opengl/program.h>
31
32class PrivateProgram
33{
34 public:
35 GLuint program;
36 bool valid;
37};
38
39
40void printShaderInfoLog (GLuint shader)
41{
42 GLint length = 0;
43 GLint chars = 0;
44 GLchar *infoLog;
45
46 glGetShaderiv (shader, GL_INFO_LOG_LENGTH, &length);
47
48 if (length > 0)
49 {
50 infoLog = new GLchar[length];
51 glGetShaderInfoLog (shader, length, &chars, infoLog);
52 std::cout << infoLog << std::endl;
53 delete[] infoLog;
54 }
55}
56
57void printProgramInfoLog(GLuint program)
58{
59 GLint length = 0;
60 GLint chars = 0;
61 GLchar *infoLog;
62
63 glGetProgramiv (program, GL_INFO_LOG_LENGTH, &length);
64
65 if (length > 0)
66 {
67 infoLog = new GLchar[length];
68 glGetProgramInfoLog (program, length, &chars, infoLog);
69 std::cout << infoLog << std::endl;
70 delete[] infoLog;
71 }
72}
73
74static bool compileShader (GLuint *shader, GLenum type, CompString &source)
75{
76 const GLchar *data;
77 GLint status;
78
79 data = (GLchar *)source.c_str ();
80
81 *shader = glCreateShader (type);
82 glShaderSource (*shader, 1, &data, NULL);
83 glCompileShader (*shader);
84
85 glGetShaderiv (*shader, GL_COMPILE_STATUS, &status);
86 return (status == GL_TRUE);
87}
88
89GLProgram::GLProgram (CompString &vertexShader, CompString &fragmentShader) :
90 priv (new PrivateProgram ())
91{
92 GLuint vertex, fragment;
93 GLint status;
94
95 priv->valid = false;
96 priv->program = glCreateProgram ();
97
98 if (!compileShader (&vertex, GL_VERTEX_SHADER, vertexShader))
99 {
100 printShaderInfoLog (vertex);
101 std::cout << vertexShader << std::endl << std::endl;
102 return;
103 }
104
105 if (!compileShader (&fragment, GL_FRAGMENT_SHADER, fragmentShader))
106 {
107 printShaderInfoLog (fragment);
108 std::cout << fragmentShader << std::endl << std::endl;
109 return;
110 }
111
112 glAttachShader (priv->program, vertex);
113 glAttachShader (priv->program, fragment);
114
115 glLinkProgram (priv->program);
116 glValidateProgram (priv->program);
117
118 glGetProgramiv (priv->program, GL_LINK_STATUS, &status);
119 if (status == GL_FALSE)
120 {
121 printProgramInfoLog (priv->program);
122 return;
123 }
124
125 glDeleteShader (vertex);
126 glDeleteShader (fragment);
127
128 priv->valid = true;
129}
130
131GLProgram::~GLProgram ()
132{
133 glDeleteProgram (priv->program);
134 delete priv;
135}
136
137bool GLProgram::valid ()
138{
139 return priv->valid;
140}
141
142void GLProgram::bind ()
143{
144 glUseProgram (priv->program);
145}
146
147void GLProgram::unbind ()
148{
149 glUseProgram (0);
150}
151
152bool GLProgram::setUniform (const char *name, GLfloat value)
153{
154 GLint location = glGetUniformLocation (priv->program, name);
155 if (location == -1)
156 return false;
157
158 glUniform1f (location, value);
159 return true;
160}
161
162bool GLProgram::setUniform (const char *name, GLint value)
163{
164 GLint location = glGetUniformLocation (priv->program, name);
165 if (location == -1)
166 return false;
167
168 glUniform1i (location, value);
169 return true;
170}
171
172bool GLProgram::setUniform (const char *name, const GLMatrix &value)
173{
174 GLint location = glGetUniformLocation (priv->program, name);
175 if (location == -1)
176 return false;
177
178 glUniformMatrix4fv (location, 1, GL_FALSE, value.getMatrix ());
179 return true;
180}
181
182bool GLProgram::setUniform2f (const char *name,
183 GLfloat x,
184 GLfloat y)
185{
186 GLint location = glGetUniformLocation (priv->program, name);
187 if (location == -1)
188 return false;
189
190 glUniform2f (location, x, y);
191 return true;
192}
193
194bool GLProgram::setUniform3f (const char *name,
195 GLfloat x,
196 GLfloat y,
197 GLfloat z)
198{
199 GLint location = glGetUniformLocation (priv->program, name);
200 if (location == -1)
201 return false;
202
203 glUniform3f (location, x, y, z);
204 return true;
205}
206
207bool GLProgram::setUniform4f (const char *name,
208 GLfloat x,
209 GLfloat y,
210 GLfloat z,
211 GLfloat w)
212{
213 GLint location = glGetUniformLocation (priv->program, name);
214 if (location == -1)
215 return false;
216
217 glUniform4f (location, x, y, z, w);
218 return true;
219}
220
221GLuint GLProgram::attributeLocation (const char *name)
222{
223 return glGetAttribLocation (priv->program, name);
224}
225
0226
=== added file 'plugins/opengl/src/programcache.cpp'
--- plugins/opengl/src/programcache.cpp 1970-01-01 00:00:00 +0000
+++ plugins/opengl/src/programcache.cpp 2011-08-10 17:09:44 +0000
@@ -0,0 +1,175 @@
1/*
2 * Copyright © 2011 Linaro Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Linaro Ltd. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * Linaro Ltd. makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
14 *
15 * LINARO LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL LINARO LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors: Travis Watkins <travis.watkins@linaro.org>
24 */
25
26#include <opengl/programcache.h>
27#include "privates.h"
28
29typedef std::list<std::string> access_history_t;
30typedef std::pair<GLProgram*, access_history_t::iterator> value;
31
32static GLProgram *
33compileProgram (std::string name, std::list<GLShaderData*> shaders)
34{
35 std::list<GLShaderData*>::iterator it;
36 std::string vertex_shader;
37 std::string fragment_shader;
38 std::string vertex_functions = "";
39 std::string vertex_function_calls = "";
40 std::string fragment_functions = "";
41 std::string fragment_function_calls = "";
42 int vpos, vcallpos, fpos, fcallpos;
43
44 for (it = shaders.begin (); it != shaders.end (); it++)
45 {
46 //find the special shaders to put the rest in
47 if ((*it)->vertex_shader.find ("@VERTEX_FUNCTIONS@") != std::string::npos)
48 {
49 vertex_shader = (*it)->vertex_shader;
50 }
51 else
52 {
53 if ((*it)->vertex_shader.length ())
54 {
55 vertex_functions += (*it)->vertex_shader;
56 vertex_function_calls += (*it)->name + "_vertex();\n";
57 }
58 }
59
60 if ((*it)->fragment_shader.find ("@FRAGMENT_FUNCTIONS@") != std::string::npos)
61 {
62 fragment_shader = (*it)->fragment_shader;
63 }
64 else
65 {
66 if ((*it)->fragment_shader.length ())
67 {
68 fragment_functions += (*it)->fragment_shader;
69 fragment_function_calls += (*it)->name + "_fragment();\n";
70 }
71 }
72 }
73
74 // put shader functions and function calls into the main shader
75 vpos = vertex_shader.find ("@VERTEX_FUNCTIONS@");
76 vertex_shader.replace (vpos, 18, vertex_functions);
77
78 vcallpos = vertex_shader.find ("@VERTEX_FUNCTION_CALLS@");
79 vertex_shader.replace (vcallpos, 23, vertex_function_calls);
80
81 fpos = fragment_shader.find ("@FRAGMENT_FUNCTIONS@");
82 fragment_shader.replace (fpos, 20, fragment_functions);
83
84 fcallpos = fragment_shader.find ("@FRAGMENT_FUNCTION_CALLS@");
85 fragment_shader.replace (fcallpos, 25, fragment_function_calls);
86
87 return new GLProgram (vertex_shader, fragment_shader);
88}
89
90class PrivateProgramCache
91{
92 public:
93 PrivateProgramCache (size_t);
94
95 const size_t capacity;
96 access_history_t access_history;
97 std::map<std::string, value> cache;
98
99 void insert (std::string, GLProgram *);
100 void evict ();
101};
102
103GLProgramCache::GLProgramCache (size_t capacity) :
104 priv (new PrivateProgramCache (capacity))
105{
106 assert (priv->capacity != 0);
107}
108
109GLProgramCache::~GLProgramCache ()
110{
111 delete priv;
112}
113
114GLProgram* GLProgramCache::operator () (std::list<GLShaderData*> shaders)
115{
116 std::list<GLShaderData*>::iterator name_it;
117 std::string name;
118
119 for (name_it = shaders.begin(); name_it != shaders.end(); name_it++)
120 {
121 if (name.length () == 0)
122 name += (*name_it)->name;
123 else
124 name += ":" + (*name_it)->name;
125 }
126
127 std::map<std::string, value>::iterator it = priv->cache.find (name);
128
129 if (it == priv->cache.end ())
130 {
131 GLProgram *program = compileProgram (name, shaders);
132 priv->insert (name, program);
133 return program;
134 }
135 else
136 {
137 priv->access_history.splice (priv->access_history.end (),
138 priv->access_history,
139 (*it).second.second);
140 (*it).second.second = priv->access_history.rbegin ().base ();
141
142 return (*it).second.first;
143 }
144}
145
146PrivateProgramCache::PrivateProgramCache (size_t c) :
147 capacity (c)
148{
149}
150
151void PrivateProgramCache::insert (std::string name, GLProgram *program)
152{
153 assert (cache.find (name) == cache.end ());
154
155 if (cache.size () == capacity)
156 evict ();
157
158 // update most recently used GLProgram
159 access_history_t::iterator it = access_history.insert (access_history.end (), name);
160
161 cache.insert (std::make_pair (name, std::make_pair (program, it)));
162}
163
164void PrivateProgramCache::evict ()
165{
166 assert (!access_history.empty ());
167
168 // find least recently used GLProgram
169 std::map<std::string, value>::iterator it = cache.find (access_history.front ());
170 assert (it != cache.end ());
171
172 cache.erase (it);
173 access_history.pop_front ();
174}
175
0176
=== modified file 'plugins/opengl/src/screen.cpp'
--- plugins/opengl/src/screen.cpp 2011-02-24 07:52:09 +0000
+++ plugins/opengl/src/screen.cpp 2011-08-10 17:09:44 +0000
@@ -1,4 +1,5 @@
1/*1/*
2 * Copyright © 2011 Linaro Ltd.
2 * Copyright © 2008 Dennis Kasprzyk3 * Copyright © 2008 Dennis Kasprzyk
3 * Copyright © 2007 Novell, Inc.4 * Copyright © 2007 Novell, Inc.
4 *5 *
@@ -23,6 +24,7 @@
23 *24 *
24 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>25 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
25 * David Reveman <davidr@novell.com>26 * David Reveman <davidr@novell.com>
27 * Travis Watkins <travis.watkins@linaro.org>
26 */28 */
2729
28#include "privates.h"30#include "privates.h"
@@ -31,6 +33,13 @@
31#include <math.h>33#include <math.h>
3234
33namespace GL {35namespace GL {
36 #ifdef USE_GLES
37 EGLCreateImageKHRProc createImage;
38 EGLDestroyImageKHRProc destroyImage;
39
40 GLEGLImageTargetTexture2DOESProc eglImageTargetTexture;
41 #else
42
34 GLXBindTexImageProc bindTexImage = NULL;43 GLXBindTexImageProc bindTexImage = NULL;
35 GLXReleaseTexImageProc releaseTexImage = NULL;44 GLXReleaseTexImageProc releaseTexImage = NULL;
36 GLXQueryDrawableProc queryDrawable = NULL;45 GLXQueryDrawableProc queryDrawable = NULL;
@@ -42,10 +51,6 @@
42 GLXCreatePixmapProc createPixmap = NULL;51 GLXCreatePixmapProc createPixmap = NULL;
43 GLXDestroyPixmapProc destroyPixmap = NULL;52 GLXDestroyPixmapProc destroyPixmap = NULL;
4453
45 GLActiveTextureProc activeTexture = NULL;
46 GLClientActiveTextureProc clientActiveTexture = NULL;
47 GLMultiTexCoord2fProc multiTexCoord2f = NULL;
48
49 GLGenProgramsProc genPrograms = NULL;54 GLGenProgramsProc genPrograms = NULL;
50 GLDeleteProgramsProc deletePrograms = NULL;55 GLDeleteProgramsProc deletePrograms = NULL;
51 GLBindProgramProc bindProgram = NULL;56 GLBindProgramProc bindProgram = NULL;
@@ -53,6 +58,11 @@
53 GLProgramParameter4fProc programEnvParameter4f = NULL;58 GLProgramParameter4fProc programEnvParameter4f = NULL;
54 GLProgramParameter4fProc programLocalParameter4f = NULL;59 GLProgramParameter4fProc programLocalParameter4f = NULL;
55 GLGetProgramivProc getProgramiv = NULL;60 GLGetProgramivProc getProgramiv = NULL;
61 #endif
62
63 GLActiveTextureProc activeTexture = NULL;
64 GLClientActiveTextureProc clientActiveTexture = NULL;
65 GLMultiTexCoord2fProc multiTexCoord2f = NULL;
5666
57 GLGenFramebuffersProc genFramebuffers = NULL;67 GLGenFramebuffersProc genFramebuffers = NULL;
58 GLDeleteFramebuffersProc deleteFramebuffers = NULL;68 GLDeleteFramebuffersProc deleteFramebuffers = NULL;
@@ -61,6 +71,12 @@
61 GLFramebufferTexture2DProc framebufferTexture2D = NULL;71 GLFramebufferTexture2DProc framebufferTexture2D = NULL;
62 GLGenerateMipmapProc generateMipmap = NULL;72 GLGenerateMipmapProc generateMipmap = NULL;
6373
74 GLBindBufferProc bindBuffer = NULL;
75 GLDeleteBuffersProc deleteBuffers = NULL;
76 GLGenBuffersProc genBuffers = NULL;
77 GLBufferDataProc bufferData = NULL;
78 GLBufferSubDataProc bufferSubData = NULL;
79
64 bool textureFromPixmap = true;80 bool textureFromPixmap = true;
65 bool textureRectangle = false;81 bool textureRectangle = false;
66 bool textureNonPowerOfTwo = false;82 bool textureNonPowerOfTwo = false;
@@ -70,6 +86,7 @@
70 bool textureCompression = false;86 bool textureCompression = false;
71 GLint maxTextureSize = 0;87 GLint maxTextureSize = 0;
72 bool fbo = false;88 bool fbo = false;
89 bool vbo = false;
73 bool fragmentProgram = false;90 bool fragmentProgram = false;
74 GLint maxTextureUnits = 1;91 GLint maxTextureUnits = 1;
7592
@@ -83,6 +100,179 @@
83 PluginClassHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI> (s),100 PluginClassHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI> (s),
84 priv (new PrivateGLScreen (this))101 priv (new PrivateGLScreen (this))
85{102{
103 #ifdef USE_GLES
104 Display *xdpy;
105 Window overlay;
106 EGLDisplay dpy;
107 EGLConfig config;
108 EGLint major, minor;
109 const char *eglExtensions, *glExtensions;
110 XWindowAttributes attr;
111 EGLint count, visualid;
112 EGLConfig configs[1024];
113 CompOption::Vector o (0);
114
115 const EGLint config_attribs[] = {
116 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
117 EGL_RED_SIZE, 1,
118 EGL_GREEN_SIZE, 1,
119 EGL_BLUE_SIZE, 1,
120 EGL_ALPHA_SIZE, 0,
121 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
122 EGL_CONFIG_CAVEAT, EGL_NONE,
123 EGL_NONE,
124 };
125
126 const EGLint context_attribs[] = {
127 EGL_CONTEXT_CLIENT_VERSION, 2,
128 EGL_NONE
129 };
130
131 xdpy = s->dpy ();
132 dpy = eglGetDisplay ((EGLNativeDisplayType)xdpy);
133 if (!eglInitialize (dpy, &major, &minor))
134 {
135 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
136 setFailed ();
137 return;
138 }
139
140 eglBindAPI (EGL_OPENGL_ES_API);
141
142 if (!eglChooseConfig (dpy, config_attribs, configs, 1024, &count))
143 {
144 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
145 setFailed ();
146 return;
147 }
148
149 if (!XGetWindowAttributes (xdpy, s->root (), &attr))
150 {
151 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
152 setFailed ();
153 return;
154 }
155
156 visualid = XVisualIDFromVisual (attr.visual);
157 config = configs[0];
158 for (int i = 0; i < count; i++) {
159 EGLint val;
160 eglGetConfigAttrib (dpy, configs[i], EGL_NATIVE_VISUAL_ID, &val);
161 if (visualid == val) {
162 config = configs[i];
163 break;
164 }
165 }
166
167 overlay = CompositeScreen::get (s)->overlay ();
168 priv->surface = eglCreateWindowSurface (dpy, config, overlay, 0);
169 if (priv->surface == EGL_NO_SURFACE)
170 {
171 compLogMessage ("opengl", CompLogLevelFatal,
172 "eglCreateWindowSurface failed");
173 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
174 setFailed ();
175 return;
176 }
177
178 priv->ctx = eglCreateContext (dpy, config, EGL_NO_CONTEXT, context_attribs);
179 if (priv->ctx == EGL_NO_CONTEXT)
180 {
181 compLogMessage ("opengl", CompLogLevelFatal, "eglCreateContext failed");
182 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
183 setFailed ();
184 return;
185 }
186
187 if (!eglMakeCurrent (dpy, priv->surface, priv->surface, priv->ctx))
188 {
189 compLogMessage ("opengl", CompLogLevelFatal,
190 "eglMakeCurrent failed");
191 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
192 setFailed ();
193 return;
194 }
195
196 eglExtensions = (const char *) eglQueryString (dpy, EGL_EXTENSIONS);
197 glExtensions = (const char *) glGetString (GL_EXTENSIONS);
198
199 if (!glExtensions || !eglExtensions)
200 {
201 compLogMessage ("opengl", CompLogLevelFatal,
202 "No valid GL extensions string found.");
203 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
204 setFailed ();
205 return;
206 }
207
208 GL::textureFromPixmap = true;
209 GL::textureNonPowerOfTwo = true;
210 GL::fbo = true;
211 GL::vbo = true;
212 GL::maxTextureUnits = 4;
213 glGetIntegerv (GL_MAX_TEXTURE_SIZE, &GL::maxTextureSize);
214
215 GL::createImage = (GL::EGLCreateImageKHRProc)
216 eglGetProcAddress ("eglCreateImageKHR");
217 GL::destroyImage = (GL::EGLDestroyImageKHRProc)
218 eglGetProcAddress ("eglDestroyImageKHR");
219 GL::eglImageTargetTexture = (GL::GLEGLImageTargetTexture2DOESProc)
220 eglGetProcAddress ("glEGLImageTargetTexture2DOES");
221
222 if (!strstr (eglExtensions, "EGL_KHR_image_pixmap") ||
223 !strstr (glExtensions, "GL_OES_EGL_image") ||
224 !GL::createImage || !GL::destroyImage || !GL::eglImageTargetTexture)
225 {
226 compLogMessage ("opengl", CompLogLevelFatal,
227 "GL_OES_EGL_image is missing");
228 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
229 setFailed ();
230 return;
231 }
232
233// work around efika supporting GL_BGRA directly instead of via this extension
234#ifndef GL_BGRA
235 if (!strstr (glExtensions, "GL_EXT_texture_format_BGRA8888"))
236 {
237 compLogMessage ("opengl", CompLogLevelFatal,
238 "GL_EXT_texture_format_BGRA8888 is missing");
239 screen->handleCompizEvent ("opengl", "fatal_fallback", o);
240 setFailed ();
241 return;
242 }
243#endif
244
245 GL::activeTexture = glActiveTexture;
246 GL::genFramebuffers = glGenFramebuffers;
247 GL::deleteFramebuffers = glDeleteFramebuffers;
248 GL::bindFramebuffer = glBindFramebuffer;
249 GL::checkFramebufferStatus = glCheckFramebufferStatus;
250 GL::framebufferTexture2D = glFramebufferTexture2D;
251 GL::generateMipmap = glGenerateMipmap;
252
253 GL::bindBuffer = glBindBuffer;
254 GL::deleteBuffers = glDeleteBuffers;
255 GL::genBuffers = glGenBuffers;
256 GL::bufferData = glBufferData;
257 GL::bufferSubData = glBufferSubData;
258
259 glClearColor (0.0, 0.0, 0.0, 1.0);
260 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
261 glEnable (GL_CULL_FACE);
262
263 priv->updateView ();
264
265 priv->lighting = false;
266
267 priv->filter[NOTHING_TRANS_FILTER] = GLTexture::Fast;
268 priv->filter[SCREEN_TRANS_FILTER] = GLTexture::Good;
269 priv->filter[WINDOW_TRANS_FILTER] = GLTexture::Good;
270
271 if (GL::textureFromPixmap)
272 registerBindPixmap (EglTexture::bindPixmapToTexture);
273
274 #else
275
86 Display *dpy = s->dpy ();276 Display *dpy = s->dpy ();
87 XVisualInfo templ;277 XVisualInfo templ;
88 XVisualInfo *visinfo;278 XVisualInfo *visinfo;
@@ -359,6 +549,27 @@
359 GL::fbo = true;549 GL::fbo = true;
360 }550 }
361551
552 if (strstr (glExtensions, "GL_ARB_vertex_buffer_object"))
553 {
554 GL::bindBuffer = (GL::GLBindBufferProc)
555 getProcAddress ("glBindBufferARB");
556 GL::deleteBuffers = (GL::GLDeleteBuffersProc)
557 getProcAddress ("glDeleteBuffersARB");
558 GL::genBuffers = (GL::GLGenBuffersProc)
559 getProcAddress ("glGenBuffersARB");
560 GL::bufferData = (GL::GLBufferDataProc)
561 getProcAddress ("glBufferDataARB");
562 GL::bufferSubData = (GL::GLBufferSubDataProc)
563 getProcAddress ("glBufferSubDataARB");
564
565 if (GL::bindBuffer &&
566 GL::deleteBuffers &&
567 GL::genBuffers &&
568 GL::bufferData &&
569 GL::bufferSubData)
570 GL::vbo = true;
571 }
572
362 if (strstr (glExtensions, "GL_ARB_texture_compression"))573 if (strstr (glExtensions, "GL_ARB_texture_compression"))
363 GL::textureCompression = true;574 GL::textureCompression = true;
364575
@@ -495,7 +706,6 @@
495 glClearColor (0.0, 0.0, 0.0, 1.0);706 glClearColor (0.0, 0.0, 0.0, 1.0);
496 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);707 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
497 glEnable (GL_CULL_FACE);708 glEnable (GL_CULL_FACE);
498 glDisable (GL_BLEND);
499 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);709 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
500 glColor4usv (defaultColor);710 glColor4usv (defaultColor);
501 glEnableClientState (GL_VERTEX_ARRAY);711 glEnableClientState (GL_VERTEX_ARRAY);
@@ -530,14 +740,27 @@
530740
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches