2019-08-24 15:07:28 +00:00
|
|
|
// enve - 2D animations software
|
2020-01-02 19:46:10 +00:00
|
|
|
// Copyright (C) 2016-2020 Maurycy Liebner
|
2019-08-24 15:07:28 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-07-15 17:06:24 +00:00
|
|
|
#include "dabtest.h"
|
|
|
|
|
2020-03-31 14:18:42 +00:00
|
|
|
void eCreateNewestVersion(qsptr<CustomRasterEffect> &result) {
|
2019-07-15 17:06:24 +00:00
|
|
|
// Use default, most up to date, version
|
2020-03-31 14:18:42 +00:00
|
|
|
result = enve::make_shared<DabTest000>();
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 14:18:42 +00:00
|
|
|
void eCreate(const CustomIdentifier &identifier,
|
|
|
|
qsptr<CustomRasterEffect>& result) {
|
2019-12-23 13:02:55 +00:00
|
|
|
Q_UNUSED(identifier)
|
2019-07-15 17:06:24 +00:00
|
|
|
// Choose version based on identifier
|
|
|
|
// if(identifier.fVersion == CustomIdentifier::Version{0, 0, 0})
|
2020-03-31 14:18:42 +00:00
|
|
|
result = enve::make_shared<DabTest000>();
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returned value must be unique, lets enve distinguish effects
|
|
|
|
QString effectId() {
|
|
|
|
return "3535afs7535gst";
|
|
|
|
}
|
|
|
|
|
2020-03-31 14:18:42 +00:00
|
|
|
#define eDTName QStringLiteral("Dab Test")
|
|
|
|
|
2019-07-15 17:06:24 +00:00
|
|
|
// Name of your effect used in UI
|
2020-03-31 14:18:42 +00:00
|
|
|
void eName(QString& result) {
|
|
|
|
result = eDTName;
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// here specify your effect's most up to date version
|
|
|
|
CustomIdentifier::Version effectVersion() {
|
|
|
|
return { 0, 0, 0 };
|
|
|
|
}
|
|
|
|
|
2020-03-31 14:18:42 +00:00
|
|
|
void eIdentifier(CustomIdentifier &result) {
|
|
|
|
result = { effectId(), eDTName, effectVersion() };
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:45:22 +00:00
|
|
|
bool eSupports(const CustomIdentifier &identifier) {
|
2019-07-15 17:06:24 +00:00
|
|
|
if(identifier.fEffectId != effectId()) return false;
|
2020-03-31 14:18:42 +00:00
|
|
|
if(identifier.fEffectName != eDTName) return false;
|
2019-07-15 17:06:24 +00:00
|
|
|
return identifier.fVersion == effectVersion();
|
|
|
|
}
|
|
|
|
|
2019-07-20 18:08:42 +00:00
|
|
|
#include "enveCore/Animators/qrealanimator.h"
|
|
|
|
|
2019-07-15 17:06:24 +00:00
|
|
|
DabTest000::DabTest000() :
|
2020-03-31 14:18:42 +00:00
|
|
|
CustomRasterEffect(eDTName.toLower(), HardwareSupport::gpuOnly, false) {
|
2019-08-07 08:51:45 +00:00
|
|
|
mRadius = enve::make_shared<QrealAnimator>(0.5, 0, 0.5, 0.1, "radius");
|
2019-07-30 16:55:43 +00:00
|
|
|
ca_addChild(mRadius);
|
2019-07-15 17:06:24 +00:00
|
|
|
|
2019-08-07 08:51:45 +00:00
|
|
|
mHardness = enve::make_shared<QrealAnimator>(1, 0, 1, 0.1, "hardness");
|
2019-07-30 16:55:43 +00:00
|
|
|
ca_addChild(mHardness);
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 18:34:37 +00:00
|
|
|
stdsptr<RasterEffectCaller> DabTest000::getEffectCaller(
|
2020-03-11 09:54:26 +00:00
|
|
|
const qreal relFrame, const qreal resolution,
|
|
|
|
const qreal influence, BoxRenderData * const data) const {
|
|
|
|
Q_UNUSED(data)
|
2019-12-28 17:33:20 +00:00
|
|
|
const qreal radius = mRadius->getEffectiveValue(relFrame)*resolution*influence;
|
2019-07-15 17:06:24 +00:00
|
|
|
const qreal hardness = mHardness->getEffectiveValue(relFrame);
|
|
|
|
|
|
|
|
Dab dab;
|
|
|
|
dab.fRadius = toSkScalar(radius);
|
|
|
|
dab.fHardness = toSkScalar(hardness);
|
|
|
|
dab.fSeg1Slope = -(1.f/dab.fHardness - 1.f);
|
|
|
|
dab.fSeg2Offset = dab.fHardness/(1.f - dab.fHardness);
|
|
|
|
dab.fSeg2Slope = -dab.fHardness/(1.f - dab.fHardness);
|
2019-08-07 08:51:45 +00:00
|
|
|
return enve::make_shared<DabTestCaller000>(dab);
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CustomIdentifier DabTest000::getIdentifier() const {
|
2020-03-31 14:18:42 +00:00
|
|
|
return { effectId(), eDTName, { 0, 0, 0 } };
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DabTestCaller000::sInitialized = false;
|
|
|
|
GLuint DabTestCaller000::sDataId = 0;
|
|
|
|
GLuint DabTestCaller000::sProgramId = 0;
|
|
|
|
|
2019-07-16 14:10:34 +00:00
|
|
|
void DabTestCaller000::sInitialize(QGL33 * const gl) {
|
2019-07-15 17:06:24 +00:00
|
|
|
try {
|
2020-05-25 11:58:34 +00:00
|
|
|
gIniProgram(gl, sProgramId, GL_TEXTURED_VERT,
|
2019-08-05 16:32:07 +00:00
|
|
|
":/shaders/normal.frag");
|
2019-07-15 17:06:24 +00:00
|
|
|
} catch(...) {
|
2019-08-01 19:52:22 +00:00
|
|
|
RuntimeThrow("Could not initialize a program for DabTestCaller000");
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gl->glGenTextures(1, &sDataId);
|
|
|
|
|
|
|
|
gl->glBindTexture(GL_TEXTURE_2D, sDataId);
|
|
|
|
gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
gl->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
gl->glUseProgram(sProgramId);
|
|
|
|
|
|
|
|
const auto dabDataU = gl->glGetUniformLocation(sProgramId, "dabData");
|
|
|
|
|
|
|
|
gl->glUniform1i(dabDataU, 0);
|
|
|
|
}
|
|
|
|
|
2019-07-25 17:21:26 +00:00
|
|
|
void DabTestCaller000::processGpu(QGL33 * const gl,
|
2020-03-02 22:43:08 +00:00
|
|
|
GpuRenderTools &renderTools) {
|
2019-08-23 19:47:16 +00:00
|
|
|
renderTools.switchToOpenGL(gl);
|
2019-07-15 17:06:24 +00:00
|
|
|
|
|
|
|
if(!sInitialized) {
|
|
|
|
sInitialize(gl);
|
|
|
|
sInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTools.requestTargetFbo();
|
|
|
|
renderTools.swapTextures();
|
|
|
|
renderTools.requestTargetFbo().bind(gl);
|
|
|
|
|
|
|
|
gl->glUseProgram(sProgramId);
|
|
|
|
|
|
|
|
gl->glActiveTexture(GL_TEXTURE0);
|
|
|
|
gl->glBindTexture(GL_TEXTURE_2D, sDataId);
|
|
|
|
gl->glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 16, 1,
|
|
|
|
0, GL_RED, GL_FLOAT, &mDab);
|
|
|
|
|
|
|
|
gl->glBindVertexArray(renderTools.getSquareVAO());
|
|
|
|
gl->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2019-09-09 07:31:43 +00:00
|
|
|
|
|
|
|
renderTools.swapTextures();
|
2019-07-15 17:06:24 +00:00
|
|
|
}
|