Hi,

I am wondering if i am fully understanding how texture value
should be computed. I am refering here to section 3.8.13
of opengl specification and specialy to table 3.21.

My understanding is that when you got an RGB texture the
As = 1 but when computing you use Ap which equal to the
primary color component of incoming fragment if you are
texture 0, or to the previous A value if you are texture > 0
ie if you are texture 1 you use A from texture 0, if you are
texture 2 you use A from texture 1 right ?

According to fragment program extension, TEX, TXP, ... should
give you the right A value (Ap depending on which texture unit
you are using). I got the feeling that r300/r400 hardware doesn't
follow this. At least fglrx driver (one packaged in ubuntu edgy)
fail at pixel format test using TEX instruction. I also attach a
small app which should test that. If you launch it res should
be (255, 0, 0, 0) but i will be (255, 0, 0, 255). If anyone could
test that on a windows with r300 hardware.

I may also don't fully understand this part of the specification :)
Btw the Ap value seems a bit hard things to follow i guess that
ATI might have choose to save some silicon and simplify design
than to conform to this specification.

best,
Jerome Glisse
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/glut.h>

#define W 64
#define H 64

static GLubyte my_image[W*H*4];
static GLuint alphaBits;

#define USE_FRAG_PROG 1

void makeCheckImages(void)
{
	int i, j, c;
   
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			c = ((((i&0x8)==0)^((j&0x8)==0)))*255;
			c = 255;
			my_image[j * 4 + i * W * 4 + 0] = (GLubyte) c;
			my_image[j * 4 + i * W * 4 + 1] = (GLubyte) 0;
			my_image[j * 4 + i * W * 4 + 2] = (GLubyte) 0;
			my_image[j * 4 + i * W * 4 + 3] = (GLubyte) 0;
		}
	}
}

void init(void)
{
	glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
	printf("GL_ALPHA_BITS: %d\n", alphaBits);

	glDrawBuffer(GL_FRONT);
	glReadBuffer(GL_FRONT);
	glClearColor(0.0, 0.0, 0.0, 0.0);

	makeCheckImages();

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, W, H, 0,
		     GL_RGBA, GL_UNSIGNED_BYTE, my_image);

#if USE_FRAG_PROG
	{
		GLuint prog;
		static const char *progText =
			"!!ARBfp1.0\n"
			"TEX result.color, fragment.texcoord[0], "
			"texture[0], 2D; \n"
			"END \n"
			;

		if (!glutExtensionSupported("GL_ARB_fragment_program")) {
			printf("Error: GL_ARB_fragment_program "
			       "not supported!\n");
			exit(1);
		}

		glGenProgramsARB(1, &prog);
		glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
		glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
				   GL_PROGRAM_FORMAT_ASCII_ARB,
				   strlen(progText),
				   (const GLubyte *) progText);
		if (glGetError()) {
			fprintf(stderr, "Bad fragment program, error: %s\n",
				glGetString(GL_PROGRAM_ERROR_STRING_ARB));
			exit(0);
		}
	}
#endif
}

void display(void)
{
	GLubyte *res = (GLubyte *)malloc(W * H * 4);	

	glClear(GL_COLOR_BUFFER_BIT);

	glViewport(0, 0, W, H);

	glColor4f(0.0, 0.0, 0.0, 0.0);
	glEnable(GL_TEXTURE_2D);

#if USE_FRAG_PROG
	glEnable(GL_FRAGMENT_PROGRAM_ARB);
#endif

	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);  glVertex2f(-1.0, -1.0);
	glTexCoord2f(1.0, 0.0);  glVertex2f( 1.0, -1.0);
	glTexCoord2f(1.0, 1.0);  glVertex2f( 1.0,  1.0);
	glTexCoord2f(0.0, 1.0);  glVertex2f(-1.0,  1.0);
	glEnd();

#if USE_FRAG_PROG
	glDisable(GL_FRAGMENT_PROGRAM_ARB);
#endif

	glDisable(GL_TEXTURE_2D);

	glFlush();
//	glutSwapBuffers();

	glReadPixels(0, 0, W, H, GL_RGBA, GL_UNSIGNED_BYTE, res);

	printf("pixel(0,0)=(%d, %d, %d, %d)\n",
	       my_image[0],my_image[1],
	       my_image[2],my_image[3]);
	printf("->res(0,0)=(%d, %d, %d, %d)\n",
	       res[0],res[1],
	       res[2],res[3]);

	free(res);
}

void reshape(int w, int h)
{
	glLoadIdentity();
}

void keyboard(unsigned char key, int x, int y)
{
	switch ( key ) {
	case 27:
		exit(0);
		break;
	default:
		break;
	}
}

void idle(void)
{
//	glutPostRedisplay();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA);
	glutInitWindowSize(W, H);
	glutCreateWindow("BUG 7235");

	init();

	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutIdleFunc(idle);
	glutMainLoop();
	return 0;
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
--
_______________________________________________
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel

Reply via email to