RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText, size_t shaderLength, const uint32_t * params, size_t paramLength) { ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, params, paramLength); pv->incUserRef(); return pv; }
RsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText, size_t shaderLength, const char** textureNames, size_t textureNamesCount, const size_t *textureNamesLength, const uintptr_t * params, size_t paramLength) { ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, textureNames, textureNamesCount, textureNamesLength, params, paramLength); pv->incUserRef(); return pv; }
void ProgramVertexState::init(Context *rsc) { ObjectBaseRef<const Element> matrixElem = Element::createRef(rsc, RS_TYPE_MATRIX_4X4, RS_KIND_USER, false, 1); ObjectBaseRef<const Element> f2Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 2); ObjectBaseRef<const Element> f3Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 3); ObjectBaseRef<const Element> f4Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 4); Element::Builder constBuilder; constBuilder.add(matrixElem.get(), "MV", 1); constBuilder.add(matrixElem.get(), "P", 1); constBuilder.add(matrixElem.get(), "TexMatrix", 1); constBuilder.add(matrixElem.get(), "MVP", 1); ObjectBaseRef<const Element> constInput = constBuilder.create(rsc); Element::Builder inputBuilder; inputBuilder.add(f4Elem.get(), "position", 1); inputBuilder.add(f4Elem.get(), "color", 1); inputBuilder.add(f3Elem.get(), "normal", 1); inputBuilder.add(f2Elem.get(), "texture0", 1); ObjectBaseRef<const Element> attrElem = inputBuilder.create(rsc); ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false); String8 shaderString(RS_SHADER_INTERNAL); shaderString.append("varying vec4 varColor;\n"); shaderString.append("varying vec2 varTex0;\n"); shaderString.append("void main() {\n"); shaderString.append(" gl_Position = UNI_MVP * ATTRIB_position;\n"); shaderString.append(" gl_PointSize = 1.0;\n"); shaderString.append(" varColor = ATTRIB_color;\n"); shaderString.append(" varTex0 = ATTRIB_texture0;\n"); shaderString.append("}\n"); uint32_t tmp[4]; tmp[0] = RS_PROGRAM_PARAM_CONSTANT; tmp[1] = (uint32_t)inputType.get(); tmp[2] = RS_PROGRAM_PARAM_INPUT; tmp[3] = (uint32_t)attrElem.get(); ProgramVertex *pv = new ProgramVertex(rsc, shaderString.string(), shaderString.length(), tmp, 4); Allocation *alloc = Allocation::createAllocation(rsc, inputType.get(), RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS); pv->bindAllocation(rsc, alloc, 0); mDefaultAlloc.set(alloc); mDefault.set(pv); updateSize(rsc); }
void ProgramVertexState::init(Context *rsc) { ObjectBaseRef<const Element> matrixElem = Element::createRef(rsc, RS_TYPE_MATRIX_4X4, RS_KIND_USER, false, 1); ObjectBaseRef<const Element> f2Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 2); ObjectBaseRef<const Element> f3Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 3); ObjectBaseRef<const Element> f4Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 4); const char *ebn1[] = { "MV", "P", "TexMatrix", "MVP" }; const Element *ebe1[] = {matrixElem.get(), matrixElem.get(), matrixElem.get(), matrixElem.get()}; ObjectBaseRef<const Element> constInput = Element::create(rsc, 4, ebe1, ebn1); const char *ebn2[] = { "position", "color", "normal", "texture0" }; const Element *ebe2[] = {f4Elem.get(), f4Elem.get(), f3Elem.get(), f2Elem.get()}; ObjectBaseRef<const Element> attrElem = Element::create(rsc, 4, ebe2, ebn2); ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false, 0); const char *shaderString = RS_SHADER_INTERNAL "varying vec4 varColor;\n" "varying vec2 varTex0;\n" "void main() {\n" " gl_Position = UNI_MVP * ATTRIB_position;\n" " gl_PointSize = 1.0;\n" " varColor = ATTRIB_color;\n" " varTex0 = ATTRIB_texture0;\n" "}\n"; uintptr_t tmp[4]; tmp[0] = RS_PROGRAM_PARAM_CONSTANT; tmp[1] = (uintptr_t)inputType.get(); tmp[2] = RS_PROGRAM_PARAM_INPUT; tmp[3] = (uintptr_t)attrElem.get(); ProgramVertex *pv = new ProgramVertex(rsc, shaderString, strlen(shaderString), NULL, 0, NULL, tmp, 4); Allocation *alloc = Allocation::createAllocation(rsc, inputType.get(), RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS); pv->bindAllocation(rsc, alloc, 0); mDefaultAlloc.set(alloc); mDefault.set(pv); updateSize(rsc); }