blob: 43e77d0168e37196fccdaf55016416aeff1204ec [file] [log] [blame]
cjgrant1ce4ff32016-09-19 14:03:361// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Tibor Goldschwendt13aead392017-07-14 03:02:435#ifndef CHROME_BROWSER_VR_VR_GL_UTIL_H_
6#define CHROME_BROWSER_VR_VR_GL_UTIL_H_
cjgrant1ce4ff32016-09-19 14:03:367
mthiessef5a56e092016-10-06 15:27:138#include <array>
cjgrant962dfbc2017-02-13 18:50:489#include <string>
mthiessef5a56e092016-10-06 15:27:1310
Christopher Grant7e73a4f2018-05-30 21:13:1411#include "chrome/browser/vr/vr_export.h"
Ian Vollick826f56b02017-11-13 19:53:5712#include "third_party/skia/include/core/SkColor.h"
Ian Vollick909b2942017-06-15 15:11:0213#include "ui/gfx/geometry/rect.h"
cjgrant1ce4ff32016-09-19 14:03:3614#include "ui/gl/gl_bindings.h"
15
Ian Vollick826f56b02017-11-13 19:53:5716#define SHADER(Src) "#version 100\n" #Src
17#define OEIE_SHADER(Src) \
18 "#version 100\n#extension GL_OES_EGL_image_external : require\n" #Src
19#define VOID_OFFSET(x) reinterpret_cast<void*>(x)
20
Ian Vollick909b2942017-06-15 15:11:0221namespace gfx {
22class RectF;
23class Size;
Tibor Goldschwendtdd659e92017-08-16 22:14:1124class SizeF;
Ian Vollick909b2942017-06-15 15:11:0225class Transform;
26} // namespace gfx
27
Tibor Goldschwendt13aead392017-07-14 03:02:4328namespace vr {
cjgrant1ce4ff32016-09-19 14:03:3629
Ian Vollick909b2942017-06-15 15:11:0230std::array<float, 16> MatrixToGLArray(const gfx::Transform& matrix);
cjgrant1ce4ff32016-09-19 14:03:3631
Christopher Grant7e73a4f2018-05-30 21:13:1432VR_EXPORT gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size,
33 const gfx::RectF& texture_rect);
cjgrant1ce4ff32016-09-19 14:03:3634
cjgrant1ce4ff32016-09-19 14:03:3635// Compile a shader.
36GLuint CompileShader(GLenum shader_type,
37 const GLchar* shader_source,
38 std::string& error);
39
40// Compile and link a program.
41GLuint CreateAndLinkProgram(GLuint vertex_shader_handle,
42 GLuint fragment_shader_handle,
cjgrant1ce4ff32016-09-19 14:03:3643 std::string& error);
44
Tibor Goldschwendtdd659e92017-08-16 22:14:1145// Returns the normalized size of the element projected into screen space.
46// If (1, 1) the element fills the entire buffer.
Christopher Grant7e73a4f2018-05-30 21:13:1447VR_EXPORT gfx::SizeF CalculateScreenSize(const gfx::Transform& proj_matrix,
48 float distance,
49 const gfx::SizeF& size);
Tibor Goldschwendtdd659e92017-08-16 22:14:1150
Ian Vollick826f56b02017-11-13 19:53:5751// Sets default texture parameters given a texture type.
52void SetTexParameters(GLenum texture_type);
53
54// Sets color uniforms given an SkColor.
55void SetColorUniform(GLuint handle, SkColor c);
56
Ian Vollick8e4a824f2018-01-06 05:15:1257// Sets color uniforms (but not alpha) given an SkColor. The alpha is assumed to
58// be 1.0 in this case.
59void SetOpaqueColorUniform(GLuint handle, SkColor c);
60
Tibor Goldschwendt13aead392017-07-14 03:02:4361} // namespace vr
cjgrant1ce4ff32016-09-19 14:03:3662
Tibor Goldschwendt13aead392017-07-14 03:02:4363#endif // CHROME_BROWSER_VR_VR_GL_UTIL_H_