glutils.cpp

来自「ncbi源码」· C++ 代码 · 共 309 行

CPP
309
字号
/* * =========================================================================== * PRODUCTION $Log: glutils.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 20:51:07  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * PRODUCTION * =========================================================================== *//*  $Id: glutils.cpp,v 1000.1 2004/06/01 20:51:07 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: *    OpenGL utility functions */#include <ncbi_pch.hpp>#include <gui/opengl.h>#include <gui/opengl/glutils.hpp>#include <gui/opengl/glexception.hpp>BEGIN_NCBI_SCOPE// static accelerated state - default to 'not determined'CGlUtils::EAccelState CGlUtils::m_Accel = CGlUtils::eNotDetermined;//// access the accelerated flag// this defaults to autodetect, and is user-overridable//CGlUtils::EAccelState CGlUtils::GetAccelerated(void){    if ( m_Accel != eNotDetermined ) {        return m_Accel;    }    const char* str = reinterpret_cast<const char*> (glGetString(GL_RENDERER));    if ( !str ) {        return eNotDetermined;    }    _TRACE("GL_VERSION = "    << glGetString(GL_VERSION));    _TRACE("GL_RENDERER = "   << glGetString(GL_RENDERER));    _TRACE("GL_EXTENSIONS = " << glGetString(GL_EXTENSIONS));    // Solaris software renderer returns:    // GL_RENDERER = Sun dpa software renderer, VIS    string s(str);    if (s.find("software renderer") != string::npos) {        LOG_POST(Info                 << "CGlUtils::GetAccelerated(): "                 "auto-detected non-hardware-accelerated platform");        m_Accel = eNotAccelerated;    } else {        LOG_POST(Info                 << "CGlUtils::GetAccelerated(): "                 "auto-detected hardware-accelerated platform");        m_Accel = eAccelerated;    }    return m_Accel;}//// check for and report OpenGL errors//void CGlUtils::CheckGlError(void){    GLint error = glGetError();    if (error == GL_NO_ERROR) {        return;    }    static int mode = 0;    if ( !mode ) {        const char* value = getenv("NCBI_GBENCH_GLERROR");        if ( !value ) {            mode = 1;        } else {            if (strcmp(value, "ABORT") == 0) {                mode = 2;            } else {                mode = 3;            }        }    }    string msg;    switch ( error ) {    default:        msg = "CGlUtils::CheckGlError(): unknown error";        break;    case GL_INVALID_OPERATION:        msg = "CGlUtils::CheckGlError(): invalid operation";        break;    case GL_INVALID_ENUM:        msg = "CGlUtils::CheckGlError(): invalid enum";        break;    case GL_INVALID_VALUE:        msg = "CGlUtils::CheckGlError(): invalid value";        break;    case GL_STACK_OVERFLOW:        msg = "CGlUtils::CheckGlError(): stack overflow";        break;    case GL_STACK_UNDERFLOW:        msg = "CGlUtils::CheckGlError(): stack underflow";        break;    case GL_OUT_OF_MEMORY:        msg = "CGlUtils::CheckGlError(): out of memory";        break;    }    switch (mode) {    case 0:    default:        // shouldn't happen        LOG_POST(Error << msg);        break;    case 1:        // abort        LOG_POST(Error << msg);        Abort();        break;    case 2:        // throw        NCBI_THROW(COpenGLException, eGlError, msg);        break;    }}#ifdef _DEBUG//// dumpState()// this is a debugging function designed to show a bunch of OpenGL enables//void CGlUtils::DumpState(void){    LOG_POST(Info << "OpenGL Vendor: " << glGetString(GL_VENDOR));    LOG_POST(Info << "OpenGL Renderer: " << glGetString(GL_RENDERER));    LOG_POST(Info << "OpenGL Version: " << glGetString(GL_VERSION));    LOG_POST(Info << "OpenGL Extensions: " << glGetString(GL_EXTENSIONS));    LOG_POST(Info << "\n");    GLint viewport[4];    float modelview[16];    float projection[16];    float color[4];    glGetIntegerv(GL_VIEWPORT, viewport);    glGetFloatv(GL_MODELVIEW_MATRIX, modelview);    glGetFloatv(GL_PROJECTION_MATRIX, projection);    glGetFloatv(GL_CURRENT_COLOR, color);    GLint red_bits = 0;    GLint green_bits = 0;    GLint blue_bits = 0;    GLint alpha_bits = 0;    GLint depth_bits = 0;    GLint stencil_bits = 0;    glGetIntegerv(GL_RED_BITS,     &red_bits);    glGetIntegerv(GL_GREEN_BITS,   &green_bits);    glGetIntegerv(GL_BLUE_BITS,    &blue_bits);    glGetIntegerv(GL_ALPHA_BITS,   &alpha_bits);    glGetIntegerv(GL_DEPTH_BITS,   &depth_bits);    glGetIntegerv(GL_STENCIL_BITS, &stencil_bits);    LOG_POST(Info << "Buffers:");    LOG_POST(Info << "  Color:"             << " Red=" << red_bits << " bits"             << " Green=" << green_bits << " bits"             << " Blue=" << blue_bits << " bits"             << " Alpha=" << alpha_bits << " bits");    LOG_POST(Info << "  Depth: " << depth_bits << " bits");    LOG_POST(Info << "  Stencil: " << alpha_bits << " bits");    LOG_POST(Info << "Viewport: "        << viewport[0] << ", " << viewport[1] << ", "        << viewport[2] << ", " << viewport[3]);    int i;    int j;    LOG_POST(Info << "Projection matrix:");    for (i = 0;  i < 4;  ++i) {        string msg;        for (j = 0;  j < 4;  ++j) {            // remember, OpenGL matrices are transposed!            msg += NStr::DoubleToString(projection[j * 4+i]) + " ";        }        LOG_POST(Info << msg);    }    LOG_POST(Info << "Modelview matrix:");    for (i = 0;  i < 4;  ++i) {        string msg;        for (j = 0;  j < 4;  ++j) {            // remember, OpenGL matrices are transposed!            msg += NStr::DoubleToString(modelview[j * 4+i]) + " ";        }        LOG_POST(Info << msg);    }    LOG_POST(Info << "Current draw color: "        << color[0] << ", " << color[1] << ", "        << color[2] << ", " << color[3]);    LOG_POST(Info << "Lighting:      "             << (glIsEnabled(GL_LIGHTING)   ? "enabled" : "disabled"));    LOG_POST(Info << "Depth Testing: "             << (glIsEnabled(GL_DEPTH_TEST) ? "enabled" : "disabled"));    LOG_POST(Info << "Face Culling:  "             << (glIsEnabled(GL_CULL_FACE)  ? "enabled" : "disabled"));    LOG_POST(Info << "Blending:      "             << (glIsEnabled(GL_BLEND)      ? "enabled" : "disabled"));    LOG_POST(Info << "Alpha Testing: "             << (glIsEnabled(GL_ALPHA_TEST) ? "enabled" : "disabled"));    LOG_POST(Info << "2D Texture:    "             << (glIsEnabled(GL_TEXTURE_2D) ? "enabled" : "disabled"));}#endifEND_NCBI_SCOPE/* * =========================================================================== * $Log: glutils.cpp,v $ * Revision 1000.1  2004/06/01 20:51:07  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * * Revision 1.10  2004/05/21 22:27:45  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.9  2003/10/23 16:20:41  dicuccio * Changed CheckGlError() to respond to an environment variable and, potentially, * either abort or throw an exception on error * * Revision 1.8  2003/06/09 19:25:25  dicuccio * Changed dumping of GL strings to _TRACE.  Added dumping of buffer resolution * * Revision 1.7  2003/06/03 17:42:06  dicuccio * Added texture support.  Added classes to handle OpenGL camera setup and * viewport specification. * * Revision 1.6  2003/05/06 15:59:59  dicuccio * Moved hardware check from CGlCanvas into CGlUtils * * Revision 1.5  2003/04/01 21:05:11  rsmith * in CGlUtils::DumpState, change type of viewport from int to GLint for better * compiler portability. * * Revision 1.4  2003/01/13 13:10:11  dicuccio * Namespace clean-up.  Retired namespace gui -> converted all to namespace * ncbi.  Moved all FLUID-generated code into namespace ncbi. * * Revision 1.3  2002/11/14 16:24:44  dicuccio * Changed to include standard OpenGL headers through 'gui/opengl.h' * * Revision 1.2  2002/11/07 18:57:47  dicuccio * Changed code to use LOG_POST() and _TRACE(). * * Revision 1.1  2002/11/05 20:21:48  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?