Beispiel #1
0
/* TODO: Keep a static copy in device so we don't have to memset every time ? */
void
nine_convert_rasterizer_state(struct cso_context *ctx, const DWORD *rs)
{
    struct pipe_rasterizer_state rast;

    memset(&rast, 0, sizeof(rast)); /* memcmp safety */

    rast.flatshade = rs[D3DRS_SHADEMODE] == D3DSHADE_FLAT;
 /* rast.light_twoside = 0; */
 /* rast.clamp_fragment_color = 0; */
 /* rast.clamp_vertex_color = 0; */
 /* rast.front_ccw = 0; */
    rast.cull_face = d3dcull_to_pipe_face(rs[D3DRS_CULLMODE]);
    rast.fill_front = d3dfillmode_to_pipe_polygon_mode(rs[D3DRS_FILLMODE]);
    rast.fill_back = rast.fill_front;
    rast.offset_tri = !!(rs[D3DRS_DEPTHBIAS] | rs[D3DRS_SLOPESCALEDEPTHBIAS]);
    rast.offset_line = rast.offset_tri; /* triangles in wireframe mode */
    rast.offset_point = 0; /* XXX ? */
    rast.scissor = !!rs[D3DRS_SCISSORTESTENABLE];
 /* rast.poly_smooth = 0; */
 /* rast.poly_stipple_enable = 0; */
 /* rast.point_smooth = 0; */
    rast.sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT;
    rast.point_quad_rasterization = !!rs[D3DRS_POINTSPRITEENABLE];
    rast.point_size_per_vertex = rs[NINED3DRS_VSPOINTSIZE];
    rast.multisample = !!rs[D3DRS_MULTISAMPLEANTIALIAS];
    rast.line_smooth = !!rs[D3DRS_ANTIALIASEDLINEENABLE];
 /* rast.line_stipple_enable = 0; */
    rast.line_last_pixel = !!rs[D3DRS_LASTPIXEL];
    rast.flatshade_first = 1;
 /* rast.half_pixel_center = 0; */
 /* rast.lower_left_origin = 0; */
 /* rast.bottom_edge_rule = 0; */
 /* rast.rasterizer_discard = 0; */
    rast.depth_clip = 1;
    rast.clip_halfz = 1;
    rast.clip_plane_enable = rs[D3DRS_CLIPPLANEENABLE];
 /* rast.line_stipple_factor = 0; */
 /* rast.line_stipple_pattern = 0; */
    rast.sprite_coord_enable = rs[D3DRS_POINTSPRITEENABLE] ? 0xff : 0x00;
    rast.line_width = 1.0f;
    rast.point_size = rs[NINED3DRS_VSPOINTSIZE] ? 1.0f : asfloat(rs[D3DRS_POINTSIZE]); /* XXX: D3DRS_POINTSIZE_MIN/MAX */
    rast.offset_units = asfloat(rs[D3DRS_DEPTHBIAS]) * asfloat(rs[NINED3DRS_ZBIASSCALE]);
    rast.offset_scale = asfloat(rs[D3DRS_SLOPESCALEDEPTHBIAS]);
 /* rast.offset_clamp = 0.0f; */

    cso_set_rasterizer(ctx, &rast);
}
Beispiel #2
0
void
nine_dump_D3DTSS_value(unsigned ch, D3DTEXTURESTAGESTATETYPE type, DWORD value)
{
    float rgba[4];

    switch (type) {
    case D3DTSS_COLOROP:
    case D3DTSS_ALPHAOP:
        DBG_FLAG(ch, "D3DTSS_%s = %s\n",
                 nine_D3DTSS_to_str(type), nine_D3DTOP_to_str(value));
        break;
    case D3DTSS_COLORARG0:
    case D3DTSS_COLORARG1:
    case D3DTSS_COLORARG2:
    case D3DTSS_ALPHAARG0:
    case D3DTSS_ALPHAARG1:
    case D3DTSS_ALPHAARG2:
    case D3DTSS_RESULTARG:
        DBG_FLAG(ch, "D3DTSS_%s = %s%s%s\n",
                 nine_D3DTSS_to_str(type),
                 (value & D3DTA_COMPLEMENT) ? "COMPLEMENT " : "",
                 (value & D3DTA_ALPHAREPLICATE) ? "ALPHAREPLICATE " : "",
                 nine_D3DTA_to_str(value));
        break;
    case D3DTSS_BUMPENVMAT00:
    case D3DTSS_BUMPENVMAT01:
    case D3DTSS_BUMPENVMAT10:
    case D3DTSS_BUMPENVMAT11:
    case D3DTSS_BUMPENVLSCALE:
    case D3DTSS_BUMPENVLOFFSET:
        DBG_FLAG(ch, "D3DTSS_%s = %f\n",
                 nine_D3DTSS_to_str(type), asfloat(value));
        break;
    case D3DTSS_TEXCOORDINDEX:
        DBG_FLAG(ch, "D3DTSS_TEXCOORDINDEX = %s %u\n",
                 nine_D3DTSS_TCI_to_str(value),
                 value & 0xffff);
        break;
    case D3DTSS_TEXTURETRANSFORMFLAGS:
        DBG_FLAG(ch, "D3DTSS_TEXTURETRANSFORMFLAGS = %s\n",
                 nine_D3DTTFF_to_str(value));
        break;
    case D3DTSS_CONSTANT:
        d3dcolor_to_rgba(rgba, value);
        DBG_FLAG(ch, "D3DTSS_CONSTANT = %f %f %f %F\n",
                 rgba[0],rgba[1],rgba[2],rgba[3]);
        break;
    default:
        DBG_FLAG(ch, "D3DTSS_? = 0x%08x\n", value);
        break;
    }
}
Beispiel #3
0
void *
NineVertexShader9_GetVariant( struct NineVertexShader9 *This )
{
    void *cso;
    uint64_t key;

    key = This->next_key;
    if (key == This->last_key)
        return This->last_cso;

    cso = nine_shader_variant_get(&This->variant, key);
    if (!cso) {
        struct NineDevice9 *device = This->base.device;
        struct nine_shader_info info;
        HRESULT hr;

        info.type = PIPE_SHADER_VERTEX;
        info.const_i_base = NINE_CONST_I_BASE(device->max_vs_const_f) / 16;
        info.const_b_base = NINE_CONST_B_BASE(device->max_vs_const_f) / 16;
        info.byte_code = This->byte_code.tokens;
        info.sampler_mask_shadow = key & 0xf;
        info.fog_enable = device->state.rs[D3DRS_FOGENABLE];
        info.point_size_min = asfloat(device->state.rs[D3DRS_POINTSIZE_MIN]);
        info.point_size_max = asfloat(device->state.rs[D3DRS_POINTSIZE_MAX]);
        info.swvp_on = device->swvp;
        info.process_vertices = false;

        hr = nine_translate_shader(This->base.device, &info);
        if (FAILED(hr))
            return NULL;
        nine_shader_variant_add(&This->variant, key, info.cso);
        cso = info.cso;
    }

    This->last_key = key;
    This->last_cso = cso;

    return cso;
}
Beispiel #4
0
void
nine_convert_sampler_state(struct cso_context *ctx, int idx, const DWORD *ss)
{
    struct pipe_sampler_state samp;

    assert(idx >= 0 &&
           (idx < NINE_MAX_SAMPLERS_PS || idx >= NINE_SAMPLER_VS(0)) &&
           (idx < NINE_MAX_SAMPLERS));

    memset(&samp, 0, sizeof(samp)); /* memcmp safety */

    if (ss[D3DSAMP_MIPFILTER] != D3DTEXF_NONE) {
        samp.lod_bias = asfloat(ss[D3DSAMP_MIPMAPLODBIAS]);
        samp.min_lod = ss[NINED3DSAMP_MINLOD];
        samp.min_mip_filter = (ss[D3DSAMP_MIPFILTER] == D3DTEXF_POINT) ? PIPE_TEX_FILTER_NEAREST : PIPE_TEX_FILTER_LINEAR;
    } else {
        samp.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
    }
    samp.max_lod = 15.0f;
    samp.wrap_s = d3dtextureaddress_to_pipe_tex_wrap(ss[D3DSAMP_ADDRESSU]);
    samp.wrap_t = d3dtextureaddress_to_pipe_tex_wrap(ss[D3DSAMP_ADDRESSV]);
    samp.wrap_r = d3dtextureaddress_to_pipe_tex_wrap(ss[D3DSAMP_ADDRESSW]);
    samp.min_img_filter = ss[D3DSAMP_MINFILTER] == D3DTEXF_POINT ? PIPE_TEX_FILTER_NEAREST : PIPE_TEX_FILTER_LINEAR;
    samp.mag_img_filter = ss[D3DSAMP_MAGFILTER] == D3DTEXF_POINT ? PIPE_TEX_FILTER_NEAREST : PIPE_TEX_FILTER_LINEAR;
    if (ss[D3DSAMP_MINFILTER] == D3DTEXF_ANISOTROPIC ||
        ss[D3DSAMP_MAGFILTER] == D3DTEXF_ANISOTROPIC)
        samp.max_anisotropy = ss[D3DSAMP_MAXANISOTROPY];
    samp.compare_mode = ss[NINED3DSAMP_SHADOW] ? PIPE_TEX_COMPARE_R_TO_TEXTURE : PIPE_TEX_COMPARE_NONE;
    samp.compare_func = PIPE_FUNC_LEQUAL;
    samp.normalized_coords = 1;
    samp.seamless_cube_map = 1;
    d3dcolor_to_pipe_color_union(&samp.border_color, ss[D3DSAMP_BORDERCOLOR]);

    /* see nine_state.h */
    if (idx < NINE_MAX_SAMPLERS_PS)
        cso_single_sampler(ctx, PIPE_SHADER_FRAGMENT, idx - NINE_SAMPLER_PS(0), &samp);
    else
        cso_single_sampler(ctx, PIPE_SHADER_VERTEX, idx - NINE_SAMPLER_VS(0), &samp);
}
Beispiel #5
0
static void SDIFlistpoke_listpoke(SDIFlistpoke *x, t_symbol *dummy, short argc, t_atom *argv) {
	int i;
	SDIFmem_Frame f;
	SDIFmem_Matrix m;
	float *mdata;
	char myFrameType[4];
	char myMatrixType[4];
	SDIFresult r;


	// post("* SDIFlistpoke_listpoke: x %p, argc %ld, argv %p", x, argc, argv);
	
 	
	/* Check that arguments are all numbers */
	for (i = 0; i < argc; ++i) {
		if (argv[i].a_type != A_FLOAT && argv[i].a_type != A_LONG) {
			object_post((t_object *)x, "¥ SDIF-listpoke: only numbers allowed in list.");
			return;
		}
	}
	
	/* Check that the number of arguments is a multiple of x->t_num_columns */
	if (argc % x->t_num_columns != 0) {
		post("¥ SDIF-listpoke: %d element list doesn't go into %ld columns.  Ignoring.",
			 argc, x->t_num_columns);
		return;
	}

	/* Get the frame */
	LookupMyBuffer(x);
	
	if (x->t_buffer == 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: no buffer!");
		return;
	}

  //  decide the frame type
  if(f = SDIFbuf_GetFirstFrame(x->t_buf))
    SDIF_Copy4Bytes(myFrameType, f->header.frameType);
  else
    //  we are about to create first frame in the buffer
    //  (give it the same type as the matrix we are adding)
    SDIF_Copy4Bytes(myFrameType, x->t_matrixType);
  
  //  decide the matrix type
	if (x->t_mainMatrix) {
		SDIF_Copy4Bytes(myMatrixType, myFrameType);
	} else {
		SDIF_Copy4Bytes(myMatrixType, x->t_matrixType);
	}

	/* post("** myMatrixType: %c%c%c%c", myMatrixType[0], myMatrixType[1],
		 myMatrixType[2], myMatrixType[3]); */
	
	f = (*(x->t_buffer->FrameLookup))(x->t_buffer, x->t_time, 0);
	
	if (f == 0) {
		/* There was no frame at the given time */
		// post("** There was no frame at that time");
		f = SDIFmem_CreateEmptyFrame();
		
		if (f == 0) {
			object_post((t_object *)x, "¥ SDIF-listpoke: out of memory for new frame in SDIF-buffer!");
			return;
		}
		
		SDIF_Copy4Bytes(f->header.frameType, myFrameType);
		f->header.time = x->t_time;
		f->header.streamID = x->t_buffer->streamID;
		
		i = (*(x->t_buffer->FrameInsert))(f, x->t_buffer);
		if (i) {
			object_post((t_object *)x, "¥ SDIF-listpoke: FrameInsert returned %d", i);
		}

				
	} else {
		/* There was already a frame at the given time */

		for (m = f->matrices; m != 0; m = m->next) {
			if (SDIF_Char4Eq(myMatrixType, m->header.matrixType)) {
				post("SDIF-listpoke: deleting old matrix %c%c%c%c at time %f",
					 m->header.matrixType[0], m->header.matrixType[1], 
					 m->header.matrixType[2], m->header.matrixType[3], x->t_time);
				r = SDIFmem_RemoveMatrix(f, m);
				if (r != ESDIF_SUCCESS) {
					object_post((t_object *)x, "¥ SDIF-listpoke: Problem removing matrix: %s", SDIF_GetErrorString(r));
				}
			}
		}
	}

	/* Now we know f is a frame in x->t_buffer, at the right time, with no matrix of 
	   the type we want to write into, and that we have to call SDIFmem_RepairFrameHeader(f) */

	m = SDIFmem_CreateEmptyMatrix();

	if (m == 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: out of memory for new matrix in SDIF-buffer!");
		SDIFmem_FreeFrame(f);
		return;
	}
	
	SDIF_Copy4Bytes(m->header.matrixType, myMatrixType);
	m->header.matrixDataType = SDIF_FLOAT32;
	
	m->header.columnCount = x->t_num_columns;
	m->header.rowCount = argc / x->t_num_columns;  // We checked above that it divides evenly

	// post("** about to getbytes() for the matrix data");

	m->data = getbytes(argc * sizeof(float));
	if (m->data == 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: out of memory for matrix data in SDIF-buffer!");
		SDIFmem_RemoveMatrix(f, m);
		SDIFmem_FreeMatrix(m);
		SDIFmem_RepairFrameHeader(f);	
		return;
	}

	mdata = m->data;
	for (i = 0; i < argc; ++i) {
		mdata[i] = asfloat(argv[i]);
	}	

	/*
	{
		SDIFmem_Matrix p;
		for (p = f->matrices; p != NULL; p = p->next) {
			post("Matrix: %p, type %c%c%c%c", p, 
				 p->header.matrixType[0], p->header.matrixType[1], p->header.matrixType[2],
				 p->header.matrixType[3]);
		}
	}
	*/
	
	
	// post("** about to SDIFmem_AddMatrix");
	SDIFmem_AddMatrix(f, m);

	// post("** about to SDIFmem_RepairFrameHeader");
	SDIFmem_RepairFrameHeader(f);	
}
Beispiel #6
0
static void SDIFlistpoke_newmatrix(SDIFlistpoke *x, t_symbol *s, short argc, t_atom *argv) {
	sdif_float64 time, oldtime;
	int numrows, numcols, oldnumcols, oldmainmatrix;
	char oldmatrixtype[4];
	char *type;
	
	if (argc < 5) {
		badargs:
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix args: frametime, matrixtype, #rows, #cols, data...");
		return;
	}
	
	if (argv[0].a_type == A_SYM) {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: frame time must be a number");
		return;
	}
	time = asfloat(argv[0]);


	if (argv[1].a_type != A_SYM ) {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: matrix type must be a symbol");
		return;
	}
	
	type = argv[1].a_w.w_sym->s_name;
	if (type[0] == '\0' || type[1] == '\0' || type[2] == '\0' || type[3] == '\0' || type[4] != '\0') {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: illegal type \"%s\" is not 4 characters.", type);
		return;
	}

	
	if (argv[2].a_type != A_LONG) {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: #rows must be an int.");
		return;
	}
	numrows = argv[2].a_w.w_long;

	if (numrows <= 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: #rows must be >= 1");
		return;
	}

	if (argv[3].a_type != A_LONG) {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: #columns must be an int.");
		return;
	}
	numcols = argv[3].a_w.w_long;
	
	if (numcols <= 0) {
		object_post((t_object *)x, "¥ SDIF-listpoke: newmatrix: #columns must be >= 1");
		return;
	}

	
	if (numrows*numcols != argc-4) {
		post("¥ SDIF-listpoke: newmatrix: %ld rows times %ld columns is %ld,", 
			  numrows, numcols, numrows*numcols);
		object_post((t_object *)x, "   but there are %ld elements of matrix data.  Dropping.", argc-4);
		return;
	}
	
	
	/* Store old instance variables  */
	oldtime = x->t_time;
	oldnumcols = x->t_num_columns;
	oldmainmatrix = x->t_mainMatrix;
	SDIF_Copy4Bytes(oldmatrixtype, x->t_matrixType);
	
	
	/*temporarily overwrite them */
	x->t_time = time;
	x->t_num_columns = numcols;
	x->t_mainMatrix = 0;
	SDIF_Copy4Bytes(x->t_matrixType, type);
	
	/* Store the new matrix via listpoke */
	SDIFlistpoke_listpoke(x, s, argc-4, argv+4);
	
	/* Restore instance variables */
	x->t_time = oldtime;
	x->t_num_columns = oldnumcols;
	x->t_mainMatrix = oldmainmatrix;
	SDIF_Copy4Bytes(x->t_matrixType, oldmatrixtype);
}