245{
248
251
252
253 unsigned int framebuffer;
254 glGenFramebuffers(1, &framebuffer);
255 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
256
257 unsigned int textureColorBufferMultiSampled;
258 glGenTextures(1, &textureColorBufferMultiSampled);
259 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled);
260 glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA, width, height,
GL_TRUE);
261 glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
262 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled, 0);
263
264 unsigned int rbo;
265 glGenRenderbuffers(1, &rbo);
266 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
267 glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height);
268 glBindRenderbuffer(GL_RENDERBUFFER, 0);
269 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
270 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
271 glBindFramebuffer(GL_FRAMEBUFFER, 0);
272
273
274 unsigned int intermediateFBO;
275 glGenFramebuffers(1, &intermediateFBO);
276 glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO);
277
278 unsigned int screenTexture;
279 glGenTextures(1, &screenTexture);
280 glBindTexture(GL_TEXTURE_2D, screenTexture);
281 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
284 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, screenTexture, 0);
285 assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
286 glBindFramebuffer(GL_FRAMEBUFFER, 0);
287
288 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
289
290
292 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
293
294 Eigen::Vector4f viewport_ori =
viewport;
296
297 draw(data,update_matrices);
298
300
301 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
302 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, intermediateFBO);
303 glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
304
305 glBindFramebuffer(GL_FRAMEBUFFER, intermediateFBO);
306
308 glReadPixels(0, 0,width, height,GL_RGBA, GL_UNSIGNED_BYTE, pixels);
309
310
311 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
312 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
313 glBindFramebuffer(GL_FRAMEBUFFER, 0);
314 glDeleteTextures(1, &screenTexture);
315 glDeleteTextures(1, &textureColorBufferMultiSampled);
316 glDeleteFramebuffers(1, &framebuffer);
317 glDeleteFramebuffers(1, &intermediateFBO);
318 glDeleteRenderbuffers(1, &rbo);
319
321 for (
unsigned j=0; j<
height; ++j)
322 {
323 for (
unsigned i=0; i<
width; ++i)
324 {
325 R(i,j) = pixels[
count*4+0];
326 G(i,j) = pixels[
count*4+1];
327 B(i,j) = pixels[
count*4+2];
328 A(i,j) = pixels[
count*4+3];
330 }
331 }
332
334}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
Definition PlainObjectBase.h:153
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
Definition PlainObjectBase.h:151
IGL_INLINE void draw(ViewerData &data, bool update_matrices=true)
Definition ViewerCore.cpp:97
unsigned char GLubyte
Definition glu-libtess.h:60
#define GL_TRUE
Definition glu-libtess.h:70
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12