Exemple #1
0
static void *
thread_read(void* ptr) { 
	struct table * t = ptr;
	int last=0;
	struct table * n = stable_table(t, TKEY("number"));
	struct table * s = stable_table(t, TKEY("string"));
	char buf[32];
	while (last != MAX_COUNT) {
		int i = stable_number(t,TKEY("count"));
		if (i == last)
			continue;
		if (i > last+1) {
			printf("%d-%d\n",last,i);
		}
		last = i;
		i--;
		sprintf(buf,"%d",i);
		int v = 0;
		stable_string(n,TINDEX(i),_strto_l,&v);
		assert(v == i);
		double d = stable_number(s,buf,strlen(buf));
		if ((int)d!=i) {
			printf("key = %s i=%d d=%f\n",buf,i,d);
		}
		assert((int)d == i);
	}

	return NULL;
}
Exemple #2
0
static int fboVertices(CompScreen * s, GLenum type, XPoint * p, int n, float v)
{
	WATER_SCREEN(s);

	if (!fboPrologue(s, TINDEX(ws, 0)))
		return 0;

	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
	glColor4f(0.0f, 0.0f, 0.0f, v);

	glPointSize(3.0f);
	glLineWidth(1.0f);

	glScalef(1.0f / ws->width, 1.0f / ws->height, 1.0);
	glTranslatef(0.5f, 0.5f, 0.0f);

	glBegin(type);

	while (n--) {
		glVertex2i(p->x, p->y);
		p++;
	}

	glEnd();

	glColor4usv(defaultColor);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

	fboEpilogue(s);

	return 1;
}
Exemple #3
0
static void
test_read(struct table *t) {
	struct table * n = stable_table(t, TKEY("number"));
	struct table * s = stable_table(t, TKEY("string"));
	char buf[32];
	int i;
	for (i=0;i<MAX_COUNT;i++) {
		sprintf(buf,"%d",i);
		int v = 0;
		stable_string(n,TINDEX(i),_strto_l,&v);
		assert(v == i);
		double d = stable_number(s,buf,strlen(buf));
		if ((int)d!=i) {
			printf("key = %s i=%d d=%f\n",buf,i,d);
		}
		assert((int)d == i);
	}
}
Exemple #4
0
static void *
thread_write(void *ptr) {
	struct table * t = ptr;
	int i;
	char buf[32];

	struct table * n = stable_table(t, TKEY("number"));
	struct table * s = stable_table(t, TKEY("string"));

	assert(n && s);

	for (i = 0; i<MAX_COUNT; i++) {
		sprintf(buf,"%d",i);
		stable_setstring(n,TINDEX(i),buf,strlen(buf));
		stable_setnumber(s,buf,strlen(buf),i);
		stable_setnumber(t,TKEY("count"),i+1);
	}

	return NULL;
}
Exemple #5
0
static void
waterDrawWindowTexture(CompWindow * w,
		       CompTexture * texture,
		       const FragmentAttrib * attrib, unsigned int mask)
{
	WATER_SCREEN(w->screen);

	if (ws->count) {
		FragmentAttrib fa = *attrib;
		Bool lighting = w->screen->lighting;
		int param, function, unit;
		GLfloat plane[4];

		WATER_DISPLAY(w->screen->display);

		param = allocFragmentParameters(&fa, 1);
		unit = allocFragmentTextureUnits(&fa, 1);

		function =
		    getBumpMapFragmentFunction(w->screen, texture, unit, param);
		if (function) {
			addFragmentFunction(&fa, function);

			screenLighting(w->screen, TRUE);

			(*w->screen->activeTexture) (GL_TEXTURE0_ARB + unit);

			glBindTexture(ws->target, ws->texture[TINDEX(ws, 0)]);

			plane[1] = plane[2] = 0.0f;
			plane[0] = ws->tx / (GLfloat) w->screen->width;
			plane[3] = 0.0f;

			glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
			glTexGenfv(GL_S, GL_EYE_PLANE, plane);
			glEnable(GL_TEXTURE_GEN_S);

			plane[0] = plane[2] = 0.0f;
			plane[1] = ws->ty / (GLfloat) w->screen->height;
			plane[3] = 0.0f;

			glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
			glTexGenfv(GL_T, GL_EYE_PLANE, plane);
			glEnable(GL_TEXTURE_GEN_T);

			(*w->screen->activeTexture) (GL_TEXTURE0_ARB);

			(*w->screen->
			 programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, param,
						 texture->matrix.yy *
						 wd->offsetScale,
						 -texture->matrix.xx *
						 wd->offsetScale, 0.0f, 0.0f);
		}

		/* to get appropriate filtering of texture */
		mask |= PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK;

		UNWRAP(ws, w->screen, drawWindowTexture);
		(*w->screen->drawWindowTexture) (w, texture, &fa, mask);
		WRAP(ws, w->screen, drawWindowTexture, waterDrawWindowTexture);

		if (function) {
			(*w->screen->activeTexture) (GL_TEXTURE0_ARB + unit);
			glDisable(GL_TEXTURE_GEN_T);
			glDisable(GL_TEXTURE_GEN_S);
			glBindTexture(ws->target, 0);
			(*w->screen->activeTexture) (GL_TEXTURE0_ARB);

			screenLighting(w->screen, lighting);
		}
	} else {
		UNWRAP(ws, w->screen, drawWindowTexture);
		(*w->screen->drawWindowTexture) (w, texture, attrib, mask);
		WRAP(ws, w->screen, drawWindowTexture, waterDrawWindowTexture);
	}
}
Exemple #6
0
static void softwareUpdate(CompScreen * s, float dt, float fade)
{
	float *dTmp;
	int i, j;
	float v0, v1, inv;
	float accel, value;
	unsigned char *t0, *t;
	int dWidth, dHeight;
	float *d01, *d10, *d11, *d12;

	WATER_SCREEN(s);

	if (!ws->texture[TINDEX(ws, 0)])
		allocTexture(s, TINDEX(ws, 0));

	dt *= K * 2.0f;
	fade *= 0.99f;

	dWidth = ws->width + 2;
	dHeight = ws->height + 2;

#define D(d, j) (*((d) + (j)))

	d01 = ws->d0 + dWidth;
	d10 = ws->d1;
	d11 = d10 + dWidth;
	d12 = d11 + dWidth;

	for (i = 1; i < dHeight - 1; i++) {
		for (j = 1; j < dWidth - 1; j++) {
			accel = dt * (D(d10, j) +
				      D(d12, j) +
				      D(d11, j - 1) +
				      D(d11, j + 1) - 4.0f * D(d11, j));

			value = (2.0f * D(d11, j) - D(d01, j) + accel) * fade;

			CLAMP(value, 0.0f, 1.0f);

			D(d01, j) = value;
		}

		d01 += dWidth;
		d10 += dWidth;
		d11 += dWidth;
		d12 += dWidth;
	}

	/* update border */
	memcpy(ws->d0, ws->d0 + dWidth, dWidth * sizeof(GLfloat));
	memcpy(ws->d0 + dWidth * (dHeight - 1),
	       ws->d0 + dWidth * (dHeight - 2), dWidth * sizeof(GLfloat));

	d01 = ws->d0 + dWidth;

	for (i = 1; i < dHeight - 1; i++) {
		D(d01, 0) = D(d01, 1);
		D(d01, dWidth - 1) = D(d01, dWidth - 2);

		d01 += dWidth;
	}

	d10 = ws->d1;
	d11 = d10 + dWidth;
	d12 = d11 + dWidth;

	t0 = ws->t0;

	/* update texture */
	for (i = 0; i < ws->height; i++) {
		for (j = 0; j < ws->width; j++) {
			v0 = (D(d12, j) - D(d10, j)) * 1.5f;
			v1 = (D(d11, j - 1) - D(d11, j + 1)) * 1.5f;

			/* 0.5 for scale */
			inv = 0.5f / sqrtf(v0 * v0 + v1 * v1 + 1.0f);

			/* add scale and bias to normal */
			v0 = v0 * inv + 0.5f;
			v1 = v1 * inv + 0.5f;

			/* store normal map in RGB components */
			t = t0 + (j * 4);
			t[0] = (unsigned char)((inv + 0.5f) * 255.0f);
			t[1] = (unsigned char)(v1 * 255.0f);
			t[2] = (unsigned char)(v0 * 255.0f);

			/* store height in A component */
			t[3] = (unsigned char)(D(d11, j) * 255.0f);
		}

		d10 += dWidth;
		d11 += dWidth;
		d12 += dWidth;

		t0 += ws->width * 4;
	}

#undef D

	/* swap height maps */
	dTmp = ws->d0;
	ws->d0 = ws->d1;
	ws->d1 = dTmp;

	if (ws->texture[TINDEX(ws, 0)]) {
		glBindTexture(ws->target, ws->texture[TINDEX(ws, 0)]);
		glTexImage2D(ws->target,
			     0, GL_RGBA, ws->width, ws->height, 0, GL_BGRA,
#if IMAGE_BYTE_ORDER == MSBFirst
			     GL_UNSIGNED_INT_8_8_8_8_REV,
#else
			     GL_UNSIGNED_BYTE,
#endif
			     ws->t0);
	}
}
Exemple #7
0
static int fboUpdate(CompScreen * s, float dt, float fade)
{
	WATER_SCREEN(s);

	if (!fboPrologue(s, TINDEX(ws, 1)))
		return 0;

	if (!ws->texture[TINDEX(ws, 2)])
		allocTexture(s, TINDEX(ws, 2));

	if (!ws->texture[TINDEX(ws, 0)])
		allocTexture(s, TINDEX(ws, 0));

	glEnable(ws->target);

	(*s->activeTexture) (GL_TEXTURE0_ARB);
	glBindTexture(ws->target, ws->texture[TINDEX(ws, 2)]);

	glTexParameteri(ws->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(ws->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	(*s->activeTexture) (GL_TEXTURE1_ARB);
	glBindTexture(ws->target, ws->texture[TINDEX(ws, 0)]);
	glTexParameteri(ws->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(ws->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	glEnable(GL_FRAGMENT_PROGRAM_ARB);
	(*s->bindProgram) (GL_FRAGMENT_PROGRAM_ARB, ws->program);

	(*s->programLocalParameter4f) (GL_FRAGMENT_PROGRAM_ARB, 0,
				       dt * K, fade, 1.0f, 1.0f);

	glBegin(GL_QUADS);

	glTexCoord2f(0.0f, 0.0f);
	glVertex2f(0.0f, 0.0f);
	glTexCoord2f(ws->tx, 0.0f);
	glVertex2f(1.0f, 0.0f);
	glTexCoord2f(ws->tx, ws->ty);
	glVertex2f(1.0f, 1.0f);
	glTexCoord2f(0.0f, ws->ty);
	glVertex2f(0.0f, 1.0f);

	glEnd();

	glDisable(GL_FRAGMENT_PROGRAM_ARB);

	glTexParameteri(ws->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(ws->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindTexture(ws->target, 0);
	(*s->activeTexture) (GL_TEXTURE0_ARB);
	glTexParameteri(ws->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(ws->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glBindTexture(ws->target, 0);

	glDisable(ws->target);

	fboEpilogue(s);

	/* increment texture index */
	ws->tIndex = TINDEX(ws, 1);

	return 1;
}