• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2 
3  @File         OGLES2/PVRTgles2Ext.cpp
4 
5  @Title        OGLES2/PVRTgles2Ext
6 
7  @Version
8 
9  @Copyright    Copyright (c) Imagination Technologies Limited.
10 
11  @Platform     Independent
12 
13  @Description  OpenGL ES 2.0 extensions
14 
15 ******************************************************************************/
16 #include <string.h>
17 
18 #include "PVRTContext.h"
19 #include "PVRTgles2Ext.h"
20 
21 /****************************************************************************
22 ** Local code
23 ****************************************************************************/
24 
25 /****************************************************************************
26 ** Class: CPVRTgles2Ext
27 ****************************************************************************/
28 
29 /*!***************************************************************************
30  @Function			LoadExtensions
31  @Description		Initialises IMG extensions
32 *****************************************************************************/
LoadExtensions()33 void CPVRTgles2Ext::LoadExtensions()
34 {
35 	glMultiDrawElementsEXT = 0;
36 	glMultiDrawArraysEXT = 0;
37 	glMapBufferOES = 0;
38 	glUnmapBufferOES = 0;
39 	glGetBufferPointervOES = 0;
40 	glDiscardFramebufferEXT = 0;
41 	glBindVertexArrayOES = 0;
42 	glDeleteVertexArraysOES = 0;
43 	glGenVertexArraysOES = 0;
44 	glIsVertexArrayOES = 0;
45 	glRenderbufferStorageMultisampleIMG = 0;
46 	glFramebufferTexture2DMultisampleIMG = 0;
47 	glGenQueriesEXT = 0;
48 	glDeleteQueriesEXT = 0;
49 	glIsQueryEXT = 0;
50 	glBeginQueryEXT = 0;
51 	glEndQueryEXT = 0;
52 	glGetQueryivEXT = 0;
53 	glGetQueryObjectuivEXT = 0;
54 	glRenderbufferStorageMultisampleANGLE = 0;
55 	glBlitFramebufferNV = 0;
56 	glTexImage3DOES = 0;
57 	glTexSubImage3DOES = 0;
58 	glCopyTexSubImage3DOES = 0;
59 	glCompressedTexImage3DOES = 0;
60 	glCompressedTexSubImage3DOES = 0;
61 	glFramebufferTexture3DOES = 0;
62 	glDrawBuffersEXT = 0;
63 
64 	// Supported extensions provide new entry points for OpenGL ES 2.0.
65 
66 	const GLubyte *pszGLExtensions;
67 
68 	/* Retrieve GL extension string */
69     pszGLExtensions = glGetString(GL_EXTENSIONS);
70 
71 #if !defined(TARGET_OS_IPHONE)
72 	/* GL_EXT_multi_draw_arrays */
73 	if (strstr((char *)pszGLExtensions, "GL_EXT_multi_draw_arrays"))
74 	{
75 		glMultiDrawElementsEXT = (PFNGLMULTIDRAWELEMENTS) PVRGetProcAddress(glMultiDrawElementsEXT);
76 		glMultiDrawArraysEXT = (PFNGLMULTIDRAWARRAYS) PVRGetProcAddress(glMultiDrawArraysEXT);
77 	}
78 
79 	/* GL_EXT_multi_draw_arrays */
80 	if (strstr((char *)pszGLExtensions, "GL_OES_mapbuffer"))
81 	{
82         glMapBufferOES = (PFNGLMAPBUFFEROES) PVRGetProcAddress(glMapBufferOES);
83         glUnmapBufferOES = (PFNGLUNMAPBUFFEROES) PVRGetProcAddress(glUnmapBufferOES);
84         glGetBufferPointervOES = (PFNGLGETBUFFERPOINTERVOES) PVRGetProcAddress(glGetBufferPointervOES);
85 	}
86 
87 	/* GL_OES_vertex_array_object */
88 	if (strstr((char *)pszGLExtensions, "GL_OES_vertex_array_object"))
89 	{
90         glBindVertexArrayOES = (PFNGLBINDVERTEXARRAYOES) PVRGetProcAddress(glBindVertexArrayOES);
91         glDeleteVertexArraysOES = (PFNGLDELETEVERTEXARRAYSOES) PVRGetProcAddress(glDeleteVertexArraysOES);
92         glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOES) PVRGetProcAddress(glGenVertexArraysOES);
93 		glIsVertexArrayOES = (PFNGLISVERTEXARRAYOES) PVRGetProcAddress(glIsVertexArrayOES);
94 	}
95 
96 	/* GL_IMG_multisampled_render_to_texture */
97 	if (strstr((char *)pszGLExtensions, "GL_IMG_multisampled_render_to_texture"))
98 	{
99 		glRenderbufferStorageMultisampleIMG = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG) PVRGetProcAddress(glRenderbufferStorageMultisampleIMG);
100 		glFramebufferTexture2DMultisampleIMG = (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMG) PVRGetProcAddress(glFramebufferTexture2DMultisampleIMG);
101 	}
102 
103 	/* GL_ANGLE_framebuffer_multisample */
104 	if (strstr((char *)pszGLExtensions, "GL_ANGLE_framebuffer_multisample"))
105 	{
106 		glRenderbufferStorageMultisampleANGLE = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC)PVRGetProcAddress(glRenderbufferStorageMultisampleANGLE);
107 	}
108 
109 	/* GL_NV_framebuffer_blit */
110 	if (strstr((char *)pszGLExtensions, "GL_NV_framebuffer_blit"))
111 	{
112 		glBlitFramebufferNV = (PFNGLBLITFRAMEBUFFERNVPROC) PVRGetProcAddress(glBlitFramebufferNV);
113 	}
114 
115 	/* GL_OES_texture_3D */
116 	if(strstr((char *)pszGLExtensions, "GL_OES_texture_3D"))
117 	{
118 		glTexImage3DOES = (PFNGLTEXIMAGE3DOES) PVRGetProcAddress(glTexImage3DOES);
119 		glTexSubImage3DOES = (PFNGLTEXSUBIMAGE3DOES) PVRGetProcAddress(glTexSubImage3DOES);
120 		glCopyTexSubImage3DOES = (PFNGLCOPYTEXSUBIMAGE3DOES) PVRGetProcAddress(glCopyTexSubImage3DOES);
121 		glCompressedTexImage3DOES = (PFNGLCOMPRESSEDTEXIMAGE3DOES) PVRGetProcAddress(glCompressedTexImage3DOES);
122 		glCompressedTexSubImage3DOES = (PFNGLCOMPRESSEDTEXSUBIMAGE3DOES) PVRGetProcAddress(glCompressedTexSubImage3DOES);
123 		glFramebufferTexture3DOES = (PFNGLFRAMEBUFFERTEXTURE3DOES) PVRGetProcAddress(glFramebufferTexture3DOES);
124 	}
125 
126 	/* GL_EXT_draw_buffers */
127 	if (strstr((char *)pszGLExtensions, "GL_EXT_draw_buffers"))
128 	{
129 		glDrawBuffersEXT = (PFNGLDRAWBUFFERSEXT) PVRGetProcAddress(glDrawBuffersEXT);
130 	}
131 #endif
132 
133 #if defined(GL_EXT_discard_framebuffer)
134 	/* GL_EXT_discard_framebuffer */
135 	if (strstr((char *)pszGLExtensions, "GL_EXT_discard_framebuffer"))
136 	{
137         glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXT) PVRGetProcAddress(glDiscardFramebufferEXT);
138 	}
139 #endif
140 
141 	/* GL_EXT_occlusion_query_boolean */
142 	if (strstr((char *)pszGLExtensions, "GL_EXT_occlusion_query_boolean"))
143 	{
144 		glGenQueriesEXT = (PFNGLGENQUERIESEXT) PVRGetProcAddress(glGenQueriesEXT);
145 		glDeleteQueriesEXT = (PFNGLDELETEQUERIESEXT) PVRGetProcAddress(glDeleteQueriesEXT);
146 		glIsQueryEXT = (PFNGLISQUERYEXT) PVRGetProcAddress(glIsQueryEXT);
147 		glBeginQueryEXT = (PFNGLBEGINQUERYEXT) PVRGetProcAddress(glBeginQueryEXT);
148 		glEndQueryEXT = (PFNGLENDQUERYEXT) PVRGetProcAddress(glEndQueryEXT);
149 		glGetQueryivEXT = (PFNGLGETQUERYIVEXT) PVRGetProcAddress(glGetQueryivEXT);
150 		glGetQueryObjectuivEXT = (PFNGLGETQUERYOBJECTUIVEXT) PVRGetProcAddress(glGetQueryObjectuivEXT);
151 	}
152 }
153 
154 /*!***********************************************************************
155 @Function			IsGLExtensionSupported
156 @Input				extension extension to query for
157 @Returns			True if the extension is supported
158 @Description		Queries for support of an extension
159 *************************************************************************/
IsGLExtensionSupported(const char * const extension)160 bool CPVRTgles2Ext::IsGLExtensionSupported(const char * const extension)
161 {
162 	// The recommended technique for querying OpenGL extensions;
163 	// from http://opengl.org/resources/features/OGLextensions/
164 	const GLubyte *extensions = NULL;
165 	const GLubyte *start;
166 	GLubyte *where, *terminator;
167 
168 	/* Extension names should not have spaces. */
169 	where = (GLubyte *) strchr(extension, ' ');
170 	if (where || *extension == '\0')
171 		return 0;
172 
173 	extensions = glGetString(GL_EXTENSIONS);
174 
175 	/* It takes a bit of care to be fool-proof about parsing the
176 	OpenGL extensions string. Don't be fooled by sub-strings, etc. */
177 	start = extensions;
178 	for (;;) {
179 		where = (GLubyte *) strstr((const char *) start, extension);
180 		if (!where)
181 			break;
182 		terminator = where + strlen(extension);
183 		if (where == start || *(where - 1) == ' ')
184 			if (*terminator == ' ' || *terminator == '\0')
185 				return true;
186 		start = terminator;
187 	}
188 
189 	return false;
190 }
191 
192 /*****************************************************************************
193  End of file (PVRTglesExt.cpp)
194 *****************************************************************************/
195 
196