Example #1
0
int test_compiler(int i)
{
	static char vert_shader[64 * 1024], frag_shader[64 * 1024];
	GLuint program;
	int vert_fd, frag_fd;
	int ret;

	vert_fd = openfile("shaders/%04d.vs", i);
	frag_fd = openfile("shaders/%04d.fs", i);
	if ((vert_fd < 0) || (frag_fd < 0))
		return -1;

	ret = read(vert_fd, vert_shader, sizeof(vert_shader));
	if (ret < 0)
		return ret;
	vert_shader[ret] = '\0';

	ret = read(frag_fd, frag_shader, sizeof(frag_shader));
	if (ret < 0)
		return ret;
	frag_shader[ret] = '\0';

	RD_START("compiler", "%d", i);

	program = get_program(vert_shader, frag_shader);

	link_program(program);
	GCHK(glFlush());

	RD_END();

	return 0;
}
Example #2
0
void test_fill(uint32_t w, uint32_t h, uint32_t format)
{
	PixmapPtr dest;
	C2D_RECT rect;
	c2d_ts_handle curTimestamp;

	DEBUG_MSG("fill: %04dx%04d-%08x", w, h, format);
	RD_START("fill", "%dx%d-%08x", w, h, format);

	dest = create_pixmap(w, h, format);

	rect.x = 1 + (w / 64);
	rect.y = 2 + (w / 32);
	rect.width = w - 2 * rect.x;
	rect.height = h - 2 * rect.y;

	// note: look for pattern 0xff556677 in memory to find cmdstream:
	CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	// second blit.. fill a sub-rect in center of surface:
	rect.x = (w - 10) / 2;
	rect.y = (h - 16) / 2;
	rect.width = 10;
	rect.height = 16;
	CHK(c2dFillSurface(dest->id, 0xff223344, &rect));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	RD_END();

	dump_pixmap(dest, "fill-%04dx%04d-%08x.bmp", w, h, format);
}
Example #3
0
void test_fill(uint32_t w, uint32_t h, uint32_t format,
		uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2)
{
	PixmapPtr dest;
	C2D_RECT rect;
	c2d_ts_handle curTimestamp;

	DEBUG_MSG("----------------------------------------------------------------");
	DEBUG_MSG("fill2: %04dx%04d-%08x-%d,%d,%d,%d", w, h, format, x1, y1, x2, y2);
	RD_START("fill2", "%dx%d-%08x-%d-%d-%d-%d", w, h, format, x1, y1, x2, y2);

	dest = create_pixmap(w, h, format);

	rect.x = x1;
	rect.y = y1;
	rect.width = x2 - x1;
	rect.height = y2 - y1;

	CHK(c2dFillSurface(dest->id, 0x00585a5d, &rect));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	RD_END();

	dump_pixmap(dest, "fill-%04dx%04d-%08x.bmp", w, h, format);
}
Example #4
0
static void test_mipmap(int maxlevels, int w, int h, unsigned filt)
{
	RD_START("mipmap", "maxlevels=%d, texsize=%dx%d", maxlevels, w, h);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 400, 240);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	programObject = get_program(vShaderStr, fShaderStr);
	link_program(programObject);

	// Get the attribute locations
	GCHK(positionLoc = glGetAttribLocation(programObject, "a_position"));
	GCHK(texCoordLoc = glGetAttribLocation(programObject, "a_texCoord"));

	// Get the sampler location
	GCHK(samplerLoc = glGetUniformLocation(programObject, "s_texture"));

	// Get the offset location
	GCHK(offsetLoc = glGetUniformLocation(programObject, "u_offset"));

	// Load the texture
	GCHK(textureId = CreateMipMappedTexture2D(maxlevels, w, h, filt));

	GCHK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));

	GCHK(Draw());

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

#ifndef BIONIC
	sleep(5);
#endif

	ECHK(eglDestroySurface(display, surface));
#ifdef BIONIC
	ECHK(eglTerminate(display));
