blob: 9c182a8c95fad22ba8a5c20f6df4da747963c9cf [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
Jamie Madillf386bf72013-07-08 14:02:41 -040012#include <stddef.h>
13
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000014// A macro to disallow the copy constructor and operator= functions
15// This must be used in the private: declarations for a class
16#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
17 TypeName(const TypeName&); \
18 void operator=(const TypeName&)
19
shannon.woods@transgaming.com6d792572013-02-28 23:07:25 +000020template <typename T, unsigned int N>
21inline unsigned int ArraySize(T(&)[N])
22{
23 return N;
24}
25
shannon.woods%transgaming.com@gtempaccount.com96224772013-04-13 03:30:18 +000026template <typename T, unsigned int N>
27void SafeRelease(T (&resourceBlock)[N])
28{
29 for (unsigned int i = 0; i < N; i++)
30 {
31 SafeRelease(resourceBlock[i]);
32 }
33}
34
35template <typename T>
36void SafeRelease(T& resource)
37{
38 if (resource)
39 {
40 resource->Release();
41 resource = NULL;
42 }
43}
44
Geoff Langea228632013-07-30 15:17:12 -040045template <typename T>
46void SafeDelete(T*& resource)
47{
48 delete resource;
49 resource = NULL;
50}
51
52template <typename T>
53void SafeDeleteArray(T*& resource)
54{
55 delete[] resource;
56 resource = NULL;
57}
58
Jamie Madilld3f0f1e2013-09-20 13:31:08 -040059// Provide a less-than function for comparing structs
60// Note: struct memory must be initialized to zero, because of packing gaps
61template <typename T>
62inline bool StructLessThan(const T &a, const T &b)
63{
64 return (memcmp(&a, &b, sizeof(T)) < 0);
65}
66
67// Provide a less-than function for comparing structs
68// Note: struct memory must be initialized to zero, because of packing gaps
69template <typename T>
70inline bool StructEquals(const T &a, const T &b)
71{
72 return (memcmp(&a, &b, sizeof(T)) == 0);
73}
74
75template <typename T>
76inline void StructZero(T *obj)
77{
78 memset(obj, 0, sizeof(T));
79}
80
alokp@chromium.org79fb1012012-04-26 21:07:39 +000081#if defined(_MSC_VER)
82#define snprintf _snprintf
83#endif
84
apatrick@chromium.org85e44192012-08-17 20:58:01 +000085#define VENDOR_ID_AMD 0x1002
86#define VENDOR_ID_INTEL 0x8086
87#define VENDOR_ID_NVIDIA 0x10DE
88
daniel@transgaming.com106e1f72012-10-31 18:38:36 +000089#define GL_BGRA4_ANGLEX 0x6ABC
90#define GL_BGR5_A1_ANGLEX 0x6ABD
Jamie Madill0fda9862013-07-19 16:36:55 -040091#define GL_INT_64_ANGLEX 0x6ABE
Jamie Madill28167c62013-08-30 13:21:10 -040092#define GL_STRUCT_ANGLEX 0x6ABF
daniel@transgaming.com106e1f72012-10-31 18:38:36 +000093
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000094#endif // COMMON_ANGLEUTILS_H_