コード例 #1
0
void AddDebugLog(xlGLCanvas *c) {
    static log4cpp::Category &logger_opengl = log4cpp::Category::getInstance(std::string("log_opengl_trace"));
    PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC)wglGetProcAddress("glDebugMessageCallbackARB");
    PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC)wglGetProcAddress("glDebugMessageControlARB");
    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
    if (glDebugMessageCallbackARB == nullptr) {
        logger_opengl.debug("Did not find debug callback ARB, attempting 4.3");
        glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC)wglGetProcAddress("glDebugMessageCallback");
        glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC)wglGetProcAddress("glDebugMessageControl");
    }

    if (glDebugMessageCallbackARB != nullptr) {
        logger_opengl.debug("Adding debug callback.  %X", glDebugMessageControlARB);
        LOG_GL_ERRORV(glDebugMessageCallbackARB(DebugLog, c));
        if (glDebugMessageControlARB != nullptr) {
            GLuint unusedIds = 0;
            glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unusedIds, GL_TRUE);
        }
    }
    PFNGLDEBUGMESSAGECALLBACKAMDPROC glDebugMessageCallbackAMD = (PFNGLDEBUGMESSAGECALLBACKAMDPROC)wglGetProcAddress("glDebugMessageCallbackAMD");
    if (glDebugMessageCallbackAMD != nullptr) {
        logger_opengl.debug("Adding AMD debug callback");
        LOG_GL_ERRORV(glDebugMessageCallbackAMD(DebugLogAMD, c));
    }
}
コード例 #2
0
void Waveform::InitializeGLCanvas()
{
    if(!IsShownOnScreen()) return;
    SetCurrentGLContext();
    LOG_GL_ERRORV(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); // Black Background
    LOG_GL_ERRORV(glDisable(GL_BLEND));
    LOG_GL_ERRORV(glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA));
    LOG_GL_ERRORV(glClear(GL_COLOR_BUFFER_BIT));
    prepare2DViewport(0,0,mWindowWidth, mWindowHeight);
    mIsInitialized = true;
    SetZoomLevel(mZoomLevel);
}
コード例 #3
0
void xlGridCanvasPictures::DrawSelection()
{
    if( mPaintMode == PAINT_SELECTCOPY && mDragStartX > 0 ) {
        int start_x = (mStartCol+1)*mCellSize;
        int start_y = (mStartRow+1)*mCellSize;
        int height = mCellSize * (mEndRow-mStartRow+1);
        int width = mCellSize * (mEndCol-mStartCol+1);
        LOG_GL_ERRORV(glEnable(GL_BLEND));
        DrawGLUtils::DrawFillRectangle(*mSelectionColor,70,start_x,start_y,width,height);
        DrawGLUtils::DrawRectangle(xlYELLOW,true,start_x,start_y,start_x+width,start_y+height);
        LOG_GL_ERRORV(glDisable(GL_BLEND));
    }
}
コード例 #4
0
void Waveform::renderGL( )
{
    if(!mIsInitialized) { InitializeGLCanvas(); }

    if(!IsShownOnScreen()) return;

    SetCurrentGLContext();

    LOG_GL_ERRORV(glClear(GL_COLOR_BUFFER_BIT));
    prepare2DViewport(0,0,mWindowWidth, mWindowHeight);

	if (mCurrentWaveView >= 0)
	{
		DrawWaveView(views[mCurrentWaveView]);
	}
    LOG_GL_ERRORV(SwapBuffers());
}
コード例 #5
0
void xlGridCanvasPictures::render( wxPaintEvent& event )
{
    if(!mIsInitialized) { InitializeGLCanvas(); }
    if(!IsShownOnScreen()) return;

    SetCurrentGLContext();

    LOG_GL_ERRORV(glClear(GL_COLOR_BUFFER_BIT));
    prepare2DViewport(0,0,mWindowWidth, mWindowHeight);

    if( mEffect != nullptr )
    {
        DrawPicturesEffect();
        DrawBaseGrid();
        DrawSelection();
    }
    SwapBuffers();
}
コード例 #6
0
void xlGLCanvas::CreateGLContext() {
    static log4cpp::Category &logger_opengl_trace = log4cpp::Category::getInstance(std::string("log_opengl_trace"));
    if (m_context == nullptr) {
        //trying to detect OGL verions and stuff can result in unwanted logs
        wxLogLevel cur = wxLog::GetLogLevel();
        wxLog::SetLogLevel(wxLOG_Error);
        wxLog::Suspend();

        wxConfigBase* config = wxConfigBase::Get();
        int ver = 99;
        config->Read("ForceOpenGLVer", &ver, 99);

        static bool supportsCoreProfile = true;

        if (supportsCoreProfile && m_coreProfile && ver >= 3) {
            wxGLContextAttrs atts;
            static log4cpp::Category &logger_opengl = log4cpp::Category::getInstance(std::string("log_opengl"));
            atts.PlatformDefaults().OGLVersion(3, 3).CoreProfile();
            if (logger_opengl_trace.isDebugEnabled()) {
                atts.ForwardCompatible().DebugCtx().EndList();
            }
            atts.EndList();
            glGetError();
            LOG_GL_ERRORV(m_context = new wxGLContext(this, nullptr, &atts));
            if (!m_context->IsOK()) {
                logger_opengl.debug("Could not create a valid CoreProfile context");
                LOG_GL_ERRORV(delete m_context);
                m_context = nullptr;
                supportsCoreProfile = false;
            } else {
                LOG_GL_ERROR();
                const GLubyte* rend = glGetString(GL_RENDERER);
                if (wxString(rend) == "GDI Generic") {
                    //no way 3.x is going to work, software rendered, flip to 1.x
                    LOG_GL_ERRORV(delete m_context);
                    m_context = nullptr;
                    supportsCoreProfile = false;
                }
            }
        }
        if (m_context == nullptr) {
            glGetError();
            LOG_GL_ERRORV(m_context = new wxGLContext(this));
        }
        if (!functionsLoaded) {
            LOG_GL_ERROR();
            functionsLoaded = DrawGLUtils::LoadGLFunctions();
            glGetError(); // likely a function not there
        }
        if (!m_context->IsOK()) {
            LOG_GL_ERRORV(delete m_context);
            m_context = nullptr;
        }
        wxLog::SetLogLevel(cur);
        wxLog::Resume();

        if (m_context == nullptr)
        {
            static log4cpp::Category &logger_opengl = log4cpp::Category::getInstance(std::string("log_opengl"));
            logger_opengl.error("Error creating GL context.");
        }
    }
}
コード例 #7
0
void xlGLCanvas::SetCurrentGLContext() {
    glGetError();
    if (m_context == nullptr) {
        LOG_GL_ERRORV(CreateGLContext());
    }
    LOG_GL_ERRORV(m_context->SetCurrent(*this));
    if (!functionsLoaded) {
        LOG_GL_ERRORV(DrawGLUtils::LoadGLFunctions());
        functionsLoaded = true;
    }
    if (cache == nullptr) {
        wxConfigBase* config = wxConfigBase::Get();
        int ver = 99;
        config->Read("ForceOpenGLVer", &ver, 99);

        static log4cpp::Category &logger_opengl = log4cpp::Category::getInstance(std::string("log_opengl"));
        const GLubyte* str = glGetString(GL_VERSION);
        const GLubyte* rend = glGetString(GL_RENDERER);
        const GLubyte* vend = glGetString(GL_VENDOR);
        wxString configs = wxString::Format("%s - glVer:  %s  (%s)(%s)",
                                           (const char *)GetName().c_str(),
                                           (const char *)str,
                                           (const char *)rend,
                                           (const char *)vend);

        if (wxString(rend) == "GDI Generic"
            || wxString(vend).Contains("Microsoft")) {

            bool warned;
            config->Read("GDI-Warned", &warned, false);
            if (!warned) {
                config->Write("GDI-Warned", true);
                wxString msg = wxString::Format("Generic non-accelerated graphics driver detected (%s - %s). Performance will be poor.  "
                                               "Please install updated video drivers for your video card.",
                                               vend, rend);
                CallAfter(&xlGLCanvas::DisplayWarning, msg);
            }
            //need to use 1.x
            ver = 1;
        }

        logger_opengl.info(std::string(configs.c_str()));
        printf("%s\n", (const char *)configs.c_str());
        if (ver >= 3 && (str[0] > '3' || (str[0] == '3' && str[2] >= '3'))) {
            if (logger_opengl.isDebugEnabled()) {
                AddDebugLog(this);
            }
            logger_opengl.info("Try creating 3.3 Cache");
            LOG_GL_ERRORV(cache = Create33Cache(UsesVertexTextureAccumulator(),
                                  UsesVertexColorAccumulator(),
                                  UsesVertexAccumulator(),
                                  UsesAddVertex()));
        }
        if (cache == nullptr && ver >=2
            && ((str[0] > '2') || (str[0] == '2' && str[2] >= '1'))) {
            logger_opengl.info("Try creating 2.1 Cache");
            LOG_GL_ERRORV(cache = Create21Cache());
        }
        if (cache == nullptr) {
            logger_opengl.info("Try creating 1.1 Cache");
            LOG_GL_ERRORV(cache = Create11Cache());
        }
        if (cache == nullptr) {
            logger_opengl.error("All attempts at cache creation have failed.");
        }
    }
    LOG_GL_ERRORV(DrawGLUtils::SetCurrentCache(cache));
}
コード例 #8
0
void xlGridCanvasPictures::DrawPicturesEffect()
{
    if( NewPictureName == "" ) return;
    if( NewPictureName != PictureName || sprite == NULL || mPasteCopy)
    {
        if( sprite != NULL ) {
            delete sprite;
        }
        if( use_ping )
        {
            imageGL_ping = new Image(image);
            sprite = new xLightsDrawable(imageGL_ping);
            imageWidth = imageGL_ping->width;
            imageHeight = imageGL_ping->height;
            mImage = imageGL_ping;
        }
        else
        {
            imageGL_pong = new Image(image);
            sprite = new xLightsDrawable(imageGL_pong);
            imageWidth = imageGL_pong->width;
            imageHeight = imageGL_pong->height;
            mImage = imageGL_pong;
        }
        sprite->setFlip(false, false);
    }
    sprite->scale(mCellSize, mCellSize);
    sprite->setHotspot(-1, -mRows - 1 + imageHeight);

    DrawGLUtils::PushMatrix();

    if( mPaintMode != PAINT_SELECTCOPY || !mCopyAvailable )
    {
        sprite->render();
    }
    else
    {
        LOG_GL_ERRORV(glColor4f(1.0f, 1.0f, 1.0f, 0.8f));
        LOG_GL_ERRORV(glEnable(GL_TEXTURE_2D));   // textures
        sprite->render();
        LOG_GL_ERRORV(glColor4f(1.0f, 1.0f, 1.0f, 0.5f));
        LOG_GL_ERRORV(glEnable(GL_BLEND));
        LOG_GL_ERRORV(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
        copy_sprite->render();
        LOG_GL_ERRORV(glDisable(GL_BLEND));
        LOG_GL_ERRORV(glDisable(GL_TEXTURE_2D));
    }

    DrawGLUtils::PopMatrix();

    if( NewPictureName != PictureName || mPasteCopy)
    {
        mPasteCopy = false;
        if( use_ping ) {
            if( imageGL_pong != NULL ) {
                delete imageGL_pong;
            }
            use_ping = false;
        } else {
            if( imageGL_ping != NULL ) {
                delete imageGL_ping;
            }
            use_ping = true;
        }
        PictureName = NewPictureName;
    }
}