bool BootAnimation::android() { initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); // clear screen glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_SCISSOR_TEST); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay, mSurface); glEnable(GL_TEXTURE_2D); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); const GLint xc = (mWidth - mAndroid[0].w) / 2; const GLint yc = (mHeight - mAndroid[0].h) / 2; const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h); glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), updateRect.height()); // Blend state glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); const nsecs_t startTime = systemTime(); do { nsecs_t now = systemTime(); double time = now - startTime; float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; GLint x = xc - offset; glDisable(GL_SCISSOR_TEST); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h); EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); if (res == EGL_FALSE) break; // 12fps: don't animate too fast to preserve CPU const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); if (sleepTime > 0) usleep(sleepTime); checkExit(); } while (!exitPending()); glDeleteTextures(1, &mAndroid[0].name); glDeleteTextures(1, &mAndroid[1].name); return false; }
Picture::~Picture() { if (texture) glDeleteTextures(1, &texture); }
Exercise13::~Exercise13() { if (m_textureID != -1) glDeleteTextures(1, &m_textureID); }
void CQuake3BSP::Destroy() { // If we still have valid memory for our vertices, free them if(m_pVerts) { delete [] m_pVerts; m_pVerts = NULL; } // If we still have valid memory for our faces, free them if(m_pFaces) { delete [] m_pFaces; m_pFaces = NULL; } // If we still have valid memory for our indices, free them if(m_pIndices) { delete [] m_pIndices; m_pIndices = NULL; } // If we still have valid memory for our nodes, free them if(m_pNodes) { delete [] m_pNodes; m_pNodes = NULL; } // If we still have valid memory for our leafs, free them if(m_pLeafs) { delete [] m_pLeafs; m_pLeafs = NULL; } // If we still have valid memory for our leaf faces, free them if(m_pLeafFaces) { delete [] m_pLeafFaces; m_pLeafFaces = NULL; } // If we still have valid memory for our planes, free them if(m_pPlanes) { delete [] m_pPlanes; m_pPlanes = NULL; } // If we still have valid memory for our clusters, free them if(m_clusters.pBitsets) { delete [] m_clusters.pBitsets; m_clusters.pBitsets = NULL; } // If we still have valid memory for our brushes, free them if(m_pBrushes) { delete [] m_pBrushes; m_pBrushes = NULL; } // If we still have valid memory for our brush sides, free them if(m_pBrushSides) { delete [] m_pBrushSides; m_pBrushSides = NULL; } // If we still have valid memory for our leaf brushes, free them if(m_pLeafBrushes) { delete [] m_pLeafBrushes; m_pLeafBrushes = NULL; } // If we still have valid memory for our BSP texture info, free it if(m_pTextures) { delete [] m_pTextures; m_pTextures = NULL; } // Free all the textures glDeleteTextures(m_numOfTextures, m_textures); // Delete the lightmap textures glDeleteTextures(m_numOfLightmaps, m_lightmaps); }
void OpenglES3Device::deleteTexture(unsigned int textureId){ glDeleteTextures(1, &textureId); this->evaluateErrorsAndLog("deleteTexture"); }
void Texture::deleteTexture(GLuint texture_handle) { glDeleteTextures(1, &texture_handle); }
CBaseGroundDrawer::~CBaseGroundDrawer(void) { delete[] infoTexMem; if(infoTex!=0) glDeleteTextures(1,&infoTex); }
int main(void) { EGLint major, minor, eglCfgCount, eglCfgVisualId, width, height; const IMG_gralloc_module_public_t *module; buffer_handle_t srcBuffer, destBuffer; EGLImageKHR eglSrcImage, eglDestImage; EGLConfig eglConfig, eglFBConfig; GLuint fboName, textureNames[2]; EGLNativeWindowType eglWindow; EGLSurface eglWindowSurface; alloc_device_t *device; EGLContext eglContext; EGLDisplay eglDisplay; int err = 1, stride; GLenum glError; ANativeWindowBuffer sSrcBuffer = { .common.magic = ANDROID_NATIVE_BUFFER_MAGIC, .common.version = sizeof(ANativeWindowBuffer), .common.incRef = incRefNop, .common.decRef = decRefNop, .width = SRC_WIDTH, .height = SRC_HEIGHT, .stride = SRC_STRIDE, .usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, }; ANativeWindowBuffer sDestBuffer = { .common.magic = ANDROID_NATIVE_BUFFER_MAGIC, .common.version = sizeof(ANativeWindowBuffer), .common.incRef = incRefNop, .common.decRef = decRefNop, .width = DEST_WIDTH, .height = DEST_HEIGHT, .stride = DEST_STRIDE, .format = DEST_FORMAT, .usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, }; EGLint eglCfgAttribs[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_ALPHA_SIZE, 0, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, #ifdef EGL_ANDROID_recordable EGL_RECORDABLE_ANDROID, EGL_TRUE, #endif EGL_NONE, }; const float srcVertexArray[2 * 4] = { 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, }; const float texCoordArray[2 * 4] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, }; const float destVertexArray[2 * 4] = { -1.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, }; eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if(eglDisplay == EGL_NO_DISPLAY) { printf("eglGetDisplay failed\n"); goto err_out; } if(!eglInitialize(eglDisplay, &major, &minor)) { printf("eglInitialize failed (err=0x%x)\n", eglGetError()); goto err_out; } if(!eglChooseConfig(eglDisplay, eglCfgAttribs, &eglConfig, 1, &eglCfgCount)) { printf("eglChooseConfig failed (err=0x%x)\n", eglGetError()); goto err_terminate; } if(!eglCfgCount) { printf("eglChooseConfig found no suitable configs\n"); goto err_terminate; } if(!eglGetConfigAttrib(eglDisplay, eglConfig, EGL_NATIVE_VISUAL_ID, &eglCfgVisualId)) { printf("eglGetConfigAttrib failed (err=0x%x)\n", eglGetError()); goto err_terminate; } sSrcBuffer.format = eglCfgVisualId; /* Handle FB rendering ***************************************************/ eglWindow = android_createDisplaySurface(); if(!eglWindow) { printf("android_createDisplaySurface returned NULL\n"); goto err_terminate; } eglWindow->common.incRef(&eglWindow->common); eglFBConfig = findMatchingWindowConfig(eglDisplay, EGL_OPENGL_ES_BIT, eglWindow); /* FIXME: findMatchingWindowConfig returns no error code */ eglContext = eglCreateContext(eglDisplay, eglFBConfig, EGL_NO_CONTEXT, NULL); if(eglContext == EGL_NO_CONTEXT) { printf("eglCreateContext failed (err=0x%x)\n", eglGetError()); goto err_window_decref; } eglWindowSurface = eglCreateWindowSurface(eglDisplay, eglFBConfig, eglWindow, NULL); if(eglWindowSurface == EGL_NO_SURFACE) { printf("eglCreateWindowSurface failed (err=0x%x)\n", eglGetError()); goto err_destroy_context; } if(!eglQuerySurface(eglDisplay, eglWindowSurface, EGL_WIDTH, &width)) { printf("eglQuerySurface #1 failed (err=0x%x)\n", eglGetError()); goto err_destroy_context; } if(!eglQuerySurface(eglDisplay, eglWindowSurface, EGL_HEIGHT, &height)) { printf("eglQuerySurface #2 failed (err=0x%x)\n", eglGetError()); goto err_destroy_context; } if(!eglMakeCurrent(eglDisplay, eglWindowSurface, eglWindowSurface, eglContext)) { printf("eglMakeCurrent failed (err=0x%x)\n", eglGetError()); goto err_destroy_surface; } /* Allocate some compatible buffers with gralloc *************************/ err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&module); if(err) { printf("hw_get_module failed (err=%d)\n", err); goto err_make_non_current; } err = module->base.common.methods->open((const hw_module_t *)module, GRALLOC_HARDWARE_GPU0, (hw_device_t **)&device); if(err) { printf("module->common.methods->open() failed (err=%d)\n", err); goto err_make_non_current; } err = device->alloc(device, SRC_WIDTH, SRC_HEIGHT, eglCfgVisualId, GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, &srcBuffer, &stride); if(err) { printf("device->alloc() failed (err=%d)\n", err); goto err_close; } err = device->alloc(device, DEST_WIDTH, DEST_HEIGHT, DEST_FORMAT, GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE, &destBuffer, &stride); if(err) { printf("device->alloc() failed (err=%d)\n", err); goto err_free_src; } err = module->base.registerBuffer(&module->base, srcBuffer); if(err) { printf("module->registerBuffer() failed (err=%d)\n", err); goto err_free_dest; } err = module->base.registerBuffer(&module->base, destBuffer); if(err) { printf("module->registerBuffer() failed (err=%d)\n", err); goto err_unregister_src; } sSrcBuffer.handle = srcBuffer; sDestBuffer.handle = destBuffer; /* Make some EGLImageKHRs out of them ************************************/ eglSrcImage = eglCreateImageKHR(eglDisplay, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, (EGLClientBuffer)&sSrcBuffer, 0); if(eglSrcImage == EGL_NO_IMAGE_KHR) { printf("eglCreateImageKHR #1 failed (err=0x%x)\n", eglGetError()); goto err_unregister_dest; } eglDestImage = eglCreateImageKHR(eglDisplay, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, (EGLClientBuffer)&sDestBuffer, 0); if(eglDestImage == EGL_NO_IMAGE_KHR) { printf("eglCreateImageKHR #2 failed (err=0x%x)\n", eglGetError()); goto err_destroy_src_image; } /* Create funny textures *************************************************/ glGenTextures(2, textureNames); glError = glGetError(); if(glError != GL_NO_ERROR) { printf("glGenTextures generated error 0x%x\n", glError); goto err_destroy_dest_image; } glBindTexture(GL_TEXTURE_2D, textureNames[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglSrcImage); glError = glGetError(); if(glError != GL_NO_ERROR) { printf("glEGLImageTargetTexture2DOES generated error 0x%x\n", glError); goto err_delete_textures; } glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureNames[1]); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, eglDestImage); glError = glGetError(); if(glError != GL_NO_ERROR) { printf("glEGLImageTargetTexture2DOES generated error 0x%x\n", glError); goto err_delete_textures; } /* Create FBO ************************************************************/ glGenFramebuffersOES(1, &fboName); glError = glGetError(); if(glError != GL_NO_ERROR) { printf("glGenFrameBuffersOES generated error 0x%x\n", glError); goto err_delete_textures; } glBindFramebufferOES(GL_FRAMEBUFFER_OES, fboName); glError = glGetError(); if(glError != GL_NO_ERROR) { printf("glBindFramebufferOES generated error 0x%x\n", glError); goto err_delete_framebuffer; } glBindTexture(GL_TEXTURE_2D, textureNames[0]); glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, textureNames[0], 0); glError = glGetError(); if(glError != GL_NO_ERROR) { printf("glFramebufferTexture2DOES generated error 0x%x\n", glError); goto err_delete_framebuffer; } /*************************************************************************/ glError = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); if(glError != GL_FRAMEBUFFER_COMPLETE_OES) { printf("glCheckFramebufferStatus generated error 0x%x\n", glError); goto err_delete_framebuffer; } /* Draw some stuff */ { const float vertexArray[2 * 4] = { -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, }; const float colorArray[4 * 4] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, }; char dummy[4]; glViewport(0, 0, SRC_WIDTH, SRC_HEIGHT); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertexArray); glColorPointer(4, GL_FLOAT, 0, colorArray); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, dummy); } /* RGB -> YUV blit */ err = module->Blit2(module, srcBuffer, destBuffer, SRC_WIDTH, SRC_HEIGHT, 0, 0); if(err) { printf("module->Blit2() failed (err=%d)\n", err); goto err_delete_framebuffer; } /* Present both to screen (should appear identical) */ glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); glViewport(0, 0, width, height); glClearColor(0.0f, 1.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, texCoordArray); glEnable(GL_TEXTURE_EXTERNAL_OES); glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureNames[1]); glVertexPointer(2, GL_FLOAT, 0, destVertexArray); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisable(GL_TEXTURE_EXTERNAL_OES); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textureNames[0]); glVertexPointer(2, GL_FLOAT, 0, srcVertexArray); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); eglSwapBuffers(eglDisplay, eglWindowSurface); sleep(1); err_delete_framebuffer: glDeleteFramebuffersOES(1, &fboName); err_delete_textures: glDeleteTextures(2, textureNames); err_destroy_dest_image: eglDestroyImageKHR(eglDisplay, eglDestImage); err_destroy_src_image: eglDestroyImageKHR(eglDisplay, eglSrcImage); err_unregister_dest: err = module->base.unregisterBuffer(&module->base, destBuffer); if(err) printf("module->unregisterBuffer() failed (err=%d)\n", err); err_unregister_src: err = module->base.unregisterBuffer(&module->base, srcBuffer); if(err) printf("module->unregisterBuffer() failed (err=%d)\n", err); err_free_dest: err = device->free(device, destBuffer); if(err) printf("device->free() failed (err=%d)\n", err); err_free_src: err = device->free(device, srcBuffer); if(err) printf("device->free() failed (err=%d)\n", err); err_close: err = device->common.close((hw_device_t *)device); if(err) printf("hal->close() failed (err=%d)\n", err); err_make_non_current: eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); err_destroy_surface: eglDestroySurface(eglDisplay, eglWindowSurface); err_destroy_context: eglDestroyContext(eglDisplay, eglContext); err_window_decref: eglWindow->common.decRef(&eglWindow->common); err_terminate: eglTerminate(eglDisplay); err_out: return err; }
enum piglit_result piglit_display(void) { GLuint tex, tex_src; bool pass; int level; unsigned bw, bh, bs; piglit_get_compressed_block_size(format->token, &bw, &bh, &bs); glClearColor(0.5, 0.5, 0.5, 0.5); glClear(GL_COLOR_BUFFER_BIT); tex_src = piglit_rgbw_texture(format->token, SIZE, SIZE, true, false, GL_UNSIGNED_NORMALIZED); glCreateTextures(GL_TEXTURE_2D, 1, &tex); for (level = 0; (SIZE >> level) > 0; level++) { int w, h; int expected_size, size; void *compressed; w = SIZE >> level; h = SIZE >> level; expected_size = piglit_compressed_image_size(format->token, w, h); glBindTexture(GL_TEXTURE_2D, tex_src); glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &size); if (size != expected_size) { fprintf(stderr, "Format %s level %d (%dx%d) size %d " "doesn't match expected size %d\n", piglit_get_gl_enum_name(format->token), level, w, h, size, expected_size); piglit_report_result(PIGLIT_FAIL); } compressed = malloc(size); glGetCompressedTextureImage(tex_src, level, size, compressed); glBindTexture(GL_TEXTURE_2D, tex); glCompressedTexImage2D(GL_TEXTURE_2D, level, format->token, w, h, 0, size, compressed); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); free(compressed); } glDeleteTextures(1, &tex_src); glBindTextureUnit(tex, 0); display_mipmaps(10, 10); pass = check_resulting_mipmaps(10, 10); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
void SurfaceSdlGraphicsManager::updateScreen() { #ifdef USE_OPENGL if (_opengl) { if (_overlayVisible) { if (_overlayDirty) { // remove if already exist if (_overlayNumTex > 0) { glDeleteTextures(_overlayNumTex, _overlayTexIds); delete[] _overlayTexIds; _overlayNumTex = 0; } _overlayNumTex = ((_overlayWidth + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) * ((_overlayHeight + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE); _overlayTexIds = new GLuint[_overlayNumTex]; glGenTextures(_overlayNumTex, _overlayTexIds); for (int i = 0; i < _overlayNumTex; i++) { glBindTexture(GL_TEXTURE_2D, _overlayTexIds[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); } glPixelStorei(GL_UNPACK_ALIGNMENT, 2); glPixelStorei(GL_UNPACK_ROW_LENGTH, _overlayWidth); int curTexIdx = 0; for (int y = 0; y < _overlayHeight; y += BITMAP_TEXTURE_SIZE) { for (int x = 0; x < _overlayWidth; x += BITMAP_TEXTURE_SIZE) { int t_width = (x + BITMAP_TEXTURE_SIZE >= _overlayWidth) ? (_overlayWidth - x) : BITMAP_TEXTURE_SIZE; int t_height = (y + BITMAP_TEXTURE_SIZE >= _overlayHeight) ? (_overlayHeight - y) : BITMAP_TEXTURE_SIZE; glBindTexture(GL_TEXTURE_2D, _overlayTexIds[curTexIdx]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, t_width, t_height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, (byte *)_overlayscreen->pixels + (y * 2 * _overlayWidth) + (2 * x)); curTexIdx++; } } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } // Save current state glPushAttrib(GL_TRANSFORM_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_SCISSOR_BIT); // prepare view glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, _overlayWidth, _overlayHeight, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); glScissor(0, 0, _overlayWidth, _overlayHeight); int curTexIdx = 0; for (int y = 0; y < _overlayHeight; y += BITMAP_TEXTURE_SIZE) { for (int x = 0; x < _overlayWidth; x += BITMAP_TEXTURE_SIZE) { glBindTexture(GL_TEXTURE_2D, _overlayTexIds[curTexIdx]); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2i(x, y); glTexCoord2f(1.0f, 0.0f); glVertex2i(x + BITMAP_TEXTURE_SIZE, y); glTexCoord2f(1.0f, 1.0f); glVertex2i(x + BITMAP_TEXTURE_SIZE, y + BITMAP_TEXTURE_SIZE); glTexCoord2f(0.0f, 1.0f); glVertex2i(x, y + BITMAP_TEXTURE_SIZE); glEnd(); curTexIdx++; } } // Restore previous state glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_TEXTURE); glPopMatrix(); glPopAttrib(); } SDL_GL_SwapBuffers(); } else #endif { if (_overlayVisible) { SDL_LockSurface(_screen); SDL_LockSurface(_overlayscreen); Graphics::PixelBuffer srcBuf(_overlayFormat, (byte *)_overlayscreen->pixels); Graphics::PixelBuffer dstBuf(_screenFormat, (byte *)_screen->pixels); int h = _overlayHeight; do { dstBuf.copyBuffer(0, _overlayWidth, srcBuf); srcBuf.shiftBy(_overlayWidth); dstBuf.shiftBy(_overlayWidth); } while (--h); SDL_UnlockSurface(_screen); SDL_UnlockSurface(_overlayscreen); } SDL_Flip(_screen); } }
void ocpnDC::DrawText( const wxString &text, wxCoord x, wxCoord y ) { if( dc ) dc->DrawText( text, x, y ); #ifdef ocpnUSE_GL else { wxCoord w = 0; wxCoord h = 0; if(m_buseTex){ m_texfont.Build( m_font ); // make sure the font is ready m_texfont.GetTextExtent(text, &w, &h); if( w && h ) { glEnable( GL_BLEND ); glEnable( GL_TEXTURE_2D ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glPushMatrix(); glTranslatef(x, y, 0); glColor3ub( m_textforegroundcolour.Red(), m_textforegroundcolour.Green(), m_textforegroundcolour.Blue() ); m_texfont.RenderString(text); glPopMatrix(); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); } } else{ wxScreenDC sdc; sdc.SetFont(m_font); sdc.GetTextExtent(text, &w, &h, NULL, NULL, &m_font); /* create bitmap of appropriate size and select it */ wxBitmap bmp( w, h ); wxMemoryDC temp_dc; temp_dc.SelectObject( bmp ); /* fill bitmap with black */ temp_dc.SetBackground( wxBrush( wxColour( 0, 0, 0 ) ) ); temp_dc.Clear(); /* draw the text white */ temp_dc.SetFont( m_font ); temp_dc.SetTextForeground( wxColour( 255, 255, 255 ) ); temp_dc.DrawText( text, 0, 0 ); temp_dc.SelectObject( wxNullBitmap ); /* use the data in the bitmap for alpha channel, and set the color to text foreground */ wxImage image = bmp.ConvertToImage(); if( x < 0 || y < 0 ) { // Allow Drawing text which is offset to start off screen int dx = ( x < 0 ? -x : 0 ); int dy = ( y < 0 ? -y : 0 ); w = bmp.GetWidth() - dx; h = bmp.GetHeight() - dy; /* picture is out of viewport */ if( w <= 0 || h <= 0 ) return; image = image.GetSubImage( wxRect( dx, dy, w, h ) ); x += dx; y += dy; } unsigned char *data = new unsigned char[w * h * 4]; unsigned char *im = image.GetData(); if(im){ unsigned int r = m_textforegroundcolour.Red(); unsigned int g = m_textforegroundcolour.Green(); unsigned int b = m_textforegroundcolour.Blue(); for( int i = 0; i < h; i++ ){ for(int j=0 ; j < w ; j++){ unsigned int index = ((i*w) + j) * 4; data[index] = r; data[index+1] = g; data[index+2] = b; data[index+3] = im[((i*w) + j) * 3]; } } } #if 0 glColor4ub( 255, 255, 255, 255 ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glRasterPos2i( x, y ); glPixelZoom( 1, -1 ); glDrawPixels( w, h, GL_RGBA, GL_UNSIGNED_BYTE, data ); glPixelZoom( 1, 1 ); glDisable( GL_BLEND ); #else unsigned int texobj; glGenTextures(1, &texobj); glBindTexture(GL_TEXTURE_2D, texobj); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); int TextureWidth = NextPow2(w); int TextureHeight = NextPow2(h); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TextureWidth, TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor3ub(0,0,0); float u = (float)w/TextureWidth, v = (float)h/TextureHeight; glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(x, y); glTexCoord2f(u, 0); glVertex2f(x+w, y); glTexCoord2f(u, v); glVertex2f(x+w, y+h); glTexCoord2f(0, v); glVertex2f(x, y+h); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glDeleteTextures(1, &texobj); #endif delete[] data; } } #endif }
void release_texture(GLuint texture) { glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &texture); }
int _tmain(int argc, _TCHAR* argv[]) { GLFWwindow* window = 0; glfwSetErrorCallback(glfw_error_callback_func); // Initialise GLFW if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); getchar(); return -1; } //----------------------------------------------------------------------------- glfwWindowHint(GLFW_SAMPLES, 4); // GL3.3 Core profile glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_VISIBLE, 0); //オフスクリーン // Open a window and create its OpenGL context window = glfwCreateWindow(1, 1, "GPGPU Test", NULL, NULL); if (window == NULL){ fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n"); getchar(); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); #if defined _WIN32 // Initialize GLEW glewExperimental = GL_TRUE; ///!!!! important for core profile // コアプロファイルで必要となります if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); getchar(); glfwTerminate(); return -1; } #endif { cout << "GL_VENDOR:" << glGetString(GL_VENDOR) << endl; cout << "GL_RENDERER:" << glGetString(GL_RENDERER) << endl; cout << "GL_VERSION:" << glGetString(GL_VERSION) << endl; cout << "GL_SHADING_LANGUAGE_VERSION:" << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl; } // Mat imgSrc = Mat(Size(32, 24), CV_32FC1); Mat imgSrc = Mat(Size(8, 4), CV_32FC1); Mat imgDst = Mat::zeros(imgSrc.size(), imgSrc.type()); //--------------------------------- //init Src image { const int width = imgSrc.cols; const int height = imgSrc.rows; for (int y = 0; y < height; y++){ for (int x = 0; x < width; x++){ imgSrc.at<float>(y,x) = y*100.0f + x; } } } //--------------------------------- //Execute GPGPU { const int width = imgSrc.cols; const int height = imgSrc.rows; // Create and compile our GLSL program from the shaders GLuint programID = LoadShaders("GpGpuVertexShader.vertexshader", "GpGpuFragmentShader.fragmentshader"); // FBO identifier GLuint fbo = 0; //--------------------------------- // FBO // create FBO (off-screen framebuffer) glGenFramebuffers(1, &fbo); // bind offscreen framebuffer (that is, skip the window-specific render target) glBindFramebuffer(GL_FRAMEBUFFER, fbo); // texture enum E_TextureID{ SRC, DST, SIZEOF, }; unsigned int textureID[E_TextureID::SIZEOF]; //src dst //--------------------------------- // CreateTexture { GLenum format = GL_RED; //single channel GLenum type = GL_FLOAT; //float GLenum internalFormat = GL_R32F; //single channel float glGenTextures(sizeof(textureID) / sizeof(textureID[0]), textureID); // create (reference to) a new texture for (int i = 0; i < sizeof(textureID) / sizeof(textureID[0]); i++){ glBindTexture(GL_TEXTURE_2D, textureID[i]); // (set texture parameters here) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //create the texture glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, 0); glBindTexture(GL_TEXTURE_2D, 0); } } //upload imgSrc to texture { GLenum format = GL_RED; //single channel GLenum type = GL_FLOAT; //float void* data = imgSrc.data; glBindTexture(GL_TEXTURE_2D, textureID[E_TextureID::SRC]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data); glBindTexture(GL_TEXTURE_2D, 0); } //Execute { glUseProgram(programID); GLuint vao; GLuint vbo; // [-1, 1] の正方形 static GLfloat position[][2] = { { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f } }; // create vao&vbo glGenVertexArrays(1, &vao); glGenBuffers(1, &vbo); // bind vao & vbo glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); // upload vbo data glBufferData(GL_ARRAY_BUFFER, (int)sizeof(position), position, GL_STATIC_DRAW); // Set VertexAttribute GLint attrLoc = glGetAttribLocation(programID, "position"); glEnableVertexAttribArray(attrLoc); //enable attribute Location glVertexAttribPointer( attrLoc, // attribute 0. No particular reason for 0, but must match the layout in the shader. 2, // size (Specifies the number of components) x,y GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (Specifies the byte offset between consecutive generic vertex attributes) (void*)0 // array buffer offset (Specifies a pointer to the first generic vertex attribute in the array) ); //Bind Texture & Fbo const int textureUnit = 0; glActiveTexture(GL_TEXTURE0 + textureUnit); glBindTexture(GL_TEXTURE_2D, textureID[E_TextureID::SRC]); glUniform1i(glGetUniformLocation(programID, "texSrc"), textureUnit); glUniform2f(glGetUniformLocation(programID, "texSrcSize"),width,height); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID[E_TextureID::DST], 0); //Viewport glViewport(0, 0, width, height); //Render!! glDrawArrays(GL_TRIANGLE_FAN, 0, (int)(sizeof(position) / sizeof(position[0]))); glFlush(); // delete vao&vbo glBindVertexArray(0); glDeleteVertexArrays(1, &vao); glDeleteBuffers(1, &vbo); } { //download from framebuffer GLenum format = GL_RED; //single channel GLenum type = GL_FLOAT; //float void* data = imgDst.data; int width = imgDst.cols; int height = imgDst.rows; //wait for Rendering glFinish(); // ReadBuffer glReadBuffer(GL_COLOR_ATTACHMENT0); // ReadPixels glReadPixels(0, 0, width, height, format, type, data); } //clean up glDeleteFramebuffers(1, &fbo); glDeleteTextures(sizeof(textureID) / sizeof(textureID[0]), textureID); glDeleteProgram(programID); } //dump { cout << "imgSrc" << endl; cout << imgSrc << endl; cout << "imgDst" << endl; cout << imgDst << endl; } //verify int errNum = 0; { //verify int width = imgSrc.cols; int height = imgSrc.rows; for (int y = 0; y < height; y++){ for (int x = 0; x < width; x++){ float src = imgSrc.at<float>(y, x); float dst = imgDst.at<float>(y, x); if (src != dst) errNum++; } } cout << "ErrNum:" << errNum << endl; } #if 0 //visualize { imshow("src", imgSrc); imshow("dst", imgDst); waitKey(); } #endif // Close OpenGL window and terminate GLFW glfwTerminate(); cout << "Hit return key" << endl; cin.get(); return errNum; }
bool BootAnimation::movie() { char bootenabled[PROPERTY_VALUE_MAX]; char bootsound[PROPERTY_VALUE_MAX]; char bootvolume[PROPERTY_VALUE_MAX]; property_get("persist.sys.boot_enabled", bootenabled, "1"); property_get("persist.sys.boot_sound", bootsound, "1"); property_get("persist.sys.boot_volume", bootvolume, "0.2"); bool bootEnabled = atoi(bootenabled) != 0; bool enableSound = atoi(bootsound) != 0; float bootVolume = strtof(bootvolume, NULL); if(!bootEnabled) { return false; } if(enableSound){ sp<MediaPlayer> mediaplay = new MediaPlayer(); mediaplay->setDataSource ("/system/media/audio.mp3", NULL); mediaplay->setVolume (bootVolume, bootVolume); mediaplay->prepare(); mediaplay->start(); } ZipFileRO& zip(mZip); size_t numEntries = zip.getNumEntries(); ZipEntryRO desc = zip.findEntryByName("desc.txt"); FileMap* descMap = zip.createEntryFileMap(desc); ALOGE_IF(!descMap, "descMap is null"); if (!descMap) { return false; } String8 desString((char const*)descMap->getDataPtr(), descMap->getDataLength()); char const* s = desString.string(); Animation animation; float r = 0.0f; float g = 0.0f; float b = 0.0f; // Parse the description file for (;;) { const char* endl = strstr(s, "\n"); if (!endl) break; String8 line(s, endl - s); const char* l = line.string(); int fps, width, height, count, pause, red, green, blue; char path[256]; char pathType; if (sscanf(l, "%d %d %d %d %d %d", &width, &height, &fps, &red, &green, &blue) == 6) { //ALOGD("> w=%d, h=%d, fps=%d, rgb=(%d, %d, %d)", width, height, fps, red, green, blue); animation.width = width; animation.height = height; animation.fps = fps; r = (float) red / 255.0f; g = (float) green / 255.0f; b = (float) blue / 255.0f; } else if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { //LOGD("> w=%d, h=%d, fps=%d", width, height, fps); animation.width = width; animation.height = height; animation.fps = fps; } else if (sscanf(l, " %c %d %d %s", &pathType, &count, &pause, path) == 4) { //LOGD("> type=%c, count=%d, pause=%d, path=%s", pathType, count, pause, path); Animation::Part part; part.playUntilComplete = pathType == 'c'; part.count = count; part.pause = pause; part.path = path; animation.parts.add(part); } s = ++endl; } // read all the data structures const size_t pcount = animation.parts.size(); for (size_t i=0 ; i<numEntries ; i++) { char name[256]; ZipEntryRO entry = zip.findEntryByIndex(i); if (zip.getEntryFileName(entry, name, 256) == 0) { const String8 entryName(name); const String8 path(entryName.getPathDir()); const String8 leaf(entryName.getPathLeaf()); if (leaf.size() > 0) { for (size_t j=0 ; j<pcount ; j++) { if (path == animation.parts[j].path) { int method; // supports only stored png files if (zip.getEntryInfo(entry, &method, 0, 0, 0, 0, 0)) { if (method == ZipFileRO::kCompressStored) { FileMap* map = zip.createEntryFileMap(entry); if (map) { Animation::Frame frame; frame.name = leaf; frame.map = map; Animation::Part& part(animation.parts.editItemAt(j)); part.frames.add(frame); } } } } } } } } #ifndef CONTINUOUS_SPLASH // clear screen glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glClearColor(r,g,b,1); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay, mSurface); #endif glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_TEXTURE_2D); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); const int xc = (mWidth - animation.width) / 2; const int yc = ((mHeight - animation.height) / 2); nsecs_t lastFrame = systemTime(); nsecs_t frameDuration = s2ns(1) / animation.fps; Region clearReg(Rect(mWidth, mHeight)); clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height)); for (int i=0 ; i<pcount ; i++) { const Animation::Part& part(animation.parts[i]); const size_t fcount = part.frames.size(); // can be 1, 0, or not set #ifdef NO_TEXTURE_CACHE const int noTextureCache = NO_TEXTURE_CACHE; #else const int noTextureCache = ((animation.width * animation.height * fcount) > 48 * 1024 * 1024) ? 1 : 0; #endif glBindTexture(GL_TEXTURE_2D, 0); for (int r=0 ; !part.count || r<part.count ; r++) { // Exit any non playuntil complete parts immediately if(exitPending() && !part.playUntilComplete) break; for (int j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { const Animation::Frame& frame(part.frames[j]); nsecs_t lastFrame = systemTime(); if (r > 0 && !noTextureCache) { glBindTexture(GL_TEXTURE_2D, frame.tid); } else { if (part.count != 1) { glGenTextures(1, &frame.tid); glBindTexture(GL_TEXTURE_2D, frame.tid); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } initTexture( frame.map->getDataPtr(), frame.map->getDataLength()); } if (!clearReg.isEmpty()) { Region::const_iterator head(clearReg.begin()); Region::const_iterator tail(clearReg.end()); glEnable(GL_SCISSOR_TEST); while (head != tail) { const Rect& r(*head++); glScissor(r.left, mHeight - r.bottom, r.width(), r.height()); glClear(GL_COLOR_BUFFER_BIT); } glDisable(GL_SCISSOR_TEST); } glDrawTexiOES(xc, yc, 0, animation.width, animation.height); eglSwapBuffers(mDisplay, mSurface); nsecs_t now = systemTime(); nsecs_t delay = frameDuration - (now - lastFrame); //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); lastFrame = now; if (delay > 0) { struct timespec spec; spec.tv_sec = (now + delay) / 1000000000; spec.tv_nsec = (now + delay) % 1000000000; int err; do { err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); } while (err<0 && errno == EINTR); } checkExit(); if (noTextureCache) glDeleteTextures(1, &frame.tid); } usleep(part.pause * ns2us(frameDuration)); // For infinite parts, we've now played them at least once, so perhaps exit if(exitPending() && !part.count) break; } // free the textures for this part if (part.count != 1 && !noTextureCache) { for (size_t j=0 ; j<fcount ; j++) { const Animation::Frame& frame(part.frames[j]); glDeleteTextures(1, &frame.tid); } } } return false; }
void MyColormap::close() { glDeleteTextures(1, &tid); }
TextureCubemap::~TextureCubemap(){ glDeleteTextures(1, &_texture); }
Texture::~Texture() { glDeleteTextures(1, &m_nTextureId); }
TextureArray::~TextureArray(){ glDeleteTextures(1, &_texture); }
static GLboolean test_with_format(GLenum internal_format, GLenum format, float results_x, float results_y) { GLuint tex, fb; GLenum status; GLboolean pass = GL_TRUE; int subrect_w = BUF_WIDTH / 5; int subrect_h = BUF_HEIGHT / 5; int x, y; int rbits, gbits, bbits, abits; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, internal_format, BUF_WIDTH, BUF_HEIGHT, 0, format, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &rbits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &gbits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &bbits); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &abits); printf("testing with format 0x%04x, 0x%04x " "(%d,%d,%d,%d rgba)\n", internal_format, format, rbits, gbits, bbits, abits); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); assert(glGetError() == 0); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "texture for internalformat 0x%04x. " "format 0x%04x is framebuffer " "incomplete (status = 0x%04x)\n", internal_format, format, status); goto done; } /* Set matrices */ glViewport(0, 0, BUF_WIDTH, BUF_HEIGHT); piglit_ortho_projection(BUF_WIDTH, BUF_HEIGHT, GL_FALSE); /* clear background to purple */ glClearColor(1.0, 0.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* lower-left square: red */ glColor4f(1.0, 0.0, 0.0, 0.0); piglit_draw_rect(subrect_w * 1, subrect_h * 1, subrect_w, subrect_h); /* lower-right square: green */ glColor4f(0.0, 1.0, 0.0, 0.0); piglit_draw_rect(subrect_w * 3, subrect_h * 1, subrect_w, subrect_h); /* upper-left square: blue */ glColor4f(0.0, 0.0, 1.0, 0.0); piglit_draw_rect(subrect_w * 1, subrect_h * 3, subrect_w, subrect_h); /* upper-right square: black */ glColor4f(0.0, 0.0, 0.0, 1.0); piglit_draw_rect(subrect_w * 3, subrect_h * 3, subrect_w, subrect_h); for (y = 0; y < BUF_HEIGHT; y++) { for (x = 0; x < BUF_WIDTH; x++) { float expected[4]; if (x >= subrect_w * 1 && x < subrect_w * 2 && y >= subrect_h * 1 && y < subrect_h * 2) { expected[0] = 1.0; expected[1] = 0.0; expected[2] = 0.0; expected[3] = 0.0; } else if (x >= subrect_w * 3 && x < subrect_w * 4 && y >= subrect_h * 1 && y < subrect_h * 2) { expected[0] = 0.0; expected[1] = 1.0; expected[2] = 0.0; expected[3] = 0.0; } else if (x >= subrect_w * 1 && x < subrect_w * 2 && y >= subrect_h * 3 && y < subrect_h * 4) { expected[0] = 0.0; expected[1] = 0.0; expected[2] = 1.0; expected[3] = 0.0; } else if (x >= subrect_w * 3 && x < subrect_w * 4 && y >= subrect_h * 3 && y < subrect_h * 4) { expected[0] = 0.0; expected[1] = 0.0; expected[2] = 0.0; expected[3] = 1.0; } else { expected[0] = 1.0; expected[1] = 0.0; expected[2] = 1.0; expected[3] = 0.0; } pass &= piglit_probe_pixel_rgb(x, y, expected); } } /* display the texture by drawing a quad */ glViewport(0, 0, piglit_width, piglit_height); piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); piglit_draw_rect_tex(results_x, results_y, BUF_WIDTH, BUF_HEIGHT, 0, 0, 1, 1); glDisable(GL_TEXTURE_2D); done: glDeleteFramebuffersEXT(1, &fb); glDeleteTextures(1, &tex); return pass; }
Texture3D::~Texture3D(){ glDeleteTextures(1, &_texture); }
void WebGraphicsContext3DDefaultImpl::deleteTexture(unsigned texture) { makeContextCurrent(); glDeleteTextures(1, &texture); }
textureCubeMap::~textureCubeMap() { assert( glGetError() == GL_NO_ERROR ); glDeleteTextures( 1, &textureId ); assert( glGetError() == GL_NO_ERROR ); }
Texture::~Texture() { glDeleteTextures(1, &m_location); }
void CShadowHandler::Init() { const bool tmpFirstInit = firstInit; firstInit = false; shadowConfig = configHandler->GetInt("Shadows"); shadowMapSize = configHandler->GetInt("ShadowMapSize"); shadowProMode = configHandler->GetInt("ShadowProjectionMode"); shadowGenBits = SHADOWGEN_BIT_NONE; shadowsLoaded = false; inShadowPass = false; shadowTexture = 0; dummyColorTexture = 0; if (!tmpFirstInit && !shadowsSupported) { return; } // possible values for the "Shadows" config-parameter: // < 0: disable and don't try to initialize // 0: disable, but still check if the hardware is able to run them // > 0: enabled (by default for all shadow-casting geometry if equal to 1) if (shadowConfig < 0) { LOG("[%s] shadow rendering is disabled (config-value %d)", __FUNCTION__, shadowConfig); return; } if (shadowConfig > 0) shadowGenBits = SHADOWGEN_BIT_MODEL | SHADOWGEN_BIT_MAP | SHADOWGEN_BIT_PROJ | SHADOWGEN_BIT_TREE; if (shadowConfig > 1) { shadowGenBits &= (~shadowConfig); } if (!globalRendering->haveARB && !globalRendering->haveGLSL) { LOG_L(L_WARNING, "[%s] GPU does not support either ARB or GLSL shaders for shadow rendering", __FUNCTION__); return; } if (!globalRendering->haveGLSL) { if (!GLEW_ARB_shadow || !GLEW_ARB_depth_texture || !GLEW_ARB_texture_env_combine) { LOG_L(L_WARNING, "[%s] required OpenGL ARB-extensions missing for shadow rendering", __FUNCTION__); // NOTE: these should only be relevant for FFP shadows // return; } if (!GLEW_ARB_shadow_ambient) { // can't use arbitrary texvals in case the depth comparison op fails (only 0) LOG_L(L_WARNING, "[%s] \"ARB_shadow_ambient\" extension missing (will probably make shadows darker than they should be)", __FUNCTION__); } } if (!InitDepthTarget()) { LOG_L(L_ERROR, "[%s] failed to initialize depth-texture FBO", __FUNCTION__); return; } if (tmpFirstInit) { shadowsSupported = true; } if (shadowConfig == 0) { // free any resources allocated by InitDepthTarget() glDeleteTextures(1, &shadowTexture ); shadowTexture = 0; glDeleteTextures(1, &dummyColorTexture); dummyColorTexture = 0; // shadowsLoaded is still false return; } LoadShadowGenShaderProgs(); }
int main(int argc, char *argv[]) { SDL_Surface *screen; // Slightly different SDL initialization if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed* if ( !screen ) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } // Set the OpenGL state after creating the context with SDL_SetVideoMode glClearColor( 0, 0, 0, 0 ); glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline. glViewport( 0, 0, 640, 480 ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); // just for testing glLoadIdentity(); glOrtho( 0, 640, 480, 0, -1000, 1000 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Load the OpenGL texture GLuint texture; // Texture object handle SDL_Surface *surface; // Gives us the information to make the texture if ( (surface = IMG_Load("screenshot.png")) ) { // Check that the image's width is a power of 2 if ( (surface->w & (surface->w - 1)) != 0 ) { printf("warning: image.bmp's width is not a power of 2\n"); } // Also check if the height is a power of 2 if ( (surface->h & (surface->h - 1)) != 0 ) { printf("warning: image.bmp's height is not a power of 2\n"); } // Have OpenGL generate a texture object handle for us glGenTextures( 1, &texture ); // Bind the texture object glBindTexture( GL_TEXTURE_2D, texture ); // Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); //SDL_LockSurface(surface); // Add some greyness memset(surface->pixels, 0x66, surface->w*surface->h); // Edit the texture object's image data using the information SDL_Surface gives us glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels ); //SDL_UnlockSurface(surface); } else { printf("SDL could not load image.bmp: %s\n", SDL_GetError()); SDL_Quit(); return 1; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); } // Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT ); // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture ); glEnable(GL_FOG); GLfloat fogColor[] = { 1.0, 0.5, 0.5, 0.05 }; glFogfv(GL_FOG_COLOR, fogColor); assert(glIsEnabled(GL_FOG)); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex3f( 10, 10, -1 ); glTexCoord2i( 1, 0 ); glVertex3f( 300, 10, -1 ); glTexCoord2i( 1, 1 ); glVertex3f( 300, 128, -1 ); glTexCoord2i( 0, 1 ); glVertex3f( 10, 128, -1 ); glTexCoord2f( 0, 0.5 ); glVertex3f( 410, 10, -5 ); glTexCoord2f( 1, 0.5 ); glVertex3f( 600, 10, -6 ); glTexCoord2f( 1, 1 ); glVertex3f( 630, 200, -7 ); glTexCoord2f( 0.5, 1 ); glVertex3f( 310, 250, -8 ); glEnd(); glBegin( GL_TRIANGLE_STRIP ); glTexCoord2i( 0, 0 ); glVertex3f( 100, 300, -1 ); glTexCoord2i( 1, 0 ); glVertex3f( 300, 300, -1 ); glTexCoord2i( 1, 1 ); glVertex3f( 300, 400, -1 ); glTexCoord2i( 0, 1 ); glVertex3f( 500, 410, -1 ); glEnd(); glDisable(GL_TEXTURE_2D); glColor3ub(90, 255, 255); glBegin( GL_QUADS ); glVertex3f( 10, 410, -5 ); glVertex3f( 300, 410, -50 ); glVertex3f( 300, 480, -100 ); glVertex3f( 10, 470, -5 ); glEnd(); glBegin( GL_QUADS ); glColor3f(1.0, 0, 1.0); glVertex3f( 410, 410, -10 ); glColor3f(0, 1.0, 0); glVertex3f( 600, 410, -10 ); glColor3f(0, 0, 1.0); glVertex3f( 600, 480, -10 ); glColor3f(1.0, 1.0, 1.0); glVertex3f( 410, 470, -10 ); glEnd(); SDL_GL_SwapBuffers(); #ifndef __EMSCRIPTEN__ // Wait for 3 seconds to give us a chance to see the image SDL_Delay(30000); #endif // Now we can delete the OpenGL texture and close down SDL glDeleteTextures( 1, &texture ); SDL_Quit(); return 0; }
void r_destroy_terrain(void) { glDeleteTextures(1, &r_hmap_tex); glDeleteBuffersARB(2, r_ter_VBOs); }
void deleteTexture(GLuint* tex){ glDeleteTextures(1, tex); *tex = (GLuint)NULL; }
static bool test_format(int width, int height, GLfloat *image, GLenum requested_format) { GLubyte *compressed_image; GLenum format2; int x, y, w, h; GLuint tex; bool pass = true; GLuint expected_size; GLint is_compressed; GLint compressed_size; GLint format; glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, width); /* Setup initial texture */ glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, requested_format, width, height, 0, GL_RGBA, GL_FLOAT, image); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; pass = check_rendering(width, height) && pass; glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED, &is_compressed); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; if (!is_compressed) { printf("Image was not compressed\n"); pass = false; } if (format != requested_format) { printf("Internal Format mismatch. Found: 0x%04x Expected: 0x%04x\n", format, requested_format); pass = false; } expected_size = piglit_compressed_image_size(requested_format, width, height); if (compressed_size != expected_size) { printf("Compressed image size mismatch. Found: %u Expected: %u\n", compressed_size, expected_size); pass = false; } /* Use GL_TEXTURE_COMPRESSED_IMAGE_SIZE even if it wasn't what we * expected to avoid corruption due to under-allocated buffer. */ compressed_image = malloc(compressed_size); /* Read back the compressed image data */ glGetCompressedTexImage(GL_TEXTURE_2D, 0, compressed_image); /* Try texsubimage on 4-texel boundary - should work */ x = 20; y = 12; w = 16; h = 8; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_FLOAT, image); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; pass = check_rendering(width, height) && pass; /* Try texsubimage on non 4-texel boundary - should not work */ x = 10; y = 11; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_FLOAT, image); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; /* Try compressed subimage on 4-texel boundary - should work */ x = 12; y = 8; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, piglit_compressed_image_size(format, w, h), compressed_image + piglit_compressed_pixel_offset(format, width, x, y)); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; pass = check_rendering(width, height) && pass; /* Try compressed subimage on non 4-texel boundary - should not work */ x = 14; y = 9; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, piglit_compressed_image_size(format, w, h), compressed_image + piglit_compressed_pixel_offset(format, width, 0, 0)); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; /* Try compressed subimage with size not a multiple of 4 - * should not work */ x = 8; y = 8; w = 14; h = 10; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, piglit_compressed_image_size(format, 4, 4), compressed_image + piglit_compressed_pixel_offset(format, width, x, y)); /* Note, we can get either of these errors depending on the order * in which glCompressedTexSubImage parameters are checked. * INVALID_OPERATION for the bad size or INVALID_VALUE for the * wrong compressed image size. */ pass = check_gl_error2(GL_INVALID_OPERATION, GL_INVALID_VALUE) && pass; /* Try compressed subimage with invalid offset - should not work */ x = -3; y = 8; w = 4; h = 4; glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, piglit_compressed_image_size(format, w, h), compressed_image + piglit_compressed_pixel_offset(format, width, 0, 0)); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; /* Try compressed subimage with too large of image - should not work */ x = 16; y = 8; w = width * 2; h = height * 2; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, piglit_compressed_image_size(format, w, h), compressed_image + piglit_compressed_pixel_offset(format, width, x, y)); pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass; /* Try compressed subimage with different format - should not work */ if (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) format2 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; else format2 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; x = 4; y = 4; w = 4; h = 4; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format2, piglit_compressed_image_size(format2, w, h), compressed_image + piglit_compressed_pixel_offset(format2, width, x, y)); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; /* Try zero-sized subimage - should not be an error */ x = 4; y = 4; w = 0; h = 0; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, piglit_compressed_image_size(format, w, h), compressed_image + piglit_compressed_pixel_offset(format, width, x, y)); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* Try CompressedTexSubImage into level 1 (which is missing) */ x = 0; y = 0; w = 4; h = 4; glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, x, y, w, h, format, piglit_compressed_image_size(format, w, h), compressed_image + piglit_compressed_pixel_offset(format, width, x, y)); pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; /* Try CompressedTexImage of size zero - should not be an erorr */ w = 0; h = 0; glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, piglit_compressed_image_size(format, w, h), compressed_image); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; /* Try CompressedTexImage with size which is a not a multiple of the * block size - should not be an erorr */ w = width - 1; h = height - 1; glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, piglit_compressed_image_size(format, w, h), compressed_image); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; pass = check_rendering(width, height) && pass; glDeleteTextures(1, &tex); free(compressed_image); return pass; }
inline void Destroy() { if (m_cubemapId) glDeleteTextures( 1, &m_cubemapId ); }
bool GBuffer::initialize( const Viewport& vp, bool multisample, int samples ) { int width =vp.width - vp.x; int height =vp.height - vp.y; /* First time initialize? */ if( !m_fbo ) { glEnable( GL_MULTISAMPLE ); glGenFramebuffers(1, &m_fbo); } else { glDeleteTextures( NUM_TEXTURES, m_textures); } glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo); // glRenderbufferStorageMultisample( GL_RENDERBUFFER, 2, GL_DEPTH24_STENCIL8, width, height ); glGenTextures( NUM_TEXTURES, m_textures ); /* Depth */ if( multisample ) { glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, m_textures[DEPTH_TEXTURE] ); glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT32F, width, height, false ); /* glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);*/ glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, m_textures[DEPTH_TEXTURE], 0 ); } else { glBindTexture(GL_TEXTURE_2D, m_textures[DEPTH_TEXTURE]); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_textures[DEPTH_TEXTURE], 0); } /* Diffuse + spec */ if( multisample ) { glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, m_textures[DIFFUSE_SPEC_TEXTURE] ); glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA16F, width, height, false ); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_textures[DIFFUSE_SPEC_TEXTURE], 0 ); } else { glBindTexture(GL_TEXTURE_2D, m_textures[DIFFUSE_SPEC_TEXTURE]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_textures[DIFFUSE_SPEC_TEXTURE], 0); } /* printf("GL error, status: 0x%x\n", glGetError());*/ /* Normals */ if( multisample ) { glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, m_textures[NORMAL_TEXTURE] ); glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB16F, width, height, false ); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, m_textures[NORMAL_TEXTURE], 0 ); } else { glBindTexture(GL_TEXTURE_2D, m_textures[NORMAL_TEXTURE]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_textures[NORMAL_TEXTURE], 0); } /* Position */ if( multisample ) { glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, m_textures[POSITION_TEXTURE] ); glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA16F, width, height, false ); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D_MULTISAMPLE, m_textures[POSITION_TEXTURE], 0 ); } else { glBindTexture(GL_TEXTURE_2D, m_textures[POSITION_TEXTURE]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_textures[POSITION_TEXTURE], 0); } GLenum DrawBuffers[] = { /*GL_DEPTH_ATTACHMENT, */GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2/*, GL_COLOR_ATTACHMENT3 */}; glDrawBuffers(NUM_TEXTURES-1, DrawBuffers); GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (Status != GL_FRAMEBUFFER_COMPLETE) { printf("FB error, status: 0x%x\n", Status); return false; } m_width =width; m_height =height; m_multisample =multisample; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); return true; }