Преглед изворни кода

fixed nvidia transparency issues

naelstrof пре 7 година
родитељ
комит
b185eada2e
8 измењених фајлова са 110 додато и 27 уклоњено
  1. 3
    0
      CMakeLists.txt
  2. 47
    0
      modules/FindXRender.cmake
  3. 1
    4
      src/framebuffer.cpp
  4. 5
    5
      src/glrectangle.cpp
  5. 1
    1
      src/options.cpp
  6. 0
    2
      src/slop.cpp
  7. 49
    15
      src/window.cpp
  8. 4
    0
      src/window.hpp

+ 3
- 0
CMakeLists.txt Прегледај датотеку

@@ -56,17 +56,20 @@ find_package(X11 REQUIRED)
56 56
 find_package(XExt REQUIRED)
57 57
 find_package(GLX REQUIRED)
58 58
 find_package(OpenGL REQUIRED)
59
+find_package(XRender REQUIRED)
59 60
 
60 61
 include_directories(${X11_INCLUDE_DIR}
61 62
                     ${GLM_INCLUDE_DIR}
62 63
                     ${XEXT_INCLUDE_DIR}
63 64
                     ${GLX_INCLUDE_DIR}
65
+		    ${XRENDER_INCLUDE_DIR}
64 66
                     ${OPENGL_INCLUDE_DIR})
65 67
 
66 68
 target_link_libraries(${LIBRARY_NAME} ${X11_LIBRARIES}
67 69
                                       ${GLM_LIBRARIES}
68 70
                                       ${OPENGL_LIBRARIES}
69 71
                                       ${GLX_LIBRARY}
72
+				      ${XRENDER_LIBRARY}
70 73
                                       ${XEXT_LIBRARIES})
71 74
 
72 75
 target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME})

+ 47
- 0
modules/FindXRender.cmake Прегледај датотеку

@@ -0,0 +1,47 @@
1
+# - Find XRender
2
+# Find the XRender libraries
3
+#
4
+# This module defines the following variables:
5
+#   XRENDER_FOUND - true if XRENDER_INCLUDE_DIR & XRENDER_LIBRARY are found
6
+#   XRENDER_LIBRARIES - Set when Xrender_LIBRARY is found
7
+#   XRENDER_INCLUDE_DIRS - Set when Xrender_INCLUDE_DIR is found
8
+#
9
+#   XRENDER_INCLUDE_DIR - where to find Xrender.h, etc.
10
+#   XRENDER_LIBRARY - the Xrender library
11
+#
12
+
13
+#=============================================================================
14
+# Copyright 2013 Corey Clayton <can.of.tuna@gmail.com>
15
+#
16
+# Licensed under the Apache License, Version 2.0 (the "License");
17
+# you may not use this file except in compliance with the License.
18
+# You may obtain a copy of the License at
19
+#
20
+#     http://www.apache.org/licenses/LICENSE-2.0
21
+#
22
+# Unless required by applicable law or agreed to in writing, software
23
+# distributed under the License is distributed on an "AS IS" BASIS,
24
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+# See the License for the specific language governing permissions and
26
+# limitations under the License.
27
+#=============================================================================
28
+
29
+find_path(XRENDER_INCLUDE_DIR NAMES X11/extensions/Xrender.h
30
+          PATHS /opt/X11/include
31
+          DOC "The Xrender include directory")
32
+
33
+find_library(XRENDER_LIBRARY NAMES Xrender
34
+          PATHS /opt/X11/lib
35
+          DOC "The Xrender library")
36
+
37
+include(FindPackageHandleStandardArgs)
38
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Xrender DEFAULT_MSG XRENDER_LIBRARY XRENDER_INCLUDE_DIR)
39
+
40
+if(XRENDER_FOUND)
41
+
42
+    set(XRENDER_LIBRARIES ${XRENDER_LIBRARY})
43
+    set(XRENDER_INCLUDE_DIRS ${XRENDER_INCLUDE_DIR})
44
+
45
+endif()
46
+
47
+mark_as_advanced(XRENDER_INCLUDE_DIR XRENDER_LIBRARY)

+ 1
- 4
src/framebuffer.cpp Прегледај датотеку

@@ -2,7 +2,7 @@
2 2
 
