blob: 5647e2cf241f9d2ea13f1591f142063fbdc35730 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// angleutils.h: Common ANGLE utilities.
8
daniel@transgaming.combbf56f72010-04-20 18:52:13 +00009#ifndef COMMON_ANGLEUTILS_H_
10#define COMMON_ANGLEUTILS_H_
11
Geoff Lang44fa7592014-05-30 11:50:07 -040012#include "common/platform.h"
13
Jamie Madillf386bf72013-07-08 14:02:41 -040014#include <stddef.h>
15
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000016// A macro to disallow the copy constructor and operator= functions
17// This must be used in the private: declarations for a class
18#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
19 TypeName(const TypeName&); \
20 void operator=(const TypeName&)
21
shannon.woods@transgaming.com6d792572013-02-28 23:07:25 +000022template <typename T, unsigned int N>
23inline unsigned int ArraySize(T(&)[N])
24{
25 return N;
26}
27
shannon.woods%transgaming.com@gtempaccount.com96224772013-04-13 03:30:18 +000028template <typename T, unsigned int N>
29void SafeRelease(T (&resourceBlock)[N])
30{
31 for (unsigned int i = 0; i < N; i++)
32 {
33 SafeRelease(resourceBlock[i]);
34 }
35}
36
37template <typename T>
38void SafeRelease(T& resource)
39{
40 if (resource)
41 {
42 resource->Release();
43 resource = NULL;
44 }
45}
46
Geoff Langea228632013-07-30 15:17:12 -040047template <typename T>
48void SafeDelete(T*& resource)
49{
50 delete resource;
51 resource = NULL;
52}
53
54template <typename T>
55void SafeDeleteArray(T*& resource)
56{
57 delete[] resource;
58 resource = NULL;
59}
60
Jamie Madilld3f0f1e2013-09-20 13:31:08 -040061// Provide a less-than function for comparing structs
62// Note: struct memory must be initialized to zero, because of packing gaps
63template <typename T>
64inline bool StructLessThan(const T &a, const T &b)
65{
66 return (memcmp(&a, &b, sizeof(T)) < 0);
67}
68
69// Provide a less-than function for comparing structs
70// Note: struct memory must be initialized to zero, because of packing gaps
71template <typename T>
72inline bool StructEquals(const T &a, const T &b)
73{
74 return (memcmp(&a, &b, sizeof(T)) == 0);
75}
76
77template <typename T>
78inline void StructZero(T *obj)
79{
80 memset(obj, 0, sizeof(T));
81}
82
alokp@chromium.org79fb1012012-04-26 21:07:39 +000083#if defined(_MSC_VER)
84#define snprintf _snprintf
85#endif
86
apatrick@chromium.org85e44192012-08-17 20:58:01 +000087#define VENDOR_ID_AMD 0x1002
88#define VENDOR_ID_INTEL 0x8086
89#define VENDOR_ID_NVIDIA 0x10DE
90
daniel@transgaming.com106e1f72012-10-31 18:38:36 +000091#define GL_BGRA4_ANGLEX 0x6ABC
92#define GL_BGR5_A1_ANGLEX 0x6ABD
Jamie Madill0fda9862013-07-19 16:36:55 -040093#define GL_INT_64_ANGLEX 0x6ABE
Jamie Madill28167c62013-08-30 13:21:10 -040094#define GL_STRUCT_ANGLEX 0x6ABF
daniel@transgaming.com106e1f72012-10-31 18:38:36 +000095
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000096#endif // COMMON_ANGLEUTILS_H_