示例#1
0
void CScope::Tick()
{
    if (m_Form->isVisible())
    {

        float* Signal=FetchA(jnIn);
        if (CurrentBuffer<MaxBuffers)
        {
            if (!Signal)
            {
                PlotBuffer[CurrentBuffer]=NULL;
            }
            else
            {
                CopyMemory(m_Buffer[CurrentBuffer],Signal,m_BufferSize*sizeof(float));
                PlotBuffer[CurrentBuffer]=m_Buffer[CurrentBuffer];
            }
            CurrentBuffer++;
        }
        else
        {
            NullBuffers++;
        }
        if (CurrentBuffer>=MaxBuffers)
        {
            DrawBuffers();
        }
    }
}
示例#2
0
void MeshActor::Render()
{
	glUseProgram(shaderProgram);
	FreeBuffers();
	SetUniforms();
	SetBufferData();
	DrawBuffers();
	CleanUp();
	FreeBuffers();
}
示例#3
0
void DrawPassGL::init( const PassDesc &desc )
{
	if( isInited() ) return;
	setInited( true );
	_desc = desc;
	N = desc._buffer_count;
	glGenFramebuffers( 1 , &_framebuffer_id );
	glBindFramebuffer( GL_FRAMEBUFFER , _framebuffer_id );
	int _gl_type;
	int _gl_store;
	int _gl_depth;
	int _gl_format;
	switch( desc._store_type )
	{
	case BufferStoreType::BUFFER_BYTE:
	{
		switch( desc._component_number )
		{
		case 1:
		{
			_gl_type = GL_R8;
			_gl_format = GL_R;
			_gl_store = GL_UNSIGNED_BYTE;
		}
		break;
		case 2:
		{
			_gl_type = GL_RG8;
			_gl_format = GL_RG;
			_gl_store = GL_UNSIGNED_BYTE;
		}
		break;
		case 3:
		{
			_gl_type = GL_RGB8;
			_gl_format = GL_RGB;
			_gl_store = GL_UNSIGNED_BYTE;
		}
		break;
		case 4:
		{
			_gl_type = GL_RGBA8;
			_gl_format = GL_RGBA;
			_gl_store = GL_UNSIGNED_BYTE;
		}
		break;
		}
		_gl_depth = GL_DEPTH_COMPONENT16;
	}
	break;
	case BufferStoreType::BUFFER_FLOAT:
	{
		switch( desc._component_number )
		{
		case 1:
		{
			_gl_format = GL_R;
			_gl_type = GL_R32F;
			_gl_store = GL_FLOAT;
		}
		break;
		case 2:
		{
			_gl_format = GL_RG;
			_gl_type = GL_RG32F;
			_gl_store = GL_FLOAT;
		}
		break;
		case 3:
		{
			_gl_format = GL_RGB;
			_gl_type = GL_RGB32F;
			_gl_store = GL_FLOAT;
		}
		break;
		case 4:
		{
			_gl_format = GL_RGBA;
			_gl_type = GL_RGBA32F;
			_gl_store = GL_FLOAT;
		}
		break;
		}
		_gl_depth = GL_DEPTH_COMPONENT32F;

	}
	break;
	case BufferStoreType::BUFFER_INT:
	{
		switch( desc._component_number )
		{
		case 1:
		{
			_gl_type = GL_R32UI;
			_gl_store = GL_UNSIGNED_INT;
			_gl_format = GL_RED_INTEGER;
		}
		break;
		case 2:
		{
			_gl_type = GL_RG32UI;
			_gl_store = GL_UNSIGNED_INT;
			_gl_format = GL_RG_INTEGER;
		}
		break;
		case 3:
		{
			_gl_type = GL_RGB32UI;
			_gl_store = GL_UNSIGNED_INT;
			_gl_format = GL_RGB_INTEGER;
		}
		break;
		case 4:
		{
			_gl_type = GL_RGBA32UI;
			_gl_store = GL_UNSIGNED_INT;
			_gl_format = GL_RGBA_INTEGER;
		}
		break;
		}
		_gl_depth = GL_DEPTH_COMPONENT32F;
	}
	break;
	}
	if( N > 0 )
	{
		std::unique_ptr< GLenum[] > DrawBuffers( new GLenum[ N ] );
		for( int i = 0; i < N; i++ )
			DrawBuffers[ i ] = GL_COLOR_ATTACHMENT0 + i;
		glDrawBuffers( N , DrawBuffers.get() );
		__texture_pointer_array = std::move( std::unique_ptr< uint[] >( new uint[ N ] ) );
		glGenTextures( N , __texture_pointer_array.get() );
		ito( N )
		{
			if( desc._cubemap )
			{
				glBindTexture( GL_TEXTURE_CUBE_MAP , __texture_pointer_array[ i ] );
				glTexParameterf( GL_TEXTURE_CUBE_MAP , GL_TEXTURE_MIN_FILTER , GL_LINEAR );
				glTexParameterf( GL_TEXTURE_CUBE_MAP , GL_TEXTURE_MAG_FILTER , GL_LINEAR );
				glTexParameterf( GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE );
				glTexParameterf( GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE );
				glTexParameterf( GL_TEXTURE_CUBE_MAP , GL_TEXTURE_WRAP_R , GL_CLAMP_TO_EDGE );
				for( int j = 0; j < 6; j++ )
				{
					glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + j , 0 , _gl_type , _desc._size._w , _desc._size._h , 0 , _gl_format , _gl_store , 0 );
				}
				///glFramebufferTexture( GL_FAMEBUFFE , GL_COLO_ATTACHMENT0 + i , __texture_pointer_array[i] , 0 );
				glFramebufferTexture2D( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + i , GL_TEXTURE_CUBE_MAP_POSITIVE_X , __texture_pointer_array[ i ] , 0 );
			} else
			{
				glBindTexture( GL_TEXTURE_2D , __texture_pointer_array[ i ] );
				glTexImage2D( GL_TEXTURE_2D , 0 , _gl_type , _desc._size._w , _desc._size._h , 0 , _gl_format , _gl_store , 0 );
				glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR );
				glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR );
				glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE );
				glTexParameteri( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE );
				glFramebufferTexture2D( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 + i , GL_TEXTURE_2D , __texture_pointer_array[ i ] , 0 );
			}
		}
	}
