Commit b8906443 authored by Jan Möbius's avatar Jan Möbius
Browse files
parents cd161990 5875bf0c
......@@ -533,7 +533,7 @@ public:
//===========================================================================
/**
* Simple wrapper around glGenBuffersARB.
* Simple wrapper around glGenBuffers.
* Useful where glew cannot be included.
*/
static void genBuffersARB(GLsizei n, GLuint* buffers);
......@@ -545,7 +545,7 @@ public:
static void genBuffers(GLsizei n, GLuint* buffers);
/**
* Simple wrapper around glBufferDataARB.
* Simple wrapper around glBufferData.
* Useful where glew cannot be included.
*/
static void bufferDataARB(
......
......@@ -921,7 +921,7 @@ void ShaderProgGenerator::init( const ShaderGenDesc* _desc, ShaderModifier* cons
desc_ = *_desc;
// We need at least version 3.2 or higher to support geometry shaders
if ( !ACG::openGLVersion(3,2) )
if ( !ACG::openGLVersionTest(3,2) )
{
if (!desc_.geometryTemplateFile.isEmpty())
std::cerr << "Warning: removing geometry shader from ShaderDesc" << std::endl;
......@@ -930,7 +930,7 @@ void ShaderProgGenerator::init( const ShaderGenDesc* _desc, ShaderModifier* cons
}
// We need at least version 4.0 or higher to support tessellation
if ( !ACG::openGLVersion(4, 0) )
if ( !ACG::openGLVersionTest(4, 0) )
{
if (!desc_.tessControlTemplateFile.isEmpty() || !desc_.tessEvaluationTemplateFile.isEmpty())
std::cerr << "Warning: removing tessellation shader from ShaderDesc" << std::endl;
......@@ -1039,6 +1039,9 @@ void ShaderProgGenerator::initGenDefines(ShaderGenerator* _gen)
std::cout << __FUNCTION__ << " -> unknown shade mode: " << desc_.shadeMode << std::endl;
}
if (desc_.twoSidedLighting)
_gen->addDefine("TWO_SIDED_LIGHTING 1");
if (desc_.textured())
_gen->addDefine("SG_TEXTURED 1");
......@@ -2761,9 +2764,8 @@ QString ShaderGenDesc::toString() const
resStrm << "}";
}
}
resStrm << "\nshaderDesc.shadeMode: " << shadeModeString[shadeMode];
resStrm << "\nshaderDesc.twoSidedLighting: " << (twoSidedLighting ? "Yes" : "No");
resStrm << "\nshaderDesc.vertexColors: " << vertexColors;
resStrm << "\nshaderDesc.textured(): " << textured();
for (std::map<size_t,TextureType>::const_iterator iter = textureTypes_.begin(); iter != textureTypes_.end();++iter)
......
......@@ -93,6 +93,7 @@ public:
ShaderGenDesc() :
version(150),
numLights(0),
twoSidedLighting(false),
shadeMode(SG_SHADE_UNLIT),
vertexColors(false),
vertexTemplateFile(""),
......@@ -110,6 +111,19 @@ public:
{
for ( unsigned int i = 0 ; i < SG_MAX_SHADER_LIGHTS ; ++i)
lightTypes[i] = SG_LIGHT_DIRECTIONAL;
if(!ACG::openGLVersionTest(3,2)) // version 140 or less
{
if(!ACG::openGLVersionTest(3,1)) // assume version 130
{ // less is not supported
version = 130;
if(ACG::checkExtensionSupported("EXT_texture_buffer"))
macros.append("#extension GL_EXT_texture_buffer: enable");
}
else // version 140 texture buffer is part of spec
{
version = 140;
}
}
}
//In case, something crashes with the light types, try this hammer ;-)
......@@ -118,6 +132,7 @@ public:
// version = _rhs.version;
//
// numLights = _rhs.numLights;
// twoSidedLighting = _rhs.twoSidedLighting;
//
// std::copy(_rhs.lightTypes,_rhs.lightTypes+SG_MAX_SHADER_LIGHTS,lightTypes);
// textureTypes_ = _rhs.textureTypes_;
......@@ -144,6 +159,8 @@ public:
int numLights;
ShaderGenLightType lightTypes[SG_MAX_SHADER_LIGHTS];
bool twoSidedLighting;
ShaderGenShadeMode shadeMode;
bool vertexColors;
......@@ -267,6 +284,9 @@ public:
if (numLights != _rhs.numLights)
return false;
if ( twoSidedLighting != _rhs.twoSidedLighting )
return false;
if (shadeMode != _rhs.shadeMode)
return false;
......
......@@ -468,7 +468,14 @@ void VertexDeclaration::activateShaderPipeline(GLSL::Program* _prog) const
if (supportsInstancedArrays())
{
glVertexAttribDivisor(loc, pElem->divisor_);
if( openGLVersionTest(3,3) )
{
glVertexAttribDivisor(loc, pElem->divisor_);
}
else
{
glVertexAttribDivisorARB(loc, pElem->divisor_);
}
}
else if (pElem->divisor_)
std::cerr << "error: VertexDeclaration::activateShaderPipeline - instanced arrays not supported by gpu!" << std::endl;
......@@ -500,7 +507,14 @@ void VertexDeclaration::deactivateShaderPipeline( GLSL::Program* _prog ) const
if (supportsInstancedArrays() && pElem->divisor_)
{
glVertexAttribDivisor(loc, 0);
if( openGLVersionTest(3,3) )
{
glVertexAttribDivisor(loc, 0);
}
else
{
glVertexAttribDivisorARB(loc, 0);
}
}
}
}
......
......@@ -126,7 +126,7 @@ bool checkExtensionSupported( const std::string& _extension ) {
/** Check if OpenGL Version is greater or equal than the given values
*/
bool openGLVersion( const int _major, const int _minor ) {
bool openGLVersion( const int _major, const int _minor, bool _verbose ) {
// Read OpenGL Version string
std::string glVersionString = (const char*)glGetString(GL_VERSION);
......@@ -148,8 +148,11 @@ bool openGLVersion( const int _major, const int _minor ) {
stream >> minor;
if ( (_major > major) || ( (_major == major) && (_minor > minor)) ) {
std::cerr << "OpenGL Version check failed. Required : " << _major << "." << _minor << std::endl;
std::cerr << "OpenGL Version check failed. Available : " << major << "." << minor << std::endl;
if(_verbose)
{
std::cerr << "OpenGL Version check failed. Required : " << _major << "." << _minor << std::endl;
std::cerr << "OpenGL Version check failed. Available : " << major << "." << minor << std::endl;
}
return false;
}
......
......@@ -269,7 +269,12 @@ bool ACGDLLEXPORT checkExtensionSupported( const std::string& _extension ) ;
/** Check if OpenGL Version is greater or equal than the given values
*/
bool ACGDLLEXPORT openGLVersion( const int _major, const int _minor );
bool ACGDLLEXPORT openGLVersion( const int _major, const int _minor, bool verbose = true );
/** Test if OpenGL Version is greater or equal than the given values
* No output is generated, if the OpenGL version is less than the tested value
*/
inline bool ACGDLLEXPORT openGLVersionTest( const int _major, const int _minor ){return openGLVersion(_major, _minor, false);}
/// Store opengl core profile setting
void ACGDLLEXPORT compatibilityProfile(bool _compatProfile);
......
......@@ -188,7 +188,7 @@ bool Texture::supportsTextureBuffer()
if (status < 0)
{
// core in version 3.0
status = checkExtensionSupported("ARB_texture_buffer_object") || openGLVersion(3,0);
status = checkExtensionSupported("EXT_texture_buffer") || openGLVersion(3,1);
}
return status > 0;
......@@ -320,13 +320,16 @@ Texture2D::Texture2D(GLenum unit)
bool Texture2D::autogenerateMipMaps()
{
if(openGLVersion(3,0))
{
// From OpenGL 3.0, glGenerateMipmap is supported and we should use that
// but glGenerateMipmap must be called AFTER the data was uploaded.
return false;
}
#ifdef GL_SGIS_generate_mipmap
if (supportsGenerateMipmap())
{
//parameter based mipmap generation was removed in 3.1
if( openGLVersion(3,1))
glGenerateMipmap(GL_TEXTURE_2D);
else
parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
return true;
}
......@@ -349,13 +352,14 @@ void Texture2D::disableAutogenerateMipMaps()
//-----------------------------------------------------------------------------
void Texture2D::setData(GLint _level,
GLint _internalFormat,
GLsizei _width,
GLsizei _height,
void Texture2D::setData(GLint _level,
GLint _internalFormat,
GLsizei _width,
GLsizei _height,
GLenum _format,
GLenum _type,
const GLvoid* _data) {
const GLvoid* _data,
bool _mipmaps) {
if (getUnit() == GL_NONE)
setUnit(GL_TEXTURE0);
......@@ -367,6 +371,10 @@ void Texture2D::setData(GLint _level,
else
glTexImage2D(GL_TEXTURE_2D, _level, _internalFormat, _width, _height, 0, _format, _type, _data);
// If mip maps should not be built on cpu and the OpenGL version is high enough, we go the default way
if(_mipmaps && !buildMipsCPU_ && openGLVersion(3,0))
glGenerateMipmap(GL_TEXTURE_2D);
width_ = _width;
height_ = _height;
internalFormat_ = _internalFormat;
......@@ -640,9 +648,9 @@ bool Texture2D::loadFromFile( const std::string& _filename, GLenum _minFilter, G
if (mipmaps)
autogenerateMipMaps();
QImage gltex = ACG::Util::convertToGLFormat(gltex);
QImage gltex = ACG::Util::convertToGLFormat(qtex);
setData(0, GL_RGBA, gltex.width(), gltex.height(), GL_RGBA, GL_UNSIGNED_BYTE, gltex.bits());
setData(0, GL_RGBA, gltex.width(), gltex.height(), GL_RGBA, GL_UNSIGNED_BYTE, gltex.bits(), mipmaps);
}
}
......@@ -794,8 +802,6 @@ TextureBuffer::~TextureBuffer() {
void TextureBuffer::setBufferData(
size_t _size, const void* _data, GLenum _internalFormat, GLenum _usage) {
if(!ACG::compatibilityProfile())
{
if (supportsTextureBuffer()) {
// setup buffer object
if (!buffer_)
......@@ -819,9 +825,6 @@ if(!ACG::compatibilityProfile())
}
else
std::cerr << "TextureBuffer::setData - gpu does not support buffer textures!" << std::endl;
} else{
std::cerr << "TextureBuffer::setData - currently only in core profile available!" << std::endl;
}
}
bool TextureBuffer::getBufferData(void* _dst) {
......@@ -860,11 +863,11 @@ bool TextureBuffer::getBufferData(std::vector<char>& _dst) {
void ProgramBaseNV::bind() {
if (!valid)
gen();
glBindProgramNV(target, program);
glBindProgramARB(target, program);
}
void ProgramBaseNV::unbind() {
glBindProgramNV(target, 0);
glBindProgramARB(target, 0);
}
bool ProgramBaseNV::load(const char* prog_text) {
......@@ -887,13 +890,13 @@ bool ProgramBaseNV::load(const char* prog_text) {
void ProgramBaseNV::gen() {
glGenProgramsNV(1, &program);
glGenProgramsARB(1, &program);
valid = true;
}
void ProgramBaseNV::del() {
if (valid)
glDeleteProgramsNV(1, &program);
glDeleteProgramsARB(1, &program);
valid = false;
}
......
......@@ -412,7 +412,7 @@ public:
void disableAutogenerateMipMaps();
// initialize and set texture data via glTexImage2D
void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLenum _format, GLenum _type, const GLvoid* _data);
void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLenum _format, GLenum _type, const GLvoid* _data, bool _mipmaps = false);
// specify storage of texture (OpenGL 4.2)
// use setData with a nullptr instead if 4.2 is not available
......
......@@ -81,37 +81,26 @@ QtGLGraphicsScene::QtGLGraphicsScene(QtBaseViewer* _w) :
void QtGLGraphicsScene::drawBackground(QPainter *_painter, const QRectF &_rect)
{
// Check for switch in qt4.6 to OpenGL2
#if QT_VERSION >= 0x040600
if (_painter->paintEngine()->type() != QPaintEngine::OpenGL && _painter->paintEngine()->type() != QPaintEngine::OpenGL2 ) {
std::cerr << "QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
return;
}
#else
if (_painter->paintEngine()->type() != QPaintEngine::OpenGL ) {
std::cerr << "QtGLGraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view\n";
return;
}
#endif
// Initialize background first
_painter->setBackground(QApplication::palette().window());
_painter->eraseRect(_rect);
// From now on we do OpenGL direct painting on the scene
#if QT_VERSION >= 0x040600
// Tell Qt that we directly use OpenGL
_painter->beginNativePainting();
#endif
// Clear the depth buffer (This is required since QT4.6 Otherwise we get an emtpty scene!
glClear(GL_DEPTH_BUFFER_BIT);
w_->paintGL();
#if QT_VERSION >= 0x040600
// The rest is painting through QT again.
_painter->endNativePainting();
#endif
}
......
......@@ -697,7 +697,10 @@ CoordsysNode::pick(GLState& _state, PickTarget _target)
GLSL::Program* pickShader = 0;
if (!fixedFunctionGL)
{
pickShader = ShaderCache::getInstance()->getProgram("Picking/vertex.glsl", "Picking/single_color_fs.glsl");
static ShaderGenDesc desc;
desc.fragmentTemplateFile = "Picking/single_color_fs.glsl";
desc.vertexTemplateFile = "Picking/vertex.glsl";
pickShader = ShaderCache::getInstance()->getProgram(&desc, nullptr);
if (!pickShader)
return;
......
......@@ -399,10 +399,10 @@ pick(GLState& _state , PickTarget _target)
for (size_t i = 0; i < primitives_.size(); ++i)
{
_state.pick_set_name(i);
glPushMatrix();
glTranslatef(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
_state.push_modelview_matrix();
_state.translate(primitives_[i].position[0], primitives_[i].position[1], primitives_[i].position[2]);
draw_obj(_state, i);
glPopMatrix();
_state.pop_modelview_matrix();
}
break;
}
......
......@@ -87,7 +87,7 @@ LineNode::LineNode( LineMode _mode,
LineNode::~LineNode() {
if (vbo_)
glDeleteBuffersARB(1, &vbo_);
glDeleteBuffers(1, &vbo_);
}
......@@ -451,7 +451,7 @@ void LineNode::createVBO()
// create vbo if it does not exist
if (!vbo_)
glGenBuffersARB(1, &vbo_);
glGenBuffers(1, &vbo_);
vertexDecl_.clear();
vertexDecl_.addElement(GL_FLOAT, 3, VERTEX_USAGE_POSITION);
......@@ -568,8 +568,8 @@ void LineNode::createVBO()
}
}
glBindBufferARB(GL_ARRA