void VFrame::to_ram()
{
#ifdef HAVE_GL
	switch(opengl_state)
	{
// Only pbuffer is supported since this is only called after the 
// overlay operation onto the pbuffer.
		case VFrame::SCREEN:
			if(pbuffer)
			{
				enable_opengl();
printf("VFrame::to_ram %d %d\n", get_w(), get_h());
				glReadPixels(0, 
					0, 
					get_w(), 
					get_h(), 
					GL_RGB,
					GL_UNSIGNED_BYTE,
					get_rows()[0]);
				flip_vert();
			}
			opengl_state = VFrame::RAM;
			return;
	}
#endif
}
Beispiel #2
0
// LoadOpenGL
//      Attempts to load the OpenGL driver. If successful, call DescribePixelFormat
// 	routine in driver.
//
// Synopsis:
//      BOOL LoadOpenGL(
//          PPDEV ppdev)
static
BOOL LoadOpenGL (PPDEV ppdev)
{
    return 0; // !!! Disable for now in Kernel Mode

#if 0

    ENABLE_OPENGL enable_opengl;
    char *file_name = "tgaglsrv.dll";
    char lpszValue[256];
    DWORD cchValue = 256;

    if (cchValue = GetEnvironmentVariable("TGAGLSRVNAME", lpszValue, cchValue ))
        file_name = lpszValue;
    ppdev->hOpenGLDll = LoadLibrary (file_name);

    if (! ppdev->hOpenGLDll)
    {
        DWORD lastError = EngGetLastError();
        DISPDBG ((1, "TGA!load_extension - Error loading OpenGL Driver as %s - %d\n",
                     file_name, lastError));
        return 0;
    }

    // Find the entry point DrvEnableEscape

    enable_opengl = (ENABLE_OPENGL)GetProcAddress (ppdev->hOpenGLDll,
                                                   "DrvEnableEscape");
    if (! enable_opengl)
    {
        DISPDBG ((0, "TGA!load_extension - Error getting address of DrvEnableEscape in OpenGL Driver %s - %d\n",
                     file_name, EngGetLastError()));
        FreeLibrary (ppdev->hOpenGLDll);
        ppdev->hOpenGLDll = NULL;
        return 0;
    }

    // Call the OpenGL driver initialization routine

    if (! enable_opengl (DDI_DRIVER_VERSION, (DHPDEV)ppdev))
    {
        DISPDBG ((0, "TGA!load_extension - Failure returned by DrvEnableEscape in library %s\n",
                     file_name));
        FreeLibrary (ppdev->hOpenGLDll);
        ppdev->hOpenGLDll = NULL;
        return 0;
    }

    // We're loaded and ready to go

    return 1;

#endif

}
void VFrame::to_texture()
{
#ifdef HAVE_GL

// Must be here so user can create textures without copying data by setting
// opengl_state to TEXTURE.
	BC_Texture::new_texture(&texture,
		get_w(),
		get_h(),
		get_color_model());

// Determine what to do based on state
	switch(opengl_state)
	{
		case VFrame::TEXTURE:
			return;

		case VFrame::SCREEN:
			if((get_w() % 4) || (get_h() % 4)) 
			{
				printf("VFrame::to_texture w=%d h=%d\n", get_w(), get_h());
				return;
			}
			if(pbuffer)
			{
				enable_opengl();
				screen_to_texture();
			}
			opengl_state = VFrame::TEXTURE;
			return;
	}

//printf("VFrame::to_texture %d\n", texture_id);

	switch(color_model)
	{
		case BC_RGB888:
		case BC_YUV888:
			glTexSubImage2D(GL_TEXTURE_2D,
				0,
				0,
				0,
				get_w(),
				get_h(),
				GL_RGB,
				GL_UNSIGNED_BYTE,
				get_rows()[0]);
			break;

		case BC_RGBA8888:
		case BC_YUVA8888:
			glTexSubImage2D(GL_TEXTURE_2D,
				0,
				0,
				0,
				get_w(),
				get_h(),
				GL_RGBA,
				GL_UNSIGNED_BYTE,
				get_rows()[0]);
			break;

		case BC_RGB_FLOAT:
			glTexSubImage2D(GL_TEXTURE_2D,
				0,
				0,
				0,
				get_w(),
				get_h(),
				GL_RGB,
				GL_FLOAT,
				get_rows()[0]);
			break;

		case BC_RGBA_FLOAT:
			glTexSubImage2D(GL_TEXTURE_2D,
				0,
				0,
				0,
				get_w(),
				get_h(),
				GL_RGBA,
				GL_FLOAT,
				get_rows()[0]);
			break;

		default:
			fprintf(stderr, 
				"VFrame::to_texture: unsupported color model %d.\n", 
				color_model);
			break;
	}

	opengl_state = VFrame::TEXTURE;
#endif
}