blob: 60534f7a98823001fded496ebcc16e2f37d7819e [file] [log] [blame]
* Copyright 2015 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
#include "glimp/egl/surface.h"
#include "glimp/gles/buffer.h"
#include "glimp/gles/pixel_format.h"
#include "glimp/gles/shader.h"
#include "nb/rect.h"
#include "nb/ref_counted.h"
namespace glimp {
namespace gles {
class TextureImpl {
virtual ~TextureImpl() {}
// Specifies texture parameters necessary to allocate texture data within
// this texture. This method must be called before pixel data can be
// provided to the texture via UpdateData*() methods. If |width| == 0,
// the texture should be placed in an uninitialized state where UpdateData*()
// methods are invalid.
// This method is called when glTexImage2D() is called.
virtual void Initialize(int level,
PixelFormat pixel_format,
int width,
int height) = 0;
// Called when glTexImage2D() is called with non-null pixels, or when
// glTexSubImage2D() or glCopyTexSubImage2D() is called. Updates an already
// allocated texture with new texture data provided by the client. The
// parameters of this method define a window within the existing texture
// data of which should be updated with the provided (non-NULL) |pixels|.
// The provided |pitch_in_bytes| refers to the input data pixel rows.
// This function will return true if successful, false if memory allocation
// failed.
virtual bool UpdateData(int level,
const nb::Rect<int>& window,
int pitch_in_bytes,
const void* pixels) = 0;
// Similar to UpdateData() above, however the source of pixels in this case
// is a buffer object, and an offset into it. This method will be called
// when glTexImage2D() or glTexSubImage2D() is called while a buffer is bound
// to the GL_PIXEL_UNPACK_BUFFER target.
virtual void UpdateDataFromBuffer(
int level,
const nb::Rect<int>& window,
int pitch_in_bytes,
const nb::scoped_refptr<Buffer>& pixel_unpack_buffer,
uintptr_t buffer_offset) = 0;
// Called when eglBindTexImage() is called. When this occurs, the texture
// should configure itself to point at the same data as the passed in
// egl::Surface is pointing to, so that the egl::Surface can effectively be
// referenced as a texture. This method should clear out any existing image
// data in the texture when it is called. When eglReleaseTexImage() is
// called, TextureImpl::Initialize() will be called with |width| = 0 to reset
// this texture.
virtual void BindToEGLSurface(egl::Surface* surface) = 0;
// This is called when glReadPixels() is called. The
virtual void ReadPixelsAsRGBA8(const nb::Rect<int>& window,
int pitch_in_bytes,
void* pixels) = 0;
// Returns true if this texture is valid for use as a Framebuffer color
// attachment. In other words, this should return true if the texture can
// be used as a render target. This method is called when the function
// glCheckFramebufferStatus() is called on a framebuffer that has this
// texture attached to it.
virtual bool CanBeAttachedToFramebuffer() const = 0;
} // namespace gles
} // namespace glimp