Ejemplo n.º 1
0
GLboolean fbo_create(fbo *F, GLsizei w, GLsizei h)
{
    if (gli.framebuffer_object == 0) return GL_FALSE;

    F->width  = w;
    F->height = h;

    glGenTextures     (1, &F->color_texture);
    glGenTextures     (1, &F->depth_texture);
    glGenFramebuffers_(1, &F->framebuffer);

    glBindTexture  (GL_TEXTURE_2D, F->color_texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D   (GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0,
                    GL_RGBA, GL_UNSIGNED_INT, NULL);

    glBindTexture  (GL_TEXTURE_2D, F->depth_texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D   (GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0,
                    GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);

    glBindFramebuffer_     (GL_FRAMEBUFFER, F->framebuffer);
    glFramebufferTexture2D_(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                            GL_TEXTURE_2D, F->color_texture, 0);
    glFramebufferTexture2D_(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                            GL_TEXTURE_2D, F->depth_texture, 0);
    glFramebufferTexture2D_(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
                            GL_TEXTURE_2D, F->depth_texture, 0);

    if (glCheckFramebufferStatus_(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
    {
        glBindFramebuffer_(GL_FRAMEBUFFER, 0);
        return GL_TRUE;
    }
    else
    {
        glBindFramebuffer_(GL_FRAMEBUFFER, 0);
        return GL_FALSE;
    }
}
Ejemplo n.º 2
0
void hmd_common_swap(float center,
                     float scale,
                     const float *barrel_correction,
                     const float *chroma_correction)
{
    int w = config_get_d(CONFIG_WIDTH);
    int h = config_get_d(CONFIG_HEIGHT);

    float a = (float) w / (float) h / 2;

    /* Prepare to draw a screen-filling pair of rectangles. */

    glBindFramebuffer_(GL_FRAMEBUFFER, 0);
    glViewport(0, 0, w, h);

    glDisable(GL_BLEND);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glUseProgram_(distortion.program);
    {
        /* Set distortion parameters for both eyes. */

        glsl_uniform2f(&distortion, "ScaleOut", 0.5f / scale, 0.5f * a / scale);
        glsl_uniform2f(&distortion, "ScaleIn",  2.0f,         2.0f / a);
        glsl_uniform4f(&distortion, "DistortionK",  barrel_correction[0],
                                                    barrel_correction[1],
                                                    barrel_correction[2],
                                                    barrel_correction[3]);
        glsl_uniform4f(&distortion, "ChromAbParam", chroma_correction[0],
                                                    chroma_correction[1],
                                                    chroma_correction[2],
                                                    chroma_correction[3]);
        /* Draw the left eye. */

        glsl_uniform2f(&distortion, "LensCenter", 0.5f + 0.5f * center, 0.5f);
        hmd_common_draw(L_fbo.color_texture, L_vbo);

        /* Draw the right eye.*/

        glsl_uniform2f(&distortion, "LensCenter", 0.5f - 0.5f * center, 0.5f);
        hmd_common_draw(R_fbo.color_texture, R_vbo);
    }
    glUseProgram_(0);

    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glEnable(GL_BLEND);
}
Ejemplo n.º 3
0
void hmd_common_right()
{
    glBindFramebuffer_(GL_FRAMEBUFFER, R_fbo.framebuffer);
    glViewport(0, 0, R_fbo.width, R_fbo.height);
}
Ejemplo n.º 4
0
int Lua_Framebuffer_new(lua_State *L)
{
	Lua_Image *ptr;
	unsigned int width, height, percision, alpha;
	GLint current_fbo;
	GLenum internal, format;
	
	if(!supported.FBO) return 0;
	
	width = luaL_checkinteger(L, 1);
	height = luaL_checkinteger(L, 2);
	percision = lua_tointeger(L, 3);
	alpha = lua_toboolean(L, 4);
	
	if(percision == 32)
	{
		internal = alpha ? GL_RGBA32F_ARB : GL_RGB32F_ARB;
		format = GL_FLOAT;
	}
	else if(percision == 16)
	{
		internal = alpha ? GL_RGBA16F_ARB : GL_RGB16F_ARB;
		format = GL_FLOAT;
	}
	else
	{
		internal = alpha ? GL_RGBA : GL_RGB;
		format = GL_UNSIGNED_BYTE;
	}
	
	//save current fbo
	glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &current_fbo);
	
	ptr = lua_newuserdata(L, sizeof(Lua_Image));
	ptr->w = width;
	ptr->h = height;
		
	// generate texture save target
	glGenTextures(1, &ptr->texture);
	glBindTexture(GL_TEXTURE_2D, ptr->texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//~ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	//~ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexImage2D(GL_TEXTURE_2D,0,internal,width,height,0,GL_RGBA,format,0);
	glBindTexture(GL_TEXTURE_2D, 0);
	
	// create framebuffer
	glGenFramebuffers_(1, &ptr->fbo);
	glBindFramebuffer_(GL_FRAMEBUFFER_EXT, ptr->fbo);
	glFramebufferTexture2D_(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
			GL_TEXTURE_2D, ptr->texture, 0);
	checkFramebufferStatus();

	// unbind framebuffer
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (GLuint)current_fbo);
	
	luaL_getmetatable(L, "scrupp.image");
	lua_setmetatable(L, -2);
	return 1;
}