Home | History | Annotate | Download | only in GLcommon
      1 /*
      2 * Copyright (C) 2011 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 #ifndef GL_UTILS_H
     17 #define GL_UTILS_H
     18 
     19 #include <assert.h>
     20 #include <inttypes.h>
     21 
     22 typedef enum {
     23     GLES_1_1 = 1,
     24     GLES_2_0 = 2,
     25     MAX_GLES_VERSION //Must be last
     26 } GLESVersion;
     27 
     28 template <class T>
     29 void swap(T& x,T& y) {
     30      T temp;
     31      temp = x;
     32      x = y;
     33      y = temp;
     34 }
     35 
     36 bool isPowerOf2(int num);
     37 
     38 // <EGL/egl.h> defines many types as 'void*' while they're really
     39 // implemented as unsigned integers. These convenience template functions
     40 // help casting between them safely without generating compiler warnings.
     41 inline void* SafePointerFromUInt(unsigned int handle) {
     42     return (void*)(uintptr_t)(handle);
     43 }
     44 
     45 inline unsigned int SafeUIntFromPointer(const void* ptr) {
     46     // Assertion error if the pointer contains a value that does not fit
     47     // in an unsigned integer!
     48     assert((uintptr_t)(ptr) == (unsigned int)(uintptr_t)(ptr));
     49     return (unsigned int)(uintptr_t)(ptr);
     50 }
     51 
     52 #endif
     53