Beispiel #1
0
 void submitDeferred()
 {
     for (auto i = deferred.begin(); i != deferred.end(); ++i)
     {
         try
         {
             Rectanglei rect;
             allocator->rect(i.key(), rect);
             submitImage(*i.value(), rect);
         }
         catch (Error const &er)
         {
             LOG_GL_ERROR("Allocation %s could not be submitted: %s")
                     << i.key() << er.asText();
         }
         delete i.value(); // we own the Image
     }
     deferred.clear();
 }
Beispiel #2
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.");
        }
    }
}
void C2DPrimitiveRenderer_GL::RenderViaVertexAttribArray(
	const General2DVertex *pVertices,
	uint num_vertices,
	ushort *indices,
	uint num_indices,
	GLenum primitive_type
	)
{
	const uint vertex_size = sizeof(General2DVertex);

	LOG_GL_ERROR( " Clearing OpenGL errors..." );

	// Unbind GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER to source a standard memory location (RAM).
	glBindBuffer( GL_ARRAY_BUFFER, 0 );
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );

	// position
	const uchar *pV = (uchar *)pVertices;
	const uchar *pPos = pV + 0;//mesh.GetVertexElementOffset( VEE::POSITION );
	glEnableVertexAttribArray( 0 );
	glVertexAttribPointer( 0, 4, GL_FLOAT, GL_FALSE, vertex_size, pPos );

	// diffuse color
	glEnableVertexAttribArray( 1 );
	glVertexAttribPointer( 1, 4, GL_FLOAT, GL_FALSE, vertex_size, pV + sizeof(float) * 4 );

	// 2D texture coordinates
	glEnableVertexAttribArray( 2 );
	glVertexAttribPointer( 2, 2, GL_FLOAT, GL_FALSE, vertex_size, pV + sizeof(float) * 8 );

	uchar *pI = NULL;


	LOG_GL_ERROR( " Clearing OpenGL errors..." );

	if( indices )
	{
		pI = (uchar *)indices;

		GLenum index_type = GL_UNSIGNED_SHORT;

		glDrawElements( primitive_type, num_indices, index_type, pI );

		LOG_GL_ERROR( "glDrawElements() failed." );
	}
	else
	{
		GLint first = 0;
		GLsizei count = 0;
		switch( primitive_type )
		{
		case GL_TRIANGLE_STRIP: count = num_vertices;     break;
		case GL_TRIANGLE_FAN:   count = num_vertices;     break;
		case GL_TRIANGLES:      count = num_vertices;     break;
			break;
		default:
			break;
		}

		glDrawArrays( primitive_type, first, count );

		LOG_GL_ERROR( "glDrawArrays() failed." );
	}
}