void loop(GLFWwindow* window, const std::function<void(int, int, float&, void*)>& loop) {
    while (!glfwWindowShouldClose(window)) {
        window_context_t* context = (window_context_t*)glfwGetWindowUserPointer(window);
        glViewport(0, 0, context->texture_width, context->texture_height);

        ImGui_ImplGlfwGL3_NewFrame();

        glClearColor(0, 0, 0, 1);
        glClear(GL_COLOR_BUFFER_BIT);

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, context->pixel_buffer_id);
        void* pointer = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);

        float scale = 0.0f;

        if (pointer) {
            loop(context->texture_width, context->texture_height, scale, pointer);
            glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
        }

        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

        draw_fullscreen_quad(window, std::vector<glm::vec4>(), scale);

        ImGui::Render();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
}
void draw_fullscreen_quad(
    GLFWwindow* window,
    const std::vector<glm::vec4>& image,
    float scale) {

    window_context_t* context = (window_context_t*)glfwGetWindowUserPointer(window);
    glUseProgram(context->program_id);
    glBindVertexArray(context->varray_id);

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, context->pixel_buffer_id);

    glUniform1f(context->scale_location, scale);

    bind_fullscreen_texture(window);

    glTexSubImage2D(
        GL_TEXTURE_2D, 0, 0, 0,
        context->texture_width,
        context->texture_height,
        GL_RGBA,
        GL_FLOAT,
        0);

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);

    draw_fullscreen_quad(context->buffer_id);
}
Example #3
0
void draw_texture(tex_unit* t, int vp[4])
{
    glActiveTexture(GL_TEXTURE0);    
    t->bind();

    draw_fullscreen_quad(vp, true);
        
    t->unbind();
}
Example #4
0
File: render.c Project: ccxvii/mio
void render_sky(void)
{
	static int prog = 0;

	if (!prog) {
		prog = compile_shader(sky_vert_src, sky_frag_src);
	}

	glUseProgram(prog);
	draw_fullscreen_quad();
}
Example #5
0
File: render.c Project: ccxvii/mio
void render_blit(mat4 proj, mat4 view, int w, int h)
{
	static int prog = 0;

	// Render fullscreen quad with post-process filter
	if (!prog) {
		prog = compile_shader(blit_vert_src, blit_frag_src);
	}

	glUseProgram(prog);
	glBindTexture(GL_TEXTURE_2D, tex_forward);

#ifdef HAVE_SRGB_FRAMEBUFFER
	draw_fullscreen_quad();
#else
	glDisable(GL_FRAMEBUFFER_SRGB);
	draw_fullscreen_quad();
	glEnable(GL_FRAMEBUFFER_SRGB);
#endif
}
Example #6
0
//---------------------------------------------------------------
// Purpose: 
//---------------------------------------------------------------
void CPostProcessor::blur( bool hori, UINT sourceTex, UINT destTex, int lod )
{
	int vpW = g_RenderInterf->GetRenderer()->GetScreenWidth() / IntPow(2, lod);
	int vpH = g_RenderInterf->GetRenderer()->GetScreenHeight() / IntPow(2, lod);

	m_shaderBlur->Enable();
	m_shaderBlur->SetLodLevel(lod);
	m_shaderBlur->SetBlurDirection(hori);

	glViewport(0,0,vpW,vpH);
	glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTex, lod );	
	glBindTexture(GL_TEXTURE_2D, sourceTex);
	draw_fullscreen_quad();
}
Example #7
0
// display the final image on the screen
void GPUVolRTV0::render_buffer_to_screen(DrawEnv *pEnv)
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);
	if(toggle_visuals)
		glBindTexture(GL_TEXTURE_2D,final_image);
	else
		glBindTexture(GL_TEXTURE_2D,backface_buffer);