void GLVoxelizerTripiana2009::initGLState(uint32_t resolution, BBox3f bbox,
                                          GLVoxelFramebuffer& framebuffer, Mat4f& gridToWorldMatrix) {
    auto v = bbox.upper - bbox.lower;

    auto bboxCenter = 0.5f * (bbox.lower + bbox.upper);
    // Grow of 5% the size of the bounding box to ensure that we don't miss any triangle that are at the edge
    bbox.lower = bboxCenter - 0.55f * v;
    bbox.upper = bboxCenter + 0.55f * v;

    auto m_res = resolution;
    // Requiered number of color buffer
    auto m_numRenderTargets = ceil((double)m_res / 128.0);

    auto bboxSize = bbox.size();
    auto m_AABCLength = reduceMax(bboxSize);

    auto m_voxelLength = m_AABCLength / (float)m_res;


    auto m_origBBox = bboxCenter - glm::vec3(0.5f * m_AABCLength);

    gridToWorldMatrix = scale(translate(Mat4f(1.f), m_origBBox), glm::vec3(m_voxelLength));

    // Use the shaders
    m_Program.use();

    // Desactivate depth, cullface
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    // Blending activated
    glEnable(GL_COLOR_LOGIC_OP);
    glLogicOp(GL_OR);

    // Init FrameBuffer
    if (!framebuffer.init(m_res, m_res, m_res, m_numRenderTargets)){
        std::cerr << "FBO Error" << std::endl;
    }

    //Projection matrix : Adapt the viewport to the size of the mesh
    glm::mat4 P = glm::ortho(-m_AABCLength * 0.5f,
        m_AABCLength * 0.5f,
        -m_AABCLength * 0.5f,
        m_AABCLength * 0.5f,
        0.f,
        m_AABCLength);

    glm::vec3 position(bboxCenter.x, bboxCenter.y, bboxCenter.z + 0.5 * m_AABCLength);
    glm::vec3 point(bboxCenter.x, bboxCenter.y, bboxCenter.z);
    glm::mat4 V = glm::lookAt(position, point, glm::vec3(0, 1, 0));

    // Get the MVP Matrix
    glm::mat4 MVPMatrix = P * V;

    // Set uniforms
    MVP.set(MVPMatrix);
    halfPixelSize.set(Vec2f(1.f / m_res));
    numVoxels.set(resolution);
    origBBox.set(m_origBBox);
    numRenderTargets.set(m_numRenderTargets);
    voxelSize.set(m_voxelLength);

    framebuffer.bind(GL_DRAW_FRAMEBUFFER);

    // Set the list of draw buffers.
    std::vector<GLenum> DrawBuffers(m_numRenderTargets, 0);
    for (int i = 0; i < m_numRenderTargets; ++i){
        DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
    }
    glDrawBuffers(m_numRenderTargets, DrawBuffers.data());

    glViewport(0, 0, m_res, m_res);

    // Clear the window
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
示例#5
0
void FrameBuffer::Init()
{
	glGenFramebuffers(1, &id);
	glBindFramebuffer(GL_FRAMEBUFFER, id);

//	GetGame()->Log(glGetError());

	drawBuffers.clear();
	Texture* tex = nullptr;
	if(textures.size() > 0)
	{
		for(uint i = 0; i < textures.size(); ++i)
		{
			tex = textures[i];
		//	tex->scaleFilter = Texture::ScaleFilter::Linear;
			tex->wrapMode = Texture::WrapMode::Clamp;
		//	tex->mode = GL_TEXTURE_2D_MULTISAMPLE;
			tex->size = uvec2(rect.width, rect.height);
			tex->SetIndex(startIndex+i);
			tex->InitData(0);

			uint32 attachment = startIndex+GL_COLOR_ATTACHMENT0+i;
			GetGame()->Log("Setting up textures for FrameBuffer, tex ", i, " gets attachment ", attachment, ". GL_COLOR_ATTACHMENT0 = ", GL_COLOR_ATTACHMENT0);

			tex->Bind();
			glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, tex->GetMode(), tex->GetId(), 0);

			drawBuffers.push_back(attachment);
		}
	}

	if(hasDepth)
	{
	/*	glGenRenderbuffers(1, &depthBuffer);
		glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
		glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rect.width, rect.height);
		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
	*/
		if(depthTexture)
		{
		//	depthTexture->SetFormat(Texture::Format::Depth32F_Stencil8, Texture::Format::Depth);
			depthTexture->SetFormat(Texture::Format::Depth32F, Texture::Format::Depth);
			depthTexture->wrapMode = Texture::WrapMode::Clamp;
			depthTexture->dataType = Texture::DataType::Float;
			depthTexture->size = uvec2(rect.width, rect.height);
			depthTexture->SetIndex(startIndex+textures.size());
			depthTexture->InitData(0);

			depthTexture->Bind();
			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depthTexture->GetMode(), depthTexture->GetId(), 0);

			GetGame()->Log(glGetError());
		}
	}

	DrawBuffers();

	BeginRender();

	Unbind();
}
示例#6
0
	static void DrawBuffers(GLsizei count, const ColorBuffer* buffers)
	{
		DrawBuffers(oglplus::EnumArray<ColorBuffer>(count, buffers));
	}