rsMesh.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (C) 2011 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_RS_MESH_H
  17. #define ANDROID_RS_MESH_H
  18. #include "rsObjectBase.h"
  19. // ---------------------------------------------------------------------------
  20. namespace android {
  21. namespace renderscript {
  22. /*****************************************************************************
  23. * CAUTION
  24. *
  25. * Any layout changes for this class may require a corresponding change to be
  26. * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
  27. * a partial copy of the information below.
  28. *
  29. *****************************************************************************/
  30. // An element is a group of Components that occupies one cell in a structure.
  31. class Mesh : public ObjectBase {
  32. public:
  33. struct Hal {
  34. mutable void *drv;
  35. struct State {
  36. // Contains vertex data
  37. // Position, normal, texcoord, etc could either be strided in one allocation
  38. // of provided separetely in multiple ones
  39. Allocation **vertexBuffers;
  40. uint32_t vertexBuffersCount;
  41. // indexBuffers[i] could be nullptr, in which case only primitives[i] is used
  42. Allocation **indexBuffers;
  43. uint32_t indexBuffersCount;
  44. RsPrimitive *primitives;
  45. uint32_t primitivesCount;
  46. };
  47. State state;
  48. };
  49. Hal mHal;
  50. explicit Mesh(Context *);
  51. Mesh(Context *, uint32_t vertexBuffersCount, uint32_t primitivesCount);
  52. ~Mesh();
  53. virtual void serialize(Context *rsc, OStream *stream) const;
  54. virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_MESH; }
  55. static Mesh *createFromStream(Context *rsc, IStream *stream);
  56. void init();
  57. void setVertexBuffer(Allocation *vb, uint32_t index) {
  58. mVertexBuffers[index].set(vb);
  59. mHal.state.vertexBuffers[index] = vb;
  60. }
  61. void setPrimitive(Allocation *idx, RsPrimitive prim, uint32_t index) {
  62. mIndexBuffers[index].set(idx);
  63. mHal.state.indexBuffers[index] = idx;
  64. mHal.state.primitives[index] = prim;
  65. }
  66. void render(Context *) const;
  67. void renderPrimitive(Context *, uint32_t primIndex) const;
  68. void renderPrimitiveRange(Context *, uint32_t primIndex, uint32_t start, uint32_t len) const;
  69. void uploadAll(Context *);
  70. // Bounding volumes
  71. float mBBoxMin[3];
  72. float mBBoxMax[3];
  73. void computeBBox(Context *rsc);
  74. protected:
  75. ObjectBaseRef<Allocation> *mVertexBuffers;
  76. ObjectBaseRef<Allocation> *mIndexBuffers;
  77. bool mInitialized;
  78. };
  79. class MeshContext {
  80. public:
  81. MeshContext() {
  82. }
  83. ~MeshContext() {
  84. }
  85. };
  86. } // namespace renderscript
  87. } // namespace android
  88. #endif //ANDROID_RS_MESH_H