#endif

	RD_END();
}
Example #5
0
void test_piglit(void)
{
	RD_START("piglit-good", "");
	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 250, 250);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "vertex"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 0.5));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (GLfloat[]){
		20.0, 5.0, 0.0, 1.0, 30.0, 5.0, 0.0, 1.0, 20.0, 15.0, 0.0, 1.0, 30.0, 15.0, 0.0, 1.0
	}));
	GCHK(glEnableVertexAttribArray(0));

	/* now set up our uniforms. */
	GCHK(uniform_location = glGetUniformLocation(program, "row"));
	GCHK(glUniform1i(uniform_location, 1));
	GCHK(uniform_location = glGetUniformLocation(program, "expect"));
	GCHK(glUniform1fv(uniform_location, 1, (GLfloat[]){ 4 }));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	usleep(1000000);

	eglTerminate(display);

	RD_END();
}
Example #6
0
void test_copy(uint32_t w, uint32_t h, uint32_t format)
{
	PixmapPtr src, dest;
	C2D_OBJECT blit = {};
	C2D_RECT rect;
	c2d_ts_handle curTimestamp;

	DEBUG_MSG("----------------------------------------------------------------");
	DEBUG_MSG("copy: %04dx%04d-%08x", w, h, format);
	RD_START("copy", "%dx%d format:%08x", w, h, format);

	dest = create_pixmap(w, h, format);
	src  = create_pixmap(13, 17, format);

	rect.x = 1;
	rect.y = 2;
	rect.width = w - 2;
	rect.height = h - 3;
	CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	rect.x = 0;
	rect.y = 0;
	rect.width = 13;
	rect.height = 17;
	CHK(c2dFillSurface(src->id, 0xff223344, &rect));
	CHK(c2dFlush(src->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	blit.surface_id = src->id;
	blit.config_mask = DEFAULT_BLIT_MASK;
	blit.next = NULL;

	blit.source_rect.x = FIXED(1);
	blit.source_rect.y = FIXED(2);
	blit.source_rect.width = FIXED(13-1);
	blit.source_rect.height = FIXED(17-2);

	blit.target_rect.x = FIXED((w - 13) / 2);
	blit.target_rect.y = FIXED((h - 17) / 2);
	blit.target_rect.width = FIXED(13);
	blit.target_rect.height = FIXED(17);
	CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	RD_END();

	dump_pixmap(dest, "copy-%04dx%04d-%08x.bmp", w, h, format);
}
Example #7
0
void test_caps(void)
{
	GLint width, height;
	EGLint pbuffer_attribute_list[] = {
		EGL_WIDTH, 256,
		EGL_HEIGHT, 256,
		EGL_LARGEST_PBUFFER, EGL_TRUE,
		EGL_NONE
	};
	EGLSurface surface;
	int i;

	RD_START("caps", "");

	ECHK(surface = eglCreatePbufferSurface(display, config, pbuffer_attribute_list));

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("PBuffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));
	GCHK(glFlush());

	printf("EGL Version %s\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor %s\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions %s\n", eglQueryString(display, EGL_EXTENSIONS));
	printf("GL Version %s\n", glGetString(GL_VERSION));
	printf("GL extensions: %s\n", glGetString(GL_EXTENSIONS));

	for (i = 0; i < ARRAY_SIZE(int_params); i++) {
		GLint val[4] = {};
		GLenum err;

		glGetIntegerv(int_params[i].pname, val);

		err = glGetError();
		if (err != GL_NO_ERROR) {
			printf("no %s: %s\n", int_params[i].name, glStrError(err));
		} else {
			printf("%s: %d %d %d %d\n", int_params[i].name,
					val[0], val[1], val[2], val[3]);
		}
	}

	RD_END();
}
Example #8
0
int main(int argc, char **argv)
{
	struct fd_state *state;
	struct fd_surface *surface, *lolstex1, *lolstex2;
	struct fd_program *cat_program, *tex_program;
	struct fd_bo *position_vbo, *normal_vbo;
	const char *cat_vertex_shader_asm =
		"@varying(R0)     vertex_normal                                                      \n"
		"@varying(R1)     vertex_position                                                    \n"
		"@attribute(R1)   normal                                                             \n"
		"@attribute(R2)   position                                                           \n"
		"@uniform(C0-C3)  ModelViewMatrix                                                    \n"
		"@uniform(C4-C7)  ModelViewProjectionMatrix                                          \n"
		"@uniform(C8-C10) NormalMatrix                                                       \n"
		"@const(C11)      1.000000, 0.000000, 0.000000, 0.000000                             \n"
		"EXEC                                                                                \n"
		"      FETCH:    VERTEX  R1.xyz_ = R0.x FMT_32_32_32_FLOAT SIGNED STRIDE(12) CONST(20, 0)\n"
		"      FETCH:    VERTEX  R2.xyz_ = R0.x FMT_32_32_32_FLOAT SIGNED STRIDE(12) CONST(20, 1)\n"
		"   (S)ALU:      MULADDv R0 = C7, R2.zzzz, C6                                        \n"
		"      ALU:      MULADDv R0 = R0, R2.yyyy, C5                                        \n"
		"ALLOC POSITION SIZE(0x0)                                                            \n"
		"EXEC                                                                                \n"
		"      ALU:      MULADDv export62 = R0, R2.xxxx, C4      ; gl_Position               \n"
		"      ALU:      MULv    R0.xyz_ = R1.zzzw, C10                                      \n"
		"      ALU:      MULADDv R0.xyz_ = R0, R1.yyyw, C9                                   \n"
		"      ALU:      MULADDv R0.xyz_ = R0, R1.xxxw, C8                                   \n"
		"      ALU:      DOT3v   R1.x___ = R0, R0                                            \n"
		"      ALU:      MULADDv R3 = C3, R2.zzzz, C2                                        \n"
		"EXEC                                                                                \n"
		"      ALU:      MULADDv R3 = R3, R2.yyyy, C1                                        \n"
		"      ALU:      MAXv    R0.____ = R0, R0                                            \n"
		"                RECIPSQ_IEEE     R0.___w = R1.xyzx                                  \n"
		"ALLOC PARAM/PIXEL SIZE(0x1)                                                         \n"
		"EXEC_END                                                                            \n"
		"      ALU:      MULADDv export1 = R3, R2.xxxx, C0                                   \n"
		"      ALU:      MULv    export0.xyz_ = R0, R0.wwww                                  \n";

	const char *cat_fragment_shader_asm =
/*
precision mediump float;
const vec4 MaterialDiffuse = vec4(0.000000, 0.000000, 1.000000, 1.000000);
const vec4 LightColor0 = vec4(0.800000, 0.800000, 0.800000, 1.000000);
const vec4 light_position = vec4(0.000000, 1.000000, 0.000000, 1.000000);
varying vec3 vertex_normal;
varying vec4 vertex_position;

void main(void)
{
    const vec4 diffuse_light_color = LightColor0;
    const vec4 lightAmbient = vec4(0.1, 0.1, 0.1, 1.0);
    const vec4 lightSpecular = vec4(0.8, 0.8, 0.8, 1.0);
    const vec4 matAmbient = vec4(0.2, 0.2, 0.2, 1.0);
    const vec4 matSpecular = vec4(1.0, 1.0, 1.0, 1.0);
    const float matShininess = 100.0;                     // C4.x
    vec3 eye_direction = normalize(-vertex_position.xyz);
    vec3 light_direction = normalize(light_position.xyz/light_position.w -
                                     vertex_position.xyz/vertex_position.w);
    vec3 normalized_normal = normalize(vertex_normal);

    // reflect(i,n) -> i - 2 * dot(n,i) * n
    vec3 reflection = reflect(-light_direction, normalized_normal);
    float specularTerm = pow(max(0.0, dot(reflection, eye_direction)), matShininess);
    float diffuseTerm = max(0.0, dot(normalized_normal, light_direction));
    vec4 specular = (lightSpecular * matSpecular);
    vec4 ambient = (lightAmbient * matAmbient);
    vec4 diffuse = (diffuse_light_color * MaterialDiffuse);
    vec4 result = (specular * specularTerm) + ambient + (diffuse * diffuseTerm);
    gl_FragColor = result;
}
*/
		"@varying(R0)    vertex_normal                                                                                \n"
		"@varying(R1)    vertex_position                                                                              \n"
		"@const(C0)      0.000000, 1.000000, 0.000000, 0.000000                                                       \n"
		"@const(C1)      0.800000, 0.800000, 0.800000, 1.000000                                                       \n"
		"@const(C2)      0.020000, 0.020000, 0.020000, 1.000000                                                       \n"
		"@const(C3)      0.000000, 0.000000, 0.800000, 1.000000                                                       \n"
		"@const(C4)      100.000000, 0.000000, 0.000000, 0.000000                                                     \n"
		"EXEC                                                                                                         \n"
		"   (S)ALU:      DOT3v   R2.x___ = R0, R0                ; normalize(vertex_normal)                           \n"
		"                RECIP_IEEE     R3.x___ = R1             ; 1/vertex_position.x ? R1.wyzw?                     \n"
		"      ALU:      MULADDv R3.xyz_ = C0.xyxw, -R1, R3.xxxw ; light_position.xyz/1.0 -                           \n"
		"                                                        ; vertex_position.xyz/vertex_position.w              \n"
		"      ALU:      DOT3v   R2.x___ = R3, R3                ; normalize(light_position...)                       \n"
		"                RECIPSQ_IEEE     R0.___w = R2.xyzx      ; normalize(vertex_normal)                           \n"
		"; here the RSQ sees the R2 value written in first instruction, rather than                                   \n"
		"; the R2 dst being calculated as part of the same VLIW instruction                                           \n"
		"      ALU:      MULv    R0.xyz_ = R0, R0.wwww           ; normalized_normal = normalize(vertex_normal)       \n"
		"                RECIPSQ_IEEE     R0.___w = R2.xyzx      ; normalize(light_position...)                       \n"
		"      ALU:      MULv    R2.xyz_ = R3, R0.wwww           ; light_direction = normalize(light_position...)     \n"
		"      ALU:      DOT3v   R3.x___ = -R1, -R1              ; normalize(-vertex_position.xyz)                    \n"
		"EXEC                                                                                                         \n"
		"; reflect(i,n) -> i - 2 * dot(n,i) * n                                                                       \n"
		"      ALU:      DOT3v   R3.x___ = -R2, R0               ; reflect(-light_direction, normalized_normal)       \n"
		"                RECIPSQ_IEEE     R0.___w = R3.xyzx      ; normalize(-vertex_position.xyz);                   \n"
		"      ALU:      MULv    R1.xyz_ = -R1, R0.wwww          ; eye_direction = normalize(-vertex_position.xyz)    \n"
		"                ADDs    R3.x___ = R3.xyzx               ; 2 * dot(n, i)                                      \n"
		"      ALU:      MULADDv R3.xyz_ = -R2, R0, -R3.xxxw     ; reflect(..) -> i + (n * (2 * dot(n, i))            \n"
		"      ALU:      DOT3v   R1.x___ = R1, R3                ; dot(reflection, eye_direction)                     \n"
		"      ALU:      MAXv    R1.x___ = R1, C0                ; max(0.0, dot(reflection, eye_direction)            \n"
		"      ALU:      DOT3v   R0.x___ = R2, R0                ; dot(normalized_normal, light_direction)            \n"
		"                LOG_CLAMP    R0.___w = R1.xyzx          ; pow(max(0.0, dot(...)), matShininess)              \n"
		"EXEC                                                                                                         \n"
		"      ALU:      MAXv    R0.x___ = R0, C0                ; diffuseTerm = max(0.0, dot(...))                   \n"
		"                MUL_CONST_0     R0.___w = C4.wyzx       ; specularTerm = pow(..., matShininess)              \n"
		"      ALU:      MAXv    R0.____ = R0, R0                                                                     \n"
		"                EXP_IEEE    R1.x___ = R0                ; specularTerm = pow(..)                             \n"
		"; C2 is ambient  = (lightAmbient * matAmbient)   = vec4(0.1,0.1,0.1,1.0) * vec4(0.2,0.2,0.2,1.0)             \n"
		"; C1 is specular = (lightSpecular * matSpecular) = vec4(0.8,0.8,0.8,1.0) * vec4(1.0,1.0,1.0,1.0)             \n"
		"      ALU:      MULADDv R1.x__w = C2, R1.xyzx, C1       ; ambient + (specularTerm * specular)                \n"
		"ALLOC PARAM/PIXEL SIZE(0x0)                                                                                  \n"
		"EXEC_END ADDR(0x12) CNT(0x1)                                                                                 \n"
		"      ALU:      MULADDv export0 = R1.xxxw, R0.xxxx, C3.xxzw     ; gl_FragColor                               \n"
		"NOP                                                                                                          \n";

	static const GLfloat texcoords[] = {
			0.0f, 1.0f,
			1.0f, 1.0f,
			0.0f, 0.0f,
			1.0f, 0.0f,
	};

	static const GLfloat tex1_vertices[] = {
			-0.95, +0.45, -1.0,
			+0.45, +0.45, -1.0,
			-0.95, +0.95, -1.0,
			+0.45, +0.95, -1.0
	};

	static const GLfloat tex2_vertices[] = {
			-0.45, -0.95, -1.0,
			+0.95, -0.95, -1.0,
			-0.45, -0.45, -1.0,
			+0.95, -0.45, -1.0
	};

	const char *tex_vertex_shader_asm =
		"@attribute(R1)  aPosition                                        \n"
		"@attribute(R2)  aTexCoord                                        \n"
		"@varying(R0)    vTexCoord                                        \n"
		"EXEC                                                             \n"
		"      FETCH:   VERTEX   R2.xy11 = R0.x FMT_32_32_FLOAT SIGNED    \n"
		"                                      STRIDE(8) CONST(20, 1)     \n"
		"   (S)FETCH:   VERTEX   R1.xyz1 = R0.x FMT_32_32_32_FLOAT SIGNED \n"
		"                                      STRIDE(12) CONST(20, 0)    \n"
		"ALLOC POSITION SIZE(0x0)                                         \n"
		"EXEC                                                             \n"
		"      ALU:   MAXv   export62 = R1, R1   ; gl_Position            \n"
		"ALLOC PARAM/PIXEL SIZE(0x0)                                      \n"
		"EXEC_END                                                         \n"
		"      ALU:   MAXv   export0 = R2, R2    ; vTexCoord              \n"
		"NOP                                                              \n";

	const char *tex_fragment_shader_asm =
		"@varying(R0)    vTexCoord                                        \n"
		"@sampler(0)     uTexture                                         \n"
		"EXEC                                                             \n"
		"   (S)FETCH:  SAMPLE  R0.xyzw = R0.xyx CONST(0)                  \n"
		"ALLOC PARAM/PIXEL SIZE(0x0)                                      \n"
		"EXEC_END                                                         \n"
		"      ALU:    MAXv    export0 = R0, R0 ; gl_FragColor            \n"
		"NOP                                                              \n";

	uint32_t width = 0, height = 0;
	int i, n = 1;

	if (argc == 2)
		n = atoi(argv[1]);

	DEBUG_MSG("----------------------------------------------------------------");
	RD_START("fd-cat", "");

	state = fd_init();
	if (!state)
		return -1;

	surface = fd_surface_screen(state, &width, &height);
	if (!surface)
		return -1;

	/* load textures: */
	lolstex1 = fd_surface_new_fmt(state, lolstex1_image.width, lolstex1_image.height,
			COLORX_8_8_8_8);
	fd_surface_upload(lolstex1, lolstex1_image.pixel_data);

	lolstex2 = fd_surface_new_fmt(state, lolstex2_image.width, lolstex2_image.height,
			COLORX_8_8_8_8);
	fd_surface_upload(lolstex2, lolstex2_image.pixel_data);

	fd_enable(state, GL_CULL_FACE);
	fd_depth_func(state, GL_LEQUAL);
	fd_enable(state, GL_DEPTH_TEST);
	fd_tex_param(state, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	fd_tex_param(state, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	fd_blend_func(state, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	/* this needs to come after enabling depth test as enabling depth test
	 * effects bin sizes:
	 */
	fd_make_current(state, surface);

	/* construct the two shader programs: */
	cat_program = fd_program_new();
	fd_program_attach_asm(cat_program, FD_SHADER_VERTEX, cat_vertex_shader_asm);
	fd_program_attach_asm(cat_program, FD_SHADER_FRAGMENT, cat_fragment_shader_asm);

	tex_program = fd_program_new();
	fd_program_attach_asm(tex_program, FD_SHADER_VERTEX, tex_vertex_shader_asm);
	fd_program_attach_asm(tex_program, FD_SHADER_FRAGMENT, tex_fragment_shader_asm);

	fd_link(state);

	position_vbo = fd_attribute_bo_new(state, cat_position_sz, cat_position);
	normal_vbo = fd_attribute_bo_new(state, cat_normal_sz, cat_normal);

	for (i = 0; i < n; i++) {
		GLfloat aspect = (GLfloat)height / (GLfloat)width;
		ESMatrix modelview;
		ESMatrix projection;
		ESMatrix modelviewprojection;
		float normal[9];
		float scale = 1.8;

		esMatrixLoadIdentity(&modelview);
		esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
		esRotate(&modelview, 45.0f - (0.5f * i), 0.0f, 1.0f, 0.0f);

		esMatrixLoadIdentity(&projection);
		esFrustum(&projection,
				-scale, +scale,
				-scale * aspect, +scale * aspect,
				5.5f, 10.0f);

		esMatrixLoadIdentity(&modelviewprojection);
		esMatrixMultiply(&modelviewprojection, &modelview, &projection);

		normal[0] = modelview.m[0][0];
		normal[1] = modelview.m[0][1];
		normal[2] = modelview.m[0][2];
		normal[3] = modelview.m[1][0];
		normal[4] = modelview.m[1][1];
		normal[5] = modelview.m[1][2];
		normal[6] = modelview.m[2][0];
		normal[7] = modelview.m[2][1];
		normal[8] = modelview.m[2][2];

		fd_clear_color(state, 0xff000000);
		fd_clear(state, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		fd_attribute_bo(state, "normal", normal_vbo);
		fd_attribute_bo(state, "position", position_vbo);

		fd_uniform_attach(state, "ModelViewMatrix",
				4, 4, &modelview.m[0][0]);
		fd_uniform_attach(state, "ModelViewProjectionMatrix",
				4, 4,  &modelviewprojection.m[0][0]);
		fd_uniform_attach(state, "NormalMatrix",
				3, 3, normal);

		/* draw cat: */
		fd_disable(state, GL_BLEND);
		fd_set_program(state, cat_program);
		fd_draw_arrays(state, GL_TRIANGLES, 0, cat_vertices);

		/* setup to draw text (common to tex1 and tex2): */
		fd_enable(state, GL_BLEND);
		fd_set_program(state, tex_program);
		fd_attribute_pointer(state, "aTexCoord", 2, 4, texcoords);

		/* draw tex1: */
		fd_set_texture(state, "uTexture", lolstex1);
		fd_attribute_pointer(state, "aPosition", 3, 4, tex1_vertices);
		fd_draw_arrays(state, GL_TRIANGLE_STRIP, 0, 4);

		/* draw tex2: */
		fd_set_texture(state, "uTexture", lolstex2);
		fd_attribute_pointer(state, "aPosition", 3, 4, tex2_vertices);
		fd_draw_arrays(state, GL_TRIANGLE_STRIP, 0, 4);

		fd_swap_buffers(state);
	}

	fd_flush(state);

	fd_dump_bmp(surface, "lolscat.bmp");

	fd_fini(state);

	RD_END();

	return 0;
}
Example #9
0
int main(int argc, char **argv)
{
	struct fd_state *state;
	struct fd_surface *surface;
	int width, height;

	static const GLfloat vertices[] = {
			-0.75f, +0.25f, +0.50f, // Quad #0
			-0.25f, +0.25f, +0.50f,
			-0.25f, +0.75f, +0.50f,
			-0.75f, +0.75f, +0.50f,
			+0.25f, +0.25f, +0.90f, // Quad #1
			+0.75f, +0.25f, +0.90f,
			+0.75f, +0.75f, +0.90f,
			+0.25f, +0.75f, +0.90f,
			-0.75f, -0.75f, +0.50f, // Quad #2
			-0.25f, -0.75f, +0.50f,
			-0.25f, -0.25f, +0.50f,
			-0.75f, -0.25f, +0.50f,
			+0.25f, -0.75f, +0.50f, // Quad #3
			+0.75f, -0.75f, +0.50f,
			+0.75f, -0.25f, +0.50f,
			+0.25f, -0.25f, +0.50f,
			-1.00f, -1.00f, +0.00f, // Big Quad
			+1.00f, -1.00f, +0.00f,
			+1.00f, +1.00f, +0.00f,
			-1.00f, +1.00f, +0.00f,
	};

	static const GLubyte indices[][6] = {
			{  0,  1,  2,  0,  2,  3 }, // Quad #0
			{  4,  5,  6,  4,  6,  7 }, // Quad #1
			{  8,  9, 10,  8, 10, 11 }, // Quad #2
			{ 12, 13, 14, 12, 14, 15 }, // Quad #3
			{ 16, 17, 18, 16, 18, 19 }, // Big Quad
	};

#define NumTests  4
	static const GLfloat colors[NumTests][4] = {
			{ 1.0f, 0.0f, 0.0f, 1.0f },
			{ 0.0f, 1.0f, 0.0f, 1.0f },
			{ 0.0f, 0.0f, 1.0f, 1.0f },
			{ 1.0f, 1.0f, 0.0f, 0.0f },
	};

#if 0
	const char *vertex_shader_source =
		"attribute vec4 aPosition;    \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_Position = aPosition; \n"
		"}                            \n";
	const char *fragment_shader_source =
		"precision highp float;       \n"
		"uniform vec4 uColor;         \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_FragColor = uColor;   \n"
		"}                            \n";
#else
	const char *vertex_shader_asm =
		"@attribute(R1)  aPosition                                        \n"
		"EXEC                                                             \n"
		"   (S)FETCH:   VERTEX   R1.xyz1 = R0.x FMT_32_32_32_FLOAT SIGNED \n"
		"                                      STRIDE(12) CONST(20, 0)    \n"
		"ALLOC POSITION SIZE(0x0)                                         \n"
		"EXEC                                                             \n"
		"      ALU:   MAXv   export62 = R1, R1   ; gl_Position            \n"
		"ALLOC PARAM/PIXEL SIZE(0x0)                                      \n"
		"EXEC_END                                                         \n"
		"NOP                                                              \n";
	const char *fragment_shader_asm =
		"@uniform(C0) uColor                                              \n"
		"ALLOC PARAM/PIXEL SIZE(0x0)                                      \n"
		"EXEC_END                                                         \n"
		"      ALU:    MAXv export0 = C0, C0    ; gl_FragColor            \n";
#endif
	GLint numStencilBits;
	GLuint stencilValues[NumTests] = {
			0x7, // Result of test 0
			0x0, // Result of test 1
			0x2, // Result of test 2
			0xff // Result of test 3.  We need to fill this value in a run-time
	};
	int i;

	DEBUG_MSG("----------------------------------------------------------------");
	RD_START("fd-stencil", "");

	state = fd_init();
	if (!state)
		return -1;

	surface = fd_surface_screen(state, &width, &height);
	if (!surface)
		return -1;

	fd_enable(state, GL_DEPTH_TEST);
	fd_enable(state, GL_STENCIL_TEST);

	/* this needs to come after enabling depth/stencil test as these
	 * effect bin sizes:
	 */
	fd_make_current(state, surface);

	fd_vertex_shader_attach_asm(state, vertex_shader_asm);
	fd_fragment_shader_attach_asm(state, fragment_shader_asm);

	fd_link(state);

	fd_clear_color(state, 0x00000000);
	fd_clear_stencil(state, 0x1);
	fd_clear_depth(state, 0.75);

	// Clear the color, depth, and stencil buffers.  At this
	//   point, the stencil buffer will be 0x1 for all pixels
	fd_clear(state, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	fd_attribute_pointer(state, "aPosition", 3, 20, vertices);

	fd_uniform_attach(state, "uColor", 4, 1, (GLfloat[]){
		0.0, 0.0, 0.0, 0.0,
	});

	// Test 0:
	//
	// Initialize upper-left region.  In this case, the
	//   stencil-buffer values will be replaced because the
	//   stencil test for the rendered pixels will fail the
	//   stencil test, which is
	//
	//        ref   mask   stencil  mask
	//      ( 0x7 & 0x3 ) < ( 0x1 & 0x7 )
	//
	//   The value in the stencil buffer for these pixels will
	//   be 0x7.
	//
	fd_stencil_func(state, GL_LESS, 0x7, 0x3);
	fd_stencil_op(state, GL_REPLACE, GL_DECR, GL_DECR);
	fd_draw_elements(state, GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[0]);

	// Test 1:
	//
	// Initialize the upper-right region.  Here, we'll decrement
	//   the stencil-buffer values where the stencil test passes
	//   but the depth test fails.  The stencil test is
	//
	//        ref  mask    stencil  mask
	//      ( 0x3 & 0x3 ) > ( 0x1 & 0x3 )
	//
	//    but where the geometry fails the depth test.  The
	//    stencil values for these pixels will be 0x0.
	//
	fd_stencil_func(state, GL_GREATER, 0x3, 0x3);
	fd_stencil_op(state, GL_KEEP, GL_DECR, GL_KEEP);
	fd_draw_elements(state, GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[1]);

	// Test 2:
	//
	// Initialize the lower-left region.  Here we'll increment
	//   (with saturation) the stencil value where both the
	//   stencil and depth tests pass.  The stencil test for
	//   these pixels will be
	//
	//        ref  mask     stencil  mask
	//      ( 0x1 & 0x3 ) == ( 0x1 & 0x3 )
	//
	//   The stencil values for these pixels will be 0x2.
	//
	fd_stencil_func(state, GL_EQUAL, 0x1, 0x3);
	fd_stencil_op(state, GL_KEEP, GL_INCR, GL_INCR);
	fd_draw_elements(state, GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[2]);

	// Test 3:
	//
	// Finally, initialize the lower-right region.  We'll invert
	//   the stencil value where the stencil tests fails.  The
	//   stencil test for these pixels will be
	//
	//        ref   mask    stencil  mask
	//      ( 0x2 & 0x1 ) == ( 0x1 & 0x1 )
	//
	//   The stencil value here will be set to ~((2^s-1) & 0x1),
	//   (with the 0x1 being from the stencil clear value),
	//   where 's' is the number of bits in the stencil buffer
	//
	fd_stencil_func(state, GL_EQUAL, 0x2, 0x1);
	fd_stencil_op(state, GL_INVERT, GL_KEEP, GL_KEEP);
	fd_draw_elements(state, GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[3]);

	// Since we don't know at compile time how many stencil bits are present,
	//   we'll query, and update the value correct value in the
	//   stencilValues arrays for the fourth tests.  We'll use this value
	//   later in rendering.
	numStencilBits = 8;

	stencilValues[3] = ~(((1 << numStencilBits) - 1) & 0x1) & 0xff;

	// Use the stencil buffer for controlling where rendering will
	//   occur.  We disable writing to the stencil buffer so we
	//   can test against them without modifying the values we
	//   generated.
	fd_stencil_mask(state, 0x0);

	for (i = 0; i < NumTests; i++) {
		fd_stencil_func(state, GL_EQUAL, stencilValues[i], 0xff);
		fd_uniform_attach(state, "uColor", 4, 1, colors[i]);
		fd_draw_elements(state, GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[4]);
	}

	fd_swap_buffers(state);

	fd_flush(state);

	fd_dump_bmp(surface, "stencil.bmp");

	fd_fini(state);

	RD_END();

	return 0;
}
Example #10
0
void test_triangle_quad(int samples, int depth, int stencil)
{
	EGLDisplay display;
	EGLConfig config;
	EGLint num_config;
	EGLContext context;
	EGLSurface surface;
	GLuint program;
	GLint width, height;
	int uniform_location;
	const char *vertex_shader_source =
		"precision mediump float;     \n"
		"attribute vec4 aPosition;    \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_Position = aPosition; \n"
		"}                            \n";

	const char *fragment_shader_source =
		"precision mediump float;     \n"
		"uniform vec4 uColor;         \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_FragColor = uColor;   \n"
		"}                            \n";

	EGLint const config_attribute_list[] = {
		EGL_RED_SIZE, 8,
		EGL_GREEN_SIZE, 8,
		EGL_BLUE_SIZE, 8,
		EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
		EGL_STENCIL_SIZE, stencil,
		EGL_DEPTH_SIZE, depth,
		EGL_SAMPLES, samples,
		EGL_NONE
	};

	GLfloat vertices[] = {
		/* triangle */
		-0.8,  0.50, 0.0,
		-0.2,  0.50, 0.0,
		-0.5, -0.50, 0.0,
		/* quad */
		0.2, -0.50, 0.0,
		0.8, -0.50, 0.0,
		0.2,  0.50, 0.0,
		0.8,  0.50, 0.0 };
	GLfloat triangle_color[] = {0.0, 1.0, 0.0, 1.0 };
	GLfloat quad_color[] = {1.0, 0.0, 0.0, 1.0 };

	RD_START("triangle-quad", "samples=%d, depth=%d, stencil=%d", samples, depth, stencil);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 400, 240);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));
	ECHK(eglGetConfigAttrib(display, config, EGL_SAMPLES, &samples));
	ECHK(eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depth));
	ECHK(eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencil));

	DEBUG_MSG("Buffer: %dx%d (samples=%d, depth=%d, stencil=%d)", width, height,
			samples, depth, stencil);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.3125, 0.3125, 0.3125, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glEnableVertexAttribArray(0));

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glUniform4fv(uniform_location, 1, triangle_color));
	GCHK(glDrawArrays(GL_TRIANGLES, 0, 3));

	GCHK(glUniform4fv(uniform_location, 1, quad_color));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 3, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	usleep(1000000);

	RD_END();
}
Example #11
0
/* Run through multiple variants to detect mrt settings
 */
static void test(unsigned w, unsigned h, unsigned cpp, GLenum ifmt, GLenum fmt, GLenum type, int mipmap)
{
	GLint width, height;
	GLuint fbo, fbotex;
	GLenum mrt_bufs[] = {GL_COLOR_ATTACHMENT0};

	GLfloat quad_color[] =  {1.0, 0.0, 0.0, 1.0};
	GLfloat vertices[] = {
			-0.45, -0.75, 0.1,
			 0.45, -0.75, 0.1,
			-0.45,  0.75, 0.1,
			 0.45,  0.75, 0.1 };
	EGLSurface surface;

	////////////////////////////////////////////
	// calculate ubwc layout, see:
	// https://android.googlesource.com/platform/hardware/qcom/display/+/master/msm8996/libgralloc/alloc_controller.cpp#1057
	unsigned block_width, block_height;

	switch (cpp) {
	case 2:
	case 4:
		block_width = 16;
		block_height = 4;
		break;
	case 8:
		block_width = 8;
		block_height = 4;
		break;
	case 16:
		block_width = 4;
		block_height = 4;
		break;
	default:
		DEBUG_MSG("invalid cpp: %u", cpp);
		return;
	}

	// div_round_up():
	unsigned aligned_height = (h + block_height - 1) / block_height;
	unsigned aligned_width  = (w + block_width - 1) / block_width;

	// Align meta buffer height to 16 blocks
	unsigned meta_height = ALIGN(aligned_height, 16);

	// Align meta buffer width to 64 blocks
	unsigned meta_width = ALIGN(aligned_width, 64);

	// Align meta buffer size to 4K
	unsigned meta_size = ALIGN((meta_width * meta_height), 4096);

	////////////////////////////////////////////

	RD_START(mipmap ? "ubwc-layout-mipmap" : "ubwc-layout",
			"%dx%d, ifmt=%s, fmt=%s, type=%s, meta=%ux%u@0x%x (%ux%u)", w, h,
			formatname(fmt), formatname(ifmt), typename(type),
			meta_width, meta_height, meta_size, aligned_width, aligned_height);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, w, h);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);
	GCHK(glBindAttribLocation(program, 0, "aPosition"));
	link_program(program);

	GCHK(glGenFramebuffers(1, &fbo));
	GCHK(glGenTextures(1, &fbotex));
	GCHK(glBindFramebuffer(GL_FRAMEBUFFER, fbo));

	GCHK(glBindTexture(GL_TEXTURE_2D, fbotex));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexImage2D(GL_TEXTURE_2D, 0, ifmt, width, height, 0, fmt, type, 0));
	GCHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbotex, 0));

	DEBUG_MSG("status=%04x", glCheckFramebufferStatus(GL_FRAMEBUFFER));

	GCHK(glBindFramebuffer(GL_FRAMEBUFFER, fbo));

	GCHK(glViewport(0, 0, width, height));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glEnableVertexAttribArray(0));

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glDrawBuffers(1, mrt_bufs));

