| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/gpu/gl_texture.h" | 5 #include "mojo/gpu/gl_texture.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 | 8 |
| 9 namespace mojo { | 9 namespace mojo { |
| 10 | 10 |
| 11 GLTexture::GLTexture(base::WeakPtr<GLContext> context, mojo::Size size) | 11 GLTexture::GLTexture(base::WeakPtr<GLContext> context, mojo::Size size) |
| 12 : context_(context), size_(size), texture_id_(0u) { | 12 : context_(context), size_(size), texture_id_(0u) { |
| 13 DCHECK(context_); | 13 DCHECK(context_); |
| 14 context_->MakeCurrent(); | 14 context_->MakeCurrent(); |
| 15 glGenTextures(1, &texture_id_); | 15 glGenTextures(1, &texture_id_); |
| 16 glBindTexture(GL_TEXTURE_2D, texture_id_); | 16 glBindTexture(GL_TEXTURE_2D, texture_id_); |
| 17 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width, size_.height, 0, GL_RGBA, | 17 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width, size_.height, 0, GL_RGBA, |
| 18 GL_UNSIGNED_BYTE, 0); | 18 GL_UNSIGNED_BYTE, 0); |
| 19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 20 glBindTexture(GL_TEXTURE_2D, 0); |
| 20 } | 21 } |
| 21 | 22 |
| 22 GLTexture::~GLTexture() { | 23 GLTexture::~GLTexture() { |
| 23 if (context_) { | 24 if (context_) { |
| 24 context_->MakeCurrent(); | 25 context_->MakeCurrent(); |
| 25 glDeleteTextures(1, &texture_id_); | 26 glDeleteTextures(1, &texture_id_); |
| 26 } | 27 } |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace mojo | 30 } // namespace mojo |
| OLD | NEW |