static void
magOptionsChanged (CompScreen	   *s,
		   CompOption	   *opt,
		   MagScreenOptions num)
{
    MAG_SCREEN (s);

    magCleanup (s);

    switch (magGetMode (s))
    {
    case ModeImageOverlay:
	if (loadImages (s))
	    ms->mode = ModeImageOverlay;
	else
	    ms->mode = ModeSimple;
	break;
    case ModeFisheye:
	if (loadFragmentProgram (s))
	    ms->mode = ModeFisheye;
	else
	    ms->mode = ModeSimple;
	break;
    default:
	ms->mode = ModeSimple;
    }
    
    if (ms->zoom != 1.0)
	damageScreen (s);
}
Exemplo n.º 2
0
void
MagScreen::optionChanged (CompOption	      *opt,
		   	  MagOptions::Options num)
{
    cleanup ();

    switch (optionGetMode ())
    {
    case ModeImageOverlay:
	if (loadImages ())
	    mode = MagOptions::ModeImageOverlay;
	else
	    mode = MagOptions::ModeSimple;
	break;
    case MagOptions::ModeFisheye:
	if (loadFragmentProgram ())
	    mode = MagOptions::ModeFisheye;
	else
	    mode = MagOptions::ModeSimple;
	break;
    default:
	mode = MagOptions::ModeSimple;
    }
    
    if (zoom != 1.0)
	cScreen->damageScreen ();
}
Exemplo n.º 3
0
bool ShaderTextureInterface::InitProgram() {
	if (!loadVertexProgram("CG/shaderTexture.cg", "VertexMain")) return false;

	if (!loadFragmentProgram("CG/shaderTexture.cg", "FragmentMain")) return false;

	// build some parameters by name such that we can set them later...
	vertexModelViewProj = cgGetNamedParameter(vertexProgram, "modelViewProj");
	fragmentTex = cgGetNamedParameter(fragmentProgram, "tex");

	return true;
}
Exemplo n.º 4
0
static int loadWaterProgram(CompScreen * s)
{
	char buffer[1024];

	WATER_SCREEN(s);

	if (ws->target == GL_TEXTURE_2D)
		sprintf(buffer, waterFpString,
			"2D", "2D",
			1.0f / ws->width, 1.0f / ws->width,
			1.0f / ws->height, 1.0f / ws->height,
			"2D", "2D", "2D", "2D");
	else
		sprintf(buffer, waterFpString,
			"RECT", "RECT",
			1.0f, 1.0f, 1.0f, 1.0f, "RECT", "RECT", "RECT", "RECT");

	return loadFragmentProgram(s, &ws->program, buffer);
}
Exemplo n.º 5
0
/*
 * Load filters from a list of files for current screen
 */
static int
loadFilters (CompScreen  *s,
             CompTexture *texture)
{
	int i, target, loaded, function, count;
	char *name;
	CompWindow *w;

	FILTER_SCREEN (s);

	cfs->filtersLoaded = TRUE;

	/* Fetch filters filenames */
	const BananaValue *
	option_filters = bananaGetOption (bananaIndex,
	                                  "filters",
	                                  s->screenNum);

	count = option_filters->list.nItem;

	/* The texture target that will be used for some ops */
	if (texture->target == GL_TEXTURE_2D)
		target = COMP_FETCH_TARGET_2D;
	else
		target = COMP_FETCH_TARGET_RECT;

	/* Free previously loaded filters and malloc */
	unloadFilters (s);
	cfs->filtersFunctions = malloc (sizeof (int) * count);

	if (!cfs->filtersFunctions)
		return 0;

	cfs->filtersCount = count;

	/* Load each filter one by one */
	loaded = 0;

	for (i = 0; i < count; i++)
	{
		name = base_name (option_filters->list.item[i].s);
		if (!name || !strlen (name))
		{
			if (name)
				free (name);

			cfs->filtersFunctions[i] = 0;
			continue;
		}

		compLogMessage ("colorfilter", CompLogLevelInfo,
		                "Loading filter %s (item %s).", name,
		                option_filters->list.item[i].s);

		function = loadFragmentProgram (option_filters->list.item[i].s, name, s, target);
		free (name);

		cfs->filtersFunctions[i] = function;

		if (function)
			loaded++;
	}

	/* Warn if there was at least one loading failure */
	if (loaded < count)
		compLogMessage ("colorfilter", CompLogLevelWarn,
		                "Tried to load %d filter(s), %d succeeded.",
		                count, loaded);

	if (!loaded)
		cfs->filtersCount = 0;

	/* Damage currently filtered windows */
	for (w = s->windows; w; w = w->next)
	{
		FILTER_WINDOW (w);

		if (cfw->isFiltered)
			addWindowDamage (w);
	}

	return loaded;
}
static Bool
magInitScreen (CompPlugin *p,
	       CompScreen *s)
{
    MagScreen *ms;

    MAG_DISPLAY (s->display);

    ms = calloc (1, sizeof (MagScreen));
    if (!ms)
	return FALSE;

    s->base.privates[md->screenPrivateIndex].ptr = ms;

    WRAP (ms, s, paintScreen, magPaintScreen);
    WRAP (ms, s, preparePaintScreen, magPreparePaintScreen);
    WRAP (ms, s, donePaintScreen, magDonePaintScreen);

    ms->zoom = 1.0;
    ms->zVelocity = 0.0;
    ms->zTarget = 1.0;

    ms->pollHandle = 0;

    glGenTextures (1, &ms->texture);

    if (s->textureNonPowerOfTwo)
	ms->target = GL_TEXTURE_2D;
    else
	ms->target = GL_TEXTURE_RECTANGLE_ARB;

    glEnable (ms->target);

    /* Bind the texture */
    glBindTexture (ms->target, ms->texture);

    /* Load the parameters */
    glTexParameteri (ms->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri (ms->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri (ms->target, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri (ms->target, GL_TEXTURE_WRAP_T, GL_CLAMP);

    glTexImage2D (ms->target, 0, GL_RGB, 0, 0, 0,
		  GL_RGB, GL_UNSIGNED_BYTE, NULL);

    ms->width = 0;
    ms->height = 0;

    glBindTexture (ms->target, 0);

    glDisable (ms->target);

    initTexture (s, &ms->overlay.tex);
    initTexture (s, &ms->mask.tex);
    ms->overlay.loaded = FALSE;
    ms->mask.loaded    = FALSE;

    ms->program = 0;

    magSetOverlayNotify (s, magOptionsChanged);
    magSetMaskNotify (s, magOptionsChanged);
    magSetModeNotify (s, magOptionsChanged);

    switch (magGetMode (s))
    {
    case ModeImageOverlay:
	if (loadImages (s))
	    ms->mode = ModeImageOverlay;
	else
	    ms->mode = ModeSimple;
	break;
    case ModeFisheye:
	if (loadFragmentProgram (s))
	    ms->mode = ModeFisheye;
	else
	    ms->mode = ModeSimple;
	break;
    default:
	ms->mode = ModeSimple;
    }

    if (!s->fragmentProgram)
	compLogMessage ("mag", CompLogLevelWarn,
			"GL_ARB_fragment_program not supported. "
			"Fisheye mode will not work.");

    return TRUE;
}