Sampler.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2008-2012 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. #include "RenderScript.h"
  17. #include "rsCppInternal.h"
  18. using android::RSC::Sampler;
  19. using android::RSC::sp;
  20. Sampler::Sampler(sp<RS> rs, void* id):
  21. BaseObj(id, rs)
  22. {
  23. RsSamplerValue mMin = RS_SAMPLER_INVALID;
  24. RsSamplerValue mMag = RS_SAMPLER_INVALID;
  25. RsSamplerValue mWrapS = RS_SAMPLER_INVALID;
  26. RsSamplerValue mWrapT = RS_SAMPLER_INVALID;
  27. float mAniso = 0.f;
  28. }
  29. Sampler::Sampler(sp<RS> rs, void* id, RsSamplerValue min, RsSamplerValue mag,
  30. RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy):
  31. BaseObj(id, rs)
  32. {
  33. RsSamplerValue mMin = min;
  34. RsSamplerValue mMag = mag;
  35. RsSamplerValue mWrapS = wrapS;
  36. RsSamplerValue mWrapT = wrapT;
  37. float mAniso = anisotropy;
  38. }
  39. RsSamplerValue Sampler::getMinification() {
  40. return mMin;
  41. }
  42. RsSamplerValue Sampler::getMagnification() {
  43. return mMag;
  44. }
  45. RsSamplerValue Sampler::getWrapS() {
  46. return mWrapS;
  47. }
  48. RsSamplerValue Sampler::getWrapT() {
  49. return mWrapT;
  50. }
  51. float Sampler::getAnisotropy() {
  52. return mAniso;
  53. }
  54. sp<Sampler> Sampler::create(const sp<RS>& rs, RsSamplerValue min, RsSamplerValue mag,
  55. RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy) {
  56. // We aren't supporting wrapR in C++ API atm, so always pass wrap for that.
  57. void* id = RS::dispatch->SamplerCreate(rs->getContext(), min, mag, wrapS, wrapT,
  58. RS_SAMPLER_WRAP, anisotropy);
  59. return new Sampler(rs, id, min, mag, wrapS, wrapT, anisotropy);
  60. }
  61. #define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(const sp<RS> &rs) { \
  62. if (rs->mSamplers.N == nullptr) { \
  63. rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)); \
  64. } \
  65. return rs->mSamplers.N; \
  66. }
  67. CREATE_SAMPLER(CLAMP_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP);
  68. CREATE_SAMPLER(CLAMP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP);
  69. CREATE_SAMPLER(CLAMP_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP);
  70. CREATE_SAMPLER(WRAP_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP);
  71. CREATE_SAMPLER(WRAP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP);
  72. CREATE_SAMPLER(WRAP_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP);
  73. CREATE_SAMPLER(MIRRORED_REPEAT_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT);
  74. CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT);
  75. CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT);