Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 ref_->texture()->OnWillModifyPixels(); | 408 ref_->texture()->OnWillModifyPixels(); |
| 409 } | 409 } |
| 410 | 410 |
| 411 ScopedModifyPixels::~ScopedModifyPixels() { | 411 ScopedModifyPixels::~ScopedModifyPixels() { |
| 412 if (ref_) | 412 if (ref_) |
| 413 ref_->texture()->OnDidModifyPixels(); | 413 ref_->texture()->OnDidModifyPixels(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 class ScopedRenderTo { | 416 class ScopedRenderTo { |
| 417 public: | 417 public: |
| 418 explicit ScopedRenderTo(Framebuffer* framebuffer); | 418 explicit ScopedRenderTo(Framebuffer* framebuffer) |
| 419 : ScopedRenderTo(framebuffer, 0) {} | |
| 420 ScopedRenderTo(Framebuffer* framebuffer, GLenum attachment); | |
| 419 ~ScopedRenderTo(); | 421 ~ScopedRenderTo(); |
| 420 | 422 |
| 421 private: | 423 private: |
| 422 const Framebuffer* framebuffer_; | 424 const Framebuffer* framebuffer_; |
| 425 GLenum attachment_; | |
| 423 }; | 426 }; |
| 424 | 427 |
| 425 ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer) | 428 ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer, GLenum attachment) |
| 426 : framebuffer_(framebuffer) { | 429 : framebuffer_(framebuffer), |
| 427 if (framebuffer) | 430 attachment_(attachment) { |
| 428 framebuffer_->OnWillRenderTo(); | 431 if (framebuffer_) |
| 432 framebuffer_->OnWillRenderTo(attachment_); | |
| 429 } | 433 } |
| 430 | 434 |
| 431 ScopedRenderTo::~ScopedRenderTo() { | 435 ScopedRenderTo::~ScopedRenderTo() { |
| 432 if (framebuffer_) | 436 if (framebuffer_) |
| 433 framebuffer_->OnDidRenderTo(); | 437 framebuffer_->OnDidRenderTo(attachment_); |
| 434 } | 438 } |
| 435 | 439 |
| 436 // Encapsulates an OpenGL texture. | 440 // Encapsulates an OpenGL texture. |
| 437 class BackTexture { | 441 class BackTexture { |
| 438 public: | 442 public: |
| 439 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); | 443 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
| 440 ~BackTexture(); | 444 ~BackTexture(); |
| 441 | 445 |
| 442 // Create a new render texture. | 446 // Create a new render texture. |
| 443 void Create(); | 447 void Create(); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 // Get the size (in pixels) of the currently bound frame buffer (either FBO | 902 // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 899 // or regular back buffer). | 903 // or regular back buffer). |
| 900 gfx::Size GetBoundReadFrameBufferSize(); | 904 gfx::Size GetBoundReadFrameBufferSize(); |
| 901 | 905 |
| 902 // Get the format/type of the currently bound frame buffer (either FBO or | 906 // Get the format/type of the currently bound frame buffer (either FBO or |
| 903 // regular back buffer). | 907 // regular back buffer). |
| 904 // If the color image is a renderbuffer, returns 0 for type. | 908 // If the color image is a renderbuffer, returns 0 for type. |
| 905 GLenum GetBoundReadFrameBufferTextureType(); | 909 GLenum GetBoundReadFrameBufferTextureType(); |
| 906 GLenum GetBoundReadFrameBufferInternalFormat(); | 910 GLenum GetBoundReadFrameBufferInternalFormat(); |
| 907 | 911 |
| 912 // Get the i-th draw buffer's internal format from the bound framebuffer. | |
| 913 // If no framebuffer is bound, or no image is attached, or the DrawBuffers | |
| 914 // setting for that image is GL_NONE, return 0. | |
| 915 GLenum GetBoundColorDrawBufferInternalFormat(GLint drawbuffer_i); | |
| 916 | |
| 917 void MarkDrawBufferAsCleared(GLenum buffer, GLint drawbuffer_i); | |
| 918 | |
| 908 // Wrapper for CompressedTexImage2D commands. | 919 // Wrapper for CompressedTexImage2D commands. |
| 909 error::Error DoCompressedTexImage2D( | 920 error::Error DoCompressedTexImage2D( |
| 910 GLenum target, | 921 GLenum target, |
| 911 GLint level, | 922 GLint level, |
| 912 GLenum internal_format, | 923 GLenum internal_format, |
| 913 GLsizei width, | 924 GLsizei width, |
| 914 GLsizei height, | 925 GLsizei height, |
| 915 GLint border, | 926 GLint border, |
| 916 GLsizei image_size, | 927 GLsizei image_size, |
| 917 const void* data); | 928 const void* data); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1447 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, | 1458 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1448 GLbitfield mask, GLenum filter); | 1459 GLbitfield mask, GLenum filter); |
| 1449 | 1460 |
| 1450 // Wrapper for glBufferSubData. | 1461 // Wrapper for glBufferSubData. |
| 1451 void DoBufferSubData( | 1462 void DoBufferSubData( |
| 1452 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); | 1463 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1453 | 1464 |
| 1454 // Wrapper for glCheckFramebufferStatus | 1465 // Wrapper for glCheckFramebufferStatus |
| 1455 GLenum DoCheckFramebufferStatus(GLenum target); | 1466 GLenum DoCheckFramebufferStatus(GLenum target); |
| 1456 | 1467 |
| 1457 // Wrapper for glClear | 1468 // Wrapper for glClear*() |
| 1458 error::Error DoClear(GLbitfield mask); | 1469 error::Error DoClear(GLbitfield mask); |
| 1470 void DoClearBufferiv( | |
| 1471 GLenum buffer, GLint drawbuffer, const GLint* value); | |
| 1472 void DoClearBufferuiv( | |
| 1473 GLenum buffer, GLint drawbuffer, const GLuint* value); | |
| 1474 void DoClearBufferfv( | |
| 1475 GLenum buffer, GLint drawbuffer, const GLfloat* value); | |
| 1476 void DoClearBufferfi( | |
| 1477 GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); | |
| 1459 | 1478 |
| 1460 // Wrappers for various state. | 1479 // Wrappers for various state. |
| 1461 void DoDepthRangef(GLclampf znear, GLclampf zfar); | 1480 void DoDepthRangef(GLclampf znear, GLclampf zfar); |
| 1462 void DoSampleCoverage(GLclampf value, GLboolean invert); | 1481 void DoSampleCoverage(GLclampf value, GLboolean invert); |
| 1463 | 1482 |
| 1464 // Wrapper for glCompileShader. | 1483 // Wrapper for glCompileShader. |
| 1465 void DoCompileShader(GLuint shader); | 1484 void DoCompileShader(GLuint shader); |
| 1466 | 1485 |
| 1467 // Wrapper for glDetachShader | 1486 // Wrapper for glDetachShader |
| 1468 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); | 1487 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| (...skipping 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3819 } else { // Back buffer. | 3838 } else { // Back buffer. |
| 3820 if (back_buffer_read_buffer_ == GL_NONE) | 3839 if (back_buffer_read_buffer_ == GL_NONE) |
| 3821 return 0; | 3840 return 0; |
| 3822 if (offscreen_target_frame_buffer_.get()) { | 3841 if (offscreen_target_frame_buffer_.get()) { |
| 3823 return offscreen_target_color_format_; | 3842 return offscreen_target_color_format_; |
| 3824 } | 3843 } |
| 3825 return back_buffer_color_format_; | 3844 return back_buffer_color_format_; |
| 3826 } | 3845 } |
| 3827 } | 3846 } |
| 3828 | 3847 |
| 3848 GLenum GLES2DecoderImpl::GetBoundColorDrawBufferInternalFormat( | |
| 3849 GLint drawbuffer_i) { | |
| 3850 DCHECK(drawbuffer_i >= 0 && | |
| 3851 drawbuffer_i < static_cast<GLint>(group_->max_draw_buffers())); | |
| 3852 Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER); | |
| 3853 if (!framebuffer) { | |
| 3854 return 0; | |
| 3855 } | |
| 3856 GLenum drawbuffer = static_cast<GLenum>(GL_DRAW_BUFFER0 + drawbuffer_i); | |
| 3857 if (framebuffer->GetDrawBuffer(drawbuffer) == GL_NONE) { | |
| 3858 return 0; | |
| 3859 } | |
| 3860 GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer_i); | |
| 3861 const Framebuffer::Attachment* buffer = | |
| 3862 framebuffer->GetAttachment(attachment); | |
| 3863 if (!buffer) { | |
| 3864 return 0; | |
| 3865 } | |
| 3866 return buffer->internal_format(); | |
| 3867 } | |
| 3868 | |
| 3869 void GLES2DecoderImpl::MarkDrawBufferAsCleared( | |
| 3870 GLenum buffer, GLint drawbuffer_i) { | |
| 3871 Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER); | |
| 3872 if (!framebuffer) | |
| 3873 return; | |
| 3874 GLenum attachment = 0; | |
| 3875 switch (buffer) { | |
| 3876 case GL_COLOR: | |
| 3877 DCHECK(drawbuffer_i >= 0 && | |
| 3878 drawbuffer_i < static_cast<GLint>(group_->max_draw_buffers())); | |
| 3879 attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer_i); | |
| 3880 break; | |
| 3881 case GL_DEPTH: | |
| 3882 attachment = GL_DEPTH; | |
| 3883 break; | |
| 3884 case GL_STENCIL: | |
| 3885 attachment = GL_STENCIL; | |
| 3886 break; | |
| 3887 default: | |
| 3888 // Caller is responsible for breaking GL_DEPTH_STENCIL into GL_DEPTH and | |
| 3889 // GL_STENCIL. | |
| 3890 NOTREACHED(); | |
| 3891 } | |
| 3892 framebuffer->MarkAttachmentAsCleared( | |
| 3893 renderbuffer_manager(), texture_manager(), attachment, true); | |
| 3894 } | |
| 3895 | |
| 3829 void GLES2DecoderImpl::UpdateParentTextureInfo() { | 3896 void GLES2DecoderImpl::UpdateParentTextureInfo() { |
| 3830 if (!offscreen_saved_color_texture_info_.get()) | 3897 if (!offscreen_saved_color_texture_info_.get()) |
| 3831 return; | 3898 return; |
| 3832 GLenum target = offscreen_saved_color_texture_info_->texture()->target(); | 3899 GLenum target = offscreen_saved_color_texture_info_->texture()->target(); |
| 3833 glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); | 3900 glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); |
| 3834 texture_manager()->SetLevelInfo( | 3901 texture_manager()->SetLevelInfo( |
| 3835 offscreen_saved_color_texture_info_.get(), GL_TEXTURE_2D, | 3902 offscreen_saved_color_texture_info_.get(), GL_TEXTURE_2D, |
| 3836 0, // level | 3903 0, // level |
| 3837 GL_RGBA, offscreen_size_.width(), offscreen_size_.height(), | 3904 GL_RGBA, offscreen_size_.width(), offscreen_size_.height(), |
| 3838 1, // depth | 3905 1, // depth |
| (...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5654 GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); | 5721 GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
| 5655 } | 5722 } |
| 5656 } | 5723 } |
| 5657 return error::kNoError; | 5724 return error::kNoError; |
| 5658 } | 5725 } |
| 5659 | 5726 |
| 5660 error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { | 5727 error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
| 5661 DCHECK(!ShouldDeferDraws()); | 5728 DCHECK(!ShouldDeferDraws()); |
| 5662 if (CheckBoundFramebuffersValid("glClear")) { | 5729 if (CheckBoundFramebuffersValid("glClear")) { |
| 5663 ApplyDirtyState(); | 5730 ApplyDirtyState(); |
| 5731 // TODO(zmo): Filter out INTEGER/SIGNED INTEGER images to avoid | |
| 5732 // undefined results. | |
| 5664 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); | 5733 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
| 5665 if (workarounds().gl_clear_broken) { | 5734 if (workarounds().gl_clear_broken) { |
| 5666 ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", | 5735 ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", |
| 5667 GetErrorState()); | 5736 GetErrorState()); |
| 5668 if (!BoundFramebufferHasDepthAttachment()) | 5737 if (!BoundFramebufferHasDepthAttachment()) |
| 5669 mask &= ~GL_DEPTH_BUFFER_BIT; | 5738 mask &= ~GL_DEPTH_BUFFER_BIT; |
| 5670 if (!BoundFramebufferHasStencilAttachment()) | 5739 if (!BoundFramebufferHasStencilAttachment()) |
| 5671 mask &= ~GL_STENCIL_BUFFER_BIT; | 5740 mask &= ~GL_STENCIL_BUFFER_BIT; |
| 5672 clear_framebuffer_blit_->ClearFramebuffer( | 5741 clear_framebuffer_blit_->ClearFramebuffer( |
| 5673 this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, | 5742 this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, |
| 5674 state_.color_clear_green, state_.color_clear_blue, | 5743 state_.color_clear_green, state_.color_clear_blue, |
| 5675 state_.color_clear_alpha, state_.depth_clear, state_.stencil_clear); | 5744 state_.color_clear_alpha, state_.depth_clear, state_.stencil_clear); |
| 5676 return error::kNoError; | 5745 return error::kNoError; |
| 5677 } | 5746 } |
| 5678 glClear(mask); | 5747 glClear(mask); |
| 5679 } | 5748 } |
| 5680 return error::kNoError; | 5749 return error::kNoError; |
| 5681 } | 5750 } |
| 5682 | 5751 |
| 5752 void GLES2DecoderImpl::DoClearBufferiv( | |
| 5753 GLenum buffer, GLint drawbuffer, const GLint* value) { | |
| 5754 if (!CheckBoundFramebuffersValid("glClearBufferiv")) | |
| 5755 return; | |
| 5756 ApplyDirtyState(); | |
| 5757 | |
| 5758 switch (buffer) { | |
| 5759 case GL_COLOR: | |
| 5760 case GL_STENCIL: | |
| 5761 break; | |
| 5762 default: | |
| 5763 LOCAL_SET_GL_ERROR( | |
| 5764 GL_INVALID_ENUM, "glClearBufferiv", "invalid buffer"); | |
| 5765 return; | |
| 5766 } | |
| 5767 GLenum attachment = 0; | |
| 5768 if (buffer == GL_COLOR) { | |
| 5769 if (drawbuffer < 0 || | |
| 5770 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { | |
| 5771 LOCAL_SET_GL_ERROR( | |
| 5772 GL_INVALID_VALUE, "glClearBufferiv", "invalid drawBuffer"); | |
| 5773 return; | |
| 5774 } | |
| 5775 GLenum internal_format = | |
| 5776 GetBoundColorDrawBufferInternalFormat(drawbuffer); | |
| 5777 if (!GLES2Util::IsSignedIntegerFormat(internal_format)) { | |
| 5778 // To avoid undefined results, return without calling the gl function. | |
|
Ken Russell (switch to Gerrit)
2015/08/24 23:16:13
Here and throughout, I guess we're silently failin
Zhenyao Mo
2015/08/24 23:39:25
No, we are silently passing through, no error gene
| |
| 5779 return; | |
| 5780 } | |
| 5781 attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer); | |
| 5782 } else { | |
| 5783 DCHECK(buffer == GL_STENCIL); | |
| 5784 if (drawbuffer != 0) { | |
| 5785 LOCAL_SET_GL_ERROR( | |
| 5786 GL_INVALID_VALUE, "glClearBufferiv", "invalid drawBuffer"); | |
| 5787 return; | |
| 5788 } | |
| 5789 if (!BoundFramebufferHasStencilAttachment()) { | |
| 5790 return; | |
| 5791 } | |
| 5792 attachment = GL_STENCIL_ATTACHMENT; | |
| 5793 } | |
| 5794 MarkDrawBufferAsCleared(buffer, drawbuffer); | |
| 5795 { | |
| 5796 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get(), | |
| 5797 attachment); | |
| 5798 glClearBufferiv(buffer, drawbuffer, value); | |
| 5799 } | |
| 5800 } | |
| 5801 | |
| 5802 void GLES2DecoderImpl::DoClearBufferuiv( | |
| 5803 GLenum buffer, GLint drawbuffer, const GLuint* value) { | |
| 5804 if (!CheckBoundFramebuffersValid("glClearBufferuiv")) | |
| 5805 return; | |
| 5806 ApplyDirtyState(); | |
| 5807 | |
| 5808 switch (buffer) { | |
| 5809 case GL_COLOR: | |
| 5810 break; | |
| 5811 default: | |
| 5812 LOCAL_SET_GL_ERROR( | |
| 5813 GL_INVALID_ENUM, "glClearBufferuiv", "invalid buffer"); | |
| 5814 return; | |
| 5815 } | |
| 5816 if (drawbuffer < 0 || | |
| 5817 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { | |
| 5818 LOCAL_SET_GL_ERROR( | |
| 5819 GL_INVALID_VALUE, "glClearBufferuiv", "invalid drawBuffer"); | |
| 5820 return; | |
| 5821 } | |
| 5822 GLenum internal_format = | |
| 5823 GetBoundColorDrawBufferInternalFormat(drawbuffer); | |
| 5824 if (!GLES2Util::IsUnsignedIntegerFormat(internal_format)) { | |
| 5825 // To avoid undefined results, return without calling the gl function. | |
| 5826 return; | |
| 5827 } | |
| 5828 MarkDrawBufferAsCleared(buffer, drawbuffer); | |
| 5829 GLenum attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer); | |
| 5830 { | |
| 5831 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get(), | |
| 5832 attachment); | |
| 5833 glClearBufferuiv(buffer, drawbuffer, value); | |
| 5834 } | |
| 5835 } | |
| 5836 | |
| 5837 void GLES2DecoderImpl::DoClearBufferfv( | |
| 5838 GLenum buffer, GLint drawbuffer, const GLfloat* value) { | |
| 5839 if (!CheckBoundFramebuffersValid("glClearBufferfv")) | |
| 5840 return; | |
| 5841 ApplyDirtyState(); | |
| 5842 | |
| 5843 switch (buffer) { | |
| 5844 case GL_COLOR: | |
| 5845 case GL_DEPTH: | |
| 5846 break; | |
| 5847 default: | |
| 5848 LOCAL_SET_GL_ERROR( | |
| 5849 GL_INVALID_ENUM, "glClearBufferfv", "invalid buffer"); | |
| 5850 return; | |
| 5851 } | |
| 5852 GLenum attachment = 0; | |
| 5853 if (buffer == GL_COLOR) { | |
| 5854 if (drawbuffer < 0 || | |
| 5855 drawbuffer >= static_cast<GLint>(group_->max_draw_buffers())) { | |
| 5856 LOCAL_SET_GL_ERROR( | |
| 5857 GL_INVALID_VALUE, "glClearBufferfv", "invalid drawBuffer"); | |
| 5858 return; | |
| 5859 } | |
| 5860 GLenum internal_format = | |
| 5861 GetBoundColorDrawBufferInternalFormat(drawbuffer); | |
| 5862 if (GLES2Util::IsIntegerFormat(internal_format)) { | |
| 5863 // To avoid undefined results, return without calling the gl function. | |
| 5864 return; | |
| 5865 } | |
| 5866 attachment = static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + drawbuffer); | |
| 5867 } else { | |
| 5868 DCHECK(buffer == GL_DEPTH); | |
| 5869 if (drawbuffer != 0) { | |
| 5870 LOCAL_SET_GL_ERROR( | |
| 5871 GL_INVALID_VALUE, "glClearBufferfv", "invalid drawBuffer"); | |
| 5872 return; | |
| 5873 } | |
| 5874 if (!BoundFramebufferHasDepthAttachment()) { | |
| 5875 return; | |
| 5876 } | |
| 5877 attachment = GL_DEPTH_ATTACHMENT; | |
| 5878 } | |
| 5879 MarkDrawBufferAsCleared(buffer, drawbuffer); | |
| 5880 { | |
| 5881 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get(), | |
| 5882 attachment); | |
| 5883 glClearBufferfv(buffer, drawbuffer, value); | |
| 5884 } | |
| 5885 } | |
| 5886 | |
| 5887 void GLES2DecoderImpl::DoClearBufferfi( | |
| 5888 GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { | |
| 5889 if (!CheckBoundFramebuffersValid("glClearBufferfi")) | |
| 5890 return; | |
| 5891 ApplyDirtyState(); | |
| 5892 | |
| 5893 switch (buffer) { | |
| 5894 case GL_DEPTH_STENCIL: | |
| 5895 break; | |
| 5896 default: | |
| 5897 LOCAL_SET_GL_ERROR( | |
| 5898 GL_INVALID_ENUM, "glClearBufferfi", "invalid buffer"); | |
| 5899 return; | |
| 5900 } | |
| 5901 if (drawbuffer != 0) { | |
| 5902 LOCAL_SET_GL_ERROR( | |
| 5903 GL_INVALID_VALUE, "glClearBufferfi", "invalid drawBuffer"); | |
| 5904 return; | |
| 5905 } | |
| 5906 if (!BoundFramebufferHasDepthAttachment() && | |
| 5907 !BoundFramebufferHasStencilAttachment()) { | |
| 5908 return; | |
| 5909 } | |
| 5910 MarkDrawBufferAsCleared(GL_DEPTH, drawbuffer); | |
| 5911 MarkDrawBufferAsCleared(GL_STENCIL, drawbuffer); | |
| 5912 { | |
| 5913 ScopedRenderTo do_render_depth( | |
| 5914 framebuffer_state_.bound_draw_framebuffer.get(), | |
| 5915 GL_DEPTH_ATTACHMENT); | |
| 5916 ScopedRenderTo do_render_stencil( | |
| 5917 framebuffer_state_.bound_draw_framebuffer.get(), | |
| 5918 GL_STENCIL_ATTACHMENT); | |
| 5919 glClearBufferfi(buffer, drawbuffer, depth, stencil); | |
| 5920 } | |
| 5921 } | |
| 5922 | |
| 5683 void GLES2DecoderImpl::DoFramebufferRenderbuffer( | 5923 void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 5684 GLenum target, GLenum attachment, GLenum renderbuffertarget, | 5924 GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 5685 GLuint client_renderbuffer_id) { | 5925 GLuint client_renderbuffer_id) { |
| 5686 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); | 5926 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5687 if (!framebuffer) { | 5927 if (!framebuffer) { |
| 5688 LOCAL_SET_GL_ERROR( | 5928 LOCAL_SET_GL_ERROR( |
| 5689 GL_INVALID_OPERATION, | 5929 GL_INVALID_OPERATION, |
| 5690 "glFramebufferRenderbuffer", "no framebuffer bound"); | 5930 "glFramebufferRenderbuffer", "no framebuffer bound"); |
| 5691 return; | 5931 return; |
| 5692 } | 5932 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5751 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); | 5991 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 5752 } | 5992 } |
| 5753 GLbitfield clear_bits = 0; | 5993 GLbitfield clear_bits = 0; |
| 5754 if (framebuffer->HasUnclearedColorAttachments()) { | 5994 if (framebuffer->HasUnclearedColorAttachments()) { |
| 5755 // We should always use alpha == 0 here, because 1) some draw buffers may | 5995 // We should always use alpha == 0 here, because 1) some draw buffers may |
| 5756 // have alpha and some may not; 2) we won't have the same situation as the | 5996 // have alpha and some may not; 2) we won't have the same situation as the |
| 5757 // back buffer where alpha channel exists but is not requested. | 5997 // back buffer where alpha channel exists but is not requested. |
| 5758 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | 5998 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 5759 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 5999 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 5760 clear_bits |= GL_COLOR_BUFFER_BIT; | 6000 clear_bits |= GL_COLOR_BUFFER_BIT; |
| 5761 if (feature_info_->feature_flags().ext_draw_buffers) | 6001 if (feature_info_->feature_flags().ext_draw_buffers || |
| 6002 feature_info_->IsES3Enabled()) { | |
| 5762 framebuffer->PrepareDrawBuffersForClear(); | 6003 framebuffer->PrepareDrawBuffersForClear(); |
| 6004 } | |
| 5763 } | 6005 } |
| 5764 | 6006 |
| 5765 if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || | 6007 if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 5766 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { | 6008 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 5767 glClearStencil(0); | 6009 glClearStencil(0); |
| 5768 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); | 6010 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 5769 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); | 6011 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
| 5770 clear_bits |= GL_STENCIL_BUFFER_BIT; | 6012 clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 5771 } | 6013 } |
| 5772 | 6014 |
| 5773 if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || | 6015 if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 5774 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { | 6016 framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 5775 glClearDepth(1.0f); | 6017 glClearDepth(1.0f); |
| 5776 state_.SetDeviceDepthMask(GL_TRUE); | 6018 state_.SetDeviceDepthMask(GL_TRUE); |
| 5777 clear_bits |= GL_DEPTH_BUFFER_BIT; | 6019 clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 5778 } | 6020 } |
| 5779 | 6021 |
| 5780 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); | 6022 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
| 5781 glClear(clear_bits); | 6023 glClear(clear_bits); |
| 5782 | 6024 |
| 5783 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0 && | 6025 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0 && |
| 5784 feature_info_->feature_flags().ext_draw_buffers) | 6026 (feature_info_->feature_flags().ext_draw_buffers || |
| 6027 feature_info_->IsES3Enabled())) { | |
| 5785 framebuffer->RestoreDrawBuffersAfterClear(); | 6028 framebuffer->RestoreDrawBuffersAfterClear(); |
| 6029 } | |
| 6030 | |
| 6031 if (feature_info_->IsES3Enabled()) { | |
| 6032 framebuffer->ClearIntegerBuffers(); | |
|
Ken Russell (switch to Gerrit)
2015/08/24 23:16:13
Is it worth tracking more state to know whether th
Zhenyao Mo
2015/08/24 23:39:25
Good point. I'll revise accordingly.
Zhenyao Mo
2015/08/25 02:17:28
Actually it is no trivia code, so I'll do it in a
Ken Russell (switch to Gerrit)
2015/08/25 02:18:38
Sounds fine. If it adds more complexity than it's
| |
| 6033 } | |
| 5786 | 6034 |
| 5787 framebuffer_manager()->MarkAttachmentsAsCleared( | 6035 framebuffer_manager()->MarkAttachmentsAsCleared( |
| 5788 framebuffer, renderbuffer_manager(), texture_manager()); | 6036 framebuffer, renderbuffer_manager(), texture_manager()); |
| 5789 | 6037 |
| 5790 RestoreClearState(); | 6038 RestoreClearState(); |
| 5791 | 6039 |
| 5792 if (target == GL_READ_FRAMEBUFFER_EXT) { | 6040 if (target == GL_READ_FRAMEBUFFER_EXT) { |
| 5793 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); | 6041 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 5794 Framebuffer* draw_framebuffer = | 6042 Framebuffer* draw_framebuffer = |
| 5795 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); | 6043 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| (...skipping 8987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14783 return error::kNoError; | 15031 return error::kNoError; |
| 14784 } | 15032 } |
| 14785 | 15033 |
| 14786 // Include the auto-generated part of this file. We split this because it means | 15034 // Include the auto-generated part of this file. We split this because it means |
| 14787 // we can easily edit the non-auto generated parts right here in this file | 15035 // we can easily edit the non-auto generated parts right here in this file |
| 14788 // instead of having to edit some template or the code generator. | 15036 // instead of having to edit some template or the code generator. |
| 14789 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15037 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 14790 | 15038 |
| 14791 } // namespace gles2 | 15039 } // namespace gles2 |
| 14792 } // namespace gpu | 15040 } // namespace gpu |
| OLD | NEW |