本文整理汇总了C++中GrPaint::textureSampler方法的典型用法代码示例。如果您正苦于以下问题:C++ GrPaint::textureSampler方法的具体用法?C++ GrPaint::textureSampler怎么用?C++ GrPaint::textureSampler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrPaint
的用法示例。
在下文中一共展示了GrPaint::textureSampler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkDevice* device = canvas->getDevice();
GrRenderTarget* target = (GrRenderTarget*) device->accessRenderTarget();
GrContext* ctx = GetGr();
if (ctx && target) {
SkPMColor gTextureData[(2 * S) * (2 * S)];
static const int stride = 2 * S;
static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
for (int i = 0; i < 2; ++i) {
int offset = 0;
// fill upper-left
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
// fill upper-right
offset = S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = white;
}
}
// fill lower left
offset = S * stride;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = black;
}
}
// fill lower right
offset = S * stride + S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
GrTextureDesc desc;
desc.fAALevel = kNone_GrAALevel;
// use RT flag bit because in GL it makes the texture be bottom-up
desc.fFlags = i ? kRenderTarget_GrTextureFlagBit :
kNone_GrTextureFlags;
desc.fConfig = kSkia8888_PM_GrPixelConfig;
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
GrTexture* texture =
ctx->createUncachedTexture(desc, gTextureData, 0);
if (!texture) {
return;
}
GrAutoUnref au(texture);
ctx->setClip(GrRect::MakeWH(2*S, 2*S));
ctx->setRenderTarget(target);
GrPaint paint;
paint.reset();
paint.fColor = 0xffffffff;
paint.fSrcBlendCoeff = kOne_BlendCoeff;
paint.fDstBlendCoeff = kISA_BlendCoeff;
GrMatrix vm;
if (i) {
vm.setRotate(90 * SK_Scalar1,
S * SK_Scalar1,
S * SK_Scalar1);
} else {
vm.reset();
}
ctx->setMatrix(vm);
GrMatrix tm;
tm = vm;
tm.postIDiv(2*S, 2*S);
paint.textureSampler(0)->setMatrix(tm);
paint.setTexture(0, texture);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
// now update the lower right of the texture in first pass
// or upper right in second pass
offset = 0;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] =
((x + y) % 2) ? (i ? green : red) : blue;
}
}
texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData,
4 * stride);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
}
}
}