Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: samples/android_sample/jni/graphics.cc

Issue 11434046: Android rayshader sample. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #include "graphics.h"
2 #include <GLES2/gl2.h>
3 #include <GLES2/gl2ext.h>
4
5 Graphics::Graphics(android_app* pApplication, Timer* pTimer) :
6 mApplication(pApplication),
7 mTimer(pTimer),
8 mWidth(0),
9 mHeight(0),
10 mDisplay(EGL_NO_DISPLAY),
11 mSurface(EGL_NO_SURFACE),
12 mContext(EGL_NO_CONTEXT) {
13 }
14
15 const int32_t& Graphics::getHeight() {
16 return mHeight;
17 }
18
19 const int32_t& Graphics::getWidth() {
20 return mWidth;
21 }
22
23 int32_t Graphics::start() {
24 EGLint format, numConfigs, errorResult;
25 EGLConfig config;
26 const EGLint attributes[] = {
27 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
28 //EGL_BLUE_SIZE, 5,
29 //EGL_GREEN_SIZE, 6,
30 //EGL_RED_SIZE, 5,
31 //EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
32 EGL_NONE
33 };
34 static const EGLint ctx_attribs[] = {
35 EGL_CONTEXT_CLIENT_VERSION, 2,
36 EGL_NONE
37 };
38
39 mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
40 if (mDisplay != EGL_NO_DISPLAY) {
41 Log::Print("eglInitialize");
42 if (eglInitialize(mDisplay, NULL, NULL)) {
43 Log::Print("eglChooseConfig");
44 if (eglChooseConfig(mDisplay, attributes, &config, 1, &numConfigs) &&
45 numConfigs > 0) {
46 Log::Print("eglGetConfigAttrib");
47 if (eglGetConfigAttrib(mDisplay, config,
48 EGL_NATIVE_VISUAL_ID, &format)) {
49 ANativeWindow_setBuffersGeometry(mApplication->window, 0, 0, format);
50 mSurface = eglCreateWindowSurface(mDisplay, config,
51 (EGLNativeWindowType)mApplication->window, NULL);
52 if (mSurface != EGL_NO_SURFACE) {
53 Log::Print("eglCreateContext");
54 mContext = eglCreateContext(mDisplay, config, EGL_NO_CONTEXT,
55 ctx_attribs);
56 if (mContext != EGL_NO_CONTEXT) {
57 if (eglMakeCurrent(mDisplay, mSurface, mSurface, mContext) &&
58 eglQuerySurface(mDisplay, mSurface, EGL_WIDTH, &mWidth) &&
59 mWidth > 0 &&
60 eglQuerySurface(mDisplay, mSurface, EGL_HEIGHT, &mHeight) &&
61 mHeight > 0) {
62 glViewport(0, 0, mWidth, mHeight);
63 return 0;
64 }
65 }
66 }
67 }
68 }
69 }
70 }
71 Log::PrintErr("Error starting graphics");
72 stop();
73 return -1;
74 }
75
76 void Graphics::stop() {
77 Log::Print("Stopping graphics");
78 if (mDisplay != EGL_NO_DISPLAY) {
79 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
80 if (mContext != EGL_NO_CONTEXT) {
81 eglDestroyContext(mDisplay, mContext);
82 mContext = EGL_NO_CONTEXT;
83 }
84 if (mSurface != EGL_NO_SURFACE) {
85 eglDestroySurface(mDisplay, mSurface);
86 mSurface = EGL_NO_SURFACE;
87 }
88 eglTerminate(mDisplay);
89 mDisplay = EGL_NO_DISPLAY;
90 }
91 }
92
93 int32_t Graphics::update() {
94 return 0;
95 /*
96 if (eglSwapBuffers(mDisplay, mSurface) != EGL_TRUE) {
97 Log::PrintErr("Error %d swapping buffers.", eglGetError());
98 return -1;
99 }
100 return 0;
101 */
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698