3 3
 slop::Framebuffer::Framebuffer( int w, int h ) {
4 4
     std::string vert = "#version 130\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 uvCoord;\nvoid main()\n{\nuvCoord = uv;\ngl_Position = vec4(position,0,1);\n}\n";
5
-    std::string frag = "#version 130\nuniform sampler2D texture;\nvarying vec2 uvCoord;\nout vec4 outColor;void main()\n{\noutColor = texture2D( texture, uvCoord );\n}\n";
5
+    std::string frag = "#version 130\n uniform sampler2D texture;\n varying vec2 uvCoord;\n out vec4 outColor;\n void main()\n {\n outColor = texture2D( texture, uvCoord );\n }\n";
6 6
     shader = new Shader( vert, frag, false );
7 7
     glGenFramebuffers( 1, &fbuffer );
8 8
     glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
@@ -73,8 +73,6 @@ void slop::Framebuffer::unbind() {
73 73
 }
74 74
 
75 75
 void slop::Framebuffer::draw(){
76
-    glEnable( GL_BLEND );
77
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
78 76
     shader->bind();
79 77
     shader->setParameter( "texture", 0 );
80 78
     shader->setAttribute( "position", buffers[0], 2 );
@@ -84,6 +82,5 @@ void slop::Framebuffer::draw(){
84 82
     glEnable( GL_TEXTURE_2D );
85 83
     glDrawArrays( GL_TRIANGLES, 0, vertCount );
86 84
     glDisable( GL_TEXTURE_2D );
87
-    glDisable( GL_BLEND );
88 85
     shader->unbind();
89 86
 }

+ 5
- 5
src/glrectangle.cpp Прегледај датотеку

@@ -21,8 +21,8 @@ slop::GLRectangle::GLRectangle( glm::vec2 p1, glm::vec2 p2, float border, float
21 21
     our = ur + glm::vec2(border,border);
22 22
     obr = br + glm::vec2(border,-border);
23 23
     generateBuffers();
24
-    std::string vert = "#version 130\nin vec2 position;\nuniform mat4 projection;\nvoid main() {\ngl_Position = projection*vec4(position,0,1);\n }";
25
-    std::string frag = "#version 130\nuniform vec4 color;\nout vec4 outColor;\nvoid main() {\noutColor = color;\n}";
24
+    std::string vert = "#version 130\n in vec2 position;\n uniform mat4 projection;\n void main() {\n gl_Position = projection*vec4(position,0,1);\n }";
25
+    std::string frag = "#version 130\n uniform vec4 color;\n out vec4 outColor;\n void main() {\n outColor = color;\n }";
26 26
 
27 27
     shader = new Shader( vert, frag, false );
28 28
 }
@@ -214,8 +214,8 @@ slop::GLRectangle::~GLRectangle() {
214 214
 }
215 215
 
216 216
 void slop::GLRectangle::draw( glm::mat4& matrix ) {
217
-    glEnable( GL_BLEND );
218
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
217
+    //glEnable( GL_BLEND );
218
+    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
219 219
     shader->bind();
220 220
     shader->setParameter( "projection", matrix );
221 221
     if ( highlight ) {
@@ -238,7 +238,7 @@ void slop::GLRectangle::draw( glm::mat4& matrix ) {
238 238
         glDrawArrays(GL_TRIANGLES, 0, rectangle_vertCount );
239 239
     }
240 240
     shader->unbind();
241
-    glDisable( GL_BLEND );
241
+    //glDisable( GL_BLEND );
242 242
 }
243 243
 
244 244
 glm::vec4 slop::GLRectangle::getRect() {

+ 1
- 1
src/options.cpp Прегледај датотеку

@@ -5,7 +5,7 @@ Options::Options( int argc, char** argv ) {
5 5
     validArguments.push_back( Argument( "padding",      'p', false ) );
6 6
     validArguments.push_back( Argument( "color",        'c', false ) );
7 7
     validArguments.push_back( Argument( "shader",       'r', false ) );
8
-    validArguments.push_back( Argument( "highlight",    'h', true ) );
8
+    validArguments.push_back( Argument( "highlight",    'l', true ) );
9 9
     validArguments.push_back( Argument( "format",       'f', false ) );
10 10
     validArguments.push_back( Argument( "tolerance",    't', false ) );
11 11
     validArguments.push_back( Argument( "nodecorations", 'n', false ) );

+ 0
- 2
src/slop.cpp Прегледај датотеку

@@ -176,8 +176,6 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
176 176
         window->framebuffer->unbind();
177 177
 
178 178
         // Then we draw the framebuffer to the screen
179
-        glClearColor (0.0, 0.0, 0.0, 0.0);
180
-        glClear (GL_COLOR_BUFFER_BIT);
181 179
         window->framebuffer->draw();
182 180
         window->display();
183 181
         GLenum err = glGetError();

+ 49
- 15
src/window.cpp Прегледај датотеку

@@ -3,11 +3,46 @@
3 3
 using namespace slop;
4 4
 
5 5
 slop::SlopWindow::SlopWindow() {
6
-    XVisualInfo visual;
7
-    XMatchVisualInfo(x11->display, DefaultScreen(x11->display), 32, TrueColor, &visual);
6
+    // Load up a opengl context
7
+    static int attributeList[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT,
8
+                                   GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
9
+                                   GLX_DOUBLEBUFFER, True,
10
+                                   GLX_RED_SIZE, 1,
11
+                                   GLX_GREEN_SIZE, 1,
12
+                                   GLX_BLUE_SIZE, 1,
13
+                                   GLX_ALPHA_SIZE, 1,
14
+				   GLX_DEPTH_SIZE, 1,
15
+                                   None };
16
+    int nelements;
17
+    int render_event_base, render_error_base;
18
+    if(!XRenderQueryExtension(x11->display, &render_event_base, &render_error_base)) {
19
+        throw new std::runtime_error("No XRENDER extension found\n");
20
+    }
21
+
22
+    GLXFBConfig* fbc = glXChooseFBConfig(x11->display, DefaultScreen(x11->display), attributeList, &nelements);
23
+    GLXFBConfig fbconfig;
24
+    if ( !fbc ) {
25
+        throw new std::runtime_error("No matching visuals available.\n");
26
+    }
27
+    XVisualInfo* vi ;
28
+    XRenderPictFormat *pictFormat;
29
+    int i;
30
+    for (i=0; i<nelements; i++) {
31
+        vi = glXGetVisualFromFBConfig(x11->display, fbc[i]);
32
+        if (!vi) { continue; }
33
+        pictFormat = XRenderFindVisualFormat(x11->display, vi->visual);
34
+        if (!pictFormat) { continue; }
35
+        if(pictFormat->direct.alphaMask > 0) {
36
+            fbconfig = fbc[i];
37
+            break;
38
+        }
39
+    }
40
+    if (i == nelements ) {
41
+	    throw new std::runtime_error( "No matching visuals available" );
42
+    }
8 43
 
9 44
     XSetWindowAttributes attributes;
10
-    attributes.colormap = XCreateColormap( x11->display, x11->root, visual.visual, AllocNone );
45
+    attributes.colormap = XCreateColormap(x11->display, RootWindow(x11->display, vi->screen), vi->visual, AllocNone);
11 46
     attributes.background_pixmap = None;
12 47
     attributes.border_pixel = 0;
13 48
     // Disable window decorations.
@@ -18,15 +53,15 @@ slop::SlopWindow::SlopWindow() {
18 53
 
19 54
 
20 55
     // Create the window
21
-    window = XCreateWindow( slop::x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
22
-                            0, visual.depth, InputOutput,
23
-                            visual.visual, valueMask, &attributes );
56
+    window = XCreateWindow( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
57
+                            0, vi->depth, InputOutput,
58
+                            vi->visual, valueMask, &attributes );
24 59
 
25 60
     if ( !window ) {
26 61
         throw new std::runtime_error( "Couldn't create a GL window!" );
27 62
     }
28 63
 
29
-	// Prep some hints for the window
64
+    // Prep some hints for the window
30 65
     static char title[] = "slop";
31 66
     XWMHints* startup_state = XAllocWMHints();
32 67
     startup_state->initial_state = NormalState;
@@ -46,18 +81,17 @@ slop::SlopWindow::SlopWindow() {
46 81
     char name[] = "slop";
47 82
     classhints.res_name = name;
48 83
     classhints.res_class = name;
49
-	// Finally send it all over...
84
+    // Finally send it all over...
50 85
     XSetClassHint( x11->display, window, &classhints );
51 86
     XSetWMProperties( x11->display, window, &textprop, &textprop, NULL, 0, &sizehints, startup_state, NULL );
52 87
     XFree( startup_state );
53
-	// Keep the window on top of all other windows.
54
-	Atom stateAbove = XInternAtom(x11->display, "_NET_WM_STATE_ABOVE", False);
55
-	XChangeProperty(x11->display, window, XInternAtom(x11->display, "_NET_WM_STATE", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) &stateAbove, 1);
88
+    // Keep the window on top of all other windows.
89
+    Atom stateAbove = XInternAtom(x11->display, "_NET_WM_STATE_ABOVE", False);
90
+    XChangeProperty(x11->display, window, XInternAtom(x11->display, "_NET_WM_STATE", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) &stateAbove, 1);
56 91
 
57
-    // Load up a opengl context
58
-    context = glXCreateContext( x11->display, &visual, 0, True );
92
+    context = glXCreateNewContext( x11->display, fbconfig, GLX_RGBA_TYPE, 0, True );
59 93
     if ( !context ) {
60
-		throw new std::runtime_error( "Failed to create an OpenGL context." );
94
+        throw new std::runtime_error( "Failed to create an OpenGL context." );
61 95
     }
62 96
     setCurrent();
63 97
     // Finally we grab some OpenGL 3.3 stuffs.
@@ -71,7 +105,7 @@ slop::SlopWindow::SlopWindow() {
71 105
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
72 106
 
73 107
     // Last, we actually display the window <:o)
74
-	XMapWindow( x11->display, window );
108
+    XMapWindow( x11->display, window );
75 109
 }
76 110
 
77 111
 slop::SlopWindow::~SlopWindow() {

+ 4
- 0
src/window.hpp Прегледај датотеку

@@ -27,10 +27,14 @@
27 27
 #include <iostream>
28 28
 #include "gl_core_3_3.h"
29 29
 #include <GL/gl.h>
30
+#define GL_GLEXT_PROTOTYPES
31
+#define GLX_GLXEXT_PROTOTYPES
30 32
 #include <GL/glx.h>
33
+#include <GL/glxext.h>
31 34
 #include <glm/gtc/matrix_transform.hpp>
32 35
 #include <X11/Xutil.h>
33 36
 #include <X11/Xatom.h>
37
+#include <X11/extensions/Xrender.h>
34 38
 
35 39
 #include "x.hpp"
36 40
 #include "framebuffer.hpp"