diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-19 19:22:09 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-19 19:22:09 +0000 |
commit | 678a73f30774fadac146517a35d455bd30fb0541 (patch) | |
tree | 710ebb560bb49b0841b34cb4e3f59d3921cbbcc1 | |
parent | bb4960056dd79772d6156dd01759103cb039f7db (diff) | |
download | chromium_src-678a73f30774fadac146517a35d455bd30fb0541.zip chromium_src-678a73f30774fadac146517a35d455bd30fb0541.tar.gz chromium_src-678a73f30774fadac146517a35d455bd30fb0541.tar.bz2 |
Initialize offscreen texture to black.
This wasn't being initialized until the SwapBuffers, which meant that any draws from it before the first SwapBuffers would get garbage.
BUG=146449
Review URL: https://chromiumcodereview.appspot.com/11647004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173969 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 2d80b70..13ccc15 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -360,7 +360,7 @@ class Texture { void Create(); // Set the initial size and format of a render texture or resize it. - bool AllocateStorage(const gfx::Size& size, GLenum format); + bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); // Copy the contents of the currently bound frame buffer. void Copy(const gfx::Size& size, GLenum format); @@ -1774,7 +1774,8 @@ ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( DCHECK(decoder_->offscreen_saved_color_format_); decoder_->offscreen_resolved_color_texture_->AllocateStorage( - decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_); + decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, + false); decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( decoder_->offscreen_resolved_color_texture_.get()); if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != @@ -1862,10 +1863,21 @@ void Texture::Create() { memory_tracker_.TrackMemAlloc(bytes_allocated_); } -bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { +bool Texture::AllocateStorage(const gfx::Size& size, GLenum format, + bool zero) { DCHECK_NE(id_, 0u); ScopedGLErrorSuppressor suppressor(decoder_); ScopedTexture2DBinder binder(decoder_, id_); + uint32 image_size = 0; + GLES2Util::ComputeImageDataSizes( + size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, + NULL, NULL); + + scoped_array<char> zero_data; + if (zero) { + zero_data.reset(new char[image_size]); + memset(zero_data.get(), 0, image_size); + } WrappedTexImage2D(GL_TEXTURE_2D, 0, // mip level @@ -1875,16 +1887,12 @@ bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { 0, // border format, GL_UNSIGNED_BYTE, - NULL); + zero_data.get()); size_ = size; bool success = glGetError() == GL_NO_ERROR; if (success) { - uint32 image_size = 0; - GLES2Util::ComputeImageDataSizes( - size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, - NULL, NULL); memory_tracker_.TrackMemFree(bytes_allocated_); bytes_allocated_ = image_size; memory_tracker_.TrackMemAlloc(bytes_allocated_); @@ -2356,6 +2364,20 @@ bool GLES2DecoderImpl::Initialize( return false; } + // Allocate the offscreen saved color texture. + DCHECK(offscreen_saved_color_format_); + offscreen_saved_color_texture_->AllocateStorage( + gfx::Size(1, 1), offscreen_saved_color_format_, true); + + offscreen_saved_frame_buffer_->AttachRenderTexture( + offscreen_saved_color_texture_.get()); + if (offscreen_saved_frame_buffer_->CheckStatus() != + GL_FRAMEBUFFER_COMPLETE) { + LOG(ERROR) << "Offscreen saved FBO was incomplete."; + Destroy(true); + return false; + } + // Bind to the new default frame buffer (the offscreen target frame buffer). // This should now be associated with ID zero. DoBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -3218,7 +3240,7 @@ bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { } } else { if (!offscreen_target_color_texture_->AllocateStorage( - offscreen_size_, offscreen_target_color_format_)) { + offscreen_size_, offscreen_target_color_format_, false)) { LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " << "to allocate storage for offscreen target color texture."; return false; @@ -8591,7 +8613,7 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers( // Allocate the offscreen saved color texture. DCHECK(offscreen_saved_color_format_); offscreen_saved_color_texture_->AllocateStorage( - offscreen_size_, offscreen_saved_color_format_); + offscreen_size_, offscreen_saved_color_format_, false); offscreen_saved_frame_buffer_->AttachRenderTexture( offscreen_saved_color_texture_.get()); |