//	glClearColor(0.25, 0.5, 0.75, 1.0);
//	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glUniform4fv(uniform_location, 1, quad_color));
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	/* clear any errors, in case it wasn't a renderable format: */
	while (glGetError() != GL_NO_ERROR) {}

	GCHK(glFlush());

	/* switch back to back buffer: */
	GCHK(glBindFramebuffer(GL_FRAMEBUFFER, 0));

	program = get_program(vertex_shader_source_sam, fragment_shader_source_sam);
	GCHK(glBindAttribLocation(program, 0, "aPosition"));
	link_program(program);

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glBindTexture(GL_TEXTURE_2D, fbotex));

	if (mipmap) {
		GCHK(glGenerateMipmap(GL_TEXTURE_2D));
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
	} else {
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	}
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT));

	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));
	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Example #12
0
/* Run through multiple variants to detect clear color, quad color (frag
 * shader param), and vertices
 */
void test_tex(int nvtex, int nftex, int bcolor)
{
	GLint width, height;
	EGLint pbuffer_attribute_list[] = {
		EGL_WIDTH, 256,
		EGL_HEIGHT, 256,
		EGL_LARGEST_PBUFFER, EGL_TRUE,
		EGL_NONE
	};
	GLfloat quad_color[] =  {1.0, 0.0, 0.0, 1.0};
	GLfloat vertices[] = {
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0 };
	GLfloat bcolors[][4] = {
			{ 0.25, 0.50, 0.75, 1.0 },
			{ 1.00, 0.00, 0.00, 1.0 },
			{ 0.00, 1.00, 0.00, 1.0 },
			{ 0.00, 0.00, 1.00, 1.0 },
	};
	EGLSurface surface;
	int n;

	RD_START("tex", "%d vtex, %d ftex, bcolor=%d", nvtex, nftex, bcolor);

	ECHK(surface = eglCreatePbufferSurface(display, config, pbuffer_attribute_list));

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("PBuffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source[nvtex], fragment_shader_source[nftex]);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glEnableVertexAttribArray(0));

	/* now set up our uniforms/textures. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));
	GCHK(glUniform4fv(uniform_location, 1, quad_color));
	for (n = 0; n < max(nvtex, nftex); n++) {
		GLuint texturename = 0, texture_handle;
		static char name[8];

		GCHK(glActiveTexture(tex_enums[n]));
		GCHK(glGenTextures(1, &texturename));
		GCHK(glBindTexture(GL_TEXTURE_2D, texturename));
		GCHK(glTexImage2D(
				GL_TEXTURE_2D, 0, GL_RGB,
				cube_texture.width, cube_texture.height, 0,
				GL_RGB, GL_UNSIGNED_BYTE, cube_texture.pixel_data));

		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));

		if (bcolor) {
			GCHK(glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR_EXT, bcolors[n]));
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_EXT));
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_EXT));
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R_OES, GL_CLAMP_TO_BORDER_EXT));
		} else {
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R_OES, GL_REPEAT));
		}

		sprintf(name, "uTex%d", n+1);
		GCHK(texture_handle = glGetUniformLocation(program, name));
		GCHK(glUniform1i(texture_handle, n));
	}

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
	GCHK(glFlush());

	ECHK(eglSwapBuffers(display, surface));

	ECHK(eglDestroySurface(display, surface));
	GCHK(glFlush());

	RD_END();
}
Example #13
0
void test_composite(const char *name, const struct blend_mode *blend,
		const struct format_mode *dst_format,
		uint32_t bw, uint32_t bh,
		const struct format_mode *src_format,
		uint32_t src_repeat, uint32_t sw, uint32_t sh,
		const struct format_mode *mask_format,
		uint32_t mask_repeat, uint32_t mw, uint32_t mh)
{
	PixmapPtr src, dest, mask = NULL;
	C2D_OBJECT blit = {};
	c2d_ts_handle curTimestamp;

	DEBUG_MSG("%s: op:%s src:%s (repeat:%d) mask=%s (repeat:%d) dst:%s",
			name, blend->name, src_format->name, src_repeat,
			mask_format ? mask_format->name : "none", mask_repeat,
			dst_format->name);
	RD_START(name, "op:%s src:%s (repeat:%d) mask=%s (repeat:%d) dst:%s",
			blend->name, src_format->name, src_repeat,
			mask_format ? mask_format->name : "none", mask_repeat,
			dst_format->name);

	blit.config_mask = DEFAULT_BLEND_MASK | blend->mode;

	dest = create_pixmap(1033, 1077, dst_format->format);

	if (src_repeat) {
		src  = create_pixmap(1, 1, src_format->format);
		blit.config_mask |= C2D_SOURCE_TILE_BIT;
	} else {
		src = create_pixmap(sw, sh, src_format->format);
	}

	blit.config_mask |= C2D_SOURCE_RECT_BIT;
	blit.surface_id = src->id;

	if (mask_format) {
		/* TODO not clear if mask repeat is really supported.. msm-exa-c2d2.c
		 * seems to reject it but C2D_MASK_TILE_BIT??
		 *
		 * Also, for src format, msm-exa-c2d2.c seems to encode fgcolor (like
		 * a solid fill) for repeats.. not really clear if TILE_BIT does what
		 * we expect or not??
		 *
		 * Seems like libC2D2 doesn't actually give any way to specify the
		 * maskX/maskY!!!  The previous c2d API does, so I'd have to assume
		 * this is actually supported by the hardware and this is just C2D2
		 * retardation
		 */
		if (mask_repeat) {
			mask = create_pixmap(1, 1, mask_format->format);
			blit.config_mask |= C2D_MASK_TILE_BIT;
		} else {
			mask = create_pixmap(mw, mh, mask_format->format);
		}

		blit.config_mask |= C2D_MASK_SURFACE_BIT;
		blit.mask_surface_id = mask->id;
	} else {
		// TODO make redump not confused when one column has extra rows
		mask = create_pixmap(1, 1, ARGB);
	}

	blit.next = NULL;

	blit.source_rect.x = FIXED(1);
	blit.source_rect.y = FIXED(2);
	blit.source_rect.width = FIXED(bw - blit.source_rect.x - 1);
	blit.source_rect.height = FIXED(bh - blit.source_rect.y - 2);

	blit.target_rect.x = FIXED((dest->width - sw) / 2);
	blit.target_rect.y = FIXED((dest->height - sh) / 2);
	blit.target_rect.width = blit.source_rect.width;
	blit.target_rect.height = blit.source_rect.height;
	CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	free_pixmap(src);
	free_pixmap(dest);
	if (mask)
		free_pixmap(mask);

	RD_END();

//	dump_pixmap(dest, "copy-%04dx%04d-%08x.bmp", w, h, format);
}
Example #14
0
void test_quad_instanced(int instances, int div0, int div1)
{
	GLint width, height;
	GLuint texturename = 0, texture_handle;
	GLfloat vVertices[] = {
			// front
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0
	};

	GLfloat vTexCoords[] = {
			1.0f, 1.0f,
			0.0f, 1.0f,
			1.0f, 0.0f,
			0.0f, 0.0f,
	};

	EGLSurface surface;

	RD_START("instanced", "instances=%d, div0=%d, div1=%d", instances, div0, div1);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 255, 255);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	printf("EGL Version %s\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor %s\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions %s\n", eglQueryString(display, EGL_EXTENSIONS));
	printf("GL Version %s\n", glGetString(GL_VERSION));
	printf("GL extensions: %s\n", glGetString(GL_EXTENSIONS));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "in_position"));
	GCHK(glBindAttribLocation(program, 1, "in_TexCoord"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glGenTextures(1, &texturename));
	GCHK(glBindTexture(GL_TEXTURE_2D, texturename));

	GCHK(glTexImage2D(
			GL_TEXTURE_2D, 0, GL_RGB,
			cube_texture.width, cube_texture.height, 0,
			GL_RGB, GL_UNSIGNED_BYTE, cube_texture.pixel_data));

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));


	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));

	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glEnable(GL_CULL_FACE));

	if (instances > 0) {
		GCHK(glVertexAttribDivisor(0, div0));
		GCHK(glVertexAttribDivisor(1, div1));
		GCHK(glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, instances));
	} else {
		GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
	}

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	sleep(1);

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Example #15
0
/* Run through multiple variants to detect clear color, quad color (frag
 * shader param), and vertices
 */
