Diligent Engine API Reference
TextureBaseGL.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
26 #include "BaseInterfacesGL.h"
27 #include "TextureGL.h"
28 #include "TextureBase.h"
29 #include "RenderDevice.h"
30 #include "GLObjectWrapper.h"
31 #include "TextureViewGLImpl.h"
32 #include "AsyncWritableResource.h"
33 
34 
35 namespace Diligent
36 {
37 
38 class FixedBlockMemoryAllocator;
39 
41 class TextureBaseGL : public TextureBase<ITextureGL, TextureViewGLImpl, FixedBlockMemoryAllocator>, public AsyncWritableResource
42 {
43 public:
45 
46  TextureBaseGL(IReferenceCounters *pRefCounters,
47  FixedBlockMemoryAllocator& TexViewObjAllocator,
48  class RenderDeviceGLImpl *pDeviceGL,
49  const TextureDesc &TexDesc,
50  GLenum BindTarget,
51  const TextureData &InitData = TextureData(),
52  bool bIsDeviceInternal = false);
53 
54  TextureBaseGL(IReferenceCounters *pRefCounters,
55  FixedBlockMemoryAllocator& TexViewObjAllocator,
56  class RenderDeviceGLImpl *pDeviceGL,
57  class DeviceContextGLImpl *pDeviceContext,
58  const TextureDesc& TexDesc,
59  GLuint GLTextureHandle,
60  GLenum BindTarget,
61  bool bIsDeviceInternal);
62 
63  ~TextureBaseGL();
64 
65  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
66 
67  virtual void UpdateData( class GLContextState &CtxState, IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData );
68 
69  //virtual void CopyData(CTexture *pSrcTexture, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size);
70  virtual void Map( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData )override;
71  virtual void Unmap( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )override;
72 
73  const GLObjectWrappers::GLTextureObj& GetGLHandle()const{ return m_GlTexture; }
74  virtual GLenum GetBindTarget()const override final{return m_BindTarget;}
75  GLenum GetGLTexFormat()const{ return m_GLTexFormat; }
76 
77  void TextureMemoryBarrier( Uint32 RequiredBarriers, class GLContextState &GLContextState);
78 
79  virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, GLenum AttachmentPoint) = 0;
80 
81  virtual void CopyData(IDeviceContext *pContext,
82  ITexture *pSrcTexture,
83  Uint32 SrcMipLevel,
84  Uint32 SrcSlice,
85  const Box *pSrcBox,
86  Uint32 DstMipLevel,
87  Uint32 DstSlice,
88  Uint32 DstX,
89  Uint32 DstY,
90  Uint32 DstZ)override;
91 
92  virtual GLuint GetGLTextureHandle()override final { return GetGLHandle(); }
93  virtual void* GetNativeHandle()override final { return reinterpret_cast<void*>(static_cast<size_t>(GetGLTextureHandle())); }
94 
95 protected:
96  virtual void CreateViewInternal( const struct TextureViewDesc &ViewDesc, class ITextureView **ppView, bool bIsDefaultView )override;
97  void SetDefaultGLParameters();
98 
99  GLObjectWrappers::GLTextureObj m_GlTexture;
100  const GLenum m_BindTarget;
101  const GLenum m_GLTexFormat;
102  //Uint32 m_uiMapTarget;
103 };
104 
105 }
Base implementation of the Diligent::ITextureGL interface.
Definition: TextureBaseGL.h:41
Texture description.
Definition: Texture.h:82
virtual void CopyData(IDeviceContext *pContext, ITexture *pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, Uint32 DstMipLevel, Uint32 DstSlice, Uint32 DstX, Uint32 DstY, Uint32 DstZ) override
Base implementaiton of ITexture::CopyData(); validates input parameters.
Definition: TextureBaseGL.cpp:312
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
virtual GLuint GetGLTextureHandle() override final
Returns OpenGL texture handle.
Definition: TextureBaseGL.h:92
Implementation of the Diligent::IDeviceContextGL interface.
Definition: DeviceContextGLImpl.h:35
virtual void Unmap(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags) override
Base implementaiton of ITexture::Unmap()
Definition: TextureBaseGL.cpp:446
Describes data for one subresource.
Definition: Texture.h:193
Implementation of the render device interface in OpenGL.
Definition: RenderDeviceGLImpl.h:53
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface) override
Queries the specific interface, see IObject::QueryInterface() for details.
Describes the initial data to store in the texture.
Definition: Texture.h:243
Device context interface.
Definition: DeviceContext.h:443
Box.
Definition: GraphicsTypes.h:1005
Texture view interface.
Definition: TextureView.h:163
virtual void Map(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData) override
Base implementaiton of ITexture::Map()
Definition: TextureBaseGL.cpp:440
virtual GLenum GetBindTarget() const override final
Returns bind target of the native OpenGL texture.
Definition: TextureBaseGL.h:74
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.h:50
Texture view description.
Definition: TextureView.h:55
virtual void * GetNativeHandle() override final
Returns native texture handle specific to the underlying graphics API.
Definition: TextureBaseGL.h:93
virtual void CreateViewInternal(const struct TextureViewDesc &ViewDesc, class ITextureView **ppView, bool bIsDefaultView) override
Pure virtual function that creates texture view for the specific engine implementation.
Definition: TextureBaseGL.cpp:159
Base implementation of the ITexture interface.
Definition: TextureBase.h:52
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125