Beispiel #1
0
int
getSaturateFragmentFunction (CompScreen  *s,
                             CompTexture *texture,
                             int         param)
{
	int target;

	if (param >= 64)
		return 0;

	if (texture->target == GL_TEXTURE_2D)
		target = COMP_FETCH_TARGET_2D;
	else
		target = COMP_FETCH_TARGET_RECT;

	if (!s->saturateFunction[target][param])
	{
		static const char *saturateData =
		        "MUL temp, output, { 1.0, 1.0, 1.0, 0.0 };"
		        "DP3 temp, temp, program.env[%d];"
		        "LRP output.xyz, program.env[%d].w, output, temp;";
		CompFunctionData  *data;

		data = createFunctionData ();
		if (data)
		{
			char str[1024];

			if (!addTempHeaderOpToFunctionData (data, "temp"))
			{
				destroyFunctionData (data);
				return 0;
			}

			if (!addFetchOpToFunctionData (data, "output", NULL, target))
			{
				destroyFunctionData (data);
				return 0;
			}

			if (!addColorOpToFunctionData (data, "output", "output"))
			{
				destroyFunctionData (data);
				return 0;
			}

			snprintf (str, 1024, saturateData, param, param);

			if (!addDataOpToFunctionData (data, str))
			{
				destroyFunctionData (data);
				return 0;
			}

			s->saturateFunction[target][param] =
				createFragmentFunction (s, "__core_saturate", data);

			destroyFunctionData (data);
		}
	}

	return s->saturateFunction[target][param];
}
Beispiel #2
0
static int
getBumpMapFragmentFunction(CompScreen * s,
			   CompTexture * texture, int unit, int param)
{
	WaterFunction *function;
	CompFunctionData *data;
	int target;

	WATER_SCREEN(s);

	if (texture->target == GL_TEXTURE_2D)
		target = COMP_FETCH_TARGET_2D;
	else
		target = COMP_FETCH_TARGET_RECT;

	for (function = ws->bumpMapFunctions; function;
	     function = function->next) {
		if (function->param == param && function->unit == unit
		    && function->target == target)
			return function->handle;
	}

	data = createFunctionData();
	if (data) {
		static char *temp[] =
		    { "normal", "temp", "total", "bump", "offset" };
		int i, handle = 0;
		char str[1024];

		for (i = 0; i < sizeof(temp) / sizeof(temp[0]); i++) {
			if (!addTempHeaderOpToFunctionData(data, temp[i])) {
				destroyFunctionData(data);
				return 0;
			}
		}

		snprintf(str, 1024,
			 /* get normal from normal map */
			 "TEX normal, fragment.texcoord[%d], texture[%d], %s;"
			 /* save height */
			 "MOV offset, normal;"
			 /* remove scale and bias from normal */
			 "MAD normal, normal, 2.0, -1.0;"
			 /* normalize the normal map */
			 "DP3 temp, normal, normal;"
			 "RSQ temp, temp.x;" "MUL normal, normal, temp;"
			 /* scale down normal by height and constant and use as
			    offset in texture */
			 "MUL offset, normal, offset.w;"
			 "MUL offset, offset, program.env[%d];",
			 unit, unit,
			 (ws->target == GL_TEXTURE_2D) ? "2D" : "RECT", param);

		if (!addDataOpToFunctionData(data, str)) {
			destroyFunctionData(data);
			return 0;
		}

		if (!addFetchOpToFunctionData
		    (data, "output", "offset.yxzz", target)) {
			destroyFunctionData(data);
			return 0;
		}

		snprintf(str, 1024,
			 /* normal dot lightdir, this should eventually be
			    changed to a real light vector */
			 "DP3 bump, normal, { 0.707, 0.707, 0.0, 0.0 };"
			 "MUL bump, bump, state.light[0].diffuse;");

		if (!addDataOpToFunctionData(data, str)) {
			destroyFunctionData(data);
			return 0;
		}

		if (!addColorOpToFunctionData(data, "output", "output")) {
			destroyFunctionData(data);
			return 0;
		}

		snprintf(str, 1024,
			 /* diffuse per-vertex lighting, opacity and brightness
			    and add lightsource bump color */
			 "ADD output, output, bump;");

		if (!addDataOpToFunctionData(data, str)) {
			destroyFunctionData(data);
			return 0;
		}

		function = malloc(sizeof(WaterFunction));
		if (function) {
			handle = createFragmentFunction(s, "water", data);

			function->handle = handle;
			function->target = target;
			function->param = param;
			function->unit = unit;

			function->next = ws->bumpMapFunctions;
			ws->bumpMapFunctions = function;
		}

		destroyFunctionData(data);

		return handle;
	}

	return 0;
}
static int
getNegFragmentFunction (CompScreen  *s,
			CompTexture *texture,
			Bool        alpha)
{
    CompFunctionData *data;
    int              target;

    NEG_SCREEN (s);

    if (texture->target == GL_TEXTURE_2D)
	target = COMP_FETCH_TARGET_2D;
    else
	target = COMP_FETCH_TARGET_RECT;

    if (alpha)
    {
	if (ns->negAlphaFunction)
	    return ns->negAlphaFunction;
    }
    else
    {
	if (ns->negFunction)
	    return ns->negFunction;
    }

    data = createFunctionData ();
    if (data)
    {
	Bool ok = TRUE;
	int  handle = 0;

	if (alpha)
	    ok &= addTempHeaderOpToFunctionData (data, "neg" );

	ok &= addFetchOpToFunctionData (data, "output", NULL, target);
	if (alpha)
	{
	    ok &= addDataOpToFunctionData (data, "RCP neg.a, output.a;");
	    ok &= addDataOpToFunctionData (data,
			"MAD output.rgb, -neg.a, output, 1.0;");
	}
	else
	    ok &= addDataOpToFunctionData (data,
			"SUB output.rgb, 1.0, output;");

	if (alpha)
	    ok &= addDataOpToFunctionData (data,
			"MUL output.rgb, output.a, output;");
		
	ok &= addColorOpToFunctionData (data, "output", "output");
	if (!ok)
	{
	    destroyFunctionData (data);
	    return 0;
	}

	handle = createFragmentFunction (s, "neg", data);

	if (alpha)
	    ns->negAlphaFunction = handle;
	else
	    ns->negFunction = handle;

	destroyFunctionData (data);

	return handle;
    }

    return 0;
}