void test_query(int querytype, int w, int h)
{
	static const GLfloat clear_color[] = {0.0, 0.0, 0.0, 0.0};
	static const GLfloat quad_color[]  = {1.0, 0.0, 0.0, 1.0};
	static const GLfloat quad2_color[]  = {0.0, 1.0, 0.0, 1.0};
	static const GLfloat vertices[] = {
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0,
	};
	static const GLfloat vertices2[] = {
			-0.15, -0.23, 1.0,
			 0.25, -0.33, 1.0,
			-0.35,  0.43, 1.0,
			 0.45,  0.53, 1.0,
	};
	static const char *queryname[] = {
			"none",
			"samples-passed",
			"time-elapsed",
	};

	RD_START("query", "query=%s", queryname[querytype]);
	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, w, h);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));

	link_program(program);

	GCHK(glGenQueries(1, &query));

	GCHK(glDepthMask(GL_TRUE));
	GCHK(glEnable(GL_DEPTH_TEST));

	GCHK(glViewport(0, 0, width, height));

	if (clear_color) {
		/* clear the color buffer */
		GCHK(glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]));
		GCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	}

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glEnableVertexAttribArray(0));

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glUniform4fv(uniform_location, 1, quad_color));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	switch (querytype) {
	case 1:
		GCHK(glBeginQuery(GL_ANY_SAMPLES_PASSED, query));
		break;
	case 2:
		GCHK(glBeginQuery(GL_TIME_ELAPSED_EXT, query));
		break;
	}

	/* Quad 2 render */
	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices2));

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glUniform4fv(uniform_location, 1, quad2_color));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	switch (querytype) {
	case 1:
		GCHK(glEndQuery(GL_ANY_SAMPLES_PASSED));
		break;
	case 2:
		GCHK(glEndQuery(GL_TIME_ELAPSED_EXT));
		break;
	}

	if (querytype > 0) {
		GLuint result;
		do
		{
			GCHK(glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result));
		} while (!result);
		GCHK(glGetQueryObjectuiv(query, GL_QUERY_RESULT, &result));

		DEBUG_MSG("Query ended with %d", result);

	}

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	usleep(1000000);

	GCHK(glDeleteQueries(1, &query));

	eglTerminate(display);

	RD_END();
}
Example #16
0
static void end(void)
{
	RD_END();
	exit(-1);
}
Example #17
0
void test_strip_smoothed(int fbo)
{
	GLint width, height;
	GLfloat vVertices[] = {
			-0.7,  0.7, -0.7,
			-0.7,  0.2, -0.4,
			 0.0,  0.3, -0.5,
			-0.2, -0.3,  0.3,
			 0.5, -0.2,  0.4,
			 0.7, -0.7,  0.7 };
	GLfloat vColors[] = {
			0.1, 0.1, 0.1, 1.0,
			1.0, 0.0, 0.0, 1.0,
			0.0, 0.0, 1.0, 1.0,
			1.0, 1.0, 0.0, 1.0,
			0.0, 1.0, 1.0, 1.0,
			0.9, 0.9, 0.9, 1.0};
	EGLSurface surface;

	RD_START("strip-smoothed", "fbo=%d", fbo);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 256, 256);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));
	GCHK(glBindAttribLocation(program, 1, "aColor"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	if (fbo)
		GCHK(setup_fbo(width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.3125, 0.3125, 0.3125, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, vColors));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 6));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	if (fbo)
		GCHK(cleanup_fbo());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
