Пример #1
0
void
render_quad(float x, float y, float width, float height) {
	GLfloat vertices[] = {x + width, y + height,
						  x, y + height,
						  x, y,
						  x + width, y };
	GLfloat texCoords[] = {1.0, 1.0,
						   0.0, 1.0,
						   0.0, 0.0,
						   1.0, 0.0 };
	GLubyte indices[] = {0, 1, 2, 0, 2, 3};

	//Set color variable before rendering quad
	set_uniform_vec4(colorUni, colorRed, colorGreen, colorBlue, colorAlpha);
	
	set_uniform_float(diffuseSamplerUni, 0);
	if (currentTexture != NULL) bind_texture(currentTexture, 0);
	else bind_texture(whiteTexture, 0);

	glEnableVertexAttribArray(vertPosAttrib->handle);
	glEnableVertexAttribArray(texCoordAttrib->handle);
	
	glVertexAttribPointer(vertPosAttrib->handle, 2, GL_FLOAT, GL_FALSE, 0, vertices);
	glVertexAttribPointer(texCoordAttrib->handle, 2, GL_FLOAT, GL_FALSE, 0, texCoords);

	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
	
	glDisableVertexAttribArray(vertPosAttrib->handle);
	glDisableVertexAttribArray(texCoordAttrib->handle);
	
	unbind_texture(0);
}
Пример #2
0
	bool StateManager::unbind_textures()
	{
		Uint32 i;
		bool result;

		result = false;

		for (i = 0; i < m_textures.size(); ++i)
		{
			result |= unbind_texture(i);
		}

		return result;
	}
Пример #3
0
GLFluids::~GLFluids(){

    cudaGraphicsUnregisterResource(cuda_vbo_resource);

    unbind_texture();
    delete_texture();

    // Free all host and device resources
    free(hvfield);
    free(particles);
    cudaFree(dvfield);
    cudaFree(vxfield);
    cudaFree(vyfield);
    cufftDestroy(planr2c);
    cufftDestroy(planc2r);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDeleteBuffers(1, &vbo);

}
Пример #4
0
	void D3DUnitMap::unbind_program(D3DGraphicContextProvider *gc, D3DProgramObjectProvider *program)
	{
		for (size_t i = 0; i < program->uniforms.size(); i++)
		{
			switch (program->uniforms[i].type)
			{
			case D3DUniform::type_sampler:
				unbind_sampler(gc, program->uniforms[i].value);
				for (int j = 0; j < shadertype_num_types; j++)
					sampler_units[program->uniforms[i].value].shader_index[j] = -1;
				break;
			case D3DUniform::type_texture:
				unbind_texture(gc, program->uniforms[i].value);
				for (int j = 0; j < shadertype_num_types; j++)
					texture_units[program->uniforms[i].value].shader_index[j] = -1;
				break;
			case D3DUniform::type_image:
				unbind_image(gc, program->uniforms[i].value);
				for (int j = 0; j < shadertype_num_types; j++)
					image_units[program->uniforms[i].value].shader_index[j] = -1;
				break;
			}
		}

		for (size_t i = 0; i < program->uniform_blocks.size(); i++)
		{
			unbind_uniform_buffer(gc, program->uniform_blocks[i].value);
			for (int j = 0; j < shadertype_num_types; j++)
				uniform_units[program->uniform_blocks[i].value].shader_index[j] = -1;
		}

		for (size_t i = 0; i < program->storage_blocks.size(); i++)
		{
			unbind_storage_buffer(gc, program->storage_blocks[i].value);
			for (int j = 0; j < shadertype_num_types; j++)
			{
				storage_units[program->storage_blocks[i].value].shader_srv_index[j] = -1;
				storage_units[program->storage_blocks[i].value].shader_uav_index[j] = -1;
			}
		}
	}
Пример #5
0
//----------------------------------------------------------------------------
//draw render buffer content in offscreen viewport ofs_vp 
//to a sepearte onscreen debug viewport s_vp
//----------------------------------------------------------------------------
void GLRenderBuffer_FBO::draw_to_framebuffer(int readid,
                                        int textureid,
                                        int* ofs_vp, int* s_vp, 
                                        std::string& path,
                                        bool blend)
{

#ifdef _DEBUG7
    fprintf(stderr, "**** %s:%s() ****\n", __FILE__, __func__);
#endif

    if(m_showtex_shader == 0) init_shader(path);


    glActiveTexture(GL_TEXTURE0);    
    bind_texture(readid, textureid);

    if(blend)
    {
        glEnable(GL_BLEND);
        //enable front to back blending. 
        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
        //enable back to front blending
        //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        //glBlendFunc(GL_ONE, GL_ONE);
    }
    else glDisable(GL_DEPTH_TEST);

    push_all_matrix();
    toOrtho(s_vp);

/*
    float tex_mf[2] = {1.0, 1.0}; //min/mag filter into tex
    float tex_offset[2] = {0., 0.};

    if(ofs_vp == 0) ofs_vp = m_viewport;
    if(s_vp == 0) s_vp = m_viewport;

    if(ofs_vp && s_vp)
    {
        tex_mf[0] = 1.0 * ofs_vp[2] / m_viewport[2];
        tex_mf[1] = 1.0 * ofs_vp[3] / m_viewport[3];
        tex_offset[0] = 1.0 * ofs_vp[0] / m_viewport[2];
        tex_offset[1] = 1.0 * ofs_vp[1] / m_viewport[3];
    }

//     fprintf(stderr, "tex_offset: %f, %f\n", tex_offset[0], tex_offset[1]);
//     fprintf(stderr, "vp_offset: %f, %f\n", vp_offset[0], vp_offset[1]);
//     fprintf(stderr, "tex_mf: %f, %f\n", tex_mf[0], tex_mf[1]);

    m_showtex_shader->use();
    //by default bind to texture unit 0
    //glUniform1i(m_showtex_shader->getUniformLocation("tex"), 0);
    glUniform2f(m_showtex_shader->getUniformLocation("tex_offset"), 
                tex_offset[0], tex_offset[1]);
    glUniform2f(m_showtex_shader->getUniformLocation("tex_mf"), 
                tex_mf[0], tex_mf[1]);

*/

    glColor3f(1.0, 1.0, 1.0);    
    draw_quad();

/*
    glUseProgram(0);
*/

    unbind_texture();


    if(blend) glDisable(GL_BLEND);
    else glEnable(GL_DEPTH_TEST);


    pop_all_matrix();

}