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

Method convertImageTosRGBOpenGLTexture

Engine/TrackerNodeInteract.cpp:1149–1275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1147}
1148
1149void
1150TrackerNodeInteract::convertImageTosRGBOpenGLTexture(const boost::shared_ptr<Image>& image,
1151 const boost::shared_ptr<Texture>& tex,
1152 const RectI& renderWindow)
1153{
1154 RectI bounds;
1155 RectI roi;
1156
1157 if (image) {
1158 bounds = image->getBounds();
1159 renderWindow.intersect(bounds, &roi);
1160 } else {
1161 bounds = renderWindow;
1162 roi = bounds;
1163 }
1164 if ( roi.isNull() ) {
1165 return;
1166 }
1167
1168
1169 std::size_t bytesCount = 4 * sizeof(unsigned char) * roi.area();
1170 TextureRect region;
1171 region.x1 = roi.x1;
1172 region.x2 = roi.x2;
1173 region.y1 = roi.y1;
1174 region.y2 = roi.y2;
1175
1176 GLint currentBoundPBO = 0;
1177 glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING_ARB, &currentBoundPBO);
1178
1179 if (pboID == 0) {
1180 glGenBuffers(1, &pboID);
1181 }
1182
1183 // bind PBO to update texture source
1184 glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_ARB, pboID );
1185
1186 // Note that glMapBufferARB() causes sync issue.
1187 // If GPU is working with this buffer, glMapBufferARB() will wait(stall)
1188 // until GPU to finish its job. To avoid waiting (idle), you can call
1189 // first glBufferDataARB() with NULL pointer before glMapBufferARB().
1190 // If you do that, the previous data in PBO will be discarded and
1191 // glMapBufferARB() returns a new allocated pointer immediately
1192 // even if GPU is still working with the previous data.
1193 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, bytesCount, NULL, GL_DYNAMIC_DRAW_ARB);
1194
1195 // map the buffer object into client's memory
1196 GLvoid *buf = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
1197 glCheckError();
1198 assert(buf);
1199 if (buf) {
1200 // update data directly on the mapped buffer
1201 if (!image) {
1202 int pixelsCount = roi.area();
1203 unsigned int* dstPixels = (unsigned int*)buf;
1204 for (int i = 0; i < pixelsCount; ++i, ++dstPixels) {
1205 *dstPixels = toBGRA(0, 0, 0, 255);
1206 }

Callers

nothing calls this directly

Calls 13

getComponentsCountMethod · 0.80
validateMethod · 0.80
fillOrAllocateTextureMethod · 0.80
toBGRAFunction · 0.70
RectIClass · 0.70
getBoundsMethod · 0.45
intersectMethod · 0.45
isNullMethod · 0.45
areaMethod · 0.45
getMethod · 0.45
pixelAtMethod · 0.45

Tested by

no test coverage detected