void test_cube_textured(GLint mag_filter, GLint min_filter,
		GLint wrap_s, GLint wrap_t)
{
	GLint width, height;
	GLint modelviewmatrix_handle, modelviewprojectionmatrix_handle, normalmatrix_handle;
	GLuint texturename = 0, texture_handle;
	EGLint pbuffer_attribute_list[] = {
		EGL_WIDTH, 256,
		EGL_HEIGHT, 256,
		EGL_LARGEST_PBUFFER, EGL_TRUE,
		EGL_NONE
	};
	GLfloat vVertices[] = {
			// front
			-1.0f, -1.0f, +1.0f, // point blue
			+1.0f, -1.0f, +1.0f, // point magenta
			-1.0f, +1.0f, +1.0f, // point cyan
			+1.0f, +1.0f, +1.0f, // point white
			// back
			+1.0f, -1.0f, -1.0f, // point red
			-1.0f, -1.0f, -1.0f, // point black
			+1.0f, +1.0f, -1.0f, // point yellow
			-1.0f, +1.0f, -1.0f, // point green
			// right
			+1.0f, -1.0f, +1.0f, // point magenta
			+1.0f, -1.0f, -1.0f, // point red
			+1.0f, +1.0f, +1.0f, // point white
			+1.0f, +1.0f, -1.0f, // point yellow
			// left
			-1.0f, -1.0f, -1.0f, // point black
			-1.0f, -1.0f, +1.0f, // point blue
			-1.0f, +1.0f, -1.0f, // point green
			-1.0f, +1.0f, +1.0f, // point cyan
			// top
			-1.0f, +1.0f, +1.0f, // point cyan
			+1.0f, +1.0f, +1.0f, // point white
			-1.0f, +1.0f, -1.0f, // point green
			+1.0f, +1.0f, -1.0f, // point yellow
			// bottom
			-1.0f, -1.0f, -1.0f, // point black
			+1.0f, -1.0f, -1.0f, // point red
			-1.0f, -1.0f, +1.0f, // point blue
			+1.0f, -1.0f, +1.0f  // point magenta
	};

	GLfloat vTexCoords[] = {
			//front
			1.0f, 1.0f, //point blue
			0.0f, 1.0f, //point magenta
			1.0f, 0.0f, //point cyan
			0.0f, 0.0f, //point white
			//back
			1.0f, 1.0f, //point red
			0.0f, 1.0f, //point black
			1.0f, 0.0f, //point yellow
			0.0f, 0.0f, //point green
			//right
			1.0f, 1.0f, //point magenta
			0.0f, 1.0f, //point red
			1.0f, 0.0f, //point white
			0.0f, 0.0f, //point yellow
			//left
			1.0f, 1.0f, //point black
			0.0f, 1.0f, //point blue
			1.0f, 0.0f, //point green
			0.0f, 0.0f, //point cyan
			//top
			1.0f, 1.0f, //point cyan
			0.0f, 1.0f, //point white
			1.0f, 0.0f, //point green
			0.0f, 0.0f, //point yellow
			//bottom
			1.0f, 0.0f, //point black
			0.0f, 0.0f, //point red
			1.0f, 1.0f, //point blue
			0.0f, 1.0f, //point magenta
	};

	GLfloat vNormals[] = {
			// front
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			// back
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			// right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			// left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			// top
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			// bottom
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f  // down
	};
	EGLSurface surface;

	DEBUG_MSG("----------------------------------------------------------------");
	RD_START("cube-textured", "mag_filter=%04x, min_filter=%04x, wrap_s=%04x, wrap_t=%04x",
			mag_filter, min_filter, wrap_s, wrap_t);

	ECHK(surface = eglCreatePbufferSurface(display, config, pbuffer_attribute_list));

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("PBuffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));
	GCHK(glFlush());

	if (!program) {
		program = get_program(vertex_shader_source, fragment_shader_source);

		GCHK(glBindAttribLocation(program, 0, "in_position"));
		GCHK(glBindAttribLocation(program, 1, "in_normal"));
		GCHK(glBindAttribLocation(program, 2, "in_TexCoord"));

		link_program(program);
		GCHK(glFlush());
	}

	GCHK(glViewport(0, 0, width, height));
	GCHK(glFlush());


	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glFlush());
	GCHK(glClear(GL_COLOR_BUFFER_BIT));
	GCHK(glFlush());

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glFlush());
	GCHK(glEnableVertexAttribArray(0));
	GCHK(glFlush());

	GCHK(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, vNormals));
	GCHK(glFlush());
	GCHK(glEnableVertexAttribArray(1));
	GCHK(glFlush());

	GCHK(glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(2));

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
	esRotate(&modelview, 45.0f, 1.0f, 0.0f, 0.0f);
	esRotate(&modelview, 45.0f, 0.0f, 1.0f, 0.0f);
	esRotate(&modelview, 10.0f, 0.0f, 0.0f, 1.0f);

	GLfloat aspect = (GLfloat)(height) / (GLfloat)(width);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glFlush());
	GCHK(glGenTextures(1, &texturename));
	GCHK(glFlush());
	GCHK(glBindTexture(GL_TEXTURE_2D, texturename));
	GCHK(glFlush());
	GCHK(glTexImage2D(
			GL_TEXTURE_2D, 0, GL_RGB,
			cube_texture.width, cube_texture.height, 0,
			GL_RGB, GL_UNSIGNED_BYTE, cube_texture.pixel_data));
	GCHK(glFlush());

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter));
	GCHK(glFlush());
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter));
	GCHK(glFlush());
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s));
	GCHK(glFlush());
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t));
	GCHK(glFlush());

	GCHK(modelviewmatrix_handle = glGetUniformLocation(program, "modelviewMatrix"));
	GCHK(modelviewprojectionmatrix_handle = glGetUniformLocation(program, "modelviewprojectionMatrix"));
	GCHK(normalmatrix_handle = glGetUniformLocation(program, "normalMatrix"));
	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));
	GCHK(glFlush());

	GCHK(glUniformMatrix4fv(modelviewmatrix_handle, 1, GL_FALSE, &modelview.m[0][0]));
	GCHK(glFlush());
	GCHK(glUniformMatrix4fv(modelviewprojectionmatrix_handle, 1, GL_FALSE, &modelviewprojection.m[0][0]));
	GCHK(glFlush());
	GCHK(glUniformMatrix3fv(normalmatrix_handle, 1, GL_FALSE, normal));
	GCHK(glFlush());
	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */
	GCHK(glFlush());

	GCHK(glEnable(GL_CULL_FACE));
	GCHK(glFlush());

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 4, 4));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 8, 4));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 12, 4));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 16, 4));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 20, 4));
	GCHK(glFlush());

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));
	GCHK(glFlush());

	RD_END();
}
Example #19
0
void test_stencil(void)
{
	GLint numStencilBits;
	GLuint stencilValues[NumTests] = {
			0x7, // Result of test 0
			0x0, // Result of test 1
			0x2, // Result of test 2
			0xff // Result of test 3.  We need to fill this value in a run-time
	};
	int i;

	DEBUG_MSG("----------------------------------------------------------------");
	RD_START("stencil", "");

	ECHK(surface = eglCreatePbufferSurface(display, config, pbuffer_attribute_list));

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("PBuffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));
	GCHK(glFlush());

	if (!program) {
		program = get_program(vertex_shader_source, fragment_shader_source);

		GCHK(glBindAttribLocation(program, 0, "aPosition"));

		link_program(program);

		/* now set up our uniform. */
		GCHK(uniform_location = glGetUniformLocation(program, "uColor"));
	}

	GCHK(glClearColor(0.0, 0.0, 0.0, 0.0));
	GCHK(glClearStencil(0x1));
	GCHK(glClearDepthf(0.75));

	GCHK(glEnable(GL_DEPTH_TEST));
	GCHK(glEnable(GL_STENCIL_TEST));

	// Set the viewport
	GCHK(glViewport(0, 0, width, height));

	// Clear the color, depth, and stencil buffers.  At this
	//   point, the stencil buffer will be 0x1 for all pixels
	GCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));

	// Use the program object
	GCHK(glUseProgram(program));

	// Load the vertex position
	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));

	GCHK(glEnableVertexAttribArray(0));

	// Test 0:
	//
	// Initialize upper-left region.  In this case, the
	//   stencil-buffer values will be replaced because the
	//   stencil test for the rendered pixels will fail the
	//   stencil test, which is
	//
	//        ref   mask   stencil  mask
	//      ( 0x7 & 0x3 ) < ( 0x1 & 0x7 )
	//
	//   The value in the stencil buffer for these pixels will
	//   be 0x7.
	//
	GCHK(glStencilFunc(GL_LESS, 0x7, 0x3));
	GCHK(glStencilOp(GL_REPLACE, GL_DECR, GL_DECR));
	GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[0]));

	// Test 1:
	//
	// Initialize the upper-right region.  Here, we'll decrement
	//   the stencil-buffer values where the stencil test passes
	//   but the depth test fails.  The stencil test is
	//
	//        ref  mask    stencil  mask
	//      ( 0x3 & 0x3 ) > ( 0x1 & 0x3 )
	//
	//    but where the geometry fails the depth test.  The
	//    stencil values for these pixels will be 0x0.
	//
	GCHK(glStencilFunc(GL_GREATER, 0x3, 0x3));
	GCHK(glStencilOp(GL_KEEP, GL_DECR, GL_KEEP));
	GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[1]));

	// Test 2:
	//
	// Initialize the lower-left region.  Here we'll increment
	//   (with saturation) the stencil value where both the
	//   stencil and depth tests pass.  The stencil test for
	//   these pixels will be
	//
	//        ref  mask     stencil  mask
	//      ( 0x1 & 0x3 ) == ( 0x1 & 0x3 )
	//
	//   The stencil values for these pixels will be 0x2.
	//
	GCHK(glStencilFunc(GL_EQUAL, 0x1, 0x3));
	GCHK(glStencilOp(GL_KEEP, GL_INCR, GL_INCR));
	GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[2]));

	// Test 3:
	//
	// Finally, initialize the lower-right region.  We'll invert
	//   the stencil value where the stencil tests fails.  The
	//   stencil test for these pixels will be
	//
	//        ref   mask    stencil  mask
	//      ( 0x2 & 0x1 ) == ( 0x1 & 0x1 )
	//
	//   The stencil value here will be set to ~((2^s-1) & 0x1),
	//   (with the 0x1 being from the stencil clear value),
	//   where 's' is the number of bits in the stencil buffer
	//
	GCHK(glStencilFunc(GL_EQUAL, 0x2, 0x1));
	GCHK(glStencilOp(GL_INVERT, GL_KEEP, GL_KEEP));
	GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[3]));

	// Since we don't know at compile time how many stencil bits are present,
	//   we'll query, and update the value correct value in the
	//   stencilValues arrays for the fourth tests.  We'll use this value
	//   later in rendering.
	GCHK(glGetIntegerv(GL_STENCIL_BITS, &numStencilBits));

	stencilValues[3] = ~(((1 << numStencilBits) - 1) & 0x1) & 0xff;

	// Use the stencil buffer for controlling where rendering will
	//   occur.  We disable writing to the stencil buffer so we
	//   can test against them without modifying the values we
	//   generated.
	GCHK(glStencilMask(0x0));

	for (i = 0; i < NumTests; i++) {
		GCHK(glStencilFunc(GL_EQUAL, stencilValues[i], 0xff));
		GCHK(glUniform4fv(uniform_location, 1, colors[i]));
		GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[4]));
	}

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));
	GCHK(glFlush());

	usleep(1000000);

	dump_bmp(display, surface, "stencil.bmp");

	RD_END();
}
Example #20
0
int test_compiler(int n)
{
	static char vert_shader[64 * 1024], frag_shader[64 * 1024];
	static GLfloat v[ARRAY_SIZE(attrnames)][NVERT * 4];
	static int nattr = 0;
	GLuint program;
	int vert_fd, frag_fd, gs_fd, tcs_fd, tes_fd;
	int i, ret;

	vert_fd = openfile("shaders/%04d.vs", n);
	tcs_fd = openfile("shaders/%04d.tcs", n);
	tes_fd = openfile("shaders/%04d.tes", n);
	gs_fd = openfile("shaders/%04d.gs", n);
	frag_fd = openfile("shaders/%04d.fs", n);
	if ((vert_fd < 0) || (frag_fd < 0))
		return -1;

	ret = read(vert_fd, vert_shader, sizeof(vert_shader));
	if (ret < 0)
		return ret;
	vert_shader[ret] = '\0';

	ret = read(frag_fd, frag_shader, sizeof(frag_shader));
	if (ret < 0)
		return ret;
	frag_shader[ret] = '\0';

	RD_START("compiler", "%d", n);

	program = get_program(vert_shader, frag_shader);

	if (tcs_fd >= 0)
		compile_shader(program, tcs_fd, 0x8E88/*GL_TESS_CONTROL_SHADER*/);
	if (tes_fd >= 0)
		compile_shader(program, tes_fd, 0x8E87/*GL_TESS_EVALUATION_SHADER*/);
	if (gs_fd >= 0)
		compile_shader(program, gs_fd, 0x8DD9/*GL_GEOMETRY_SHADER*/);

	for (i = 0; i < ARRAY_SIZE(attrnames); i++) {
		glBindAttribLocation(program, i, attrnames[i]);
		if (glGetError() == GL_NO_ERROR) {
			printf("use attribute: %s\n", attrnames[i]);
			nattr++;
		}
		/* clear any errors, just in case: */
		while (glGetError() != GL_NO_ERROR) {}
	}

	link_program(program);

	GCHK(glFlush());

	for (i = 0; i < nattr; i++) {
		GCHK(glVertexAttribPointer(i, 4, GL_FLOAT, GL_FALSE, 0, v[i]));
		GCHK(glEnableVertexAttribArray(i));
	}

	if (tes_fd >= 0)
		GCHK(glDrawArrays(0x000E/*GL_PATCHES*/, 0, NVERT));
	else
		GCHK(glDrawArrays(GL_TRIANGLES, 0, NVERT));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	RD_END();

	return 0;
}
void test_triangle_quad(void)
{
	EGLDisplay display;
	EGLConfig config;
	EGLint num_config;
	EGLContext context;
	EGLSurface surface;
	GLuint program;
	GLint width, height;
	int uniform_location;
	const char *vertex_shader_source =
		"precision mediump float;     \n"
		"attribute vec4 aPosition;    \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_Position = aPosition; \n"
		"}                            \n";

	const char *fragment_shader_source =
		"precision mediump float;     \n"
		"uniform vec4 uColor;         \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_FragColor = uColor;   \n"
		"}                            \n";

	GLfloat vertices[] = {
		/* triangle */
		-0.8,  0.50, 0.0,
		-0.2,  0.50, 0.0,
		-0.5, -0.50, 0.0,
		/* quad */
		0.2, -0.50, 0.0,
		0.8, -0.50, 0.0,
		0.2,  0.50, 0.0,
		0.8,  0.50, 0.0 };
	GLfloat triangle_color[] = {0.0, 1.0, 0.0, 1.0 };
	GLfloat quad_color[] = {1.0, 0.0, 0.0, 1.0 };


	DEBUG_MSG("----------------------------------------------------------------");
	RD_START("triangle-quad", "");
	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	ECHK(surface = eglCreatePbufferSurface(display, config, pbuffer_attribute_list));

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("PBuffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));
	GCHK(glFlush());

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));
	GCHK(glFlush());

	/* clear the color buffer */
	GCHK(glClearColor(0.3125, 0.3125, 0.3125, 1.0));
	GCHK(glFlush());
	GCHK(glClear(GL_COLOR_BUFFER_BIT));
	GCHK(glFlush());

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glFlush());
	GCHK(glEnableVertexAttribArray(0));
	GCHK(glFlush());

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glUniform4fv(uniform_location, 1, triangle_color));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLES, 0, 3));
	GCHK(glFlush());

	GCHK(glUniform4fv(uniform_location, 1, quad_color));
	GCHK(glFlush());
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 3, 4));
	GCHK(glFlush());

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	usleep(1000000);

	RD_END();
}
Example #22
0
void test_quad_textured(int shadow, int cfunc)
{
	GLint width, height;
	GLuint textures[2], texture_handle;
	GLfloat vVertices[] = {
			// front
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0
	};

	GLfloat vTexCoords[] = {
			1.0f, 1.0f,
			0.0f, 1.0f,
			1.0f, 0.0f,
			0.0f, 0.0f,
	};

	EGLSurface surface;

	RD_START("quad-textured", "shadow=%d, cfunc=%x", shadow, cfunc);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 255, 255);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	printf("EGL Version %s\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor %s\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions %s\n", eglQueryString(display, EGL_EXTENSIONS));
	printf("GL Version %s\n", glGetString(GL_VERSION));
	printf("GL extensions: %s\n", glGetString(GL_EXTENSIONS));

	program = get_program(vertex_shader_source, shadow ?
			fragment_shader_source_shadow : fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "in_position"));
	GCHK(glBindAttribLocation(program, 1, "in_TexCoord"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glGenTextures(2, &textures));

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glBindTexture(GL_TEXTURE_2D, textures[0]));

	if (shadow) {
		GCHK(glTexImage2D(
				GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
				cube_texture.width/2, cube_texture.height/2, 0,
				GL_DEPTH_COMPONENT, GL_FLOAT, cube_texture.pixel_data));
	} else {
		GCHK(glTexImage2D(
				GL_TEXTURE_2D, 0, GL_RGB,
				cube_texture.width, cube_texture.height, 0,
				GL_RGB, GL_UNSIGNED_BYTE, cube_texture.pixel_data));
	}

	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));

	if (shadow) {
#define GL_TEXTURE_COMPARE_MODE           0x884C
#define GL_TEXTURE_COMPARE_FUNC           0x884D
#define GL_COMPARE_REF_TO_TEXTURE         0x884E
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
				GL_COMPARE_REF_TO_TEXTURE));
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC,
				cfunc));
	} else {
		float minlod = cfunc, maxlod = cfunc;
		GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, minlod));
		GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, maxlod));
		switch (cfunc) {
		case 0:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
			break;
		case 1:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST));
			break;
		case 2:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST));
			break;
		case 3:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR));
			break;
		case 4:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
			break;
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif
		case 5:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4));
			break;
		case 6:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8));
			break;
		case 7:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16));
			break;
		case 8:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 32));
			break;
		case 9:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 320));
			break;
		}
	}

	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));
	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glActiveTexture(GL_TEXTURE1));
	GCHK(glBindTexture(GL_TEXTURE_2D, textures[1]));

	GCHK(glTexImage2D(
			GL_TEXTURE_2D, 0, GL_RGBA,
			cube_texture.width/3, cube_texture.height-1, 0,
			GL_RGBA, GL_UNSIGNED_BYTE, cube_texture.pixel_data+1));

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));

	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));
	GCHK(glUniform1i(texture_handle, 1)); /* '1' refers to texture unit 1. */

	GCHK(glEnable(GL_CULL_FACE));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	sleep(1);

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Example #23
0
static void test_transform_feedback(int n, int separate)
{
	GLint width, height, ret, i;
	GLuint texturename = 0, texture_handle, tf;
	GLfloat vVertices[] = {
			// front
			-0.45, -0.75, 0.0,
			0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			0.45,  0.75, 0.0
	};

	const char *varyings[] = {
			"pos",
			"pos2",
			"pos3",
			"pos4",
			"pos5",
			"pos6",
			"pos7",
			//"posen[0]",
			//"posen[1]",
			//"posen[2]",
			//"posen[8]",
			//"posen[5]",
	};
	GLuint tf_bufs[ARRAY_SIZE(varyings)] = { 0 };

	EGLSurface surface;

	RD_START("transform-feedback", "n=%d, separate=%d", n, separate);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 255, 255);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	printf("EGL Version %s\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor %s\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions %s\n", eglQueryString(display, EGL_EXTENSIONS));
	printf("GL Version %s\n", glGetString(GL_VERSION));
	printf("GL extensions: %s\n", glGetString(GL_EXTENSIONS));

	program = get_program(vertex_shader_source, fragment_shader_source);

	if (n > 0)
		GCHK(glEnable(GL_RASTERIZER_DISCARD));

	GCHK(glBindAttribLocation(program, 0, "in_position"));

	if (n > 0) {
		GCHK(glTransformFeedbackVaryings(program, n, varyings,
				separate ? GL_SEPARATE_ATTRIBS : GL_INTERLEAVED_ATTRIBS));
	}

	link_program(program);

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	if (n > 0) {
		GCHK(glGenBuffers(n, tf_bufs));
		for (i = 0; i < (separate ? n : 1); i++) {
			GCHK(glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tf_bufs[i]));
			GCHK(glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 1024, NULL, GL_STREAM_DRAW));
			GCHK(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, tf_bufs[i], 32 * i, 1024));
		}
	}

	//GCHK(glGenTransformFeedbacks(1, &tf));
	//GCHK(glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tf));

	if (n > 0)
		GCHK(glBeginTransformFeedback(GL_POINTS));

	GCHK(glDrawArrays(GL_POINTS, 0, 4));

	if (n > 0)
		GCHK(glEndTransformFeedback());

	//ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	sleep(1);

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Example #24
0
void test_composite(uint32_t blend_mode,
		uint32_t dst_format, uint32_t dst_width, uint32_t dst_height,
		uint32_t src_format, uint32_t src_width, uint32_t src_height,
		uint32_t mask_format, uint32_t mask_width, uint32_t mask_height,
		uint32_t src_x, uint32_t src_y, uint32_t mask_x, uint32_t mask_y,
		uint32_t dst_x, uint32_t dst_y, uint32_t w, uint32_t h)
{
	PixmapPtr src, dest, mask = NULL;
	C2D_OBJECT blit = {};
	c2d_ts_handle curTimestamp;

	DEBUG_MSG("composite2: blend_mode:%08x, dst_format:%08x, dst_width:%x, dst_height=%x, "
			"src_format:%08x, src_width:%x, src_height:%x, "
			"mask_format:%08x, mask_width:%x, mask_height:%x, "
			"src_x:%x, src_y:%x, mask_x:%x, mask_y:%x, dst_x:%x, dst_y:%x, w:%x, h:%x",
			blend_mode, dst_format, dst_width, dst_height,
			src_format, src_width, src_height,
			mask_format, mask_width, mask_height,
			src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
	RD_START("composite2","blend_mode:%08x, dst_format:%08x, dst_width:%x, dst_height=%x, "
			"src_format:%08x, src_width:%x, src_height:%x, "
			"mask_format:%08x, mask_width:%x, mask_height:%x, "
			"src_x:%x, src_y:%x, mask_x:%x, mask_y:%x, dst_x:%x, dst_y:%x, w:%x, h:%x",
			blend_mode, dst_format, dst_width, dst_height,
			src_format, src_width, src_height,
			mask_format, mask_width, mask_height,
			src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);

	blit.config_mask = DEFAULT_BLEND_MASK | blend_mode;

	dest = create_pixmap(dst_width, dst_height, dst_format);
	src  = create_pixmap(src_width, src_height, src_format);

	blit.config_mask |= C2D_SOURCE_RECT_BIT;
	blit.surface_id = src->id;

	if (mask_format) {
		/* TODO not clear if mask repeat is really supported.. msm-exa-c2d2.c
		 * seems to reject it but C2D_MASK_TILE_BIT??
		 *
		 * Also, for src format, msm-exa-c2d2.c seems to encode fgcolor (like
		 * a solid fill) for repeats.. not really clear if TILE_BIT does what
		 * we expect or not??
		 *
		 * Seems like libC2D2 doesn't actually give any way to specify the
		 * maskX/maskY!!!  The previous c2d API does, so I'd have to assume
		 * this is actually supported by the hardware and this is just C2D2
		 * retardation
		 */
		mask = create_pixmap(mask_width, mask_height, mask_format);

		blit.config_mask |= C2D_MASK_SURFACE_BIT;
		blit.mask_surface_id = mask->id;
	}

	blit.next = NULL;

	blit.source_rect.x = FIXED(src_x);
	blit.source_rect.y = FIXED(src_y);
	blit.source_rect.width = FIXED(w);
	blit.source_rect.height = FIXED(h);

	blit.target_rect.x = FIXED(dst_x);
	blit.target_rect.y = FIXED(dst_y);
	blit.target_rect.width = FIXED(w);
	blit.target_rect.height = FIXED(h);
	CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
	CHK(c2dFlush(dest->id, &curTimestamp));
	CHK(c2dWaitTimestamp(curTimestamp));

	free_pixmap(src);
	free_pixmap(dest);
	if (mask)
		free_pixmap(mask);

	RD_END();

//	dump_pixmap(dest, "copy-%04dx%04d-%08x.bmp", w, h, format);
}
Example #25
0
void test_cube_textured(GLint mag_filter, GLint min_filter,
		GLint wrap_s, GLint wrap_t, GLint wrap_r, GLenum format, GLenum type)
{
	GLint width, height;
	GLint modelviewmatrix_handle, modelviewprojectionmatrix_handle, normalmatrix_handle;
	GLuint texturename = 0, texture_handle;
	GLfloat vVertices[] = {
			// front
			-1.0f, -1.0f, +1.0f, // point blue
			+1.0f, -1.0f, +1.0f, // point magenta
			-1.0f, +1.0f, +1.0f, // point cyan
			+1.0f, +1.0f, +1.0f, // point white
			// back
			+1.0f, -1.0f, -1.0f, // point red
			-1.0f, -1.0f, -1.0f, // point black
			+1.0f, +1.0f, -1.0f, // point yellow
			-1.0f, +1.0f, -1.0f, // point green
			// right
			+1.0f, -1.0f, +1.0f, // point magenta
			+1.0f, -1.0f, -1.0f, // point red
			+1.0f, +1.0f, +1.0f, // point white
			+1.0f, +1.0f, -1.0f, // point yellow
			// left
			-1.0f, -1.0f, -1.0f, // point black
			-1.0f, -1.0f, +1.0f, // point blue
			-1.0f, +1.0f, -1.0f, // point green
			-1.0f, +1.0f, +1.0f, // point cyan
			// top
			-1.0f, +1.0f, +1.0f, // point cyan
			+1.0f, +1.0f, +1.0f, // point white
			-1.0f, +1.0f, -1.0f, // point green
			+1.0f, +1.0f, -1.0f, // point yellow
			// bottom
			-1.0f, -1.0f, -1.0f, // point black
			+1.0f, -1.0f, -1.0f, // point red
			-1.0f, -1.0f, +1.0f, // point blue
			+1.0f, -1.0f, +1.0f  // point magenta
	};

	GLfloat vTexCoords[] = {
			//front
			1.0f, 1.0f, //point blue
			0.0f, 1.0f, //point magenta
			1.0f, 0.0f, //point cyan
			0.0f, 0.0f, //point white
			//back
			1.0f, 1.0f, //point red
			0.0f, 1.0f, //point black
			1.0f, 0.0f, //point yellow
			0.0f, 0.0f, //point green
			//right
			1.0f, 1.0f, //point magenta
			0.0f, 1.0f, //point red
			1.0f, 0.0f, //point white
			0.0f, 0.0f, //point yellow
			//left
			1.0f, 1.0f, //point black
			0.0f, 1.0f, //point blue
			1.0f, 0.0f, //point green
			0.0f, 0.0f, //point cyan
			//top
			1.0f, 1.0f, //point cyan
			0.0f, 1.0f, //point white
			1.0f, 0.0f, //point green
			0.0f, 0.0f, //point yellow
			//bottom
			1.0f, 0.0f, //point black
			0.0f, 0.0f, //point red
			1.0f, 1.0f, //point blue
			0.0f, 1.0f, //point magenta
	};

	GLfloat vNormals[] = {
			// front
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			// back
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			// right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			// left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			// top
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			// bottom
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f  // down
	};
	EGLSurface surface;
	const int texwidth = 333;
	const int texheight = 222;
	static uint8_t *buf = NULL;

	if (!buf) {
		int i;
		buf = malloc(texwidth * texheight * 16);
		for (i = 0; i < (texwidth * texheight * 16); i++)
			buf[i] = i;
	}

	RD_START("cube-textured", "mag_filter=%04x, min_filter=%04x, "
			"wrap_s=%04x, wrap_t=%04x, wrap_r=%04x, format=%s, type=%s",
			mag_filter, min_filter, wrap_s, wrap_t, wrap_r,
			formatname(format), typename(type));

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 256, 256);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "in_position"));
	GCHK(glBindAttribLocation(program, 1, "in_normal"));
	GCHK(glBindAttribLocation(program, 2, "in_TexCoord"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));


	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, vNormals));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(2));

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
	esRotate(&modelview, 45.0f, 1.0f, 0.0f, 0.0f);
	esRotate(&modelview, 45.0f, 0.0f, 1.0f, 0.0f);
	esRotate(&modelview, 10.0f, 0.0f, 0.0f, 1.0f);

	GLfloat aspect = (GLfloat)(height) / (GLfloat)(width);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glGenTextures(1, &texturename));
	GCHK(glBindTexture(GL_TEXTURE_2D, texturename));
	GCHK(glTexImage2D(GL_TEXTURE_2D, 0, format, texwidth, texheight,
			0, format, type, buf));

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R_OES, wrap_r));

	GCHK(modelviewmatrix_handle = glGetUniformLocation(program, "modelviewMatrix"));
	GCHK(modelviewprojectionmatrix_handle = glGetUniformLocation(program, "modelviewprojectionMatrix"));
	GCHK(normalmatrix_handle = glGetUniformLocation(program, "normalMatrix"));
	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));

	GCHK(glUniformMatrix4fv(modelviewmatrix_handle, 1, GL_FALSE, &modelview.m[0][0]));
	GCHK(glUniformMatrix4fv(modelviewprojectionmatrix_handle, 1, GL_FALSE, &modelviewprojection.m[0][0]));
	GCHK(glUniformMatrix3fv(normalmatrix_handle, 1, GL_FALSE, normal));
	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glEnable(GL_CULL_FACE));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 4, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 8, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 12, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 16, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 20, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Example #26
