-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgl_windows.go
124 lines (119 loc) · 6.57 KB
/
gl_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package goovr
// #include "OVR_CAPI_GL.h"
import "C"
/// Creates a TextureSwapChain suitable for use with OpenGL.
///
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
/// \param[in] desc Specifies the requested texture properties. See notes for more info about texture format.
/// \param[out] out_TextureSwapChain Returns the created ovrTextureSwapChain, which will be valid upon
/// a successful return value, else it will be NULL. This texture swap chain must be eventually
/// destroyed via ovr_DestroyTextureSwapChain before destroying the HMD with ovr_Destroy.
///
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
/// ovr_GetLastErrorInfo to get more information.
///
/// \note The \a format provided should be thought of as the format the distortion compositor will use when reading
/// the contents of the texture. To that end, it is highly recommended that the application requests texture swap chain
/// formats that are in sRGB-space (e.g. OVR_FORMAT_R8G8B8A8_UNORM_SRGB) as the distortion compositor does sRGB-correct
/// rendering. Furthermore, the app should then make sure "glEnable(GL_FRAMEBUFFER_SRGB);" is called before rendering
/// into these textures. Even though it is not recommended, if the application would like to treat the texture as a linear
/// format and do linear-to-gamma conversion in GLSL, then the application can avoid calling "glEnable(GL_FRAMEBUFFER_SRGB);",
/// but should still pass in an sRGB variant for the \a format. Failure to do so will cause the distortion compositor
/// to apply incorrect gamma conversions leading to gamma-curve artifacts.
///
/// \see ovr_GetTextureSwapChainLength
/// \see ovr_GetTextureSwapChainCurrentIndex
/// \see ovr_GetTextureSwapChainDesc
/// \see ovr_GetTextureSwapChainBufferGL
/// \see ovr_DestroyTextureSwapChain
func (s *Session) CreateTextureSwapChainGL(desc *TextureSwapChainDesc) (TextureSwapChain, error) {
var cDesc C.ovrTextureSwapChainDesc
cDesc.Type = C.ovrTextureType(desc.Typ)
cDesc.Format = C.ovrTextureFormat(desc.Format)
cDesc.ArraySize = C.int(desc.ArraySize)
cDesc.Width = C.int(desc.Width)
cDesc.Height = C.int(desc.Height)
cDesc.MipLevels = C.int(desc.MipLevels)
cDesc.SampleCount = C.int(desc.SampleCount)
cDesc.StaticImage = ovrBool(desc.StaticImage)
cDesc.MiscFlags = C.uint(desc.MiscFlags)
cDesc.BindFlags = C.uint(desc.BindFlags)
var cSwapTextureChain C.ovrTextureSwapChain
result := C.ovr_CreateTextureSwapChainGL(s.cSession, &cDesc, &cSwapTextureChain)
err := errorForResult(result)
if err != nil {
return TextureSwapChain{}, err
}
return TextureSwapChain{cTextureSwapChain: cSwapTextureChain}, nil
}
/// Get a specific buffer within the chain as a GL texture name
///
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
/// \param[in] chain Specifies an ovrTextureSwapChain previously returned by ovr_CreateTextureSwapChainGL
/// \param[in] index Specifies the index within the chain to retrieve. Must be between 0 and length (see ovr_GetTextureSwapChainLength)
/// or may pass -1 to get the buffer at the CurrentIndex location. (Saving a call to GetTextureSwapChainCurrentIndex)
/// \param[out] out_TexId Returns the GL texture object name associated with the specific index requested
///
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
/// ovr_GetLastErrorInfo to get more information.
func (s *Session) GetTextureSwapChainBufferGL(chain TextureSwapChain, index int) (uint, error) {
var texId C.uint
result := C.ovr_GetTextureSwapChainBufferGL(s.cSession, chain.cTextureSwapChain, C.int(index), &texId)
err := errorForResult(result)
if err != nil {
return 0, err
}
return uint(texId), nil
}
/// Creates a Mirror Texture which is auto-refreshed to mirror Rift contents produced by this application.
///
/// A second call to ovr_CreateMirrorTextureGL for a given ovrSession before destroying the first one
/// is not supported and will result in an error return.
///
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
/// \param[in] desc Specifies the requested mirror texture description.
/// \param[out] out_MirrorTexture Specifies the created ovrMirrorTexture, which will be valid upon a successful return value, else it will be NULL.
/// This texture must be eventually destroyed via ovr_DestroyMirrorTexture before destroying the HMD with ovr_Destroy.
///
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
/// ovr_GetLastErrorInfo to get more information.
///
/// \note The \a format provided should be thought of as the format the distortion compositor will use when writing into the mirror
/// texture. It is highly recommended that mirror textures are requested as sRGB formats because the distortion compositor
/// does sRGB-correct rendering. If the application requests a non-sRGB format (e.g. R8G8B8A8_UNORM) as the mirror texture,
/// then the application might have to apply a manual linear-to-gamma conversion when reading from the mirror texture.
/// Failure to do so can result in incorrect gamma conversions leading to gamma-curve artifacts and color banding.
///
/// \see ovr_GetMirrorTextureBufferGL
/// \see ovr_DestroyMirrorTexture
func (s *Session) CreateMirrorTextureGL(desc *TextureSwapChainDesc) (MirrorTexture, error) {
var cDesc C.ovrMirrorTextureDesc
cDesc.Format = C.ovrTextureFormat(desc.Format)
cDesc.Width = C.int(desc.Width)
cDesc.Height = C.int(desc.Height)
cDesc.MiscFlags = C.uint(desc.MiscFlags)
var cMirrorTexture C.ovrMirrorTexture
result := C.ovr_CreateMirrorTextureGL(s.cSession, &cDesc, &cMirrorTexture)
err := errorForResult(result)
if err != nil {
return MirrorTexture{}, err
}
return MirrorTexture{cMirrorTexture: cMirrorTexture}, nil
}
/// Get a the underlying buffer as a GL texture name
///
/// \param[in] session Specifies an ovrSession previously returned by ovr_Create.
/// \param[in] mirrorTexture Specifies an ovrMirrorTexture previously returned by ovr_CreateMirrorTextureGL
/// \param[out] out_TexId Specifies the GL texture object name associated with the mirror texture
///
/// \return Returns an ovrResult indicating success or failure. In the case of failure, use
/// ovr_GetLastErrorInfo to get more information.
func (s *Session) GetMirrorTextureBufferGL(mirrorTexture MirrorTexture) (uint, error) {
var texId C.uint
result := C.ovr_GetMirrorTextureBufferGL(s.cSession, mirrorTexture.cMirrorTexture, &texId)
err := errorForResult(result)
if err != nil {
return 0, err
}
return uint(texId), nil
}