Esempio n. 1
0
int GraphicsInit()
{
	if (_GraphicsRefCount <= 0)
	{
#if defined(_WIN32)
		COORD coord;
		BITMAPINFO bmi;

		curHwnd = GetConsoleWindow();
		curDc = GetDC(curHwnd);

		OptimizeConsole();
		GetConsoleBufferSize(&coord);
		curSurface.width = coord.X;
		curSurface.height = coord.Y;
		curSurface.pitch = curSurface.width;

		memset(&bmi, 0, sizeof(BITMAPINFO));
		bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
		bmi.bmiHeader.biWidth = curSurface.width;
		bmi.bmiHeader.biHeight = -curSurface.height;
		bmi.bmiHeader.biPlanes = 1;
		bmi.bmiHeader.biBitCount = 32;
		bmi.bmiHeader.biCompression = BI_RGB;

		backDc = CreateCompatibleDC(curDc);
		hBitmap = CreateDIBSection(backDc, &bmi, DIB_RGB_COLORS, (void**)&curSurface.data, NULL, 0);
		SelectObject(backDc, hBitmap);

#elif defined(PLATFORM_PSP2)
		SceGxmInitializeParams params;
		params.flags = 0x0;
		params.displayQueueMaxPendingCount = 0x2;
		params.displayQueueCallback = 0x0;
		params.displayQueueCallbackDataSize = 0x0;
		params.parameterBufferSize = (16 * 1024 * 1024);

		// initialize the GXM
		sceGxmInitialize(&params);

		// set-up and allocation of framebuffer
		if (CALL_FAILED(create_framebuffer(&fb_memuid[0], &fb[0]))) {
			printf("Could not allocate memory for fb[0]. %p", fb[0].base);
			return -1;
		}
		if (CALL_FAILED(create_framebuffer(&fb_memuid[1], &fb[1]))) {
			printf("Could not allocate memory for fb[1]. %p", fb[1].base);
			return - 1;
		}

		cur_fb = 0;
		GraphicsSwapBuffers(false);
#endif
	}
	return ++_GraphicsRefCount;
}
Esempio n. 2
0
File: glmenu.c Progetto: nasa/QuIP
static COMMAND_FUNC( do_create_fb )
{
	Framebuffer *fbp;
	const char *s;
	int w,h;

	s = NAMEOF("name for framebuffer");
	w = (int)HOW_MANY("width in pixels");
	h = (int)HOW_MANY("height in pixels");

	fbp = create_framebuffer(QSP_ARG  s,w,h);
	if( fbp == NULL ) {
		sprintf(ERROR_STRING,"Error creating framebuffer %s",s);
		WARN(ERROR_STRING);
	}
}
void
piglit_init(int argc, char**argv)
{
	GLuint ms_fbo, ms_rb;
	GLuint ss_fbo, ss_rb;
	GLuint programs[N_SAMPLES];
	bool use_uniform = false;
	GLuint shader_id_location = -1;
	GLfloat results[N_SAMPLES][2];
	bool pass = true;
	int i, j;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "uniform")) {
			use_uniform = true;
		} else {
			fprintf(stderr, "unknown argument \"%s\"\n", argv[i]);
			piglit_report_result(PIGLIT_FAIL);
		}
	}

	piglit_require_extension("GL_ARB_gpu_shader5");
	piglit_require_GLSL_version(150);

	if (use_uniform) {
		programs[0] = create_program(-1);
		glUseProgram(programs[0]);
		shader_id_location = glGetUniformLocation(programs[0],
							  "sample_id");
	} else {
		for (i = 0; i < N_SAMPLES; i++)
			programs[i] = create_program(i);
	}

	create_framebuffer(N_SAMPLES,
			   &ms_fbo, &ms_rb);
	create_framebuffer(1, /* sample_count */
			   &ss_fbo, &ss_rb);

	glViewport(0, 0, 1, 1);

	for (i = 0; i < N_SAMPLES; i++) {
		if (use_uniform)
			glUniform1i(shader_id_location, i);
		else
			glUseProgram(programs[i]);

		glBindFramebuffer(GL_FRAMEBUFFER, ms_fbo);
		glClear(GL_COLOR_BUFFER_BIT);
		piglit_draw_rect_tex(-1, -1, 2, 2,
				     0, 0, 1, 1);

		glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ss_fbo);

		glClear(GL_COLOR_BUFFER_BIT);
		glBlitFramebuffer(0, 0, /* srcX/Y0 */
				  1, 1, /* srcX/Y1 */
				  0, 0, /* dstX/Y0 */
				  1, 1, /* dstX/Y1 */
				  GL_COLOR_BUFFER_BIT,
				  GL_NEAREST);

		glBindFramebuffer(GL_FRAMEBUFFER, ss_fbo);

		glReadPixels(0, 0, /* x/y */
			     1, 1, /* width/height */
			     GL_RG, GL_FLOAT,
			     results[i]);
	}

	for (i = 0; i < N_SAMPLES; i++) {
		printf("value at sample %i = %f %f\n",
		       i,
		       results[i][0],
		       results[i][1]);
	}

	/* Check that the samples are within [0, 1] */
	for (i = 0; i < N_SAMPLES; i++) {
		if (results[i][0] < 0.0f || results[i][0] > 1.0f ||
		    results[i][1] < 0.0f || results[i][1] > 1.0f) {
			fprintf(stderr,
				"results for sample %i are out of range\n",
				i);
			pass = false;
		}
	}

	/* Check that all of the samples are different */
	for (i = 1; i < N_SAMPLES; i++) {
		for (j = 0; j < i; j++) {
			if (results[i][0] == results[j][0] &&
			    results[i][1] == results[j][1]) {
				fprintf(stderr,
					"samples %i and %i have the same "
					"value\n",
					i, j);
				pass = false;
				break;
			}
		}
	}

	glDeleteFramebuffers(1, &ms_fbo);
	glDeleteRenderbuffers(1, &ms_rb);
	glDeleteFramebuffers(1, &ss_fbo);
	glDeleteRenderbuffers(1, &ss_rb);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}