0
static void run_test(int image_width, int image_height, int image_pitch,
		int chan_order, int chan_type)
{
	unsigned int num_platforms;
	int err, i;
#define NAME(x) [x & 0xf] = #x
	static const char *channel_orders[] = {
			NAME(CL_R),
			NAME(CL_A),
			NAME(CL_RG),
			NAME(CL_RA),
			NAME(CL_RGB),
			NAME(CL_RGBA),
			NAME(CL_BGRA),
			NAME(CL_ARGB),
			NAME(CL_INTENSITY),
			NAME(CL_LUMINANCE),
			NAME(CL_Rx),
			NAME(CL_RGx),
			NAME(CL_RGBx),
	};
	static const char *channel_types[] = {
			NAME(CL_SNORM_INT8),
			NAME(CL_SNORM_INT16),
			NAME(CL_UNORM_INT8),
			NAME(CL_UNORM_INT16),
			NAME(CL_UNORM_SHORT_565),
			NAME(CL_UNORM_SHORT_555),
			NAME(CL_UNORM_INT_101010),
			NAME(CL_SIGNED_INT8),
			NAME(CL_SIGNED_INT16),
			NAME(CL_SIGNED_INT32),
			NAME(CL_UNSIGNED_INT8),
			NAME(CL_UNSIGNED_INT16),
			NAME(CL_UNSIGNED_INT32),
			NAME(CL_HALF_FLOAT),
			NAME(CL_FLOAT),
	};

	size_t global;                      // global domain size for our calculation
	size_t local;                       // local domain size for our calculation
	size_t bin_size;
	size_t len;
	unsigned char *bin;

	cl_platform_id platform;
	cl_device_id device_id;             // compute device id
	cl_context context;                 // compute context
	cl_command_queue commands;          // compute command queue
	cl_program program;                 // compute program
	cl_kernel kernel;                   // compute kernel

	cl_mem input1, input2;              // device memory used for the input array
	cl_mem output;                      // device memory used for the output array

	RD_START("image", "width=%d, height=%d, pitch=%d, order=%s, type=%s",
			image_width, image_height, image_pitch,
			channel_orders[chan_order & 0xf], channel_types[chan_type & 0xf]);

	CCHK(clGetPlatformIDs(1, &platform, &num_platforms));
	CCHK(clGetPlatformInfo(platform, CL_PLATFORM_EXTENSIONS, sizeof(buffer), buffer, &len));
	DEBUG_MSG("extensions=%s\n", buffer);

	CCHK(clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL));

	CCHK(clGetDeviceInfo(device_id, CL_DEVICE_VERSION, sizeof(buffer), buffer, &len));
	DEBUG_MSG("version=%s\n", buffer);
	CCHK(clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, sizeof(buffer), buffer, &len));
	DEBUG_MSG("device extensions=%s\n", buffer);

	context = clCreateContext(0, 1, &device_id, NULL, NULL, NULL);
	commands = clCreateCommandQueue(context, device_id, 0, NULL);
	program = clCreateProgramWithSource(context, 1, (const char **) &KernelSource, NULL, NULL);

	CCHK(clBuildProgram(program, 0, NULL, "-cl-mad-enable -DFILTER_SIZE=1 "
			"-DSAMP_MODE=CLK_NORMALIZED_COORDS_FALSE|CLK_ADDRESS_CLAMP_TO_EDGE|CLK_FILTER_NEAREST",
			NULL, NULL));

	kernel = clCreateKernel(program, "test_kernel", NULL);

	/* fill buffer with dummy pattern: */
	for (i = 0; i < 256; i++)
		buffer[i] = i;

	const cl_image_format format = { chan_order, chan_type };
	input1 = clCreateImage2D(context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, &format,
			image_width, image_height, image_pitch, buffer, &err);
	CCHK(err);
	input2 = clCreateImage2D(context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, &format,
			image_width+1, image_height+1, image_pitch, buffer + 4, &err);
	CCHK(err);

	output = clCreateImage2D(context, CL_MEM_WRITE_ONLY, &format,
			image_width+2, image_height+2, 0, NULL, &err);
	CCHK(err);

	CCHK(clSetKernelArg(kernel, 0, sizeof(cl_mem), &input1));
	CCHK(clSetKernelArg(kernel, 1, sizeof(cl_mem), &input2));
	CCHK(clSetKernelArg(kernel, 2, sizeof(cl_mem), &output));

	CCHK(clGetKernelWorkGroupInfo(kernel, device_id, CL_KERNEL_WORK_GROUP_SIZE, sizeof(local), &local, NULL));

	global = 1024;
	CCHK(clEnqueueNDRangeKernel(commands, kernel, 1, NULL, &global, &local, 0, NULL, NULL));

	CCHK(clFinish(commands));

