MCPcopy Create free account
hub / github.com/MrKepzie/Natron / applyMaskMix

Method applyMaskMix

Engine/ImageMaskMix.cpp:187–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187void
188Image::applyMaskMix(const RectI& roi,
189 const Image* maskImg,
190 const Image* originalImg,
191 bool masked,
192 bool maskInvert,
193 float mix,
194 const OSGLContextPtr& glContext)
195{
196 ///!masked && mix == 1 has nothing to do
197 if ( !masked && (mix == 1) ) {
198 return;
199 }
200
201 QWriteLocker k(&_entryLock);
202 boost::scoped_ptr<QReadLocker> originalLock;
203 boost::scoped_ptr<QReadLocker> maskLock;
204 if (originalImg) {
205 originalLock.reset( new QReadLocker(&originalImg->_entryLock) );
206 }
207 if (maskImg) {
208 maskLock.reset( new QReadLocker(&maskImg->_entryLock) );
209 }
210 RectI realRoI;
211 roi.intersect(_bounds, &realRoI);
212
213 assert( !originalImg || getBitDepth() == originalImg->getBitDepth() );
214 assert( !masked || !maskImg || maskImg->getComponents() == ImagePlaneDesc::getAlphaComponents() );
215
216 if (getStorageMode() == eStorageModeGLTex) {
217 assert(glContext);
218 assert(!originalImg || originalImg->getStorageMode() == eStorageModeGLTex);
219 boost::shared_ptr<GLShader> shader = glContext->getOrCreateMaskMixShader(maskImg != 0);
220 assert(shader);
221 GLuint fboID = glContext->getFBOId();
222
223 glBindFramebuffer(GL_FRAMEBUFFER, fboID);
224 int target = getGLTextureTarget();
225 glEnable(target);
226 glActiveTexture(GL_TEXTURE0);
227 glBindTexture( target, getGLTextureID() );
228
229 glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
230 glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
231
232 glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_REPEAT);
233 glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_REPEAT);
234
235 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, getGLTextureID(), 0 /*LoD*/);
236 glCheckFramebufferError();
237
238 glActiveTexture(GL_TEXTURE1);
239 glBindTexture(target, originalImg ? originalImg->getGLTextureID() : 0);
240
241 glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
242 glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
243
244 glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_REPEAT);

Callers 1

renderHandlerMethod · 0.80

Calls 13

getBitDepthFunction · 0.85
getComponentsMethod · 0.80
getFBOIdMethod · 0.80
bindMethod · 0.80
setUniformMethod · 0.80
unbindMethod · 0.80
getComponentsCountMethod · 0.80
resetMethod · 0.45
intersectMethod · 0.45
getBitDepthMethod · 0.45
getStorageModeMethod · 0.45

Tested by

no test coverage detected