コード例 #1
0
ファイル: set.cpp プロジェクト: cyclefusion/szarp
void Set::from_xml( const bp::ptree& ptree )
{
	set_desc = ptree;

	fold_xmlattr( set_desc );

	name = set_desc.get<std::string>("@name");

	/**
	 * Convert obsolete color format to new one
	 */
	convert_colour( set_desc , "@background_color" );
	convert_colour( set_desc , "@background_text_color" );
	convert_colour( set_desc , "@text_color" );

	convert_float( set_desc , "@spacing_vertical"   );
	convert_float( set_desc , "@spacing_horizontal" );

	params.clear();
	for( auto& c : set_desc )
		if( c.first == "param" ) {
			auto name = c.second.get<std::string>("@name");
			auto pt = c.second;

			upgrade_option( pt , "@bg_color" , "@background_color" );
			upgrade_option( pt , "@color"    , "@graph_color" );

			convert_colour( pt , "@background_color" );
			convert_colour( pt , "@graph_color" );

			pt.erase("@order");

			params.insert(
				ParamId { name , c.second.get<double>("@order") , pt } );
		}

	set_desc.erase( "param" );

	update_hash();
}
コード例 #2
0
int convert_k(char const *const s, double* k, int* n) {
  int ret;
  const char* sp = s;

  // get the first value
  *n = 1;
  if( (ret = convert_float(&sp, k)) != 0)
    return ret;

  // see if there's more data on this line
  while(isblank(*sp)) sp++;
  if(is_eol(*sp))
    return 0;

  // must be another digit, assume we're dealing with complex data
  *n = 2;
  if( (ret = convert_float(&sp, k+1)) != 0)
    return ret;

  // all done
  return 0;
}
コード例 #3
0
ファイル: put_row.c プロジェクト: AsherBond/MondocosmOS
/* writes data to fcell file for either full or partial rows */
static void put_fp_data(int fd, char *null_buf, const void *rast,
			int row, int n, RASTER_MAP_TYPE data_type)
{
    struct fileinfo *fcb = &R__.fileinfo[fd];
    int compressed = (fcb->open_mode == OPEN_NEW_COMPRESSED);
    XDR *xdrs = &fcb->xdrstream;
    void *work_buf;

    if (row < 0 || row >= fcb->cellhd.rows)
	return;

    if (n <= 0)
	return;

    work_buf = G__alloca(fcb->cellhd.cols * fcb->nbytes + 1);

    if (compressed)
	set_file_pointer(fd, row);

    xdrmem_create(xdrs, work_buf,
		  (unsigned int)fcb->nbytes * fcb->cellhd.cols, XDR_ENCODE);
    xdr_setpos(xdrs, 0);

    if (data_type == FCELL_TYPE)
	convert_float(xdrs, null_buf, rast, row, n);
    else
	convert_double(xdrs, null_buf, rast, row, n);

    xdr_destroy(&fcb->xdrstream);

    if (compressed)
	write_data_compressed(fd, row, work_buf, n);
    else
	write_data(fd, row, work_buf, n);

    G__freea(work_buf);
}
コード例 #4
0
ファイル: shader.cpp プロジェクト: Lamorna/engine
/*
==================
==================
*/
void pixel_shader(

	const unsigned __int32 i_buffer,
	const unsigned __int32 coverage_mask,
	const __m128i bazza[3][4],
	shader_input_& shader_input
) {

	static const __m128 zero = set_zero();
	static const __m128 half = set_all(0.5f);
	static const __m128 one = set_all(1.0f);
	static const __m128 two = one + one;
	static const __m128 three = two + one;
	static const __m128i zero_int = set_zero_si128();
	static const __m128 colour_clamp = broadcast(load_s(255.0f));


	unsigned __int32 depth_mask = 0x0;

	__m128 w_screen[2][4];
	w_screen[0][0] = convert_float(bazza[0][0]) * shader_input.r_area;
	w_screen[0][1] = convert_float(bazza[0][1]) * shader_input.r_area;
	w_screen[0][2] = convert_float(bazza[0][2]) * shader_input.r_area;
	w_screen[0][3] = convert_float(bazza[0][3]) * shader_input.r_area;

	w_screen[1][0] = convert_float(bazza[1][0]) * shader_input.r_area;
	w_screen[1][1] = convert_float(bazza[1][1]) * shader_input.r_area;
	w_screen[1][2] = convert_float(bazza[1][2]) * shader_input.r_area;
	w_screen[1][3] = convert_float(bazza[1][3]) * shader_input.r_area;

	__m128 z_screen[4];
	z_screen[0] = (shader_input.z_delta[X] * w_screen[0][0]) + (shader_input.z_delta[Y] * w_screen[1][0]) + shader_input.z_delta[Z];
	z_screen[1] = (shader_input.z_delta[X] * w_screen[0][1]) + (shader_input.z_delta[Y] * w_screen[1][1]) + shader_input.z_delta[Z];
	z_screen[2] = (shader_input.z_delta[X] * w_screen[0][2]) + (shader_input.z_delta[Y] * w_screen[1][2]) + shader_input.z_delta[Z];
	z_screen[3] = (shader_input.z_delta[X] * w_screen[0][3]) + (shader_input.z_delta[Y] * w_screen[1][3]) + shader_input.z_delta[Z];

	{
		//if (shader_input.is_test) {

		//	__m128 x = convert_float(set_all(shader_input.x));
		//	__m128 y = convert_float(set_all(shader_input.y));
		//	y += set_all(0.5f);
		//	x += set_all(0.5f);
		//	x += set(0.0f, 1.0f, 2.0f, 3.0f);

		//	__m128 y_block[4];
		//	y_block[0] = y;
		//	y_block[1] = y + one;
		//	y_block[2] = y + two;
		//	y_block[3] = y + three;

		//	__m128 z_interpolant[3];
		//	z_interpolant[X] = set_all(shader_input.depth_interpolants[X]);
		//	z_interpolant[Y] = set_all(shader_input.depth_interpolants[Y]);
		//	z_interpolant[Z] = set_all(shader_input.depth_interpolants[Z]);

		//	z_screen[0] = (z_interpolant[X] * x) + (z_interpolant[Y] * y_block[0]) + z_interpolant[Z];
		//	z_screen[1] = (z_interpolant[X] * x) + (z_interpolant[Y] * y_block[1]) + z_interpolant[Z];
		//	z_screen[2] = (z_interpolant[X] * x) + (z_interpolant[Y] * y_block[2]) + z_interpolant[Z];
		//	z_screen[3] = (z_interpolant[X] * x) + (z_interpolant[Y] * y_block[3]) + z_interpolant[Z];
		//}
	}

	__m128i pixel_mask[4];
	pixel_mask[0] = load_mask[(coverage_mask >> 0) & 0xf];
	pixel_mask[1] = load_mask[(coverage_mask >> 4) & 0xf];
	pixel_mask[2] = load_mask[(coverage_mask >> 8) & 0xf];
	pixel_mask[3] = load_mask[(coverage_mask >> 12) & 0xf];

	__m128 z_buffer[4];
	z_buffer[0] = load(shader_input.depth_buffer + i_buffer + 0);
	z_buffer[1] = load(shader_input.depth_buffer + i_buffer + 4);
	z_buffer[2] = load(shader_input.depth_buffer + i_buffer + 8);
	z_buffer[3] = load(shader_input.depth_buffer + i_buffer + 12);

	__m128i z_mask[4];
	z_mask[0] = (z_screen[0] > z_buffer[0]) & pixel_mask[0];
	z_mask[1] = (z_screen[1] > z_buffer[1]) & pixel_mask[1];
	z_mask[2] = (z_screen[2] > z_buffer[2]) & pixel_mask[2];
	z_mask[3] = (z_screen[3] > z_buffer[3]) & pixel_mask[3];


	depth_mask |= store_mask(z_mask[0]) << 0;
	depth_mask |= store_mask(z_mask[1]) << 4;
	depth_mask |= store_mask(z_mask[2]) << 8;
	depth_mask |= store_mask(z_mask[3]) << 12;


	__m128 z_write[4];
	z_write[0] = blend(z_screen[0], z_buffer[0], z_mask[0]);
	z_write[1] = blend(z_screen[1], z_buffer[1], z_mask[1]);
	z_write[2] = blend(z_screen[2], z_buffer[2], z_mask[2]);
	z_write[3] = blend(z_screen[3], z_buffer[3], z_mask[3]);

	{
		__m128 z_max;
		z_max = z_write[0];
		z_max = min_vec(z_write[1], z_max);
		z_max = min_vec(z_write[2], z_max);
		z_max = min_vec(z_write[3], z_max);

		__m128 z_out = z_max;
		z_max = rotate_left(z_max);
		z_out = min_vec(z_max, z_out);
		z_max = rotate_left(z_max);
		z_out = min_vec(z_max, z_out);
		z_max = rotate_left(z_max);
		z_out = min_vec(z_max, z_out);

		shader_input.z_max = store_s(z_out);
	}


	store(z_write[0], shader_input.depth_buffer + i_buffer + 0);
	store(z_write[1], shader_input.depth_buffer + i_buffer + 4);
	store(z_write[2], shader_input.depth_buffer + i_buffer + 8);
	store(z_write[3], shader_input.depth_buffer + i_buffer + 12);


	if (depth_mask == 0x0) {
		return;
	}


	__m128 screen_barry[2][4];
	screen_barry[0][0] = (w_screen[0][0] * shader_input.barycentric[0][X]) + (w_screen[1][0] * shader_input.barycentric[0][Y]) + shader_input.barycentric[0][Z];
	screen_barry[0][1] = (w_screen[0][1] * shader_input.barycentric[0][X]) + (w_screen[1][1] * shader_input.barycentric[0][Y]) + shader_input.barycentric[0][Z];
	screen_barry[0][2] = (w_screen[0][2] * shader_input.barycentric[0][X]) + (w_screen[1][2] * shader_input.barycentric[0][Y]) + shader_input.barycentric[0][Z];
	screen_barry[0][3] = (w_screen[0][3] * shader_input.barycentric[0][X]) + (w_screen[1][3] * shader_input.barycentric[0][Y]) + shader_input.barycentric[0][Z];

	screen_barry[1][0] = (w_screen[0][0] * shader_input.barycentric[1][X]) + (w_screen[1][0] * shader_input.barycentric[1][Y]) + shader_input.barycentric[1][Z];
	screen_barry[1][1] = (w_screen[0][1] * shader_input.barycentric[1][X]) + (w_screen[1][1] * shader_input.barycentric[1][Y]) + shader_input.barycentric[1][Z];
	screen_barry[1][2] = (w_screen[0][2] * shader_input.barycentric[1][X]) + (w_screen[1][2] * shader_input.barycentric[1][Y]) + shader_input.barycentric[1][Z];
	screen_barry[1][3] = (w_screen[0][3] * shader_input.barycentric[1][X]) + (w_screen[1][3] * shader_input.barycentric[1][Y]) + shader_input.barycentric[1][Z];

	__m128 r_depth[4];
	r_depth[0] = reciprocal(z_screen[0]);
	r_depth[1] = reciprocal(z_screen[1]);
	r_depth[2] = reciprocal(z_screen[2]);
	r_depth[3] = reciprocal(z_screen[3]);

	__m128 w_clip[2][4];
	w_clip[0][0] = screen_barry[0][0] * r_depth[0];
	w_clip[0][1] = screen_barry[0][1] * r_depth[1];
	w_clip[0][2] = screen_barry[0][2] * r_depth[2];
	w_clip[0][3] = screen_barry[0][3] * r_depth[3];

	w_clip[1][0] = screen_barry[1][0] * r_depth[0];
	w_clip[1][1] = screen_barry[1][1] * r_depth[1];
	w_clip[1][2] = screen_barry[1][2] * r_depth[2];
	w_clip[1][3] = screen_barry[1][3] * r_depth[3];

	__m128i colour_out[4];
	{
		const vertex4_* gradients = shader_input.gradients[ATTRIBUTE_COLOUR];

		__m128 red_float[4];
		red_float[0] = (gradients[R].x * w_clip[0][0]) + (gradients[R].y * w_clip[1][0]) + gradients[R].z;
		red_float[1] = (gradients[R].x * w_clip[0][1]) + (gradients[R].y * w_clip[1][1]) + gradients[R].z;
		red_float[2] = (gradients[R].x * w_clip[0][2]) + (gradients[R].y * w_clip[1][2]) + gradients[R].z;
		red_float[3] = (gradients[R].x * w_clip[0][3]) + (gradients[R].y * w_clip[1][3]) + gradients[R].z;

		__m128 green_float[4];
		green_float[0] = (gradients[G].x * w_clip[0][0]) + (gradients[G].y * w_clip[1][0]) + gradients[G].z;
		green_float[1] = (gradients[G].x * w_clip[0][1]) + (gradients[G].y * w_clip[1][1]) + gradients[G].z;
		green_float[2] = (gradients[G].x * w_clip[0][2]) + (gradients[G].y * w_clip[1][2]) + gradients[G].z;
		green_float[3] = (gradients[G].x * w_clip[0][3]) + (gradients[G].y * w_clip[1][3]) + gradients[G].z;

		__m128 blue_float[4];
		blue_float[0] = (gradients[B].x * w_clip[0][0]) + (gradients[B].y * w_clip[1][0]) + gradients[B].z;
		blue_float[1] = (gradients[B].x * w_clip[0][1]) + (gradients[B].y * w_clip[1][1]) + gradients[B].z;
		blue_float[2] = (gradients[B].x * w_clip[0][2]) + (gradients[B].y * w_clip[1][2]) + gradients[B].z;
		blue_float[3] = (gradients[B].x * w_clip[0][3]) + (gradients[B].y * w_clip[1][3]) + gradients[B].z;

		red_float[0] = min_vec(max_vec(red_float[0], zero), colour_clamp);
		red_float[1] = min_vec(max_vec(red_float[1], zero), colour_clamp);
		red_float[2] = min_vec(max_vec(red_float[2], zero), colour_clamp);
		red_float[3] = min_vec(max_vec(red_float[3], zero), colour_clamp);

		green_float[0] = min_vec(max_vec(green_float[0], zero), colour_clamp);
		green_float[1] = min_vec(max_vec(green_float[1], zero), colour_clamp);
		green_float[2] = min_vec(max_vec(green_float[2], zero), colour_clamp);
		green_float[3] = min_vec(max_vec(green_float[3], zero), colour_clamp);

		blue_float[0] = min_vec(max_vec(blue_float[0], zero), colour_clamp);
		blue_float[1] = min_vec(max_vec(blue_float[1], zero), colour_clamp);
		blue_float[2] = min_vec(max_vec(blue_float[2], zero), colour_clamp);
		blue_float[3] = min_vec(max_vec(blue_float[3], zero), colour_clamp);

		__m128i red_int[4];
		red_int[0] = convert_int_trunc(red_float[0]);
		red_int[1] = convert_int_trunc(red_float[1]);
		red_int[2] = convert_int_trunc(red_float[2]);
		red_int[3] = convert_int_trunc(red_float[3]);

		__m128i green_int[4];
		green_int[0] = convert_int_trunc(green_float[0]);
		green_int[1] = convert_int_trunc(green_float[1]);
		green_int[2] = convert_int_trunc(green_float[2]);
		green_int[3] = convert_int_trunc(green_float[3]);

		__m128i blue_int[4];
		blue_int[0] = convert_int_trunc(blue_float[0]);
		blue_int[1] = convert_int_trunc(blue_float[1]);
		blue_int[2] = convert_int_trunc(blue_float[2]);
		blue_int[3] = convert_int_trunc(blue_float[3]);

		colour_out[0] = red_int[0] | (green_int[0] << 8) | (blue_int[0] << 16);
		colour_out[1] = red_int[1] | (green_int[1] << 8) | (blue_int[1] << 16);
		colour_out[2] = red_int[2] | (green_int[2] << 8) | (blue_int[2] << 16);
		colour_out[3] = red_int[3] | (green_int[3] << 8) | (blue_int[3] << 16);
	}

	float4_ u_table[4];
	float4_ v_table[4];


	{
		const vertex4_* gradients = shader_input.gradients[ATTRIBUTE_TEXCOORD];

		__m128 u_axis[4];
		u_axis[0] = (gradients[U].x * w_clip[0][0]) + (gradients[U].y * w_clip[1][0]) + gradients[U].z;
		u_axis[1] = (gradients[U].x * w_clip[0][1]) + (gradients[U].y * w_clip[1][1]) + gradients[U].z;
		u_axis[2] = (gradients[U].x * w_clip[0][2]) + (gradients[U].y * w_clip[1][2]) + gradients[U].z;
		u_axis[3] = (gradients[U].x * w_clip[0][3]) + (gradients[U].y * w_clip[1][3]) + gradients[U].z;

		__m128 v_axis[4];
		v_axis[0] = (gradients[V].x * w_clip[0][0]) + (gradients[V].y * w_clip[1][0]) + gradients[V].z;
		v_axis[1] = (gradients[V].x * w_clip[0][1]) + (gradients[V].y * w_clip[1][1]) + gradients[V].z;
		v_axis[2] = (gradients[V].x * w_clip[0][2]) + (gradients[V].y * w_clip[1][2]) + gradients[V].z;
		v_axis[3] = (gradients[V].x * w_clip[0][3]) + (gradients[V].y * w_clip[1][3]) + gradients[V].z;

		store_u(u_axis[0], u_table[0].f);
		store_u(u_axis[1], u_table[1].f);
		store_u(u_axis[2], u_table[2].f);
		store_u(u_axis[3], u_table[3].f);

		store_u(v_axis[0], v_table[0].f);
		store_u(v_axis[1], v_table[1].f);
		store_u(v_axis[2], v_table[2].f);
		store_u(v_axis[3], v_table[3].f);
	}

	const texture_handler_& texture_handler = *shader_input.texture_handler;

	float2_ du;
	du.x = (u_table[0].f[3] - u_table[0].f[0]) * (float)texture_handler.width;
	du.y = (u_table[3].f[0] - u_table[0].f[0]) * (float)texture_handler.width;

	float2_ dv;
	dv.x = (v_table[0].f[3] - v_table[0].f[0]) * (float)texture_handler.height;
	dv.y = (v_table[3].f[0] - v_table[0].f[0]) * (float)texture_handler.height;

	float area = abs((du.x * dv.y) - (du.y * dv.x))  * shader_input.mip_level_bias;
	unsigned long area_int = 1 + (unsigned long)(area + 0.5f);
	__int32 i_mip_floor;
	_BitScanReverse((unsigned long*)&i_mip_floor, area_int);

	i_mip_floor = max(i_mip_floor, 0);
	i_mip_floor = min(i_mip_floor, texture_handler.n_mip_levels - 1);

	const __int32 width = texture_handler.width >> i_mip_floor;
	const __int32 height = texture_handler.height >> i_mip_floor;
	const __int32 shift = texture_handler.width_shift - i_mip_floor;

	const __m128i texture_width_int = set_all(width);
	const __m128 texture_width = convert_float(set_all(width));
	const __m128 texture_height = convert_float(set_all(height));
	const __m128i width_clamp = set_all(width - 1);
	const __m128i height_clamp = set_all(height - 1);
	const __m128i width_shift = load_s(shift);

	__m128i tex_out[4];
	{
		__m128 u_axis[4];
		u_axis[0] = (load_u(u_table[0].f) * texture_width); // - half;
		u_axis[1] = (load_u(u_table[1].f) * texture_width); // - half;
		u_axis[2] = (load_u(u_table[2].f) * texture_width); // - half;
		u_axis[3] = (load_u(u_table[3].f) * texture_width); // - half;

		__m128 v_axis[4];
		v_axis[0] = (load_u(v_table[0].f) * texture_height); // - half;
		v_axis[1] = (load_u(v_table[1].f) * texture_height); // - half;
		v_axis[2] = (load_u(v_table[2].f) * texture_height); // - half;
		v_axis[3] = (load_u(v_table[3].f) * texture_height); // - half;

		__m128i u_int[4];
		u_int[0] = convert_int_trunc(u_axis[0]);
		u_int[1] = convert_int_trunc(u_axis[1]);
		u_int[2] = convert_int_trunc(u_axis[2]);
		u_int[3] = convert_int_trunc(u_axis[3]);

		__m128i v_int[4];
		v_int[0] = convert_int_trunc(v_axis[0]);
		v_int[1] = convert_int_trunc(v_axis[1]);
		v_int[2] = convert_int_trunc(v_axis[2]);
		v_int[3] = convert_int_trunc(v_axis[3]);

		u_int[0] = max_vec(min_vec(u_int[0], width_clamp), zero_int);
		u_int[1] = max_vec(min_vec(u_int[1], width_clamp), zero_int);
		u_int[2] = max_vec(min_vec(u_int[2], width_clamp), zero_int);
		u_int[3] = max_vec(min_vec(u_int[3], width_clamp), zero_int);

		v_int[0] = max_vec(min_vec(v_int[0], height_clamp), zero_int);
		v_int[1] = max_vec(min_vec(v_int[1], height_clamp), zero_int);
		v_int[2] = max_vec(min_vec(v_int[2], height_clamp), zero_int);
		v_int[3] = max_vec(min_vec(v_int[3], height_clamp), zero_int);


		__m128i i_texels[4];
		i_texels[0] = u_int[0] + (v_int[0] * texture_width_int);
		i_texels[1] = u_int[1] + (v_int[1] * texture_width_int);
		i_texels[2] = u_int[2] + (v_int[2] * texture_width_int);
		i_texels[3] = u_int[3] + (v_int[3] * texture_width_int);

		__int32 i_texels_in[4][4];
		store_u(i_texels[0], i_texels_in[0]);
		store_u(i_texels[1], i_texels_in[1]);
		store_u(i_texels[2], i_texels_in[2]);
		store_u(i_texels[3], i_texels_in[3]);

		unsigned __int32 texels_out[4][4];
		texels_out[0][0] = texture_handler.texture[i_mip_floor][i_texels_in[0][0]];
		texels_out[0][1] = texture_handler.texture[i_mip_floor][i_texels_in[0][1]];
		texels_out[0][2] = texture_handler.texture[i_mip_floor][i_texels_in[0][2]];
		texels_out[0][3] = texture_handler.texture[i_mip_floor][i_texels_in[0][3]];

		texels_out[1][0] = texture_handler.texture[i_mip_floor][i_texels_in[1][0]];
		texels_out[1][1] = texture_handler.texture[i_mip_floor][i_texels_in[1][1]];
		texels_out[1][2] = texture_handler.texture[i_mip_floor][i_texels_in[1][2]];
		texels_out[1][3] = texture_handler.texture[i_mip_floor][i_texels_in[1][3]];

		texels_out[2][0] = texture_handler.texture[i_mip_floor][i_texels_in[2][0]];
		texels_out[2][1] = texture_handler.texture[i_mip_floor][i_texels_in[2][1]];
		texels_out[2][2] = texture_handler.texture[i_mip_floor][i_texels_in[2][2]];
		texels_out[2][3] = texture_handler.texture[i_mip_floor][i_texels_in[2][3]];

		texels_out[3][0] = texture_handler.texture[i_mip_floor][i_texels_in[3][0]];
		texels_out[3][1] = texture_handler.texture[i_mip_floor][i_texels_in[3][1]];
		texels_out[3][2] = texture_handler.texture[i_mip_floor][i_texels_in[3][2]];
		texels_out[3][3] = texture_handler.texture[i_mip_floor][i_texels_in[3][3]];

		tex_out[0] = load_u(texels_out[0]);
		tex_out[1] = load_u(texels_out[1]);
		tex_out[2] = load_u(texels_out[2]);
		tex_out[3] = load_u(texels_out[3]);
	}

	__m128i colour_buffer[4];
	colour_buffer[0] = load(shader_input.colour_buffer + i_buffer + 0);
	colour_buffer[1] = load(shader_input.colour_buffer + i_buffer + 4);
	colour_buffer[2] = load(shader_input.colour_buffer + i_buffer + 8);
	colour_buffer[3] = load(shader_input.colour_buffer + i_buffer + 12);

	colour_buffer[0] = _mm_andnot_si128(z_mask[0], colour_buffer[0]);
	colour_buffer[1] = _mm_andnot_si128(z_mask[1], colour_buffer[1]);
	colour_buffer[2] = _mm_andnot_si128(z_mask[2], colour_buffer[2]);
	colour_buffer[3] = _mm_andnot_si128(z_mask[3], colour_buffer[3]);

	colour_buffer[0] = add_uint8_saturate(colour_buffer[0], colour_out[0] & z_mask[0]);
	colour_buffer[1] = add_uint8_saturate(colour_buffer[1], colour_out[1] & z_mask[1]);
	colour_buffer[2] = add_uint8_saturate(colour_buffer[2], colour_out[2] & z_mask[2]);
	colour_buffer[3] = add_uint8_saturate(colour_buffer[3], colour_out[3] & z_mask[3]);

	colour_buffer[0] = add_uint8_saturate(colour_buffer[0], tex_out[0] & z_mask[0]);
	colour_buffer[1] = add_uint8_saturate(colour_buffer[1], tex_out[1] & z_mask[1]);
	colour_buffer[2] = add_uint8_saturate(colour_buffer[2], tex_out[2] & z_mask[2]);
	colour_buffer[3] = add_uint8_saturate(colour_buffer[3], tex_out[3] & z_mask[3]);

	store(colour_buffer[0], shader_input.colour_buffer + i_buffer + 0);
	store(colour_buffer[1], shader_input.colour_buffer + i_buffer + 4);
	store(colour_buffer[2], shader_input.colour_buffer + i_buffer + 8);
	store(colour_buffer[3], shader_input.colour_buffer + i_buffer + 12);
}
コード例 #5
0
int main(int argc, char *argv[])
{
    int server_sockfd, client_sockfd,port,server_port;
	int sockfd;
	char option;
	char server_name[20];
	char buf[BUF_SIZE];
    struct sockaddr_in server_address;
	struct sockaddr_in address;
	struct hostent *host; 
	struct information received_info,modified_info;
 
	// check for 2 command line arguments
	if (argc < 2) { 
		fprintf(stderr,"Usage: %s port\n", argv[0]); 
		exit(0);
    }
	//atoi() converts ASCII to integer and gets the port number
	port = atoi(argv[1]); 
	
	memset(&server_address,0,sizeof(server_address));
    server_address.sin_family = AF_INET;
    server_address.sin_addr.s_addr = htonl(INADDR_ANY);
    server_address.sin_port = htons(port) ; 
 
	server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (server_sockfd == -1) { 
        perror("Server socket create failed.\n") ; 
        return -1 ; 
    } 
	
	if(bind(server_sockfd, (struct sockaddr *) &server_address, sizeof(server_address)) == -1)
    {
        perror(" Bind error has occurred");
        exit(-1);
    }
    printf("Server Bind successful..\n"); 
	
    //creates a connection queue and wait for clients 
	if(listen(server_sockfd, QUEUE_LENGTH) == -1)
    {
        perror(" Listen error has occurred");
        exit(-1);
    }
	printf("Server is listening..\n");
	
    client_sockfd = accept(server_sockfd, 0, 0);
	if (client_sockfd < 0) {
		perror(" Accept error has occurred");
        exit(-1);
	}	
	printf("Server accepted the client connection..\n");
	printf("Server waiting for data..\n");
	
	if(read(client_sockfd, &received_info, sizeof(struct information)) == -1)
    {
        perror(" Read error has occurred");
        exit(-1);
    }
	received_info.number = ntohl(received_info.number);
	received_info.f = convert_float(received_info.f);

	printf("Data received from client:\n");
	printf("Integer value: %d\n", received_info.number) ; 
	printf("Char value: %c\n", received_info.letter) ;
	printf("Float value: %f\n", received_info.f) ;
	
	write(client_sockfd, "Thanks, received your data", 27);
	
	if (close(client_sockfd) == -1) { 
		perror("Error occurred while closing connection");
		exit(-1);
    }
	printf("Connection with client has been closed.\n");
	
	if (close(server_sockfd) == -1) { 
		perror("Error occurred while closing connection");
		exit(-1);
    }
	printf("Server exiting..\n");
	
	//modifing the received data as required
	modified_info.number=received_info.number*2;
	modified_info.f=received_info.f+1.0;
	if(received_info.letter == 'z')
		modified_info.letter = 'a'; 
	else if(received_info.letter == 'Z')
		modified_info.letter = 'A';
	else
		modified_info.letter = received_info.letter+1;
	
	printf("------------------------------\n");	
	printf("The values after modification:\n");	
	printf("Integer value: %d\n", modified_info.number) ; 
	printf("Char value: %c\n", modified_info.letter) ;
	printf("Float value: %f\n", modified_info.f) ;
	printf("------------------------------\n");	
	
	printf("Do you wish to send the modified data to another server? (Y/N):");
	scanf("%s", &option); 
	
	if(option =='Y'){
	printf("\nPlease enter the name of the server:");
	scanf("%s", &server_name);
	printf("\nPlease enter the port on which the server is running:");
	scanf("%d", &server_port);
	
	//Create socket for client.
	sockfd = socket(PF_INET, SOCK_STREAM, 0);
	if (sockfd == -1) { 
		perror("Socket create failed.\n") ; 
		return -1 ; 
	} 
	printf("Client socket created\n"); 
	
	host=gethostbyname(server_name);
	if(!host){
		perror("gethostbyname failed");
		exit(-1);
	}
	printf("Fetching the server's IP address..\n");
	
	memset(&address,0,sizeof(address));
	address.sin_family = AF_INET;
	memcpy(&address.sin_addr.s_addr,host->h_addr,host->h_length);
	address.sin_port = htons(server_port);
	
	printf("Connecting to the server, %s on port, %d\n", server_name, server_port); 
	if(connect(sockfd, (struct sockaddr *)&address, sizeof(address)) == -1)
	{
		perror("Error has occurred");
		exit(-1);
	}
	printf("Connected to the server!\n");
	
	//converting the data to the required before sending.
	modified_info.number = htonl(modified_info.number);
	modified_info.f = convert_float(modified_info.f);

	if(write(sockfd, &modified_info, sizeof(struct information)) == -1)
	{
		perror(" Write error has occurred");
		exit(-1);
	}
	printf("Data sent to the server..\n");
	
	read(sockfd, buf, BUF_SIZE);
	printf("Server says:%s\n", buf);
	
	close(sockfd);
	printf("Client closes the connection.\n");
	return 0;
	}
	printf("thank you!\n");	
}
コード例 #6
0
int main(int argc, char *argv[])
{
    int server_sockfd, client_sockfd,port;
    int server_len ; 
    int rc ; 
    unsigned client_len;
    struct sockaddr_in server_address;
    struct sockaddr_in client_address;
	struct information received_info;
 
	// check for 2 command line arguments
	if (argc < 2) { 
		fprintf(stderr,"Usage: %s port\n", argv[0]); 
		exit(0);
    }
	
	//atoi() converts ASCII to integer and gets the port number
	port = atoi(argv[1]); 
	
	memset(&server_address,0,sizeof(server_address));
    server_address.sin_family = AF_INET;
    server_address.sin_addr.s_addr = htons(INADDR_ANY);
    server_address.sin_port = htons(port) ; 

	server_sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (server_sockfd == -1) { 
        perror("Server socket create failed.\n") ; 
        return -1 ; 
    } 
	
    if(bind(server_sockfd, (struct sockaddr *) &server_address, sizeof(server_address)) == -1){
        perror(" Bind error has occurred");
        exit(-1);
    } 
	printf("Server Bind successful..\n"); 
	
    //creates a connection queue and wait for clients
	if(listen(server_sockfd, QUEUE_LENGTH) == -1){
        perror(" Listen error has occurred");
        exit(-1);
    }
	printf("Server is listening..\n");
	
    client_sockfd = accept(server_sockfd, 0, 0);
    if (client_sockfd < 0) {
		perror(" Accept error has occurred");
        exit(-1);
	}	
	printf("Server accepted the client connection..\n");
	printf("Server waiting for data..\n");

	if(read(client_sockfd, &received_info, sizeof(struct information)) == -1)
    {
        perror(" Read error has occurred");
        exit(-1);
    }
	received_info.number = ntohl(received_info.number);
	received_info.f = convert_float(received_info.f);

	printf("------------------------------\n");
	printf("Data received from client:\n");
	printf("------------------------------\n");
	printf("Integer value: %d\n", received_info.number) ; 
	printf("Char value: %c\n", received_info.letter) ;
	printf("Float value: %f\n", received_info.f) ;
	printf("------------------------------\n");
	
	write(client_sockfd, "Thanks, received your data", 27);
	
	if (close(client_sockfd) == -1) { 
		perror("Error occurred while closing connection");
		exit(-1);
    }
	printf("Connection with client closed.\n");
	
	if (close(server_sockfd) == -1) { 
		perror("Error occurred while closing connection");
		exit(-1);
    }
	printf("Server exiting..\n");
    return 0;
}
コード例 #7
0
ファイル: convert_store_sales.c プロジェクト: ar104/cbdma
int main(int argc, char *argv[])
{
  if(argc != 3) {
    printf("Usage: %s infile outfile\n", argv[0]);
    exit(-1);
  }
  FILE *fd_in = fopen(argv[1], "r");
  if(fd_in == NULL) {
    printf("Failed to open input file\n");
    exit(-1);
  }
  int fd_out = open(argv[2], O_WRONLY|O_CREAT, S_IRWXU);
  if(fd_out == -1) {
    printf("Failed to open output file\n");
    exit(-1);
  }
  while(1) {
    if(fgets(buffer, 10000, fd_in) == NULL)
      break;
    buf_off  = -1;
    conv_off = 0;
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_ulong();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    convert_float();
    
    int bytes_to_write = conv_off;
    char *data = converted;
    while(bytes_to_write) {
      int e = write(fd_out, data, bytes_to_write);
      if(e < 0) {
	printf("write failed\n");
	exit(-1);
      }
      bytes_to_write -= e;
      data += e;
    }
  }
  fclose(fd_in);
  close(fd_out);
}