Giter Site home page Giter Site logo

gluon's Introduction

Gluon

  • WebGL implementation for js and cpp targets with additional typing for better integration with haxe

  • Abstract enums are used to type constants, for example: enable(cap:GLenum) becomes enable(cap:Capability) and the compiler can autocomplete valid constants.

    Which means fewer trips to the OpenGL specification :)

  • Includes a TypedArray implementation designed for parity with JavaScript's TypedArrays

  • GPU resources are freed with garbage collection however best practice is to still do this manually with the gl.delete* methods because both hxcpp and browser garbage collectors cannot properly estimate memory pressure of GPU objects

Examples

See EXAMPLES.md

Design Goals

  • Dependency free and minimalistic

gluon's People

Contributors

haxiomic avatar nanjizal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gluon's Issues

new Float32Array( float32Array.subarray( start, end ) );

Haxiomic

I found subarray does not work as expected on Cpp when using bufferSubData.

This code creates 3 triangles ( x,y,z,red,green,blue,a ) and can be placed in the repo link demo I shared.

        var datum = new Float32Array([
                  0.100, 0.100, 0. , 1, 1, 1, 1
                , 0.500, 0.500, 0. , 1, 1, 1, 1
                , 0.100, 0.500, 0. , 1, 1, 1, 1
                , 0.100, 0.100, 0  , 1, 0, 0, 1
                , 0.500, 0.100, 0  , 1, 0, 0, 1
                , 0.500, 0.500, 0  , 1, 0, 0, 1
                , 0.300, 0.300, 0  , 1, 1, 0, 1
                , 0.400, 0.300, 0  , 1, 1, 0, 1
                , 0.400, 0.400, 0  , 1, 1, 0, 1
            ]);
        // use middle triangle ( start at 3, end at 6 )
        //var datum2 = new Float32Array( datum.subarray( 0 + 21, 21 + 22 ) );
        var datum2 = datum.subarray( 0 + 21, 21 + 22 );
        var info = [ 'x','y','z','r','g','b','a'];
        // check the contents...
        trace( '__' );
        for( i in 0...Std.int(datum2.length/7) ){
            var str = '';
            for( j in 0...7 ) str +=  
                info[j] +':' + Std.string( Math.round( 1000*datum2[Std.int(i*j)] )/1000 ) + ' ';
            trace( str );
            str = '';
        }
        trace( '__' );

This outputs

Demo.hx:130: __
Demo.hx:136: x:0.1 y:0.1 z:0.1 r:0.1 g:0.1 b:0.1 a:0.1 
Demo.hx:136: x:0.1 y:0.1 z:0 r:1 g:0 b:0 a:1 
Demo.hx:136: x:0.1 y:0 z:0 r:1 g:0.1 b:1 a:0 
Demo.hx:139: __

which as you your may remember is passed to the shader

gl.bufferSubData( ARRAY_BUFFER, 0, datum2 );

But draws all three triangles!!!
To fix it I need to force linking to a different part of memory.

