NCBI C++ ToolKit
mtldata.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_OPENGL___MTL_DATA__HPP
2 #define GUI_OPENGL___MTL_DATA__HPP
3 
4 /* $Id: mtldata.hpp 43570 2019-08-01 15:39:31Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Roman Katargin
30  *
31  * File Description:
32  *
33  */
34 
35 #include <gui/opengl.h>
36 #include <gui/gui.hpp>
37 
38 #import <Cocoa/Cocoa.h>
39 #import <Metal/Metal.h>
40 
41 #include <simd/simd.h>
42 
43 /** @addtogroup GUI_OPENGL
44  *
45  * @{
46  */
47 
49 
51 {
52 private:
53  CMtlData() {}
54 
55 public:
56  static CMtlData& GetInstance();
57 
63  kPipelineStateStippledPolygon
64  };
65 
66 
67  id<MTLDevice> GetMTLDevice();
68  id<MTLCommandQueue> GetCommandQueue() { return m_CommandQueue; }
69 
70  id<MTLBuffer> CreateBuffer(int length);
71 
72  void SetEncoder(id<MTLRenderCommandEncoder> encoder);
73  id<MTLRenderCommandEncoder> GetEncoder();
74 
75  void SetClientSize(simd::uint2 clientSize);
76  simd::uint2 GetClientSize();
77 
78  bool InitPipelineStates(MTLPixelFormat colorPixelFormat);
80  id<MTLRenderPipelineState> GetPipelineState(size_t index);
81  id<MTLRenderPipelineState> GetNamedPipelineState(EPipelineState state);
82 
83  id<MTLSamplerState> GetSampler();
84  void TexParameter(GLenum pname, GLint param);
85  void EnableBlending(bool enable) { m_BlendingEnabled = enable; }
86  void BlendingState(int state);
87  void EnableDepthTest(bool enable);
88  void EnableTextureModulate(bool enable) { m_TextureModulate = enable; }
89  bool GetTextureModulate() { return m_TextureModulate; }
90  void EnableTextureAlpha(bool enable) { m_TextureAlpha = enable; }
91 
92  void SetPointSize(float pointSize) { m_PointSize = pointSize; }
93  float GetPointSize() { return m_PointSize; }
94 
95  void SetLineWidth(float lineWidth) { m_LineWidth = lineWidth; }
96  float GetLineWidth() { return m_LineWidth; }
97 
98  void SetLineSmooth(bool lineSmooth) { m_LineSmooth = lineSmooth; }
99  bool GetLineSmooth() const { return m_LineSmooth; }
100 
101  void EnableLineStipple(bool enable) { m_EnableLineStipple = enable; }
102  void SetLineStipple(short factor, short pattern)
103  {
104  m_LineStippleiFactor = min<short>(256, max<short>(1, factor));
105  m_LineStipplePattern = pattern;
106  }
107 
109  GLint viewport[4],
110  const simd::float4x4& matrix,
111  size_t vertexCount,
112  const std::function<simd::float2(size_t index)>& coords,
113  const std::function<simd::uchar4(size_t index)>& colors);
114 
115 private:
116  void x_FunctionNotFound(NSString* function);
118 
119  id<MTLDevice> m_Device = nil;
120 
121  // The command Queue from which we'll obtain command buffers
122  id<MTLCommandQueue> m_CommandQueue = nil;
123 
124  id<MTLRenderCommandEncoder> m_Encoder = nil;
125  simd::uint2 m_ClientSize = {0, 0};
126 
127  float m_PointSize = 1.0f;
128  float m_LineWidth = 1.0f;
129  bool m_LineSmooth = false;
130 
131  bool m_EnableLineStipple = false;
132  short m_LineStippleiFactor = 1;
133  short m_LineStipplePattern = 0xFFFF;
134 
135  vector<id<MTLRenderPipelineState> > m_pipelineStates;
136  vector<id<MTLRenderPipelineState> > m_pipelineStatesBlend;
137  vector<id<MTLRenderPipelineState> > m_pipelineStatesBlendDest;
139  bool m_BlendingEnabled = false;
140  int m_BlendingState = 0;
141  bool m_TextureModulate = false;
142  bool m_TextureAlpha = false;
143  MTLSamplerDescriptor* m_SamplerDescriptor = nil;
144  id<MTLDepthStencilState> m_EnableDepthTest = nil;
145  id<MTLDepthStencilState> m_DisableDepthTest = nil;
146 };
147 
149 
151 
152 /* @} */
153 
154 #endif // GUI_OPENGL___MTL_DATA__HPP
Definition: map.hpp:338
static const Colors colors
Definition: cn3d_colors.cpp:50
void SetClientSize(simd::uint2 clientSize)
id< MTLRenderPipelineState > GetPipelineState(size_t index)
float GetPointSize()
Definition: mtldata.hpp:93
void EnableDepthTest(bool enable)
void EnableTextureModulate(bool enable)
Definition: mtldata.hpp:88
void SetLineWidth(float lineWidth)
Definition: mtldata.hpp:95
void SetPointSize(float pointSize)
Definition: mtldata.hpp:92
simd::uint2 GetClientSize()
CMtlData()
Definition: mtldata.hpp:53
map< EPipelineState, id< MTLRenderPipelineState > > m_NamedPipelineStates
Definition: mtldata.hpp:138
vector< id< MTLRenderPipelineState > > m_pipelineStatesBlend
Definition: mtldata.hpp:136
void EnableTextureAlpha(bool enable)
Definition: mtldata.hpp:90
id< MTLRenderPipelineState > GetNamedPipelineState(EPipelineState state)
CMtlData & Metal()
id< MTLBuffer > CreateBuffer(int length)
id< MTLDevice > GetMTLDevice()
void x_FunctionNotFound(NSString *function)
vector< id< MTLRenderPipelineState > > m_pipelineStates
Definition: mtldata.hpp:135
void EnableLineStipple(bool enable)
Definition: mtldata.hpp:101
void TexParameter(GLenum pname, GLint param)
id< MTLRenderCommandEncoder > GetEncoder()
void SetEncoder(id< MTLRenderCommandEncoder > encoder)
void DeletePipelineStates()
static CMtlData & GetInstance()
void RenderLines(GLint viewport[4], const simd::float4x4 &matrix, size_t vertexCount, const std::function< simd::float2(size_t index)> &coords, const std::function< simd::uchar4(size_t index)> &colors)
vector< id< MTLRenderPipelineState > > m_pipelineStatesBlendDest
Definition: mtldata.hpp:137
id< MTLSamplerState > GetSampler()
bool GetTextureModulate()
Definition: mtldata.hpp:89
void BlendingState(int state)
float GetLineWidth()
Definition: mtldata.hpp:96
bool InitPipelineStates(MTLPixelFormat colorPixelFormat)
bool GetLineSmooth() const
Definition: mtldata.hpp:99
void EnableBlending(bool enable)
Definition: mtldata.hpp:85
void SetLineSmooth(bool lineSmooth)
Definition: mtldata.hpp:98
void SetLineStipple(short factor, short pattern)
Definition: mtldata.hpp:102
EPipelineState
Definition: mtldata.hpp:58
void x_FailedToCreatePipelineState(NSError *error)
id< MTLCommandQueue > GetCommandQueue()
Definition: mtldata.hpp:68
@ kPipelineStateTreeNode
Definition: mtldata.hpp:62
@ kPipelineStateLineStipple
Definition: mtldata.hpp:61
@ kPipelineStateLineSmooth
Definition: mtldata.hpp:60
@ kPipelineStateLine
Definition: mtldata.hpp:59
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIOPENGL_EXPORT
Definition: gui_export.h:514
Standard mechanism to include OpenGL headers for all platforms.
Modified on Fri May 24 14:53:22 2024 by modify_doxy.py rev. 669887