1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <cassert> 19 #include <string> 20 21 #include "Renderer.h" 22 23 class Utility { 24 public: 25 static bool checkAndLogGlError(bool alwaysLog = false); 26 assertGlError()27 static inline void assertGlError() { assert(checkAndLogGlError()); } 28 29 /** 30 * Generates an orthographic projection matrix given the half height, aspect ratio, near, and 31 * far planes 32 * 33 * @param outMatrix the matrix to write into 34 * @param halfHeight half of the height of the screen 35 * @param aspect the width of the screen divided by the height 36 * @param near the distance of the near plane 37 * @param far the distance of the far plane 38 * @return the generated matrix, this will be the same as @a outMatrix so you can chain calls 39 * together if needed 40 */ 41 static float *buildOrthographicMatrix(float *outMatrix, float halfHeight, float aspect, 42 float near, float far); 43 44 static float *buildIdentityMatrix(float *outMatrix); 45 46 static void setFailure(std::string message, Renderer *renderer = nullptr); 47 }; 48