var datum2 = new Float32Array( datum.subarray( 0 + 21, 21 + 22 ) );`

I am not too sure if this is a Haxe C++ issue or a Gluon problem, I also found my clearAll depending on size provided seemed to effect the render position which is rather odd.

Really need to work on my CV and not playing with shaders, but thought I should share.
I'll let you know when I am rendering something nice, at moment my engine is just drawing these 3 triangles so pretty much the same as setting them manually, as I have disabled the lineTo test for now. Would the best approach for me to use haxe.io.Float32Array internally in trilateral and then for render, loop through to build the gluon one? I use this[0] and this[1] to store position and length.

JS seems so much more forgiving than c++.

Unclear how to compile for c++

tried linc_glfw and it opens hello world titled window no content on my mac, expected similar with gluon, modified hxml to get something to work...

-main Example
-p ../../
-cpp bin
-cmd ./bin/Example

But the output was purely textual:

haxelib run hxcpp Build.xml haxe -Dhaxe="4.0.2" -Dhaxe3="1" -Dhaxe4="1" -Dhaxe_ver="4.002" -Dhxcpp_api_level="400" -Dhxcpp_smart_strings="1" -Dsource-header="Generated by Haxe 4.0.2" -Dstatic="1" -Dtarget.name="cpp" -Dtarget.static="true" -Dtarget.sys="true" -Dtarget.threaded="true" -Dtarget.unicode="true" -Dtarget.utf16="true" -Dutf16="1" -I"../../" -I"" -I"/usr/local/lib/haxe/extraLibs/" -I"/usr/local/share/haxe/extraLibs/" -I"/usr/local/bin/extraLibs/" -I"/usr/local/lib/haxe/std/cpp/_std/" -I"/usr/local/share/haxe/std/cpp/_std/" -I"/usr/local/bin/std/cpp/_std/" -I"/usr/local/lib/haxe/std/" -I"/usr/local/share/haxe/std/" -I"/usr/local/bin/std/"
Creating /projects/May2019/December/gluon/test/gluon/bin/obj/darwin64/__pch/haxe/hxcpp.h.gch...

Compiling group: haxe
g++ -Iinclude -I/projects/May2019/December/gluon/gluon/es2/impl/include -DGLEW_STATIC -c -fvisibility=hidden -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -O2 -I/usr/local/lib/haxeLibrary/hxcpp/git/include -DHX_MACOS -m64 -Wno-parentheses -Wno-unused-value -Wno-format-extra-args -Wno-overflow -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHX_SMART_STRINGS(haxe) -DHXCPP_API_LEVEL=400(haxe) ... tags=[haxe,static]
 - src/typedarray/Uint8ArrayImpl.cpp 
 - src/typedarray/_Uint8ClampedArray/Uint8ClampedArray_Impl_.cpp 
 - src/typedarray/_Uint8Array/Uint8Array_Impl_.cpp 
 - src/typedarray/Uint8ClampedArrayImpl.cpp 
 - src/typedarray/Uint32ArrayImpl.cpp 
 - src/typedarray/_Uint32Array/Uint32Array_Impl_.cpp 
 - src/typedarray/Uint16ArrayImpl.cpp 
 - src/typedarray/_Uint16Array/Uint16Array_Impl_.cpp 
 - src/typedarray/Int8ArrayImpl.cpp 
 - src/typedarray/_Int8Array/Int8Array_Impl_.cpp 
 - src/typedarray/Int32ArrayImpl.cpp 
 - src/typedarray/_Int32Array/Int32Array_Impl_.cpp 
 - src/typedarray/Int16ArrayImpl.cpp 
 - src/typedarray/_Int16Array/Int16Array_Impl_.cpp 
 - src/typedarray/Float64ArrayImpl.cpp 
 - src/typedarray/_Float64Array/Float64Array_Impl_.cpp 
 - src/typedarray/Float32ArrayImpl.cpp 
 - src/typedarray/_Float32Array/Float32Array_Impl_.cpp 
 - src/typedarray/_BufferSource/BufferSource_Impl_.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_UInt8.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_UInt32.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_UInt16.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Int8.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Int32.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Int16.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Float64.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Float32.cpp 
 - src/typedarray/ArrayBufferViewImplIterator.cpp 
 - src/typedarray/ArrayBufferViewBase.cpp 
 - src/typedarray/ArrayBufferView.cpp 
 - src/typedarray/_ArrayBuffer/ArrayBuffer_Impl_.cpp 
 - src/haxe/io/Error.cpp 
 - src/haxe/io/Bytes.cpp 
 - src/gluon/es2/impl/ES2Context.cpp 
 - src/gluon/es2/_GLContext/GLContext_Impl_.cpp 
 - src/Example.cpp 
 - src/__boot__.cpp 
Link: Example
Example.hx:7: Hello from haxe!

Some other setups failed due to xcode paths.

I would love to draw a triangle to screen with gluon with hxcpp so that I can attempt to target it with my library - if that's feasible yet? Advise welcome. Mac 10.12.6.

Review: have haxe interpolation rules changed in 4.2+?

#6 (comment)
gluon/webgl/GLContextDebug.hx:86: OpenGL Error in "$fnName": $errorName,

In this macro

macro class ReportErrors {
	public function reportErrors(fnName: String) {
		var result: ErrorCode = NO_ERROR;
		while ((result = getError()) != NO_ERROR) {

			var errorName = switch result {
				case INVALID_ENUM: 'INVALID_ENUM';
				case INVALID_VALUE: 'INVALID_VALUE';
				case INVALID_OPERATION: 'INVALID_OPERATION';
				case INVALID_FRAMEBUFFER_OPERATION: 'INVALID_FRAMEBUFFER_OPERATION';
				case OUT_OF_MEMORY: 'OUT_OF_MEMORY';
				case NO_ERROR: 'NO_ERROR';
			}

			function printStackItem(item: haxe.CallStack.StackItem) {
				return switch item {
					case CFunction: 'CFunction';
					case Module(m): 'Module "$$m"';
					case LocalFunction(v): 'Local Function $$v';
					case Method(className, method): '$${className}.$${method}()';
					case FilePos(s, file, line): 
						'$$file:$$line' + (s != null ? (' - ' + printStackItem(s)) : '');
				}
			}

			var callStackString ='\n\t' + haxe.CallStack.callStack().slice(1).map(printStackItem).join('\n\t');
			trace('OpenGL Error in "$$fnName": $$errorName', callStackString);
		}
	}
}

Gluon use cases with Trilateral3 & linc_glfw

You can find some helpers I have created for use with Gluon, created with the help of haxeiomic.
They are still under dev:
https://github.com/nanjizal/kitGL/tree/master/src/kitGL/gluon

Graphical examples some animated using Trilateral3 using a linc_glfw window ( mac terminal code online ).
https://github.com/TrilateralX/TrilateralSamples/tree/master/gluon/

Currently Trilateral3 is quite modular all repos on my github so likely not ideal to setup just yet, but if you do try and get stuck to let me know.

AtriangleGluon
BsvgpathGluon
Cfillgluon
DecllipseGluon
EregularColor
ElinesGluon
GrotateMoveGluon

Glow

Github was suggesting repos, Glow seemed interesting Rust one with similar intentions to Gluon but maybe not as extensive? I don't know rust yet but maybe you will find some interesting ideas.
https://github.com/grovesNL/glow

by the way I never remember your github name spelling, and gluon seems very popular project name ( think there is even another project same name in haxelib ). Suggest changing/varying name to something not as widely used - GaugeBoson ?

Any assistance on using images with c++ in gluon.

Currently I have two trilateral3 WebGL tests that use images they use this base class
https://github.com/nanjizal/kitGL/blob/master/src/kitGL/glWeb/PlyUV.js.hx
and some image helpers ...
https://github.com/nanjizal/kitGL/blob/master/src/kitGL/glWeb/ImageGL.js.hx
and shaders
https://github.com/nanjizal/kitGL/blob/master/src/kitGL/glWeb/TextureShader.js.hx

The tests are of drawn shapes using textures with pos/uv moved at runtime.
https://github.com/TrilateralX/TrilateralSamples/blob/master/webgl/HtextureBasic/TrilateralTextureBasic.hx
and of using a spritesheet for text
https://github.com/TrilateralX/TrilateralSamples/blob/master/webgl/ItileSheetText/TrilateralTileSheetTexture.hx
The results in WebGL
https://trilateralx.github.io/TrilateralSamples/webgl/HtextureBasic/
https://trilateralx.github.io/TrilateralSamples/webgl/ItileSheetText/
Do you think this is feasible for Gluon target for c++, can you advise on basic use of an image, I presume most of my GL code can be quite easily ported for Gluon it's just image use I am not quite following. Have you tried wiring up Format's PNG reader, looking at your code it looks like an image is kind of treated a bit like an array?

Sorry I know my file sizes are stupid for these tests... need to look more closely at my inline use once I have more functional libraries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.