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

Unified Diff: runtime/embedders/openglui/common/gl_graphics_handler.cc

Issue 11883013: Refactored OpenGL embedder that works on Android, Mac or Linux. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: runtime/embedders/openglui/common/gl_graphics_handler.cc
===================================================================
--- runtime/embedders/openglui/common/gl_graphics_handler.cc (revision 0)
+++ runtime/embedders/openglui/common/gl_graphics_handler.cc (revision 0)
@@ -0,0 +1,64 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "embedders/openglui/common/gl_graphics_handler.h"
+#include "embedders/openglui/common/log.h"
+
+extern void CheckGLError(const char *function);
+
+void GLGraphicsHandler::SetViewport(int left, int top, int width, int height) {
+ glViewport(left, top, width, height);
+ CheckGLError("glViewPort");
+}
+
+int GLGraphicsHandler::BuildProgram(const char* vertexShaderSource,
+ const char* fragmentShaderSource) const {
+ int vertexShader = BuildShader(vertexShaderSource, GL_VERTEX_SHADER);
+ int fragmentShader = BuildShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
+ if (vertexShader < 0 || fragmentShader < 0) {
+ return -1;
+ }
+
+ GLuint programHandle = glCreateProgram();
+ glAttachShader(programHandle, static_cast<GLuint>(vertexShader));
+ glAttachShader(programHandle, static_cast<GLuint>(fragmentShader));
+ glLinkProgram(programHandle);
+
+ GLint linkSuccess;
+ glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess);
+ if (linkSuccess == GL_FALSE) {
+ GLint infoLogLength;
+ glGetProgramiv(programHandle, GL_INFO_LOG_LENGTH, &infoLogLength);
+ GLchar* strInfoLog = new GLchar[infoLogLength + 1];
+ glGetProgramInfoLog(programHandle, infoLogLength, NULL, strInfoLog);
+ strInfoLog[infoLogLength] = 0;
+ LOGE("Link failed: %s", strInfoLog);
+ delete[] strInfoLog;
+ return -1;
+ }
+ return static_cast<int>(programHandle);
+}
+
+int GLGraphicsHandler::BuildShader(const char* source,
+ GLenum shaderType) const {
+ GLuint shaderHandle = glCreateShader(shaderType);
+ glShaderSource(shaderHandle, 1, &source, NULL);
+ glCompileShader(shaderHandle);
+
+ GLint compileSuccess;
+ glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &compileSuccess);
+
+ if (compileSuccess == GL_FALSE) {
+ GLint infoLogLength = 0;
+ glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, &infoLogLength);
+ GLchar* strInfoLog = new GLchar[infoLogLength + 1];
+ glGetShaderInfoLog(shaderHandle, infoLogLength, NULL, strInfoLog);
+ strInfoLog[infoLogLength] = 0;
+ LOGE("Shader compile failed: %s", strInfoLog);
+ delete [] strInfoLog;
+ return -1;
+ }
+ return static_cast<int>(shaderHandle);
+}
+
« no previous file with comments | « runtime/embedders/openglui/common/gl_graphics_handler.h ('k') | runtime/embedders/openglui/common/graphics_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698