Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webgl fixes for linux #1920

Merged
merged 6 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/pxScene2d/external/spark-webgl/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
'libraries': ['<!@(PKG_CONFIG_PATH=/opt/vc/lib/pkgconfig pkg-config --libs brcmegl brcmglesv2)'],
'include_dirs': [ '<!@(PKG_CONFIG_PATH=/opt/vc/lib/pkgconfig pkg-config brcmegl brcmglesv2 --cflags-only-I | sed s/-I//g)']
}],
['OS=="linux" and has_glfw=="" and has_nexus=="" and has_raspbian==""', {
'sources': [
'src/glew/gles2glewimpl.cc',
'src/bindings.cc',
'src/gles2platform.cc',
'src/interface/webgl.cc'
],
'libraries': ['<!@(pkg-config --libs glew)'],
'defines': ['IS_GLEW']
}],
['OS=="mac"', {
'sources': [
'src/glew/gles2glewimpl.cc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,8 @@ function initShaders() {
}
}

gl.useProgram(shaderProgram);

shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);

shaderProgram.vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);

shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
}
Expand All @@ -138,6 +132,7 @@ function mvPopMatrix() {


function setMatrixUniforms() {

gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
}
Expand Down Expand Up @@ -287,6 +282,10 @@ function initBuffers() {
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
cubeVertexIndexBuffer.itemSize = 1;
cubeVertexIndexBuffer.numItems = 36;


gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
}


Expand All @@ -297,6 +296,10 @@ function drawScene() {
gl.viewport(0, 0, 1280, 720);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

gl.useProgram(shaderProgram);
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);

mat4.perspective(45, 1280 / 720, 0.1, 100.0, pMatrix);

mat4.identity(mvMatrix);
Expand Down Expand Up @@ -335,6 +338,8 @@ function drawScene() {

mvPopMatrix();

gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,8 @@ function initShaders() {
}
}

gl.useProgram(shaderProgram);

shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);

shaderProgram.vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);

shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
}
Expand Down Expand Up @@ -286,6 +280,9 @@ function initBuffers() {
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
cubeVertexIndexBuffer.itemSize = 1;
cubeVertexIndexBuffer.numItems = 36;

gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
}


Expand All @@ -296,6 +293,10 @@ function drawScene() {
gl.viewport(0, 0, 1280, 720);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

gl.useProgram(shaderProgram);
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);

mat4.perspective(45, 1280 / 720, 0.1, 100.0, pMatrix);

mat4.identity(mvMatrix);
Expand Down Expand Up @@ -334,6 +335,8 @@ function drawScene() {

mvPopMatrix();

gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ string init(int width, int height, bool fullscreen, std::string title) {
glfwMakeContextCurrent(window);

#endif
glewInit();

GLenum err = glewInit();
if (GLEW_OK != err) {
return string("Can't init GLEW: ") + std::to_string((int)err);
}

return string("");
}
Expand All @@ -62,4 +64,4 @@ void cleanup() {
#endif
}

} // end namespace gles2impl
} // end namespace gles2impl
20 changes: 17 additions & 3 deletions examples/pxScene2d/external/spark-webgl/src/interface/webgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ WebGLRenderingContext::WebGLRenderingContext() {
pixelStorei_UNPACK_FLIP_BLUE_RED = 0;

glGetIntegerv(GL_FRAMEBUFFER_BINDING, &mInitialFrameBuffer);
CheckGLError();
}

NAN_METHOD(WebGLRenderingContext::New) {
Expand Down Expand Up @@ -597,7 +598,10 @@ NAN_METHOD(WebGLRenderingContext::GetAttribLocation) {
int program = info[0]->Int32Value();
String::Utf8Value name(info[1]);

info.GetReturnValue().Set(Nan::New<Number>(glGetAttribLocation(program, *name)));
GLint location = glGetAttribLocation(program, *name);
CheckGLError();

info.GetReturnValue().Set(Nan::New<Number>(location));
}


Expand Down Expand Up @@ -777,7 +781,10 @@ NAN_METHOD(WebGLRenderingContext::GetUniformLocation) {
int program = info[0]->Int32Value();
v8::String::Utf8Value name(info[1]);

info.GetReturnValue().Set(JS_INT(glGetUniformLocation(program, *name)));
GLint location = glGetUniformLocation(program, *name);
CheckGLError();

info.GetReturnValue().Set(JS_INT(location));
}


Expand Down Expand Up @@ -1012,6 +1019,7 @@ NAN_METHOD(WebGLRenderingContext::BufferData) {
GLsizeiptr size = info[1]->Uint32Value();
GLenum usage = info[2]->Int32Value();
glBufferData(target, size, NULL, usage);
CheckGLError();
}
info.GetReturnValue().Set(Nan::Undefined());
}
Expand Down Expand Up @@ -1664,6 +1672,7 @@ NAN_METHOD(WebGLRenderingContext::GetShaderSource) {

GLint len;
glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &len);
CheckGLError();
GLchar *source=new GLchar[len];
glGetShaderSource(shader, len, NULL, source);
CheckGLError();
Expand Down Expand Up @@ -1938,6 +1947,7 @@ NAN_METHOD(WebGLRenderingContext::GetParameter) {
}
}

CheckGLError();
//info.GetReturnValue().Set(Nan::Undefined());
}

Expand Down Expand Up @@ -2045,6 +2055,7 @@ NAN_METHOD(WebGLRenderingContext::GetExtension) {
String::Utf8Value name(info[0]);
char *sname=*name;
char *extensions=(char*) glGetString(GL_EXTENSIONS);
CheckGLError();
char *ext=strcasestr(extensions, sname);

if(ext==NULL){
Expand All @@ -2059,7 +2070,10 @@ NAN_METHOD(WebGLRenderingContext::CheckFramebufferStatus) {

GLenum target=info[0]->Int32Value();

info.GetReturnValue().Set(JS_INT((int)glCheckFramebufferStatus(target)));
int status = (int)glCheckFramebufferStatus(target);
CheckGLError();

info.GetReturnValue().Set(JS_INT(status));
}

void WebGLRenderingContext::preprocessTexImageData(void * pixels, int width, int height, int format, int type) {
Expand Down
1 change: 1 addition & 0 deletions examples/pxScene2d/src/pxWebGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void pxWebgl::onInit()
pixelStorei_UNPACK_FLIP_BLUE_RED = 0;

glGetIntegerv(GL_FRAMEBUFFER_BINDING, &mInitialFrameBuffer);
CheckGLError();
}

rtError pxWebgl::DrawElements(uint32_t mode, uint32_t count, uint32_t type, uint32_t offset)
Expand Down
3 changes: 2 additions & 1 deletion examples/pxScene2d/src/spark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ PathR=$externalLibs:$externalDir/node/out/Release/obj.target

export LD_LIBRARY_PATH=$PathR

export NODE_PATH=.
# TODO - come back and remove node_modules and externalDir before merging to master (once we don't need node_modules for webgl)
export NODE_PATH=.:./node_modules:$externalDir

#export RT_LOG_LEVEL=info

Expand Down