void Earth::configureShaderArgs(RenderDevice* rd) { rd->clear(); rd->pushState(); // rd->setRenderMode(RenderDevice::RENDER_WIREFRAME); Args args; args.enableG3DArgs(true); args.setUniform("wsLight", light->position().xyz().direction()); args.setUniform("lightColor", light->color); args.setUniform("wsEyePosition", defaultCamera->frame().translation); args.setAttributeArray("texCoord0", gpuTexCoords); args.setUniform("textureSampler", tex, Sampler::video()); args.setAttributeArray("vertex", gpuVerts); args.setAttributeArray("normal", gpuNorms); args.setIndexStream(gpuIndices); args.setPrimitiveType(PrimitiveType::TRIANGLES); //TODO: Set the attribute arrays and primitive types to draw the geometry // that you created in setupGeometry(). rd->apply(shader, args); rd->popState(); }
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); }