blob: 04d2cb71636ce4f7dccbcadd78aff14ff787ff2c [file] [log] [blame]
joshualitt8072caa2015-02-12 14:20:52 -08001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Robert Phillips787fd9d2021-03-22 14:48:09 -04008#include "src/gpu/GrGeometryProcessor.h"
joshualitt8072caa2015-02-12 14:20:52 -08009
Brian Salomon7eabfe82019-12-02 14:20:20 -050010#include "src/gpu/GrFragmentProcessor.h"
joshualitt8072caa2015-02-12 14:20:52 -080011
joshualitt8072caa2015-02-12 14:20:52 -080012
Robert Phillips787fd9d2021-03-22 14:48:09 -040013GrGeometryProcessor::GrGeometryProcessor(ClassID classID) : GrProcessor(classID) {}
Brian Salomone782f842018-07-31 13:53:11 -040014
Robert Phillips787fd9d2021-03-22 14:48:09 -040015const GrGeometryProcessor::TextureSampler& GrGeometryProcessor::textureSampler(int i) const {
Brian Salomone782f842018-07-31 13:53:11 -040016 SkASSERT(i >= 0 && i < this->numTextureSamplers());
17 return this->onTextureSampler(i);
18}
Brian Salomon92be2f72018-06-19 14:33:47 -040019
Robert Phillips787fd9d2021-03-22 14:48:09 -040020uint32_t GrGeometryProcessor::ComputeCoordTransformsKey(const GrFragmentProcessor& fp) {
Michael Ludwige7e25ac2020-06-26 12:53:03 -040021 // This is highly coupled with the code in GrGLSLGeometryProcessor::collectTransforms().
Brian Salomon66b500a2021-08-02 12:37:14 -040022 uint32_t key = static_cast<uint32_t>(fp.sampleUsage().kind()) << 1;
23 // This needs to be updated if GP starts specializing varyings on additional matrix types.
24 if (fp.sampleUsage().hasPerspective()) {
25 key |= 0b1;
joshualitt8072caa2015-02-12 14:20:52 -080026 }
Michael Ludwige88320b2020-06-24 09:04:56 -040027 return key;
joshualitt8072caa2015-02-12 14:20:52 -080028}
Brian Salomone782f842018-07-31 13:53:11 -040029
30///////////////////////////////////////////////////////////////////////////////////////////////////
31
Brian Salomon7eae3e02018-08-07 14:02:38 +000032static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
33 GrSamplerState::Filter requestedFilter) {
34 if (GrTextureTypeHasRestrictedSampling(type)) {
Brian Salomona3b02f52020-07-15 16:02:01 -040035 return std::min(requestedFilter, GrSamplerState::Filter::kLinear);
Brian Salomon7eae3e02018-08-07 14:02:38 +000036 }
37 return requestedFilter;
Brian Salomonaf874832018-08-03 11:53:40 -040038}
39
Robert Phillips787fd9d2021-03-22 14:48:09 -040040GrGeometryProcessor::TextureSampler::TextureSampler(GrSamplerState samplerState,
41 const GrBackendFormat& backendFormat,
42 const GrSwizzle& swizzle) {
Robert Phillips323471e2019-11-11 11:33:37 -050043 this->reset(samplerState, backendFormat, swizzle);
Brian Salomon7eae3e02018-08-07 14:02:38 +000044}
45
Robert Phillips787fd9d2021-03-22 14:48:09 -040046void GrGeometryProcessor::TextureSampler::reset(GrSamplerState samplerState,
47 const GrBackendFormat& backendFormat,
48 const GrSwizzle& swizzle) {
Brian Salomone782f842018-07-31 13:53:11 -040049 fSamplerState = samplerState;
Robert Phillipsf272bea2019-10-17 08:56:16 -040050 fSamplerState.setFilterMode(clamp_filter(backendFormat.textureType(), samplerState.filter()));
51 fBackendFormat = backendFormat;
Greg Daniel2c3398d2019-06-19 11:58:01 -040052 fSwizzle = swizzle;
Brian Salomon67529b22019-08-13 15:31:04 -040053 fIsInitialized = true;
Brian Salomone782f842018-07-31 13:53:11 -040054}