Module: NvTriStrip

Defined in:
ext/RbTriStrip.cpp,
ext/RbTriStrip.cpp

Overview

NvTriStrip module.

Defined Under Namespace

Classes: PrimitiveGroup

Constant Summary collapse

PT_LIST =

Constant for list type indices

INT2NUM(PT_LIST)
PT_STRIP =

Constant for strip type indices

INT2NUM(PT_STRIP)
PT_FAN =

Constant for fan type indices

INT2NUM(PT_FAN)
CACHESIZE_GEFORCE1_2 =

Size of Geforce 1 and 2 families cachesize, value is 16

INT2NUM(CACHESIZE_GEFORCE1_2)
CACHESIZE_GEFORCE3 =

Size of Geforce 3 family cachesize, value is 24

INT2NUM(CACHESIZE_GEFORCE3)

Class Method Summary collapse

Class Method Details

.disable_restartObject

For GPUs that support primitive restart, this disables using primitive restart



253
254
255
256
# File 'ext/RbTriStrip.cpp', line 253

VALUE rbtristripper_disable_restart(VALUE self) {
	DisableRestart();
	return Qnil;
}

.valObject

For GPUs that support primitive restart, this sets a value as the restart index. (For OpenGL, the extension would be GL_NV_primitive_restart)

Restart is meaningless if strips are not being stitched together, so enabling restart makes NvTriStrip forcing stitching. So, you’ll get back one strip.

Default value is disabled.



268
269
270
271
# File 'ext/RbTriStrip.cpp', line 268

VALUE rbtristripper_enable_restart(VALUE self, VALUE val) {
	EnableRestart(NUM2INT(val));
	return Qnil;
}

.indicesObject

This function generates stripified indices for given list of triangle indices. The index list should be an array (or anything that responds to #length and #[]) of separate triangles, three indices per triangle.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'ext/RbTriStrip.cpp', line 123

VALUE rbtristripper_generate_strips(VALUE self, VALUE indices, VALUE validateEnabled) {

	ID sGet=rb_intern("[]");
	ID sSize=rb_intern("length");

	unsigned int size=NUM2INT(rb_funcall(indices,sSize,0));
	unsigned short ind[size];
		
	for(int i=0;i<size;i++) {
		int v=NUM2INT( rb_funcall(indices, sGet, 1, INT2NUM(i)) );
		if(v<0 || v>65535) {
			rb_raise(rb_eArgError, "Value of out range (0..65535)");
		}
		ind[i]=v;
	}
	unsigned short groups;
	PrimitiveGroup *p;
	GenerateStrips(ind, size, &p, &groups, validateEnabled==Qtrue);
	
	VALUE ary=rb_ary_new2(groups);
	for(int i=0;i<groups;i++) {
		VALUE v=copy_pg(&p[i]);
		rb_ary_push(ary, v);
	}
	
	delete[] p;

	return ary;
}

.remap_indices(prims, maxVerts) ⇒ Object

remap_indices primitivegroup_ary, max_verts -> remapped_primitivegroup_ary

Remaps indices to improve spatial locality in your vertex buffer With the indices handed back, you need to reorder your vertex buffer.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'ext/RbTriStrip.cpp', line 161

VALUE rbtristripper_remap_indices(VALUE self, VALUE prims, VALUE maxVerts) {


	ID sGet=rb_intern("[]");
	ID sSize=rb_intern("length");

	unsigned short size=NUM2INT(rb_funcall(prims,sSize,0));

	PrimitiveGroup groups[size];
	for(int i=0;i<size;i++) {
		
		PrimitiveGroupWrap *pgw;
		Data_Get_Struct(rb_funcall(prims, sGet, 1, INT2NUM(i)), PrimitiveGroupWrap, pgw);
		groups[i]=*(pgw->pg); // Copies the object for our own array
	}


	PrimitiveGroup *remappedGroups=new PrimitiveGroup[size];

	RemapIndices(groups, size, NUM2INT(maxVerts), &remappedGroups);

	VALUE remapped=rb_ary_new2(size);


	for(int i=0;i<size;i++) {
		// Copy resulting array to ruby array
		VALUE v=copy_pg(&remappedGroups[i]);
		rb_ary_push(remapped, v);

		// Remove reference to index array, because we don't own it,
		// and would be removed when leaving this function
		groups[i].indices=NULL;
	}

	delete[] remappedGroups;
	return remapped;
}

.valObject

Sets the cache size which the stripfier uses to optimize the data. Controls the length of the generated individual strips. This is the “actual” cache size, so 24 for GeForce3 and 16 for GeForce1/2 You may want to play around with this number to tweak performance.

Default is 16.



243
244
245
246
# File 'ext/RbTriStrip.cpp', line 243

VALUE rbtristripper_set_cache_size(VALUE self, VALUE val) {
	SetCacheSize(NUM2INT(val));
	return Qnil;
}

.booleanObject

If set to true, will return an optimized list, with no strips at all. Default is false.



206
207
208
209
# File 'ext/RbTriStrip.cpp', line 206

VALUE rbtristripper_set_lists_only(VALUE self, VALUE val) {
	SetListsOnly(val==Qtrue?true:false);
	return Qnil;
}

.valObject

Sets the minimum acceptable size for a strip, in triangles. All strips generated which are shorter than this will be thrown into one big, separate list.



216
217
218
219
# File 'ext/RbTriStrip.cpp', line 216

VALUE rbtristripper_set_min_strip_size(VALUE self, VALUE val) {
	SetMinStripSize( NUM2INT(val) );
	return Qnil;
}

.booleanObject

Boolean to indicate whether to stitch together strips into one huge strip or not. If set to true, you’ll get back one huge strip stitched together using degenerate triangles. If set to false, you’ll get back a large number of separate strips.

Default is true.



229
230
231
232
# File 'ext/RbTriStrip.cpp', line 229

VALUE rbtristripper_set_stitch_strips(VALUE self, VALUE val) {
	SetStitchStrips(val==Qtrue?true:false);
	return Qnil;
}