//	CCHK(clEnqueueReadBuffer( commands, output, CL_TRUE, 0, sizeof(float) * count, results, 0, NULL, NULL));

	clReleaseMemObject(input1);
	clReleaseMemObject(input2);
	clReleaseMemObject(output);
	clReleaseProgram(program);
	clReleaseKernel(kernel);
	clReleaseCommandQueue(commands);
	clReleaseContext(context);

	RD_END();
}
Example #27
0
void test_cat(void)
{
	GLint width, height;
	GLint modelviewmatrix_handle, modelviewprojectionmatrix_handle, normalmatrix_handle;
	GLuint position_vbo, normal_vbo;
	EGLSurface surface;
	float scale = 1.3;

	DEBUG_MSG("----------------------------------------------------------------");
	RD_START("cat", "");

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 400, 240);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "normal"));
	GCHK(glBindAttribLocation(program, 1, "position"));

	/* upload the attribute vbo's, only done once: */
	GCHK(glGenBuffers(1, &normal_vbo));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, normal_vbo));
	GCHK(glBufferData(GL_ARRAY_BUFFER, sizeof(cat_normal), cat_normal, GL_STATIC_DRAW));

	GCHK(glGenBuffers(1, &position_vbo));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, position_vbo));
	GCHK(glBufferData(GL_ARRAY_BUFFER, sizeof(cat_position), cat_position, GL_STATIC_DRAW));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glEnable(GL_DEPTH_TEST));
	GCHK(glDepthFunc(GL_LEQUAL));
	GCHK(glEnable(GL_CULL_FACE));
	GCHK(glCullFace(GL_BACK));
	GCHK(glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT));

	GCHK(glEnableVertexAttribArray(0));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, normal_vbo));
	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL));

	GCHK(glEnableVertexAttribArray(1));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, position_vbo));
	GCHK(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL));

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
	esRotate(&modelview, 45.0f, 0.0f, 1.0f, 0.0f);

	GLfloat aspect = (GLfloat)(height) / (GLfloat)(width);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection,
			-scale, +scale,
			-scale * aspect, +scale * aspect,
			5.5f, 10.0f);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	GCHK(modelviewmatrix_handle = glGetUniformLocation(program, "ModelViewMatrix"));
	GCHK(modelviewprojectionmatrix_handle = glGetUniformLocation(program, "ModelViewProjectionMatrix"));
	GCHK(normalmatrix_handle = glGetUniformLocation(program, "NormalMatrix"));

	GCHK(glUniformMatrix4fv(modelviewmatrix_handle, 1, GL_FALSE, &modelview.m[0][0]));
	GCHK(glUniformMatrix4fv(modelviewprojectionmatrix_handle, 1, GL_FALSE, &modelviewprojection.m[0][0]));
	GCHK(glUniformMatrix3fv(normalmatrix_handle, 1, GL_FALSE, normal));

	GCHK(glDrawArrays(GL_TRIANGLES, 0, cat_vertices));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Example #28
