Chromium Code Reviews| Index: mojo/apps/js/bindings/gl/context.cc |
| diff --git a/mojo/apps/js/bindings/gl/context.cc b/mojo/apps/js/bindings/gl/context.cc |
| index 27622a73d71f179cfa9406495c458499d7a53109..0f8c587fd00fde03884c7e50b4078353a85faee1 100644 |
| --- a/mojo/apps/js/bindings/gl/context.cc |
| +++ b/mojo/apps/js/bindings/gl/context.cc |
| @@ -7,6 +7,7 @@ |
| #include <GLES2/gl2.h> |
| #include "gin/arguments.h" |
| +#include "gin/array_buffer.h" |
| #include "gin/object_template_builder.h" |
| #include "gin/per_isolate_data.h" |
| #include "mojo/public/gles2/gles2.h" |
| @@ -28,44 +29,87 @@ v8::Handle<v8::ObjectTemplate> Context::GetObjectTemplate( |
| v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(&kWrapperInfo); |
| if (templ.IsEmpty()) { |
| templ = gin::ObjectTemplateBuilder(isolate) |
| + .SetValue("ARRAY_BUFFER", GL_ARRAY_BUFFER) |
| + .SetValue("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT) |
| + .SetValue("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER) |
| + .SetValue("FLOAT", GL_FLOAT) |
| + .SetValue("FRAGMENT_SHADER", GL_FRAGMENT_SHADER) |
| + .SetValue("STATIC_DRAW", GL_STATIC_DRAW) |
| .SetValue("VERTEX_SHADER", GL_VERTEX_SHADER) |
| - .SetMethod("createShader", CreateShader) |
| - .SetMethod("shaderSource", ShaderSource) |
| + .SetMethod("attachShader", glAttachShader) |
| + .SetMethod("bindBuffer", glBindBuffer) |
| + .SetMethod("bufferData", BufferData) |
| + .SetMethod("clear", glClear) |
| + .SetMethod("clearColor", glClearColor) |
| .SetMethod("compileShader", CompileShader) |
| + .SetMethod("createBuffer", CreateBuffer) |
| + .SetMethod("createProgram", glCreateProgram) |
| + .SetMethod("createShader", glCreateShader) |
| + .SetMethod("deleteShader", glDeleteShader) |
| + .SetMethod("enableVertexAttribArray", glEnableVertexAttribArray) |
| + .SetMethod("getAttribLocation", GetAttribLocation) |
| + .SetMethod("getShaderInfoLog", GetShaderInfoLog) |
| + .SetMethod("getUniformLocation", GetUniformLocation) |
| + .SetMethod("linkProgram", glLinkProgram) |
| + .SetMethod("shaderSource", ShaderSource) |
| + .SetMethod("useProgram", glUseProgram) |
| + .SetMethod("vertexAttribPointer", VertexAttribPointer) |
| + .SetMethod("viewport", glViewport) |
| .Build(); |
| + |
| templ->SetInternalFieldCount(gin::kNumberOfInternalFields); |
| data->SetObjectTemplate(&kWrapperInfo, templ); |
| } |
| return templ; |
| } |
| -gin::Handle<Shader> Context::CreateShader(const gin::Arguments& args, |
| - GLenum type) { |
| - gin::Handle<Shader> result; |
| - GLuint glshader = glCreateShader(type); |
| - if (glshader != 0u) { |
| - result = Opaque::Create(args.isolate(), glshader); |
| +void Context::BufferData(GLenum target, const gin::ArrayBufferView& buffer, |
| + GLenum usage) { |
| + glBufferData(target, buffer.num_bytes(), buffer.bytes(), usage); |
| +} |
| + |
| +void Context::CompileShader(const gin::Arguments& args, GLuint shader) { |
| + glCompileShader(shader); |
| + GLint compiled = 0; |
| + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); |
|
abarth-chromium
2013/12/13 21:30:35
Maybe http://www.khronos.org/opengles/sdk/docs/man
Aaron Boodman
2013/12/13 21:43:57
But I want the textual error message...
|
| + if (!compiled) { |
| + args.ThrowTypeError(std::string("Could not compile shader: ") + |
| + GetShaderInfoLog(shader)); |
| } |
| +} |
| + |
| +GLuint Context::CreateBuffer() { |
| + GLuint result = 0; |
| + glGenBuffers(1, &result); |
| return result; |
| } |
| -void Context::ShaderSource(gin::Handle<Shader> shader, |
| - const std::string& source) { |
| +GLint Context::GetAttribLocation(GLuint program, const std::string& name) { |
| + return glGetAttribLocation(program, name.c_str()); |
| +} |
| + |
| +std::string Context::GetShaderInfoLog(GLuint shader) { |
| + GLint info_log_length = 0; |
| + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); |
| + char info_log[info_log_length]; |
| + glGetShaderInfoLog(shader, info_log_length, NULL, info_log); |
| + return std::string(info_log, info_log_length); |
|
abarth-chromium
2013/12/13 21:30:35
You can avoid one of these copies by resizing the
Aaron Boodman
2013/12/13 21:43:57
Good point. Fixed.
|
| +} |
| + |
| +GLint Context::GetUniformLocation(GLuint program, const std::string& name) { |
| + return glGetUniformLocation(program, name.c_str()); |
| +} |
| + |
| +void Context::ShaderSource(GLuint shader, const std::string& source) { |
| const char* source_chars = source.c_str(); |
| - glShaderSource(shader->value(), 1, &source_chars, NULL); |
| + glShaderSource(shader, 1, &source_chars, NULL); |
| } |
| -void Context::CompileShader(const gin::Arguments& args, |
| - gin::Handle<Shader> shader) { |
| - glCompileShader(shader->value()); |
| - GLint compiled = 0; |
| - glGetShaderiv(shader->value(), GL_COMPILE_STATUS, &compiled); |
| - if (!compiled) { |
| - // Or should |shader| do it when it is destroyed? |
| - glDeleteShader(shader->value()); |
| - args.ThrowTypeError("Could not compile shader"); |
| - return; |
| - } |
| +void Context::VertexAttribPointer(GLuint index, GLint size, GLenum type, |
| + bool normalized, GLsizei stride, |
| + long offset) { |
| + glVertexAttribPointer(index, size, type, static_cast<GLboolean>(normalized), |
| + stride, reinterpret_cast<void*>(offset)); |
| } |
| Context::Context(uint64_t encoded, int width, int height) |