//	reshape_ortho(WINDOW_SIZE,WINDOW_SIZE);
	reshape_ortho(pEnv->getPixelWidth(), pEnv->getPixelHeight());
	draw_fullscreen_quad();
	glDisable(GL_TEXTURE_2D);
}
Example #8
0
void draw_rec_texture(tex_unit* t, int vp[4], shader_object* rectex_shader)
{
    glActiveTexture(GL_TEXTURE0);    
    t->bind();

    float mag[2];
    mag[0] = 1.0 * t->get_width() / vp[2];
    mag[1] = 1.0 * t->get_height() / vp[3];

    rectex_shader->use();
    glUniform2f(rectex_shader->getUniformLocation("vpxy"), vp[0], vp[1]);
    glUniform2f(rectex_shader->getUniformLocation("p"), mag[0], mag[1]);
    draw_fullscreen_quad(vp, false);
    glUseProgram(0);
        
    t->unbind();
}
Example #9
0
File: render.c Project: ccxvii/mio
void render_point_lamp(struct lamp *lamp, mat4 clip_from_view, mat4 view_from_world, mat4 lamp_transform)
{
	static int prog = 0;
	static int uni_viewport;
	static int uni_view_from_clip;
	static int uni_lamp_position;
	static int uni_lamp_color;
	static int uni_lamp_distance;
	static int uni_use_sphere;

	mat4 view_from_clip;
	vec2 viewport;
	vec3 lamp_position;
	vec3 lamp_color;

	if (!prog) {
		prog = compile_shader(quad_vert_src, point_frag_src);
		uni_viewport = glGetUniformLocation(prog, "viewport");
		uni_view_from_clip = glGetUniformLocation(prog, "view_from_clip");
		uni_lamp_position = glGetUniformLocation(prog, "lamp_position");
		uni_lamp_color = glGetUniformLocation(prog, "lamp_color");
		uni_lamp_distance = glGetUniformLocation(prog, "lamp_distance");
		uni_use_sphere = glGetUniformLocation(prog, "use_sphere");
	}

	mat_invert(view_from_clip, clip_from_view);

	viewport[0] = fbo_w;
	viewport[1] = fbo_h;

	mat_vec_mul(lamp_position, view_from_world, lamp_transform + 12);
	vec_scale(lamp_color, lamp->color, lamp->energy);

	glUseProgram(prog);
	glUniform2fv(uni_viewport, 1, viewport);
	glUniformMatrix4fv(uni_view_from_clip, 1, 0, view_from_clip);
	glUniform3fv(uni_lamp_position, 1, lamp_position);
	glUniform3fv(uni_lamp_color, 1, lamp_color);
	glUniform1f(uni_lamp_distance, lamp->distance);
	glUniform1i(uni_use_sphere, lamp->use_sphere);

	draw_fullscreen_quad();
}
Example #10
0
void cgtk::render_buffer_to_screen()
{
	//glEnable(GL_BLEND);

	////glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	//glMatrixMode(GL_MODELVIEW);
	//glPushMatrix();
	//glLoadIdentity();
	//glEnable(GL_TEXTURE_RECTANGLE_ARB);
	//if(toggle_visuals)
	//	glBindTexture(GL_TEXTURE_RECTANGLE_ARB,final_image);
	//else
	//	glBindTexture(GL_TEXTURE_RECTANGLE_ARB,backface_buffer);
	//reshape_ortho(WINDOW_SIZE,WINDOW_SIZE);
	//draw_fullscreen_quad();
	//glDisable(GL_TEXTURE_RECTANGLE_ARB);
	//glMatrixMode(GL_MODELVIEW);
	//glPopMatrix();

	glEnable(GL_BLEND);

	//glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	//glMatrixMode(GL_MODELVIEW);
	//glPushMatrix();
	glLoadIdentity();
	glEnable(GL_TEXTURE_RECTANGLE_ARB);
	if(toggle_visuals)
		glBindTexture(GL_TEXTURE_RECTANGLE_ARB,final_image);
	else
		glBindTexture(GL_TEXTURE_RECTANGLE_ARB,backface_buffer);
	reshape_ortho(WINDOW_SIZE_W,WINDOW_SIZE_H);
	draw_fullscreen_quad();
	glDisable(GL_TEXTURE_RECTANGLE_ARB);

	//glMatrixMode(GL_PROJECTION);
	//glLoadIdentity();
	//glPopMatrix();



}
Example #11
0
//---------------------------------------------------------------
// Purpose: 
//---------------------------------------------------------------
void CPostProcessor::tonemap( UINT sceneTex, UINT sceneDepthTex, UINT bloomTex, UINT lumTex, UINT destTex )
{
	CRenderer *r = g_RenderInterf->GetRenderer();
	m_shaderTonemap->Enable();
	m_shaderTonemap->SetZBounds( r->GetNearClippingDist(), r->GetFarClippingDist() );
	m_shaderTonemap->SetBloomLodLevels(
		render_bloom_lod_start.GetInt(), render_bloom_lod_levels.GetInt());

	r->BindTexture( sceneTex,		0 );
	r->BindTexture( sceneDepthTex,	1 );
	r->BindTexture( bloomTex,		2 );
	r->BindTexture( lumTex,			3, 0 );

	if( destTex <= 0 )
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	else
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTex, 0);

	draw_fullscreen_quad();
}
Example #12
0
File: render.c Project: ccxvii/mio
void render_sun_lamp(struct lamp *lamp, mat4 clip_from_view, mat4 view_from_world, mat4 lamp_transform)
{
	static int prog = 0;
	static int uni_viewport;
	static int uni_lamp_direction;
	static int uni_lamp_color;

	static const vec3 lamp_direction_init = { 0, 0, 1 };

	vec2 viewport;
	vec3 lamp_direction_world;
	vec3 lamp_direction_view;
	vec3 lamp_direction;
	vec3 lamp_color;

	if (!prog) {
		prog = compile_shader(quad_vert_src, sun_frag_src);
		uni_viewport = glGetUniformLocation(prog, "viewport");
		uni_lamp_direction = glGetUniformLocation(prog, "lamp_direction");
		uni_lamp_color = glGetUniformLocation(prog, "lamp_color");
	}

	viewport[0] = fbo_w;
	viewport[1] = fbo_h;

	mat_vec_mul_n(lamp_direction_world, lamp_transform, lamp_direction_init);
	mat_vec_mul_n(lamp_direction_view, view_from_world, lamp_direction_world);
	vec_normalize(lamp_direction, lamp_direction_view);

	vec_scale(lamp_color, lamp->color, lamp->energy);

	glUseProgram(prog);
	glUniform2fv(uni_viewport, 1, viewport);
	glUniform3fv(uni_lamp_direction, 1, lamp_direction);
	glUniform3fv(uni_lamp_color, 1, lamp_color);

	draw_fullscreen_quad();
}
Example #13
0
File: render.c Project: ccxvii/mio
void render_spot_lamp(struct lamp *lamp, mat4 clip_from_view, mat4 view_from_world, mat4 lamp_transform)
{
	static int prog = 0;
	static int uni_viewport;
	static int uni_view_from_clip;
	static int uni_lamp_position;
	static int uni_lamp_direction;
	static int uni_lamp_color;
	static int uni_lamp_distance;
	static int uni_spot_size;
	static int uni_spot_blend;
	static int uni_use_sphere;

	static const vec3 lamp_direction_init = { 0, 0, 1 };

	mat4 view_from_clip;
	vec2 viewport;
	vec3 lamp_position;
	vec3 lamp_direction_world;
	vec3 lamp_direction_view;
	vec3 lamp_direction;
	vec3 lamp_color;
	float spot_size;
	float spot_blend;

	if (!prog) {
		prog = compile_shader(quad_vert_src, spot_frag_src);
		uni_viewport = glGetUniformLocation(prog, "viewport");
		uni_view_from_clip = glGetUniformLocation(prog, "view_from_clip");
		uni_lamp_position = glGetUniformLocation(prog, "lamp_position");
		uni_lamp_direction = glGetUniformLocation(prog, "lamp_direction");
		uni_lamp_color = glGetUniformLocation(prog, "lamp_color");
		uni_lamp_distance = glGetUniformLocation(prog, "lamp_distance");
		uni_spot_size = glGetUniformLocation(prog, "spot_size");
		uni_spot_blend = glGetUniformLocation(prog, "spot_blend");
		uni_use_sphere = glGetUniformLocation(prog, "use_sphere");
	}

	mat_invert(view_from_clip, clip_from_view);

	viewport[0] = fbo_w;
	viewport[1] = fbo_h;

	mat_vec_mul(lamp_position, view_from_world, lamp_transform + 12);

	mat_vec_mul_n(lamp_direction_world, lamp_transform, lamp_direction_init);
	mat_vec_mul_n(lamp_direction_view, view_from_world, lamp_direction_world);
	vec_normalize(lamp_direction, lamp_direction_view);

	vec_scale(lamp_color, lamp->color, lamp->energy);

	spot_size = cos(M_PI * lamp->spot_angle / 360.0);
	spot_blend = (1.0 - spot_size) * lamp->spot_blend;

	glUseProgram(prog);
	glUniform2fv(uni_viewport, 1, viewport);
	glUniformMatrix4fv(uni_view_from_clip, 1, 0, view_from_clip);
	glUniform3fv(uni_lamp_position, 1, lamp_position);
	glUniform3fv(uni_lamp_direction, 1, lamp_direction);
	glUniform3fv(uni_lamp_color, 1, lamp_color);
	glUniform1f(uni_lamp_distance, lamp->distance);
	glUniform1f(uni_spot_size, spot_size);
	glUniform1f(uni_spot_blend, spot_blend);
	glUniform1i(uni_use_sphere, lamp->use_sphere);

	draw_fullscreen_quad();
}