0
void test_multi(void)
{
	PixmapPtr src, dest;
	C2D_OBJECT blit = {};
	C2D_RECT rect;
	c2d_ts_handle curTimestamp;
	uint32_t w = 1920, h = 1080, format = xRGB;
	int i;

	DEBUG_MSG("multi: %04dx%04d-%08x", w, h, format);
	RD_START("multi", "%dx%d format:%08x", w, h, format);

	dest = create_pixmap(w, h, format);
	src  = create_pixmap(w, h, format);

	for (i = 0; i < 200; i++ ) {

		rect.x = 1;
		rect.y = 2;
		rect.width = w - 2;
		rect.height = h - 3;
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));
		CHK(c2dFillSurface(dest->id, 0xff556677, &rect));

		rect.x = 0;
		rect.y = 0;
		rect.width = 13;
		rect.height = 17;
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));
		CHK(c2dFillSurface(src->id, 0xff223344, &rect));

		blit.surface_id = src->id;
		blit.config_mask = DEFAULT_BLIT_MASK;
		blit.next = NULL;

		blit.source_rect.x = FIXED(1);
		blit.source_rect.y = FIXED(2);
		blit.source_rect.width = FIXED(13-2);
		blit.source_rect.height = FIXED(17-4);

		blit.target_rect.x = FIXED((w - 13) / 2);
		blit.target_rect.y = FIXED((h - 17) / 2);
		blit.target_rect.width = blit.source_rect.width;
		blit.target_rect.height = blit.source_rect.height;
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		// well, identical copy twice is fine, and I'm lazy:
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));
		CHK(c2dDraw(dest->id, 0, NULL, 0, 0, &blit, 1));

		CHK(c2dFlush(dest->id, &curTimestamp));

		if (!(i % 16))
		CHK(c2dWaitTimestamp(curTimestamp));

	}

	free_pixmap(src);
	free_pixmap(dest);

	RD_END();
}