Commit 326eed21 authored by Ken Martin's avatar Ken Martin

Make X windows default to a 3.2 context

This is so that Mesa will work, but it turns out at least some
of mesa is broken so it just fails differently.

Also some fixes to texture buffer objects.
parent b8a4007f
......@@ -368,29 +368,29 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderColorMaterialValues(
actor->GetProperty()->GetAmbient() > actor->GetProperty()->GetDiffuse()))
{
substitute(FSSource,
"//VTK::Color::Impl", colorImpl +
" vec4 texColor = texelFetchBuffer(textureC, gl_PrimitiveID + PrimitiveIDOffset);\n"
" ambientColor = texColor.rgb;\n"
" opacity = opacity*texColor.a;");
"//VTK::Color::Impl", colorImpl +
" vec4 texColor = texelFetchBuffer(textureC, gl_PrimitiveID + PrimitiveIDOffset);\n"
" ambientColor = texColor.rgb;\n"
" opacity = opacity*texColor.a;");
}
else if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE ||
(this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
actor->GetProperty()->GetAmbient() <= actor->GetProperty()->GetDiffuse()))
{
substitute(FSSource,
"//VTK::Color::Impl", colorImpl +
" vec4 texColor = texelFetchBuffer(textureC, gl_PrimitiveID + PrimitiveIDOffset);\n"
" diffuseColor = texColor.rgb;\n"
" opacity = opacity*texColor.a;");
"//VTK::Color::Impl", colorImpl +
" vec4 texColor = texelFetchBuffer(textureC, gl_PrimitiveID + PrimitiveIDOffset);\n"
" diffuseColor = texColor.rgb;\n"
" opacity = opacity*texColor.a;");
}
else
{
substitute(FSSource,
"//VTK::Color::Impl", colorImpl +
"vec4 texColor = texelFetchBuffer(textureC, gl_PrimitiveID + PrimitiveIDOffset);\n"
" ambientColor = texColor.rgb;\n"
" diffuseColor = texColor.rgb;\n"
" opacity = opacity*texColor.a;");
"//VTK::Color::Impl", colorImpl +
"vec4 texColor = texelFetchBuffer(textureC, gl_PrimitiveID + PrimitiveIDOffset);\n"
" ambientColor = texColor.rgb;\n"
" diffuseColor = texColor.rgb;\n"
" opacity = opacity*texColor.a;");
}
}
substitute(FSSource,"//VTK::Color::Impl", colorImpl);
......@@ -1854,7 +1854,7 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
}
this->CellScalarBuffer->Upload(newColors,
vtkgl::BufferObject::ArrayBuffer);
vtkgl::BufferObject::TextureBuffer);
this->CellScalarTexture->CreateTextureBuffer(
static_cast<unsigned int>(newColors.size()/numComp),
numComp,
......@@ -1912,7 +1912,7 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
}
}
this->CellScalarBuffer->Upload(newColors,
vtkgl::BufferObject::ArrayBuffer);
vtkgl::BufferObject::TextureBuffer);
this->CellScalarTexture->CreateTextureBuffer(
static_cast<unsigned int>(cellCellMap.size()),
numComp,
......@@ -1940,7 +1940,7 @@ void vtkOpenGLPolyDataMapper::BuildCellTextures(
newNorms.push_back(norms[2]);
}
this->CellNormalBuffer->Upload(newNorms,
vtkgl::BufferObject::ArrayBuffer);
vtkgl::BufferObject::TextureBuffer);
this->CellNormalTexture->CreateTextureBuffer(
static_cast<unsigned int>(cellCellMap.size()),
3, VTK_FLOAT,
......
......@@ -246,6 +246,7 @@ vtkTextureObject::vtkTextureObject()
this->BorderColor[1] = 0.0f;
this->BorderColor[2] = 0.0f;
this->BorderColor[3] = 0.0f;
this->BufferObject = 0;
this->ResetFormatAndType();
}
......@@ -1746,17 +1747,18 @@ bool vtkTextureObject::CreateTextureBuffer(unsigned int numValues, int numComps,
this->Height = 1;
this->Depth = 1;
this->NumberOfDimensions = 1;
this->BufferObject = bo;
this->CreateTexture();
this->Bind();
// Source texture data from the PBO.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexBuffer(
this->Target,
this->InternalFormat,
bo->GetHandle());
this->Target,
this->InternalFormat,
this->BufferObject->GetHandle());
vtkOpenGLCheckErrorMacro("failed at glTexBuffer");
......
......@@ -649,6 +649,9 @@ protected:
// used for copying to framebuffer
vtkgl::CellBO *ShaderProgram;
// for texturebuffers we hold on to the Buffer
vtkgl::BufferObject *BufferObject;
private:
vtkTextureObject(const vtkTextureObject&); // Not implemented.
void operator=(const vtkTextureObject&); // Not implemented.
......
......@@ -17,10 +17,9 @@
#include "vtkOpenGLRenderer.h"
#include "vtk_glew.h"
// define GLX_GLXEXT_LEGACY to prevent glx.h to include glxext.h provided by
// the system
//#define GLX_GLXEXT_LEGACY
// Define GLX_GLXEXT_LEGACY to prevent glx.h from including the glxext.h
// provided by the system.
#define GLX_GLXEXT_LEGACY
#include "GL/glx.h"
#include "vtkToolkits.h"
......@@ -43,6 +42,10 @@
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
class vtkXOpenGLRenderWindow;
class vtkRenderWindow;
class vtkXOpenGLRenderWindowInternal
......@@ -52,6 +55,7 @@ private:
vtkXOpenGLRenderWindowInternal(vtkRenderWindow*);
GLXContext ContextId;
GLXFBConfig *FBConfig;
// so we basically have 4 methods here for handling drawables
// how about abstracting this a bit?
......@@ -182,52 +186,17 @@ XVisualInfo *vtkXOpenGLRenderWindowTryForVisual(Display *DisplayId,
int alphaBitPlanes,
int stencil)
{
int index;
static int attributes[50];
GLXFBConfig *fbc = vtkXOpenGLRenderWindowTryForFBConfig(DisplayId,
GLX_WINDOW_BIT,
doublebuff,
stereo, multisamples,
alphaBitPlanes,
stencil);
// setup the default stuff we ask for
index = 0;
attributes[index++] = GLX_RGBA;
attributes[index++] = GLX_RED_SIZE;
attributes[index++] = 1;
attributes[index++] = GLX_GREEN_SIZE;
attributes[index++] = 1;
attributes[index++] = GLX_BLUE_SIZE;
attributes[index++] = 1;
attributes[index++] = GLX_DEPTH_SIZE;
attributes[index++] = 1;
if (alphaBitPlanes)
{
attributes[index++] = GLX_ALPHA_SIZE;
attributes[index++] = 1;
}
if (doublebuff)
{
attributes[index++] = GLX_DOUBLEBUFFER;
}
if (stencil)
{
attributes[index++] = GLX_STENCIL_SIZE;
attributes[index++] = 8;
}
if (stereo)
{
// also try for STEREO
attributes[index++] = GLX_STEREO;
}
if (multisamples)
{
#ifdef GLX_SAMPLE_BUFFERS_SGIS
attributes[index++] = GLX_SAMPLE_BUFFERS_SGIS;
attributes[index++] = 1;
attributes[index++] = GLX_SAMPLES_SGIS;
attributes[index++] = multisamples;
#endif
}
XVisualInfo *v = glXGetVisualFromFBConfig( DisplayId, fbc[0]);
XFree (fbc);
attributes[index++] = None;
return glXChooseVisual(DisplayId, XDefaultScreen(DisplayId), attributes );
return v;
}
GLXFBConfig *vtkXOpenGLRenderWindowGetDesiredFBConfig(
......@@ -296,10 +265,6 @@ GLXFBConfig *vtkXOpenGLRenderWindowGetDesiredFBConfig(
XVisualInfo *vtkXOpenGLRenderWindow::GetDesiredVisualInfo()
{
XVisualInfo *v = NULL;
int alpha;
int multi;
int stereo = 0;
int stencil;
// get the default display connection
if (!this->DisplayId)
......@@ -316,62 +281,29 @@ XVisualInfo *vtkXOpenGLRenderWindow::GetDesiredVisualInfo()
this->OwnDisplay = 1;
}
// try every possibility stoping when we find one that works
for (stencil = this->StencilCapable; !v && stencil >= 0; stencil--)
this->Internal->FBConfig =
vtkXOpenGLRenderWindowGetDesiredFBConfig(
this->DisplayId,
this->StereoCapableWindow,
this->MultiSamples,
this->DoubleBuffer,
this->AlphaBitPlanes,
GLX_WINDOW_BIT,
this->StencilCapable);
if (!this->Internal->FBConfig)
{
for (alpha = this->AlphaBitPlanes; !v && alpha >= 0; alpha--)
{
for (stereo = this->StereoCapableWindow; !v && stereo >= 0; stereo--)
{
for (multi = this->MultiSamples; !v && multi >= 0; multi--)
{
if (v)
{
XFree(v);
}
v = vtkXOpenGLRenderWindowTryForVisual(this->DisplayId,
this->DoubleBuffer,
stereo, multi, alpha,
stencil);
if (v)
{
this->StereoCapableWindow = stereo;
this->MultiSamples = multi;
this->AlphaBitPlanes = alpha;
this->StencilCapable = stencil;
}
}
}
}
vtkErrorMacro(<< "Could not find a decent config\n");
}
for (stencil = this->StencilCapable; !v && stencil >= 0; stencil--)
else
{
for (alpha = this->AlphaBitPlanes; !v && alpha >= 0; alpha--)
v = glXGetVisualFromFBConfig( this->DisplayId,
this->Internal->FBConfig[0]);
if (!v)
{
for (stereo = this->StereoCapableWindow; !v && stereo >= 0; stereo--)
{
for (multi = this->MultiSamples; !v && multi >= 0; multi--)
{
v = vtkXOpenGLRenderWindowTryForVisual(this->DisplayId,
!this->DoubleBuffer,
stereo, multi, alpha,
stencil);
if (v)
{
this->DoubleBuffer = !this->DoubleBuffer;
this->StereoCapableWindow = stereo;
this->MultiSamples = multi;
this->AlphaBitPlanes = alpha;
this->StencilCapable = stencil;
}
}
}
vtkErrorMacro(<< "Could not find a decent visual\n");
}
}
if (!v)
{
vtkErrorMacro(<< "Could not find a decent visual\n");
}
return ( v );
}
......@@ -532,6 +464,7 @@ void vtkXOpenGLRenderWindow::CreateAWindow()
// create our own window ?
this->OwnWindow = 0;
GLXFBConfig* fb = NULL;
if (!this->WindowId)
{
v = this->GetDesiredVisualInfo();
......@@ -601,7 +534,41 @@ void vtkXOpenGLRenderWindow::CreateAWindow()
}
}
if (!this->Internal->ContextId)
// try for 32 context
if (this->Internal->FBConfig)
{
// NOTE: It is not necessary to create or make current to a context before
// calling glXGetProcAddressARB
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};
if (glXCreateContextAttribsARB)
{
this->Internal->ContextId =
glXCreateContextAttribsARB( this->DisplayId,
this->Internal->FBConfig[0], 0,
GL_TRUE, context_attribs );
// Sync to ensure any errors generated are processed.
XSync( this->DisplayId, False );
if ( this->Internal->ContextId )
{
this->SetContextSupportsOpenGL32(true);
}
}
}
// old failsafe
if (this->Internal->ContextId == NULL)
{
this->Internal->ContextId =
glXCreateContext(this->DisplayId, v, 0, GL_TRUE);
......@@ -1643,7 +1610,7 @@ const char* vtkXOpenGLRenderWindow::ReportCapabilities()
strm << "OpenGL version string: " << glVersion << endl;
strm << "OpenGL extensions: " << endl;
int n = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num);
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
for (int i = 0; i < n; i++)
{
const char *ext = (const char *)glGetStringi(GL_EXTENSIONS, i);
......
......@@ -27,6 +27,8 @@ inline GLenum convertType(BufferObject::ObjectType type)
return GL_ARRAY_BUFFER;
case BufferObject::ElementArrayBuffer:
return GL_ELEMENT_ARRAY_BUFFER;
case BufferObject::TextureBuffer:
return GL_TEXTURE_BUFFER;
}
}
}
......@@ -41,14 +43,7 @@ struct BufferObject::Private
BufferObject::BufferObject(ObjectType type)
: d(new Private), Dirty(true)
{
if (type == ArrayBuffer)
{
this->d->type = GL_ARRAY_BUFFER;
}
else
{
this->d->type = GL_ELEMENT_ARRAY_BUFFER;
}
this->d->type = convertType(type);
}
BufferObject::~BufferObject()
......@@ -76,10 +71,14 @@ BufferObject::ObjectType BufferObject::GetType() const
{
return ArrayBuffer;
}
else
if (this->d->type == GL_ELEMENT_ARRAY_BUFFER)
{
return ElementArrayBuffer;
}
else
{
return TextureBuffer;
}
}
int BufferObject::GetHandle() const
......
......@@ -31,7 +31,8 @@ class VTKRENDERINGOPENGL2_EXPORT BufferObject
public:
enum ObjectType {
ArrayBuffer,
ElementArrayBuffer
ElementArrayBuffer,
TextureBuffer
};
BufferObject(ObjectType type = ArrayBuffer);
......
......@@ -48,16 +48,23 @@
# else
/* Use the glew library configured for VTK. */
#cmakedefine VTK_USE_SYSTEM_GLEW
//#cmakedefine VTK_USE_X
# ifdef VTK_USE_SYSTEM_GLEW
# include <GL/glew.h>
# ifdef WIN32
# include <GL/wglew.h>
# endif
//# ifdef VTK_USE_X
//# include <GL/glxew.h>
//# endif
# else
# include <vtkglew/include/GL/glew.h>
# ifdef WIN32
# include <vtkglew/include/GL/wglew.h>
# endif
//# ifdef VTK_USE_X
//# include <vtkglew/include/GL/glxew.h>
//# endif
# endif
# endif
#endif
......
......@@ -5,24 +5,24 @@
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
......@@ -56,7 +56,7 @@
/*
** Copyright (c) 2007 The Khronos Group Inc.
**
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
......@@ -64,10 +64,10 @@
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
......@@ -142,7 +142,7 @@ typedef struct __glXContextRec *GLXContext;
typedef struct __GLXcontextRec *GLXContext;
#endif
typedef unsigned int GLXVideoDeviceNV;
typedef unsigned int GLXVideoDeviceNV;
extern Bool glXQueryExtension (Display *dpy, int *errorBase, int *eventBase);
extern Bool glXQueryVersion (Display *dpy, int *major, int *minor);
......@@ -264,21 +264,21 @@ typedef XID GLXWindow;
typedef struct __GLXFBConfigRec *GLXFBConfig;
typedef struct {
int event_type;
int draw_type;
unsigned long serial;
Bool send_event;
Display *display;
GLXDrawable drawable;
unsigned int buffer_mask;
unsigned int aux_buffer;
int x, y;
int width, height;
int count;
int event_type;
int draw_type;
unsigned long serial;
Bool send_event;
Display *display;
GLXDrawable drawable;
unsigned int buffer_mask;
unsigned int aux_buffer;
int x, y;
int width, height;
int count;
} GLXPbufferClobberEvent;
typedef union __GLXEvent {
GLXPbufferClobberEvent glxpbufferclobber;
long pad[24];
GLXPbufferClobberEvent glxpbufferclobber;
long pad[24];
} GLXEvent;
typedef GLXFBConfig* ( * PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements);
......@@ -1244,32 +1244,32 @@ typedef XVisualInfo* ( * PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) (Display *dpy, GLX
#define GLX_HYPERPIPE_ID_SGIX 0x8030
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int networkId;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int networkId;
} GLXHyperpipeNetworkSGIX;
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int XOrigin;
int YOrigin;
int maxHeight;
int maxWidth;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int XOrigin;
int YOrigin;
int maxHeight;
int maxWidth;
} GLXPipeRectLimits;
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int channel;
unsigned int participationType;
int timeSlice;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int channel;
unsigned int participationType;
int timeSlice;
} GLXHyperpipeConfigSGIX;
typedef struct {
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int srcXOrigin;
int srcYOrigin;
int srcWidth;
int srcHeight;
int destXOrigin;
int destYOrigin;
int destWidth;
int destHeight;
char pipeName[GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX];
int srcXOrigin;
int srcYOrigin;
int srcWidth;
int srcHeight;
int destXOrigin;
int destYOrigin;
int destWidth;
int destHeight;
} GLXPipeRect;
typedef int ( * PFNGLXBINDHYPERPIPESGIXPROC) (Display *dpy, int hpId);
......
......@@ -5,24 +5,24 @@
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE