rsProgramVertex.cpp revision a572aca4eb4ddb32c10baa1f529431cfefd756b8
1a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian/* 2a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Copyright (C) 2011 The Android Open Source Project 3a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 4a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * you may not use this file except in compliance with the License. 6a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * You may obtain a copy of the License at 7a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 8a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 10a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Unless required by applicable law or agreed to in writing, software 11a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * See the License for the specific language governing permissions and 14a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * limitations under the License. 15a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian */ 16a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 172965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian#include "rsContext.h" 182965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian#include "rsProgramVertex.h" 195880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall#include "rsMatrix4x4.h" 2030bcc61431d8e3bef779472dd52a7b156dcaba09Mathias Agopian 215880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hallusing namespace android; 22a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianusing namespace android::renderscript; 23f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian 24f1352df47fe20aed23c216a78923c7d248f2bb91Mathias Agopian 25f1352df47fe20aed23c216a78923c7d248f2bb91Mathias AgopianProgramVertex::ProgramVertex(Context *rsc, const char * shaderText, size_t shaderLength, 26a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian const char** textureNames, size_t textureNamesCount, const size_t *textureNamesLength, 27a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 28a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian const uint32_t * params, size_t paramLength) 29da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian : Program(rsc, shaderText, shaderLength, params, paramLength) { 308372785879d329f592f6883620b5a32d80d74691Mathias Agopian mRSC->mHal.funcs.vertex.init(mRSC, this, mUserShader.string(), mUserShader.length(), 313eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian textureNames, textureNamesCount, textureNamesLength); 322965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian} 3322da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian 34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias AgopianProgramVertex::~ProgramVertex() { 35921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian mRSC->mHal.funcs.vertex.destroy(mRSC, this); 36921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian} 37a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 383eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopianvoid ProgramVertex::setup(Context *rsc, ProgramVertexState *state) { 39a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian if ((state->mLast.get() == this) && !mDirty) { 40a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian return; 41e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 42a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 43921e6ac4b7610a178285898d191eb0e3afe906c0Mathias Agopian if (!isUserProgram()) { 4422da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian if (mHal.state.constants[0] == NULL) { 45a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian rsc->setError(RS_ERROR_FATAL_UNKNOWN, 46c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian "Unable to set fixed function emulation matrices because allocation is missing"); 47da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian return; 48a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian } 49a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( 505880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall rsc, mHal.state.constants[0])); 519eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall Matrix4x4 mvp; 529eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall mvp.load(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]); 539eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall Matrix4x4 t; 549eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall t.load(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET]); 559eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall mvp.multiply(&t); 569eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall for (uint32_t i = 0; i < 16; i ++) { 579eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall f[RS_PROGRAM_VERTEX_MVP_OFFSET + i] = mvp.m[i]; 589eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 599eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); 609eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 619eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 629eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall state->mLast.set(this); 639eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 649eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall rsc->mHal.funcs.vertex.setActive(rsc, this); 659eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall} 669eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall 679eb1eb5bb55740982ceae9966fc536824edc302aJesse Hallvoid ProgramVertex::setProjectionMatrix(Context *rsc, const rsc_Matrix *m) const { 689eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (isUserProgram()) { 699eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall rsc->setError(RS_ERROR_FATAL_UNKNOWN, 709eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall "Attempting to set fixed function emulation matrix projection on user program"); 719eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall return; 729eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall } 739eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall if (mHal.state.constants[0] == NULL) { 749eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall rsc->setError(RS_ERROR_FATAL_UNKNOWN, 759eb1eb5bb55740982ceae9966fc536824edc302aJesse Hall "Unable to set fixed function emulation matrix projection because allocation is missing"); 76bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall return; 77bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall } 78a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( 79a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian rsc, mHal.state.constants[0])); 803e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m, sizeof(rsc_Matrix)); 813e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian mDirty = true; 823e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); 833e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian} 843e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian 853e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopianvoid ProgramVertex::setModelviewMatrix(Context *rsc, const rsc_Matrix *m) const { 863e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (isUserProgram()) { 873e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian rsc->setError(RS_ERROR_FATAL_UNKNOWN, 883e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian "Attempting to set fixed function emulation matrix modelview on user program"); 893e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian return; 903e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian } 913e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian if (mHal.state.constants[0] == NULL) { 923e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian rsc->setError(RS_ERROR_FATAL_UNKNOWN, 933eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian "Unable to set fixed function emulation matrix modelview because allocation is missing"); 943eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian return; 95b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 96c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( 97b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden rsc, mHal.state.constants[0])); 983e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian memcpy(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], m, sizeof(rsc_Matrix)); 99e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian mDirty = true; 100e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); 101a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 102e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian 103e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopianvoid ProgramVertex::setTextureMatrix(Context *rsc, const rsc_Matrix *m) const { 104e60b0687c8d49871d0c8786cabe6851f7a7783b5Mathias Agopian if (isUserProgram()) { 105b685c542836b93c99cd85053e07696406ea37adbJesse Hall rsc->setError(RS_ERROR_FATAL_UNKNOWN, 106e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian "Attempting to set fixed function emulation matrix texture on user program"); 107e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian return; 108e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian } 109e2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8Mathias Agopian if (mHal.state.constants[0] == NULL) { 110028508cad5ef63ef9fbd42c14e76658e4fd9ebf2Mathias Agopian rsc->setError(RS_ERROR_FATAL_UNKNOWN, 1115880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall "Unable to set fixed function emulation matrix texture because allocation is missing"); 112b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 113b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 114b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D( 115bbd164a3c790a0649dffd2f015e6f47692c72e1cJesse Hall rsc, mHal.state.constants[0])); 116da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian memcpy(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET], m, sizeof(rsc_Matrix)); 117da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian mDirty = true; 118da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); 119da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian} 120da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian 121da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopianvoid ProgramVertex::getProjectionMatrix(Context *rsc, rsc_Matrix *m) const { 122da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian if (isUserProgram()) { 123da27af9832a0170f1fc40ef3f21371c4d30d21b3Mathias Agopian rsc->setError(RS_ERROR_FATAL_UNKNOWN, 124babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden "Attempting to get fixed function emulation matrix projection on user program"); 125babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden return; 126babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden } 12743601a2dc320a271ff8c3765ff61414a07221635Andy McFadden if (mHal.state.constants[0] == NULL) { 12843601a2dc320a271ff8c3765ff61414a07221635Andy McFadden rsc->setError(RS_ERROR_FATAL_UNKNOWN, 12943601a2dc320a271ff8c3765ff61414a07221635Andy McFadden "Unable to get fixed function emulation matrix projection because allocation is missing"); 13043601a2dc320a271ff8c3765ff61414a07221635Andy McFadden return; 131b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 132b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden float *f = static_cast<float *>( 133b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden rsc->mHal.funcs.allocation.lock1D(rsc, mHal.state.constants[0])); 134b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden memcpy(m, &f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], sizeof(rsc_Matrix)); 135b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); 136b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 137b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 138b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenvoid ProgramVertex::transformToScreen(Context *rsc, float *v4out, const float *v3in) const { 139b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden if (isUserProgram()) { 140b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return; 141b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden } 142b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden float *f = static_cast<float *>( 143b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden rsc->mHal.funcs.allocation.lock1D(rsc, mHal.state.constants[0])); 144b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden Matrix4x4 mvp; 145b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mvp.loadMultiply((Matrix4x4 *)&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], 146b685c542836b93c99cd85053e07696406ea37adbJesse Hall (Matrix4x4 *)&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET]); 147b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mvp.vectorMultiply(v4out, v3in); 148b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden rsc->mHal.funcs.allocation.unlock1D(rsc, mHal.state.constants[0]); 149b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 150b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 1518f971ff6661c875e7adb3f14731e1579c3c80c62Jesse Hallvoid ProgramVertex::serialize(Context *rsc, OStream *stream) const { 152b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 153b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 154b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenProgramVertex *ProgramVertex::createFromStream(Context *rsc, IStream *stream) { 155b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return NULL; 156b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 157b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 158b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 159b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden/////////////////////////////////////////////////////////////////////// 160b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 161b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenProgramVertexState::ProgramVertexState() { 162b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 163b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 164b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenProgramVertexState::~ProgramVertexState() { 165b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 166b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 167c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianvoid ProgramVertexState::init(Context *rsc) { 1683a77871383bc1a03cc866686d81628493d14de7cMathias Agopian ObjectBaseRef<const Element> matrixElem = Element::createRef(rsc, RS_TYPE_MATRIX_4X4, 1693a77871383bc1a03cc866686d81628493d14de7cMathias Agopian RS_KIND_USER, false, 1); 170b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ObjectBaseRef<const Element> f2Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, 1711bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall RS_KIND_USER, false, 2); 1721bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ObjectBaseRef<const Element> f3Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, 1731bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall RS_KIND_USER, false, 3); 174f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian ObjectBaseRef<const Element> f4Elem = Element::createRef(rsc, RS_TYPE_FLOAT_32, 175db27621e22559a1b16414f890677ef04242fbc3bJesse Hall RS_KIND_USER, false, 4); 176db27621e22559a1b16414f890677ef04242fbc3bJesse Hall 177b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden Element::Builder constBuilder; 178b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden constBuilder.add(matrixElem.get(), "MV", 1); 179b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden constBuilder.add(matrixElem.get(), "P", 1); 180f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian constBuilder.add(matrixElem.get(), "TexMatrix", 1); 181b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden constBuilder.add(matrixElem.get(), "MVP", 1); 182f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian ObjectBaseRef<const Element> constInput = constBuilder.create(rsc); 183f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian 184f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian Element::Builder inputBuilder; 185f435863467ab407f2a482604beed5fa6f0144c62Mathias Agopian inputBuilder.add(f4Elem.get(), "position", 1); 1861bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall inputBuilder.add(f4Elem.get(), "color", 1); 1871bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall inputBuilder.add(f3Elem.get(), "normal", 1); 188888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian inputBuilder.add(f2Elem.get(), "texture0", 1); 1891bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall ObjectBaseRef<const Element> attrElem = inputBuilder.create(rsc); 1901bd20e0f9ecd27cc5ad2bdf08b01837ecc10c357Jesse Hall 191888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian ObjectBaseRef<Type> inputType = Type::getTypeRef(rsc, constInput.get(), 1, 0, 0, false, false, 0); 192888c822c4cb6976aab9256c58bae9e17e3e55c5cMathias Agopian 1933a77871383bc1a03cc866686d81628493d14de7cMathias Agopian String8 shaderString(RS_SHADER_INTERNAL); 1943a77871383bc1a03cc866686d81628493d14de7cMathias Agopian shaderString.append("varying vec4 varColor;\n"); 1953a77871383bc1a03cc866686d81628493d14de7cMathias Agopian shaderString.append("varying vec2 varTex0;\n"); 196a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian shaderString.append("void main() {\n"); 197a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian shaderString.append(" gl_Position = UNI_MVP * ATTRIB_position;\n"); 198a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian shaderString.append(" gl_PointSize = 1.0;\n"); 199a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian shaderString.append(" varColor = ATTRIB_color;\n"); 200babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden shaderString.append(" varTex0 = ATTRIB_texture0;\n"); 201ae2cfb5746e87f1bf17c446e20274c41ce0a57ceAndy McFadden shaderString.append("}\n"); 202babba1868773eba5edf8a8e335b8e109a32292e0Andy McFadden 2033eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian uint32_t tmp[4]; 2043eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian tmp[0] = RS_PROGRAM_PARAM_CONSTANT; 2053eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian tmp[1] = (uint32_t)inputType.get(); 206a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian tmp[2] = RS_PROGRAM_PARAM_INPUT; 2075880cc573823148237eac9ab7bc586b8e4eb7160Jesse Hall tmp[3] = (uint32_t)attrElem.get(); 208a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 209b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ProgramVertex *pv = new ProgramVertex(rsc, shaderString.string(), shaderString.length(), 210b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden NULL, 0, NULL, tmp, 4); 211b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden Allocation *alloc = Allocation::createAllocation(rsc, inputType.get(), 2123e8b853d67c737abdb363f9c978e7d83eac4d888Mathias Agopian RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS); 213a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian pv->bindAllocation(rsc, alloc, 0); 214a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 215b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mDefaultAlloc.set(alloc); 216b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mDefault.set(pv); 217b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 218b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden updateSize(rsc); 219b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 220b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 221b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenvoid ProgramVertexState::updateSize(Context *rsc) { 222b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden float *f = static_cast<float *>(rsc->mHal.funcs.allocation.lock1D(rsc, mDefaultAlloc.get())); 223b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 224b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden float surfaceWidth = (float)rsc->getCurrentSurfaceWidth(); 225b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden float surfaceHeight = (float)rsc->getCurrentSurfaceHeight(); 226b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 227b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden Matrix4x4 m; 228b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden m.loadOrtho(0, surfaceWidth, surfaceHeight, 0, -1, 1); 229b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden memcpy(&f[RS_PROGRAM_VERTEX_PROJECTION_OFFSET], m.m, sizeof(m)); 230b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden memcpy(&f[RS_PROGRAM_VERTEX_MVP_OFFSET], m.m, sizeof(m)); 231b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 232b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden m.loadIdentity(); 233b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden memcpy(&f[RS_PROGRAM_VERTEX_MODELVIEW_OFFSET], m.m, sizeof(m)); 234b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden memcpy(&f[RS_PROGRAM_VERTEX_TEXTURE_OFFSET], m.m, sizeof(m)); 235b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden rsc->mHal.funcs.allocation.unlock1D(rsc, mDefaultAlloc.get()); 236b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 237b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 238b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenvoid ProgramVertexState::deinit(Context *rsc) { 239b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mDefaultAlloc.clear(); 240b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mDefault.clear(); 241b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden mLast.clear(); 242b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 243b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 244b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 245b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddennamespace android { 246b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddennamespace renderscript { 247b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 248b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFaddenRsProgramVertex rsi_ProgramVertexCreate(Context *rsc, const char * shaderText, size_t shaderLength, 249b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden const char** textureNames, size_t textureNamesCount, 250b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden const size_t *textureNamesLength, 251b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden const uint32_t * params, size_t paramLength) { 252b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden ProgramVertex *pv = new ProgramVertex(rsc, shaderText, shaderLength, 253b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden textureNames, textureNamesCount, textureNamesLength, 254b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden params, paramLength); 255b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden pv->incUserRef(); 256b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden return pv; 257b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 258b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden 259b0d1dd36f104c0b581674adc7f830cbf44b7db06Andy McFadden} 260a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian} 261a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian