コード例 #1
0
ファイル: stsdk.c プロジェクト: ElecardSTB/elecard-apps
int32_t st_changeOutputMode(videoOutput_t *p_videoOutput, const char *newOutputFormat)
{
	uint32_t	old_height;
	uint32_t	new_height;
	uint32_t	len;

	if(!p_videoOutput || !newOutputFormat)
		return -1;
	old_height = stHelper_getFormatHeight(p_videoOutput->currentFormat);
	new_height = stHelper_getFormatHeight(newOutputFormat);

	if (old_height != new_height) {
		gfx_stopEventThread();
		gfx_terminate();
		stHelper_sendToElcd("deinitfb");
		st_setVideoFormat(p_videoOutput->name, newOutputFormat);
		stHelper_sendToElcd("initfb");
		stHelper_waitForFBdevice("/dev/fb0");
		if(p_videoOutput->isMajor) {
			if (new_height < 720 && interfaceInfo.screenHeight >= 720) {
				// Reset graphics mode for small resolutions
				appControlInfo.outputInfo.graphicsMode[0] = 0;
				saveAppSettings();
			}
			if (appControlInfo.outputInfo.graphicsMode[0] == 0) {
				stHelper_setDirectFBMode(stHelper_getFormatWidth(new_height), new_height);
			}
		}
		gfx_init(0, NULL);
		interface_resize();
		gfx_startEventThread();
		needRestart = 1;
	} else {
		st_setVideoFormat(p_videoOutput->name, newOutputFormat);
	}

	len = sizeof(p_videoOutput->currentFormat);
	strncpy(p_videoOutput->currentFormat, newOutputFormat, len);
	p_videoOutput->currentFormat[len - 1] = 0;

#ifdef ENABLE_FUSION
	fusion_fakeRestart();
#endif

	return 0;
}
コード例 #2
0
int _gfx_platform_poll_events(void)
{
	MSG msg;
	while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		if(msg.message != WM_QUIT)
		{
			/* Dispatch any regular message */
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			/* Terminate properly on WM_QUIT */
			gfx_terminate();
			return 0;
		}
	}

	return 1;
}
コード例 #3
0
int main()
{
	/* Really this is for testing purposes, in no way will this be the final usage */

	GFXContext context;
	context.major = 0;
	context.minor = 0;

	if(!gfx_init(context, GFX_ERROR_MODE_DEBUG))
	{
		GFXError error;
		if(gfx_errors_peek(&error)) print_error(error);

		return 0;
	}


	/* Setup 2 windows */
	GFXColorDepth depth;
	depth.redBits   = 8;
	depth.greenBits = 8;
	depth.blueBits  = 8;

	GFXWindow* window1 = gfx_window_create(NULL, 0, &depth, "Window Unos", 100, 100, 800, 600, GFX_WINDOW_RESIZABLE);
	GFXWindow* window2 = gfx_window_create(NULL, 0, &depth, "Window Deux", 200, 200, 800, 600, GFX_WINDOW_RESIZABLE);


	/* Pipeline */
	GFXPipeline* pipeline = gfx_pipeline_create();

	char targets[] = { 0 };
	GFXViewport viewport = { 0, 0, 800, 600 };
	pipeline->viewport = viewport;
	gfx_pipeline_target(pipeline, 1, targets);

	GFXPipe* bucket = gfx_pipeline_push_bucket(pipeline, 0);
	gfx_pipe_get_state(bucket)->render.state = GFX_STATE_DEFAULT | GFX_CLEAR_COLOR;


	/* Texture */
	GFXTextureFormat format;
	format.components    = 3;
	format.type.unpacked = GFX_UNSIGNED_BYTE;
	format.interpret     = GFX_INTERPRET_NORMALIZED;

	GFXTexture* tex = gfx_texture_create(GFX_TEXTURE_2D, format, 0, 800, 600, 1);

	GFXTextureImage image;
	image.texture = tex;
	image.mipmap  = 0;
	image.layer   = 0;

	gfx_pipeline_attach(pipeline, image, GFX_COLOR_ATTACHMENT, 0);


	/* Post processing */
	const char* vertSrc =
		"in ivec4 data;"
		"out vec2 coord;"
		"void main() {"
		"gl_Position = vec4(data.xy, 0, 1);"
		"coord = data.zw;"
		"}";

	const char* fragSrcA =
		"in vec2 coord;"
		"out vec3 color;"
		"uniform sampler2D tex;"
		"void main() {"
		"color = vec3(1.0f) - texture(tex, coord).rgb;"
		"}";
	const char* fragSrcB =
		"in vec2 coord;"
		"out vec3 color;"
		"uniform sampler2D tex;"
		"void main() {"
		"color = texture(tex, coord).rgb;"
		"}";

	GFXShader* vert = gfx_shader_create(GFX_VERTEX_SHADER);
	GFXShader* frag = gfx_shader_create(GFX_FRAGMENT_SHADER);
	gfx_shader_set_source(vert, 1, &vertSrc, NULL);
	gfx_shader_set_source(frag, 1, &fragSrcA, NULL);

	GFXShader* shaders[] = { vert, frag };

	GFXPipe* pipeA = gfx_pipeline_push_process(pipeline, window1, 0);
	GFXProgram* programA = gfx_pipe_process_add(pipeA->process, GFX_ALL_SHADERS, 1);
	gfx_program_set_attribute(programA, 0, "data");
	gfx_program_link(programA, 2, shaders, 0);

	gfx_shader_set_source(frag, 1, &fragSrcB, NULL);

	GFXPipe* pipeB = gfx_pipeline_push_process(pipeline, window2, 0);
	GFXProgram* programB = gfx_pipe_process_add(pipeB->process, GFX_ALL_SHADERS, 1);
	gfx_program_set_attribute(programB, 0, "data");
	gfx_program_link(programB, 2, shaders, 0);

	gfx_shader_free(vert);
	gfx_shader_free(frag);


	/* Property map */
	GFXSampler sampler =
	{
		.minFilter = GFX_FILTER_LINEAR,
		.mipFilter = GFX_FILTER_NEAREST,
		.magFilter = GFX_FILTER_LINEAR,

		.maxAnisotropy = 1.0f,

		.lodMin = 0,
		.lodMax = 0,

		.wrapS = GFX_WRAP_REPEAT,
		.wrapT = GFX_WRAP_REPEAT,
		.wrapR = GFX_WRAP_REPEAT
	};

	GFXPropertyMap* mapA = gfx_pipe_process_get_map(pipeA->process, 1);
	GFXPropertyMap* mapB = gfx_pipe_process_get_map(pipeB->process, 1);
	gfx_property_map_forward_named(mapA, 0, 0, 0, GFX_FRAGMENT_SHADER, "tex");
	gfx_property_map_set_sampler(mapA, 0, 0, sampler);
	gfx_property_map_set_texture(mapA, 0, 0, tex);
	gfx_property_map_forward_named(mapB, 0, 0, 0, GFX_FRAGMENT_SHADER, "tex");
	gfx_property_map_set_sampler_share(mapB, 0, 0, mapA, 0, 0);
	gfx_property_map_set_texture(mapB, 0, 0, tex);


	/* Mesh and material */
	GFXMaterial* material = create_material();
	GFXMesh* mesh = create_mesh();


	/* Batch */
	GFXBatch* batch = gfx_batch_create(
		bucket->bucket, material, mesh, 0, 0, 1, 1);
	gfx_batch_set_level(
		batch, 0, 0, 0, 1);
	gfx_batch_set(
		batch, 0, 1, 1);


	/* Setup a loop */
	while(gfx_poll_events() && gfx_get_num_windows())
	{
		/* Execute pipeline & swap buffers */
		gfx_pipeline_execute(pipeline, 0);

		/* Print time */
		//double time = gfx_get_time();
		//gfx_set_time(0.0);

		//printf("%f\n", 1.0 / time);

		/* Print all the errors! */
		GFXError error;
		while(gfx_errors_peek(&error))
		{
			print_error(error);
			gfx_errors_pop();
		}
	}


	/* Free all the things */
	gfx_batch_free(batch);
	gfx_mesh_free(mesh);
	gfx_material_free(material);
	gfx_program_map_free(programMap);
	gfx_texture_free(tex);
	gfx_pipeline_free(pipeline);

	gfx_window_free(window1);
	gfx_window_free(window2);

	gfx_terminate();

	return 0;
}