示例#1
0
void GFont::renderCharVertexArray(RenderDevice* renderDevice, const Array<CPUCharVertex>& cpuCharArray, Array<int>& indexArray) const {

    // Avoid the overhead of Profiler events by not calling LAUNCH_SHADER...
    static const shared_ptr<Shader> fontShader = Shader::getShaderFromPattern("GFont_render.*");

    renderDevice->setBlendFunc(RenderDevice::BLEND_SRC_ALPHA, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA);
    renderDevice->setCullFace(CullFace::NONE);

    const shared_ptr<VertexBuffer>& vb = VertexBuffer::create((cpuCharArray.size() * sizeof(CPUCharVertex)) + (indexArray.size() * sizeof(int)) + 8, VertexBuffer::WRITE_EVERY_FRAME);

    IndexStream indexStream(indexArray, vb);
    AttributeArray interleavedArray(cpuCharArray.size() * sizeof(CPUCharVertex), vb);

    CPUCharVertex dummy;
#   define OFFSET(field) ((size_t)(&dummy.field) - (size_t)&dummy)
        AttributeArray  texCoordArray   (dummy.texCoord,    cpuCharArray.size(), interleavedArray, OFFSET(texCoord),    sizeof(CPUCharVertex));
        AttributeArray  positionArray   (dummy.position,    cpuCharArray.size(), interleavedArray, OFFSET(position),    sizeof(CPUCharVertex));
        AttributeArray  colorArray      (dummy.color,       cpuCharArray.size(), interleavedArray, OFFSET(color),       sizeof(CPUCharVertex));
        AttributeArray  borderColorArray(dummy.borderColor, cpuCharArray.size(), interleavedArray, OFFSET(borderColor), sizeof(CPUCharVertex));
#   undef OFFSET
    
    CPUCharVertex* dst = (CPUCharVertex*)interleavedArray.mapBuffer(GL_WRITE_ONLY);
    System::memcpy(dst, cpuCharArray.getCArray(), cpuCharArray.size() * sizeof(CPUCharVertex));
    interleavedArray.unmapBuffer();

    Args args;
    args.enableG3DArgs(false); // Lower CPU overhead for uniform bind

    args.setAttributeArray("g3d_Vertex",    positionArray);
    args.setAttributeArray("g3d_TexCoord0", texCoordArray);
    args.setAttributeArray("borderColor",   borderColorArray);    
    args.setAttributeArray("color",         colorArray);
    args.setIndexArray(indexStream);
    args.setPrimitiveType(PrimitiveType::TRIANGLES);

    args.setUniform("g3d_ObjectToScreenMatrixTranspose", RenderDevice::current->objectToScreenMatrix().transpose()); 
    args.setUniform("textureMatrix",        Matrix4(m_textureMatrix));
    args.setUniform("borderWidth",          Vector2(m_textureMatrix[0], m_textureMatrix[5]));
    args.setUniform("textureLODBias",       -0.6f);
    args.setUniform("fontTexture",          m_texture, Sampler::defaults());
    args.setUniform("alphaThreshold",       1.0f / 255.0f);
    args.setUniform("translation",          Vector2(0, 0));
    
    RenderDevice::current->apply(fontShader, args);
}
示例#2
0
UGenArray UGenArray::interleave() const throw()
{
	// need to check this
		
	if(internal->size() == 0) return UGenArray();
	
	int maxNumChannels = findMaxNumChannels();
	UGenArray interleavedArray(maxNumChannels);
	
	for(int channel = 0; channel < maxNumChannels; channel++)
	{
		UGen item;
		
		for(int arrayIndex = 0; arrayIndex < internal->size(); arrayIndex++)
		{
			item <<= wrapAt(arrayIndex).wrapAt(channel);
		}
		
		interleavedArray.put(channel, item);
	}
	
	return interleavedArray;
}