├── .gitattributes ├── assets └── neoray-dark.png ├── cmd └── neoray │ ├── assets │ ├── icons │ │ ├── neovim-16.png │ │ ├── neovim-256.png │ │ ├── neovim-32.png │ │ ├── neovim-48.png │ │ ├── neovim-64.png │ │ └── README.md │ ├── rsrc_windows_386.syso │ ├── rsrc_windows_amd64.syso │ ├── fonts │ │ ├── CascadiaCode-Bold.ttf │ │ ├── CascadiaCode-Italic.ttf │ │ ├── CaskaydiaCove-Regular.ttf │ │ └── CascadiaCode-BoldItalic.ttf │ ├── assets.go │ └── winres │ │ └── winres.json │ ├── neoray.vim │ ├── main.go │ ├── input_test.go │ └── style.go ├── .vim └── coc-settings.json ├── .gitignore ├── pkg ├── opengl │ ├── glow │ │ ├── xml │ │ │ ├── README.md │ │ │ ├── overload │ │ │ │ └── gl.xml │ │ │ └── doc │ │ │ │ ├── glXGetCurrentContext.xml │ │ │ │ ├── glXGetCurrentDrawable.xml │ │ │ │ ├── glLoadPaletteFromModelViewMatrix.xml │ │ │ │ ├── glXGetCurrentDisplay.xml │ │ │ │ ├── glXGetCurrentReadDrawable.xml │ │ │ │ ├── glXGetProcAddress.xml │ │ │ │ ├── glReleaseShaderCompiler.xml │ │ │ │ ├── glFinish.xml │ │ │ │ ├── glXWaitX.xml │ │ │ │ ├── glXWaitGL.xml │ │ │ │ ├── glResetHistogram.xml │ │ │ │ ├── glBlendBarrier.xml │ │ │ │ ├── glXDestroyGLXPixmap.xml │ │ │ │ ├── glXIsDirect.xml │ │ │ │ ├── glListBase.xml │ │ │ │ ├── glXDestroyContext.xml │ │ │ │ ├── glInitNames.xml │ │ │ │ ├── glCurrentPaletteMatrix.xml │ │ │ │ ├── glTextureBarrier.xml │ │ │ │ ├── glResetMinmax.xml │ │ │ │ ├── glIsList.xml │ │ │ │ ├── glXGetContextIDEXT.xml │ │ │ │ ├── glPauseTransformFeedback.xml │ │ │ │ ├── glResumeTransformFeedback.xml │ │ │ │ ├── glIsSync.xml │ │ │ │ ├── glXDestroyWindow.xml │ │ │ │ ├── glXDestroyPbuffer.xml │ │ │ │ ├── glXDestroyPixmap.xml │ │ │ │ ├── glIsSampler.xml │ │ │ │ ├── glXQueryExtensionsString.xml │ │ │ │ ├── glIsVertexArray.xml │ │ │ │ ├── glIsFramebuffer.xml │ │ │ │ ├── glXQueryExtension.xml │ │ │ │ ├── glFlush.xml │ │ │ │ ├── glIsQuery.xml │ │ │ │ ├── glIsTransformFeedback.xml │ │ │ │ ├── glXGetFBConfigs.xml │ │ │ │ ├── glXFreeContextEXT.xml │ │ │ │ ├── glIsBuffer.xml │ │ │ │ ├── glIsProgramPipeline.xml │ │ │ │ └── glXGetSelectedEvent.xml │ │ ├── tmpl │ │ │ ├── debug.tmpl │ │ │ └── procaddr.tmpl │ │ └── glfunclist.json │ ├── shaders │ │ ├── grid.vert │ │ ├── grid.frag │ │ └── grid.geom │ ├── gl │ │ └── procaddr.go │ ├── opengl.go │ ├── shader.go │ └── texture.go ├── bench │ ├── bench_release.go │ └── bench_debug.go ├── common │ ├── color.go │ ├── rect.go │ ├── common.go │ └── vector.go ├── fontkit │ ├── font.go │ └── fontkit.go ├── logger │ └── types.go └── window │ └── event.go ├── CHANGELOG.md ├── nvimhere.reg ├── .github ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ └── release.yml ├── minimal.vim ├── go.mod ├── LICENSE └── Makefile /.gitattributes: -------------------------------------------------------------------------------- 1 | *.go eol=lf -------------------------------------------------------------------------------- /assets/neoray-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/assets/neoray-dark.png -------------------------------------------------------------------------------- /cmd/neoray/assets/icons/neovim-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/icons/neovim-16.png -------------------------------------------------------------------------------- /cmd/neoray/assets/icons/neovim-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/icons/neovim-256.png -------------------------------------------------------------------------------- /cmd/neoray/assets/icons/neovim-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/icons/neovim-32.png -------------------------------------------------------------------------------- /cmd/neoray/assets/icons/neovim-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/icons/neovim-48.png -------------------------------------------------------------------------------- /cmd/neoray/assets/icons/neovim-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/icons/neovim-64.png -------------------------------------------------------------------------------- /cmd/neoray/assets/rsrc_windows_386.syso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/rsrc_windows_386.syso -------------------------------------------------------------------------------- /cmd/neoray/assets/rsrc_windows_amd64.syso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/rsrc_windows_amd64.syso -------------------------------------------------------------------------------- /.vim/coc-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "go.goplsOptions": { 3 | "buildFlags": [ 4 | "-tags=debug" 5 | ] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /cmd/neoray/assets/fonts/CascadiaCode-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/fonts/CascadiaCode-Bold.ttf -------------------------------------------------------------------------------- /cmd/neoray/assets/fonts/CascadiaCode-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/fonts/CascadiaCode-Italic.ttf -------------------------------------------------------------------------------- /cmd/neoray/assets/fonts/CaskaydiaCove-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/fonts/CaskaydiaCove-Regular.ttf -------------------------------------------------------------------------------- /cmd/neoray/assets/fonts/CascadiaCode-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hismailbulut/Neoray/HEAD/cmd/neoray/assets/fonts/CascadiaCode-BoldItalic.ttf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | Neoray_crash.log 3 | Neoray_verbose.log 4 | Neoray_cpu_profile.prof 5 | Neoray_heap_profile.prof 6 | .vscode 7 | boxdrawingchars.txt 8 | fontlist.txt -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/README.md: -------------------------------------------------------------------------------- 1 | XML 2 | === 3 | 4 | This directory contains the XML specification and documentation files used to generate the Glow prebuilt packages. 5 | -------------------------------------------------------------------------------- /cmd/neoray/assets/icons/README.md: -------------------------------------------------------------------------------- 1 | The Neovim logo by [Jason Long](https://twitter.com/jasonlong) is licensed under the [Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/). -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 0.2.5 2 | - Various fixes and optimizations 3 | ### 0.2.4 4 | - Neoray now requires minimum 0.5.0 version of Neovim because need of `nvim_exec` 5 | - New image viewer feature. Can be disabled by new option 'ImageViewer' 6 | - Option 'ContextMenuOn' renamed to 'ContextMenu' 7 | - Option 'BoxDrawingOn' renamed to 'BoxDrawing' 8 | -------------------------------------------------------------------------------- /pkg/bench/bench_release.go: -------------------------------------------------------------------------------- 1 | //go:build !debug 2 | // +build !debug 3 | 4 | package bench 5 | 6 | import ( 7 | "io" 8 | 9 | "github.com/hismailbulut/Neoray/pkg/logger" 10 | ) 11 | 12 | const BUILD_TYPE = logger.ReleaseBuild 13 | 14 | func IsDebugBuild() bool { return false } 15 | 16 | func Begin() func(name ...string) { 17 | return func(name ...string) {} 18 | } 19 | 20 | func PrintResults(out io.Writer) {} 21 | -------------------------------------------------------------------------------- /nvimhere.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | ; Running this file allows you to add neoray to your explorer menu. 4 | ; Uncomment all lines below and change all to your neoray.exe 5 | ; Provide absolute path to neoray.exe, separate directories with double backslash. 6 | 7 | ; [HKEY_CLASSES_ROOT\*\shell\Edit with Neovim] 8 | ; "Icon"="" 9 | ; 10 | ; [HKEY_CLASSES_ROOT\*\shell\Edit with Neovim\command] 11 | ; @="\"\" -si --file \"%1\"" 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Please complete the following information:** 11 | - OS or distro: 12 | - neoray version: 13 | 14 | **Describe the bug** 15 | 16 | **Steps to reproduce** 17 | 18 | **Your neoray config in init.vim** (Only the part that concerns neoray!) 19 | ```vim 20 | 21 | ``` 22 | 23 | **Crash log if available (may be generated by neoray after crash)** 24 | 25 | **Debug output (you can generate starting neoray with --verbose option)** 26 | -------------------------------------------------------------------------------- /pkg/common/color.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Zero values for reducing allocations 8 | var ( 9 | ZeroColor = Color{} 10 | ) 11 | 12 | type Color struct { 13 | R, G, B, A float32 14 | } 15 | 16 | func (c Color) String() string { 17 | return fmt.Sprintf("Color(R: %v, G: %v, B: %v, A: %v)", c.R, c.G, c.B, c.A) 18 | } 19 | 20 | func ColorFromUint(color uint32) Color { 21 | r := (color >> 16) & 0xff 22 | g := (color >> 8) & 0xff 23 | b := color & 0xff 24 | return Color{ 25 | R: float32(r) / 255.0, 26 | G: float32(g) / 255.0, 27 | B: float32(b) / 255.0, 28 | A: 1.0, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /minimal.vim: -------------------------------------------------------------------------------- 1 | if exists('g:neoray') 2 | set guifont=:h13 3 | set guicursor+=a:blinkwait1000-blinkon500-blinkoff250-Cursor 4 | NeoraySet CursorAnimTime 0.08 5 | NeoraySet Transparency 0.975 6 | NeoraySet TargetTPS 90 7 | NeoraySet ContextMenu TRUE 8 | " NeoraySet ContextMenuItem ------------ : 9 | " NeoraySet ContextMenuItem Say\ Hello :echo\ "Hello\ World" 10 | " NeoraySet ContextMenuItem Toggle\ Nerd :NERDTreeToggle 11 | NeoraySet BoxDrawing TRUE 12 | NeoraySet ImageViewer TRUE 13 | NeoraySet WindowSize 100x40 14 | NeoraySet WindowState centered 15 | " NeoraySet KeyFullscreen 16 | " NeoraySet KeyZoomIn 17 | " NeoraySet KeyZoomOut 18 | endif 19 | -------------------------------------------------------------------------------- /pkg/opengl/shaders/grid.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(location = 0) in vec4 pos; 3 | layout(location = 1) in vec4 tex1; 4 | layout(location = 2) in vec4 tex2; 5 | layout(location = 3) in vec4 fg; 6 | layout(location = 4) in vec4 bg; 7 | layout(location = 5) in vec4 sp; 8 | 9 | uniform mat4 projection; 10 | uniform vec4 undercurlRect; 11 | 12 | out VS_OUT { 13 | vec4 tex1pos; 14 | vec4 tex2pos; 15 | vec4 ucPos; 16 | mat4 projection; 17 | vec4 fgColor; 18 | vec4 bgColor; 19 | vec4 spColor; 20 | } vs_out; 21 | 22 | void main() { 23 | gl_Position = pos; 24 | vs_out.tex1pos = tex1; 25 | vs_out.tex2pos = tex2; 26 | vs_out.ucPos = undercurlRect; 27 | vs_out.projection = projection; 28 | vs_out.fgColor = fg; 29 | vs_out.bgColor = bg; 30 | vs_out.spColor = sp; 31 | } 32 | -------------------------------------------------------------------------------- /cmd/neoray/assets/assets.go: -------------------------------------------------------------------------------- 1 | 2 | // Neoray package for windows syso files and other assets 3 | // Main must include this package 4 | 5 | package assets 6 | 7 | import _ "embed" 8 | 9 | var ( 10 | // Icons 11 | 12 | //go:embed icons/neovim-16.png 13 | NeovimIconData16x16 []byte 14 | //go:embed icons/neovim-32.png 15 | NeovimIconData32x32 []byte 16 | //go:embed icons/neovim-48.png 17 | NeovimIconData48x48 []byte 18 | 19 | // Fonts 20 | // The regular one is completely packed with nerd fonts. 21 | // Others are original. 22 | 23 | //go:embed fonts/CaskaydiaCove-Regular.ttf 24 | Regular []byte 25 | //go:embed fonts/CascadiaCode-BoldItalic.ttf 26 | BoldItalic []byte 27 | //go:embed fonts/CascadiaCode-Italic.ttf 28 | Italic []byte 29 | //go:embed fonts/CascadiaCode-Bold.ttf 30 | Bold []byte 31 | ) 32 | -------------------------------------------------------------------------------- /pkg/opengl/glow/tmpl/debug.tmpl: -------------------------------------------------------------------------------- 1 | //glow:keepspace 2 | // Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT. 3 | 4 | package {{.Name}} 5 | //glow:rmspace 6 | 7 | import "C" 8 | import "unsafe" 9 | 10 | type DebugProc func( 11 | source uint32, 12 | gltype uint32, 13 | id uint32, 14 | severity uint32, 15 | length int32, 16 | message string, 17 | userParam unsafe.Pointer) 18 | 19 | var userDebugCallback DebugProc 20 | 21 | //export glowDebugCallback_{{.UniqueName}} 22 | func glowDebugCallback_{{.UniqueName}}( 23 | source uint32, 24 | gltype uint32, 25 | id uint32, 26 | severity uint32, 27 | length int32, 28 | message *uint8, 29 | userParam unsafe.Pointer) { 30 | if userDebugCallback != nil { 31 | userDebugCallback(source, gltype, id, severity, length, GoStr(message), userParam) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hismailbulut/Neoray 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/adrg/sysfont v0.1.2 7 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220806181222-55e207c401ad 8 | github.com/neovim/go-client v1.2.1 9 | github.com/olekukonko/tablewriter v0.0.5 10 | github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf 11 | golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 12 | ) 13 | 14 | require ( 15 | github.com/TheTitanrain/w32 v0.0.0-20200114052255-2654d97dbd3d // indirect 16 | github.com/adrg/strutil v0.3.0 // indirect 17 | github.com/adrg/xdg v0.4.0 // indirect 18 | github.com/davecgh/go-spew v1.1.1 // indirect 19 | github.com/mattn/go-runewidth v0.0.13 // indirect 20 | github.com/rivo/uniseg v0.3.4 // indirect 21 | golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect 22 | golang.org/x/text v0.3.7 // indirect 23 | ) 24 | -------------------------------------------------------------------------------- /pkg/opengl/shaders/grid.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout(location = 0) out vec4 outFragColor; 3 | 4 | in GS_OUT { 5 | vec2 tex1pos; 6 | vec2 tex2pos; 7 | vec2 ucPos; 8 | vec4 fgColor; 9 | vec4 bgColor; 10 | vec4 spColor; 11 | } fs_in; 12 | 13 | uniform sampler2D atlas; 14 | 15 | void main() { 16 | vec4 tex1 = texture(atlas, fs_in.tex1pos); 17 | vec4 fg = mix(tex1, fs_in.fgColor, fs_in.fgColor.a); // Use texture color if fg.A < 1 18 | float texA = max(tex1.a, texture(atlas, fs_in.tex2pos).a); // Use both of textures 19 | float ucA = min(texture(atlas, fs_in.ucPos).a, fs_in.spColor.a); // If sp.A == 0 we don't draw undercurl 20 | vec4 result = mix(fs_in.bgColor, fg, texA); // Draw foreground over background 21 | outFragColor = mix(result, fs_in.spColor, ucA); // Draw special over result color 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ismail Bulut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /pkg/opengl/shaders/grid.geom: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (points) in; 3 | layout (triangle_strip, max_vertices = 4) out; 4 | 5 | in VS_OUT { 6 | vec4 tex1pos; 7 | vec4 tex2pos; 8 | vec4 ucPos; 9 | mat4 projection; 10 | vec4 fgColor; 11 | vec4 bgColor; 12 | vec4 spColor; 13 | } gs_in[]; 14 | 15 | out GS_OUT { 16 | vec2 tex1pos; 17 | vec2 tex2pos; 18 | vec2 ucPos; 19 | vec4 fgColor; 20 | vec4 bgColor; 21 | vec4 spColor; 22 | } gs_out; 23 | 24 | vec2 pluspos[] = vec2[4]( 25 | vec2(0, 1), 26 | vec2(0, 0), 27 | vec2(1, 1), 28 | vec2(1, 0) 29 | ); 30 | 31 | void main() { 32 | for(int i = 0; i < 4; i++) { 33 | vec4 pos = gl_in[0].gl_Position; 34 | gl_Position = vec4(pos.xy + (pluspos[i] * pos.zw), 0, 1) * gs_in[0].projection; 35 | gs_out.tex1pos = gs_in[0].tex1pos.xy + (pluspos[i] * gs_in[0].tex1pos.zw); 36 | gs_out.tex2pos = gs_in[0].tex2pos.xy + (pluspos[i] * gs_in[0].tex2pos.zw); 37 | gs_out.ucPos = gs_in[0].ucPos.xy + (pluspos[i] * gs_in[0].ucPos.zw); 38 | gs_out.fgColor = gs_in[0].fgColor; 39 | gs_out.bgColor = gs_in[0].bgColor; 40 | gs_out.spColor = gs_in[0].spColor; 41 | EmitVertex(); 42 | } 43 | EndPrimitive(); 44 | } 45 | -------------------------------------------------------------------------------- /pkg/common/rect.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | // Zero values for reducing allocations 9 | var ( 10 | ZeroRectangleF32 = Rectangle[float32]{} 11 | ZeroRectangleINT = Rectangle[int]{} 12 | ) 13 | 14 | type Rectangle[T Numbers] struct { 15 | X, Y, W, H T 16 | } 17 | 18 | func (rect Rectangle[T]) String() string { 19 | return fmt.Sprintf("Rectangle(X: %v, Y: %v, W: %v, H: %v)", rect.X, rect.Y, rect.W, rect.H) 20 | } 21 | 22 | // Shortcut for creating a new rectangle 23 | func Rect[T Numbers](X, Y, W, H T) Rectangle[T] { 24 | return Rectangle[T]{X: X, Y: Y, W: W, H: H} 25 | } 26 | 27 | func (rect Rectangle[T]) ToInt() Rectangle[int] { 28 | return Rectangle[int]{ 29 | X: int(math.Floor(float64(rect.X))), 30 | Y: int(math.Floor(float64(rect.Y))), 31 | W: int(math.Floor(float64(rect.W))), 32 | H: int(math.Floor(float64(rect.H))), 33 | } 34 | } 35 | 36 | func (rect Rectangle[T]) ToF32() Rectangle[float32] { 37 | return Rectangle[float32]{ 38 | X: float32(rect.X), 39 | Y: float32(rect.Y), 40 | W: float32(rect.W), 41 | H: float32(rect.H), 42 | } 43 | } 44 | 45 | func (rect Rectangle[T]) Area() float32 { 46 | return float32(rect.W * rect.H) 47 | } 48 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | isWindows :=$(filter Windows_NT, $(OS)) 2 | 3 | ifeq ($(EXECNAME),) 4 | EXECNAME=neoray 5 | endif 6 | 7 | ifeq ($(OUTDIR),) 8 | OUTDIR=bin 9 | endif 10 | 11 | VERSION :=0.2.6 12 | SRCDIR :=./cmd/neoray 13 | SRCTESTDIR :=./cmd/neoray/... 14 | PKGTESTDIR :=./pkg/... 15 | GLOWDIR :=./pkg/opengl/glow 16 | OUTEXE :=./$(OUTDIR)/$(EXECNAME) 17 | OUTDBG :=$(OUTEXE)_debug 18 | LDFLAGS :=-s -w 19 | 20 | ifeq ($(OS),Windows_NT) 21 | OUTDBG :=$(OUTDBG).exe 22 | OUTEXE :=$(OUTEXE).exe 23 | LDFLAGS :=$(LDFLAGS) -H=windowsgui 24 | endif 25 | 26 | build: 27 | go build -tags debug -race -o $(OUTDBG) $(SRCDIR) 28 | 29 | run: build 30 | $(OUTDBG) $(ARGS) 31 | 32 | generate: 33 | $(if $(isWindows), cd cmd/neoray/assets && go-winres make --product-version=$(VERSION) --file-version=$(VERSION)) 34 | glow generate -out=./pkg/opengl/gl -api=gl -version=3.3 -profile=core -restrict=$(GLOWDIR)/glfunclist.json -tmpl=$(GLOWDIR)/tmpl -xml=$(GLOWDIR)/xml 35 | 36 | release: 37 | go build -ldflags="$(LDFLAGS)" -o $(OUTEXE) $(SRCDIR) 38 | 39 | test: 40 | go test -race $(SRCTESTDIR) 41 | go test -race $(PKGTESTDIR) 42 | 43 | bench: 44 | go test -run=XXX -bench=. -benchmem -race $(SRCTESTDIR) 45 | go test -run=XXX -bench=. -benchmem -race $(PKGTESTDIR) 46 | 47 | debug: 48 | dlv debug $(SRCDIR) 49 | 50 | all: generate test bench build release 51 | -------------------------------------------------------------------------------- /pkg/fontkit/font.go: -------------------------------------------------------------------------------- 1 | package fontkit 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "golang.org/x/image/font/opentype" 8 | "golang.org/x/image/font/sfnt" 9 | ) 10 | 11 | type Font struct { 12 | handle *sfnt.Font 13 | buffer sfnt.Buffer 14 | filePath string 15 | faceCache map[FaceParams]*Face 16 | } 17 | 18 | func CreateFontFromFile(pathToFile string) (*Font, error) { 19 | fileData, err := os.ReadFile(pathToFile) 20 | if err != nil { 21 | return nil, fmt.Errorf("Failed to read file: %s\n", err) 22 | } 23 | font, err := CreateFontFromMem(fileData) 24 | if err != nil { 25 | return nil, err 26 | } 27 | font.filePath = pathToFile 28 | return font, nil 29 | } 30 | 31 | func CreateFontFromMem(data []byte) (*Font, error) { 32 | font := new(Font) 33 | var err error 34 | font.handle, err = opentype.Parse(data) 35 | if err != nil { 36 | return nil, fmt.Errorf("Failed to parse font data: %s\n", err) 37 | } 38 | font.faceCache = make(map[FaceParams]*Face) 39 | return font, nil 40 | } 41 | 42 | func (font *Font) FilePath() string { 43 | return font.filePath 44 | } 45 | 46 | func (font *Font) FamilyName() (string, error) { 47 | name, err := font.handle.Name(&font.buffer, sfnt.NameIDFamily) 48 | if err != nil { 49 | return "", err 50 | } 51 | return name, nil 52 | } 53 | 54 | // ContainsGlyph returns the whether font contains the given glyph. 55 | func (font *Font) ContainsGlyph(char rune) bool { 56 | i, err := font.handle.GlyphIndex(&font.buffer, char) 57 | return i != 0 && err == nil 58 | } 59 | -------------------------------------------------------------------------------- /cmd/neoray/neoray.vim: -------------------------------------------------------------------------------- 1 | # This is template for Neoray runtime files 2 | function s:NeorayOptionSet(...) 3 | if a:0 < 2 4 | echoerr 'NeoraySet needs at least 2 arguments' 5 | return 6 | endif 7 | call call(function("rpcnotify"), [$(CHANID), "NeorayOptionSet"] + a:000) 8 | endfunction 9 | 10 | # TODO: The completion must respect user input 11 | function s:NeorayCompletion(A, L, P) 12 | return 13 | \ [ 14 | \ 'CursorAnimTime', 15 | \ 'Transparency', 16 | \ 'TargetTPS', 17 | \ 'ContextMenu', 18 | \ 'ContextButton', 19 | \ 'BoxDrawing', 20 | \ 'ImageViewer', 21 | \ 'WindowState', 22 | \ 'WindowSize', 23 | \ 'KeyFullscreen', 24 | \ 'KeyZoomIn', 25 | \ 'KeyZoomOut' 26 | \ ] 27 | endfunction 28 | 29 | command -nargs=+ -complete=customlist,s:NeorayCompletion NeoraySet call s:NeorayOptionSet() 30 | 31 | # Delete buffer but keep window layout 32 | function s:NeorayDeleteBuffer() 33 | let l:currentBufNum = bufnr("%") 34 | let l:alternateBufNum = bufnr("#") 35 | if buflisted(l:alternateBufNum) 36 | buffer # 37 | else 38 | bnext 39 | endif 40 | if bufnr("%") == l:currentBufNum 41 | new 42 | endif 43 | if buflisted(l:currentBufNum) 44 | execute("bwipeout! ".l:currentBufNum) 45 | endif 46 | endfunction 47 | 48 | augroup Neoray 49 | autocmd VimEnter * call rpcnotify($(CHANID), 'NeorayVimEnter') 50 | autocmd VimLeave * call rpcnotify($(CHANID), 'NeorayVimLeave') 51 | autocmd BufReadPre *.png,*.jpg,*.jpeg,*.gif,*.webp,*.bmp let s:imageViewed = rpcrequest($(CHANID), "NeorayViewImage", expand("%:p")) 52 | autocmd BufReadPost *.png,*.jpg,*.jpeg,*.gif,*.webp,*.bmp if s:imageViewed == 1 | call s:NeorayDeleteBuffer() | endif 53 | augroup end 54 | -------------------------------------------------------------------------------- /cmd/neoray/assets/winres/winres.json: -------------------------------------------------------------------------------- 1 | { 2 | "RT_GROUP_ICON": { 3 | "APP": { 4 | "0000": [ 5 | "../icons/neovim-256.png", 6 | "../icons/neovim-64.png", 7 | "../icons/neovim-48.png", 8 | "../icons/neovim-32.png", 9 | "../icons/neovim-16.png" 10 | ] 11 | } 12 | }, 13 | "RT_MANIFEST": { 14 | "#1": { 15 | "0409": { 16 | "identity": { 17 | "name": "", 18 | "version": "" 19 | }, 20 | "description": "", 21 | "minimum-os": "win7", 22 | "execution-level": "as invoker", 23 | "ui-access": false, 24 | "auto-elevate": false, 25 | "dpi-awareness": "per monitor v2", 26 | "disable-theming": false, 27 | "disable-window-filtering": false, 28 | "high-resolution-scrolling-aware": false, 29 | "ultra-high-resolution-scrolling-aware": false, 30 | "long-path-aware": false, 31 | "printer-driver-isolation": false, 32 | "gdi-scaling": false, 33 | "segment-heap": false, 34 | "use-common-controls-v6": false 35 | } 36 | } 37 | }, 38 | "RT_VERSION": { 39 | "#1": { 40 | "0000": { 41 | "fixed": { 42 | "file_version": "", 43 | "product_version": "" 44 | }, 45 | "info": { 46 | "0409": { 47 | "Comments": "", 48 | "CompanyName": "", 49 | "FileDescription": "Neoray", 50 | "FileVersion": "", 51 | "InternalName": "", 52 | "LegalCopyright": "", 53 | "LegalTrademarks": "", 54 | "OriginalFilename": "Neoray.exe", 55 | "PrivateBuild": "", 56 | "ProductName": "", 57 | "ProductVersion": "", 58 | "SpecialBuild": "" 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /cmd/neoray/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "runtime" 6 | "runtime/debug" 7 | "time" 8 | 9 | "github.com/hismailbulut/Neoray/pkg/bench" 10 | "github.com/hismailbulut/Neoray/pkg/logger" 11 | ) 12 | 13 | const ( 14 | NAME = "Neoray" 15 | VERSION_MAJOR = 0 16 | VERSION_MINOR = 2 17 | VERSION_PATCH = 5 18 | WEBPAGE = "github.com/hismailbulut/Neoray" 19 | LICENSE = "MIT" 20 | ) 21 | 22 | // Start time of the program 23 | var StartTime time.Time 24 | 25 | func init() { 26 | runtime.LockOSThread() 27 | // Enabling this helps us to catch and print segfaults (Does it?) 28 | debug.SetPanicOnFault(true) 29 | } 30 | 31 | func main() { 32 | StartTime = time.Now() 33 | // Init logger 34 | logger.Init(NAME, logger.Version{Major: VERSION_MAJOR, Minor: VERSION_MINOR, Patch: VERSION_PATCH}, bench.BUILD_TYPE, true) 35 | defer logger.Shutdown() 36 | // Print benchmark results 37 | defer bench.PrintResults(os.Stdout) 38 | // Parse args 39 | var err error 40 | var quit bool 41 | Editor.parsedArgs, err, quit = ParseArgs(os.Args[1:]) 42 | if err != nil { 43 | logger.Log(logger.FATAL, err) 44 | } 45 | if quit { 46 | return 47 | } 48 | // If ProcessBefore returns true, neoray will not start. 49 | // Initializes logfile if required argument passed 50 | // And also initializes server if required argument passed 51 | quit = Editor.parsedArgs.ProcessBefore() 52 | if quit { 53 | return 54 | } 55 | // Initializing editor will initialize everything 56 | InitEditor() 57 | // And shutdown will frees resources and closes everything 58 | defer ShutdownEditor() 59 | // Some arguments must be processed after initialization 60 | Editor.parsedArgs.ProcessAfter() 61 | // Start time information 62 | logger.Log(logger.TRACE, "Initialization time:", time.Since(StartTime)) 63 | // MainLoop is main loop of the neoray. 64 | MainLoop() 65 | } 66 | -------------------------------------------------------------------------------- /pkg/logger/types.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import "fmt" 4 | 5 | type BuildType uint8 6 | 7 | func (buildType BuildType) String() string { 8 | switch buildType { 9 | case DebugBuild: 10 | return "Debug" 11 | case ReleaseBuild: 12 | return "Release" 13 | } 14 | panic("unknown build type") 15 | } 16 | 17 | const ( 18 | DebugBuild BuildType = iota 19 | ReleaseBuild 20 | ) 21 | 22 | type Version struct { 23 | Major int 24 | Minor int 25 | Patch int 26 | } 27 | 28 | func (version Version) String() string { 29 | return fmt.Sprintf("v%d.%d.%d", version.Major, version.Minor, version.Patch) 30 | } 31 | 32 | type AnsiTermColor string 33 | 34 | const ( 35 | AnsiBlack AnsiTermColor = "\u001b[30m" 36 | AnsiRed AnsiTermColor = "\u001b[31m" 37 | AnsiGreen AnsiTermColor = "\u001b[32m" 38 | AnsiYellow AnsiTermColor = "\u001b[33m" 39 | AnsiBlue AnsiTermColor = "\u001b[34m" 40 | AnsiMagenta AnsiTermColor = "\u001b[35m" 41 | AnsiCyan AnsiTermColor = "\u001b[36m" 42 | AnsiWhite AnsiTermColor = "\u001b[37m" 43 | AnsiReset AnsiTermColor = "\u001b[0m" 44 | ) 45 | 46 | type LogLevel uint32 47 | 48 | const ( 49 | // log levels 50 | DEBUG LogLevel = iota 51 | TRACE 52 | WARN 53 | ERROR 54 | FATAL 55 | ) 56 | 57 | func (logLevel LogLevel) String() string { 58 | switch logLevel { 59 | case DEBUG: 60 | return "[DEBUG]" 61 | case TRACE: 62 | return "[TRACE]" 63 | case WARN: 64 | return "[WARNING]" 65 | case ERROR: 66 | return "[ERROR]" 67 | case FATAL: 68 | return "[FATAL]" 69 | } 70 | panic("unknown log level") 71 | } 72 | 73 | func (logLevel LogLevel) Color() AnsiTermColor { 74 | switch logLevel { 75 | case DEBUG: 76 | return AnsiWhite 77 | case TRACE: 78 | return AnsiGreen 79 | case WARN: 80 | return AnsiYellow 81 | case ERROR: 82 | return AnsiRed 83 | case FATAL: 84 | return AnsiRed 85 | } 86 | panic("unknown log level") 87 | } 88 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/overload/gl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /pkg/window/event.go: -------------------------------------------------------------------------------- 1 | package window 2 | 3 | import "github.com/go-gl/glfw/v3.3/glfw" 4 | 5 | type WindowEventType uint32 6 | 7 | const ( 8 | WindowEventRefresh WindowEventType = iota 9 | WindowEventResize 10 | WindowEventKeyInput 11 | WindowEventCharInput 12 | WindowEventMouseInput 13 | WindowEventMouseMove 14 | WindowEventScroll 15 | WindowEventDrop 16 | WindowEventScaleChanged 17 | WindowEventClose 18 | ) 19 | 20 | func (Type WindowEventType) String() string { 21 | switch Type { 22 | case WindowEventRefresh: 23 | return "WindowEventRefresh" 24 | case WindowEventResize: 25 | return "WindowEventResize" 26 | case WindowEventKeyInput: 27 | return "WindowEventKeyInput" 28 | case WindowEventCharInput: 29 | return "WindowEventCharInput" 30 | case WindowEventMouseInput: 31 | return "WindowEventMouseInput" 32 | case WindowEventMouseMove: 33 | return "WindowEventMouseMove" 34 | case WindowEventScroll: 35 | return "WindowEventScroll" 36 | case WindowEventDrop: 37 | return "WindowEventDrop" 38 | case WindowEventClose: 39 | return "WindowEventClose" 40 | default: 41 | panic("unknown window event type") 42 | } 43 | } 44 | 45 | type WindowEvent struct { 46 | Type WindowEventType 47 | Params []any 48 | } 49 | 50 | type WindowEventStack []WindowEvent 51 | 52 | func (stack *WindowEventStack) Push(eventType WindowEventType, params ...any) { 53 | *stack = append(*stack, WindowEvent{ 54 | Type: eventType, 55 | Params: params, 56 | }) 57 | } 58 | 59 | func (window *Window) SetEventHandler(eventHandler func(event WindowEvent)) { 60 | window.handle.SetRefreshCallback(func(w *glfw.Window) { 61 | eventHandler(WindowEvent{Type: WindowEventRefresh}) 62 | }) 63 | window.eventHandler = eventHandler 64 | } 65 | 66 | func (window *Window) PollEvents() { 67 | glfw.PollEvents() 68 | resizeIndex := -1 69 | for i := 0; i < len(window.events); i++ { 70 | event := window.events[i] 71 | if event.Type == WindowEventResize { 72 | resizeIndex = i 73 | } else { 74 | window.eventHandler(event) 75 | } 76 | } 77 | // NOTE: Only send last resize event because when refreshing happens glfw 78 | // pollevents call blocked but glfw stores all resize events and sends them 79 | // at same time, only the last one is the actual size of the window 80 | if resizeIndex != -1 { 81 | window.eventHandler(window.events[resizeIndex]) 82 | } 83 | // Check close event 84 | if window.handle.ShouldClose() { 85 | window.eventHandler(WindowEvent{Type: WindowEventClose}) 86 | } 87 | // Clear event stack 88 | window.events = window.events[0:0] 89 | } 90 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build-windows: 8 | runs-on: windows-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | 12 | - name: Set up Go 13 | uses: actions/setup-go@v2 14 | with: 15 | go-version: '1.20' 16 | 17 | - name: Install tools 18 | run: | 19 | go install github.com/tc-hib/go-winres@latest 20 | go install github.com/go-gl/glow@latest 21 | 22 | - name: Generate 23 | run: make generate 24 | 25 | - name: Build 26 | env: 27 | CGO_ENABLED: 1 28 | GOOS: windows 29 | GOARCH: amd64 30 | run: make release 31 | 32 | - name: Upload binaries 33 | uses: actions/upload-artifact@v2 34 | if: success() 35 | with: 36 | name: neoray-windows 37 | path: | 38 | bin/neoray.exe 39 | 40 | build-macos: 41 | runs-on: macos-latest 42 | steps: 43 | - uses: actions/checkout@v2 44 | 45 | - name: Set up Go 46 | uses: actions/setup-go@v2 47 | with: 48 | go-version: '1.20' 49 | 50 | - name: Install tools 51 | run: go install github.com/go-gl/glow@latest 52 | 53 | - name: Generate 54 | run: make generate 55 | 56 | - name: Build 57 | env: 58 | CGO_ENABLED: 1 59 | GOOS: darwin 60 | GOARCH: amd64 61 | run: make release 62 | 63 | - name: Upload binaries 64 | uses: actions/upload-artifact@v2 65 | if: success() 66 | with: 67 | name: neoray-macos 68 | path: | 69 | bin/neoray 70 | 71 | build-linux: 72 | runs-on: ubuntu-latest 73 | steps: 74 | - uses: actions/checkout@v2 75 | 76 | - name: Set up Go 77 | uses: actions/setup-go@v2 78 | with: 79 | go-version: '1.20' 80 | 81 | - name: Set up required libs 82 | run: | 83 | sudo apt update && sudo apt upgrade 84 | sudo apt install libx11-dev libgtk-3-dev libgl1-mesa-dev xorg-dev 85 | 86 | - name: Install tools 87 | run: go install github.com/go-gl/glow@latest 88 | 89 | - name: Generate 90 | run: make generate 91 | 92 | - name: Build 93 | env: 94 | CGO_ENABLED: 1 95 | GOOS: linux 96 | GOARCH: amd64 97 | run: make release 98 | 99 | - name: Upload binaries 100 | uses: actions/upload-artifact@v2 101 | if: success() 102 | with: 103 | name: neoray-linux 104 | path: | 105 | bin/neoray 106 | -------------------------------------------------------------------------------- /pkg/opengl/gl/procaddr.go: -------------------------------------------------------------------------------- 1 | // Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT. 2 | 3 | // This file implements GlowGetProcAddress for every supported platform. The 4 | // correct version is chosen automatically based on build tags: 5 | // 6 | // windows: WGL 7 | // darwin: CGL 8 | // linux freebsd netbsd openbsd: GLX 9 | // 10 | // Use of EGL instead of the platform's default (listed above) is made possible 11 | // via the "egl" build tag. 12 | // 13 | // It is also possible to install your own function outside this package for 14 | // retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc. 15 | 16 | package gl 17 | 18 | /* 19 | #cgo windows CFLAGS: -DTAG_WINDOWS 20 | #cgo !gles2,windows LDFLAGS: -lopengl32 21 | #cgo gles2,windows LDFLAGS: -lGLESv2 22 | #cgo darwin CFLAGS: -DTAG_DARWIN 23 | #cgo !gles2,darwin LDFLAGS: -framework OpenGL 24 | #cgo gles2,darwin LDFLAGS: -framework OpenGLES 25 | #cgo linux freebsd netbsd openbsd CFLAGS: -DTAG_POSIX 26 | #cgo !egl,linux !egl,freebsd !egl,netbsd !egl,openbsd pkg-config: gl 27 | #cgo egl,linux egl,freebsd egl,netbsd egl,openbsd egl,windows CFLAGS: -DTAG_EGL 28 | #cgo egl,linux egl,freebsd egl,netbsd egl,openbsd pkg-config: egl 29 | #cgo egl,windows LDFLAGS: -lEGL 30 | #cgo egl,darwin LDFLAGS: -lEGL 31 | // Check the EGL tag first as it takes priority over the platform's default 32 | // configuration of WGL/GLX/CGL. 33 | #if defined(TAG_EGL) 34 | #include 35 | #include 36 | static void* GlowGetProcAddress(const char* name) { 37 | return eglGetProcAddress(name); 38 | } 39 | #elif defined(TAG_WINDOWS) 40 | #define WIN32_LEAN_AND_MEAN 1 41 | #include 42 | #include 43 | static HMODULE ogl32dll = NULL; 44 | static void* GlowGetProcAddress(const char* name) { 45 | void* pf = wglGetProcAddress((LPCSTR) name); 46 | if (pf) { 47 | return pf; 48 | } 49 | if (ogl32dll == NULL) { 50 | ogl32dll = LoadLibraryA("opengl32.dll"); 51 | } 52 | return GetProcAddress(ogl32dll, (LPCSTR) name); 53 | } 54 | #elif defined(TAG_DARWIN) 55 | #include 56 | #include 57 | static void* GlowGetProcAddress(const char* name) { 58 | return dlsym(RTLD_DEFAULT, name); 59 | } 60 | #elif defined(TAG_POSIX) 61 | #include 62 | #include 63 | static void* GlowGetProcAddress(const char* name) { 64 | return glXGetProcAddress((const GLubyte *) name); 65 | } 66 | #endif 67 | */ 68 | import "C" 69 | import "unsafe" 70 | 71 | func getProcAddress(namea string) unsafe.Pointer { 72 | cname := C.CString(namea) 73 | defer C.free(unsafe.Pointer(cname)) 74 | return C.GlowGetProcAddress(cname) 75 | } 76 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetCurrentContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetCurrentContext 13 | 3G 14 | 15 | 16 | glXGetCurrentContext 17 | return the current context 18 | 19 | C Specification 20 | 21 | 22 | GLXContext glXGetCurrentContext 23 | 24 | 25 | 26 | 27 | 28 | Description 29 | 30 | glXGetCurrentContext returns the current context, 31 | as specified by glXMakeCurrent. 32 | If there is no current context, 33 | NULL is returned. 34 | 35 | 36 | glXGetCurrentContext returns client-side information. 37 | It does not make a round trip to the server. 38 | 39 | 40 | 41 | 42 | See Also 43 | 44 | glXCreateContext, 45 | glXGetCurrentDisplay, 46 | glXGetCurrentDrawable, 47 | glXMakeCurrent 48 | 49 | 50 | Copyright 51 | 52 | Copyright 1991-2006 53 | Silicon Graphics, Inc. This document is licensed under the SGI 54 | Free Software B License. For details, see 55 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /pkg/opengl/glow/tmpl/procaddr.tmpl: -------------------------------------------------------------------------------- 1 | //glow:keepspace 2 | // Code generated by glow (https://github.com/go-gl/glow). DO NOT EDIT. 3 | 4 | // This file implements GlowGetProcAddress for every supported platform. The 5 | // correct version is chosen automatically based on build tags: 6 | // 7 | // windows: WGL 8 | // darwin: CGL 9 | // linux freebsd netbsd openbsd: GLX 10 | // 11 | // Use of EGL instead of the platform's default (listed above) is made possible 12 | // via the "egl" build tag. 13 | // 14 | // It is also possible to install your own function outside this package for 15 | // retrieving OpenGL function pointers, to do this see InitWithProcAddrFunc. 16 | 17 | package {{.Name}} 18 | //glow:rmspace 19 | 20 | /* 21 | #cgo windows CFLAGS: -DTAG_WINDOWS 22 | #cgo !gles2,windows LDFLAGS: -lopengl32 23 | #cgo gles2,windows LDFLAGS: -lGLESv2 24 | 25 | #cgo darwin CFLAGS: -DTAG_DARWIN 26 | #cgo !gles2,darwin LDFLAGS: -framework OpenGL 27 | #cgo gles2,darwin LDFLAGS: -framework OpenGLES 28 | 29 | #cgo linux freebsd netbsd openbsd CFLAGS: -DTAG_POSIX 30 | #cgo !egl,linux !egl,freebsd !egl,netbsd !egl,openbsd pkg-config: gl 31 | 32 | #cgo egl,linux egl,freebsd egl,netbsd egl,openbsd egl,windows CFLAGS: -DTAG_EGL 33 | #cgo egl,linux egl,freebsd egl,netbsd egl,openbsd pkg-config: egl 34 | #cgo egl,windows LDFLAGS: -lEGL 35 | #cgo egl,darwin LDFLAGS: -lEGL 36 | 37 | 38 | // Check the EGL tag first as it takes priority over the platform's default 39 | // configuration of WGL/GLX/CGL. 40 | #if defined(TAG_EGL) 41 | 42 | #include 43 | #include 44 | static void* GlowGetProcAddress(const char* name) { 45 | return eglGetProcAddress(name); 46 | } 47 | 48 | #elif defined(TAG_WINDOWS) 49 | 50 | #define WIN32_LEAN_AND_MEAN 1 51 | #include 52 | #include 53 | static HMODULE ogl32dll = NULL; 54 | static void* GlowGetProcAddress(const char* name) { 55 | void* pf = wglGetProcAddress((LPCSTR) name); 56 | if (pf) { 57 | return pf; 58 | } 59 | if (ogl32dll == NULL) { 60 | ogl32dll = LoadLibraryA("opengl32.dll"); 61 | } 62 | return GetProcAddress(ogl32dll, (LPCSTR) name); 63 | } 64 | 65 | #elif defined(TAG_DARWIN) 66 | 67 | #include 68 | #include 69 | static void* GlowGetProcAddress(const char* name) { 70 | return dlsym(RTLD_DEFAULT, name); 71 | } 72 | 73 | #elif defined(TAG_POSIX) 74 | 75 | #include 76 | #include 77 | static void* GlowGetProcAddress(const char* name) { 78 | return glXGetProcAddress((const GLubyte *) name); 79 | } 80 | 81 | #endif 82 | */ 83 | import "C" 84 | 85 | import "unsafe" 86 | 87 | func getProcAddress(namea string) unsafe.Pointer { 88 | cname := C.CString(namea) 89 | defer C.free(unsafe.Pointer(cname)) 90 | return C.GlowGetProcAddress(cname) 91 | } 92 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetCurrentDrawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetCurrentDrawable 13 | 3G 14 | 15 | 16 | glXGetCurrentDrawable 17 | return the current drawable 18 | 19 | C Specification 20 | 21 | 22 | GLXDrawable glXGetCurrentDrawable 23 | 24 | 25 | 26 | Description 27 | 28 | glXGetCurrentDrawable returns the current drawable, 29 | as specified by glXMakeCurrent. 30 | If there is no current drawable, 31 | None is returned. 32 | 33 | 34 | glXGetCurrentDrawable returns client-side information. 35 | It does not make a round trip to the server. 36 | 37 | 38 | See Also 39 | 40 | glXCreateGLXPixmap, 41 | glXGetCurrentContext, 42 | glXGetCurrentDisplay, 43 | glXGetCurrentReadDrawable, 44 | glXMakeCurrent 45 | 46 | 47 | Copyright 48 | 49 | Copyright 1991-2006 50 | Silicon Graphics, Inc. This document is licensed under the SGI 51 | Free Software B License. For details, see 52 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glLoadPaletteFromModelViewMatrix.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 2003-2004 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glLoadPaletteFromModelViewMatrix 13 | 3G 14 | 15 | 16 | 17 | glLoadPaletteFromModelViewMatrix 18 | glLoadPaletteFromModelViewMatrixOES 19 | 20 | copies the current model view matrix to a 21 | matrix in the current matrix palette 22 | 23 | 24 | 25 | 26 | C Specification 27 | 28 | 29 | 30 | void glLoadPaletteFromModelViewMatrixOES 31 | 32 | 33 | 34 | 35 | 36 | Description 37 | 38 | 39 | glLoadPaletteFromModelViewMatrixOES 40 | copies the current model view matrix to a 41 | matrix in the current matrix palette, as specified by 42 | glCurrentPaletteMatrix. 43 | 44 | 45 | 46 | 47 | See Also 48 | 49 | 50 | glCurrentPaletteMatrix, 51 | glMatrixIndexPointer, 52 | glMatrixMode, 53 | glWeightPointer 54 | 55 | 56 | Copyright 57 | 58 | Copyright 2003-2004 59 | Silicon Graphics, Inc. This document is licensed under the SGI 60 | Free Software B License. For details, see 61 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetCurrentDisplay.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetCurrentDisplay 13 | 3G 14 | 15 | 16 | glXGetCurrentDisplay 17 | get display for current context 18 | 19 | C Specification 20 | 21 | 22 | Display * glXGetCurrentDisplay 23 | 24 | 25 | 26 | 27 | Description 28 | 29 | glXGetCurrentDisplay returns the display for the current context. If no 30 | context is current, NULL is returned. 31 | 32 | 33 | glXGetCurrentDisplay returns client-side information. It does not make a round-trip 34 | to the server, and therefore does not flush any pending events. 35 | 36 | 37 | Notes 38 | 39 | glXGetCurrentDisplay is only supported if the GLX version is 1.2 or greater. 40 | 41 | 42 | See Also 43 | 44 | glXGetCurrentContext, 45 | glXGetCurrentDrawable, 46 | glXQueryVersion, 47 | glXQueryExtensionsString 48 | 49 | 50 | Copyright 51 | 52 | Copyright 1991-2006 53 | Silicon Graphics, Inc. This document is licensed under the SGI 54 | Free Software B License. For details, see 55 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /pkg/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | // Constraints 4 | type Integers interface { 5 | int | int8 | int16 | int32 | int64 6 | } 7 | 8 | type UnsignedIntegers interface { 9 | uint | uint8 | uint16 | uint32 | uint64 10 | } 11 | 12 | type Floats interface { 13 | float32 | float64 14 | } 15 | 16 | type Numbers interface { 17 | Integers | UnsignedIntegers | Floats 18 | } 19 | 20 | func Min[T Numbers](v1, v2 T) T { 21 | if v1 < v2 { 22 | return v1 23 | } 24 | return v2 25 | } 26 | 27 | func Max[T Numbers](v1, v2 T) T { 28 | if v1 > v2 { 29 | return v1 30 | } 31 | return v2 32 | } 33 | 34 | func Clamp[T Numbers](v, minv, maxv T) T { 35 | return Min(maxv, Max(minv, v)) 36 | } 37 | 38 | func Abs[T Numbers](v T) T { 39 | if v < 0 { 40 | return -v 41 | } 42 | return v 43 | } 44 | 45 | // Animation used for calculating positions of animated objects (points) 46 | type Animation struct { 47 | from Vector2[float32] 48 | to Vector2[float32] 49 | time float32 50 | lifeTime float32 51 | } 52 | 53 | // Lifetime is the life of the animation. Animation speed is depends of the 54 | // delta time and lifetime. For lifeTime parameter, 1.0 value is 1 seconds 55 | func NewAnimation(from, to Vector2[float32], lifeTime float32) Animation { 56 | return Animation{ 57 | from: from, 58 | to: to, 59 | time: 0, 60 | lifeTime: lifeTime, 61 | } 62 | } 63 | 64 | // Returns current position of animation 65 | func (anim *Animation) Step(delta float32) Vector2[float32] { 66 | if anim.lifeTime <= 0 { 67 | return anim.to 68 | } 69 | anim.time += delta 70 | return anim.from.Add(anim.to.Sub(anim.from).DivS(anim.lifeTime).MulS(Min(anim.time, anim.lifeTime))) 71 | } 72 | 73 | func (anim *Animation) IsFinished() bool { 74 | return anim.time >= anim.lifeTime 75 | } 76 | 77 | // This is just for making code more readable 78 | // Can hold up to 32 enums 79 | type BitMask uint32 80 | 81 | func (mask BitMask) String() string { 82 | str := "" 83 | for i := 31; i >= 0; i-- { 84 | if mask.Has(1 << i) { 85 | str += "1" 86 | } else { 87 | str += "0" 88 | } 89 | } 90 | return str 91 | } 92 | 93 | func (mask *BitMask) Enable(flag BitMask) { 94 | *mask |= flag 95 | } 96 | 97 | func (mask *BitMask) Disable(flag BitMask) { 98 | *mask &= ^flag 99 | } 100 | 101 | func (mask *BitMask) Toggle(flag BitMask) { 102 | *mask ^= flag 103 | } 104 | 105 | // Enables flag if cond is true, disables otherwise. 106 | func (mask *BitMask) EnableIf(flag BitMask, cond bool) { 107 | if cond { 108 | mask.Enable(flag) 109 | } else { 110 | mask.Disable(flag) 111 | } 112 | } 113 | 114 | func (mask BitMask) Has(flag BitMask) bool { 115 | return mask&flag == flag 116 | } 117 | 118 | // Returns true if the mask only has the flag 119 | func (mask BitMask) HasOnly(flag BitMask) bool { 120 | return mask.Has(flag) && mask|flag == flag 121 | } 122 | 123 | func (mask *BitMask) Clear() { 124 | *mask = *mask & BitMask(0) 125 | } 126 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetCurrentReadDrawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetCurrentReadDrawable 13 | 3G 14 | 15 | 16 | glXGetCurrentReadDrawable 17 | return the current drawable 18 | 19 | C Specification 20 | 21 | 22 | GLXDrawable glXGetCurrentReadDrawable 23 | 24 | 25 | 26 | Description 27 | 28 | glXGetCurrentReadDrawable returns the current read drawable, 29 | as specified by read parameter 30 | of glXMakeContextCurrent. 31 | If there is no current drawable, 32 | None is returned. 33 | 34 | 35 | glXGetCurrentReadDrawable returns client-side information. 36 | It does not make a round-trip to the server. 37 | 38 | 39 | Notes 40 | 41 | glXGetCurrentReadDrawable is only supported if the GLX version is 1.3 or greater. 42 | 43 | 44 | See Also 45 | 46 | glXGetCurrentContext, 47 | glXGetCurrentDisplay, 48 | glXGetCurrentDrawable, 49 | glXMakeContextCurrent 50 | 51 | 52 | Copyright 53 | 54 | Copyright 1991-2006 55 | Silicon Graphics, Inc. This document is licensed under the SGI 56 | Free Software B License. For details, see 57 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetProcAddress.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetProcAddress 13 | 3G 14 | 15 | 16 | glXGetProcAddress 17 | obtain a pointer to an OpenGL or GLX function 18 | 19 | C Specification 20 | 21 | 22 | void(*)() glXGetProcAddress 23 | const GLubyte * procName 24 | 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | procName 32 | 33 | 34 | Specifies the name of the OpenGL or GLX function whose address is to be returned. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glXGetProcAddress returns the address of the function specified in procName. This is 43 | necessary in environments where the OpenGL link library exports a different 44 | set of functions than the runtime library. 45 | 46 | 47 | Notes 48 | 49 | A NULL pointer is returned if function requested is not suported 50 | in the implementation being queried. 51 | 52 | 53 | GLU functions are not queryable due to the fact that the library may not be 54 | loaded at the time of the query. 55 | 56 | 57 | Copyright 58 | 59 | Copyright 1991-2006 60 | Silicon Graphics, Inc. This document is licensed under the SGI 61 | Free Software B License. For details, see 62 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /pkg/opengl/glow/glfunclist.json: -------------------------------------------------------------------------------- 1 | { 2 | "Enums": [ 3 | "GL_ARRAY_BUFFER", 4 | "GL_BLEND", 5 | "GL_CLAMP_TO_BORDER", 6 | "GL_CLAMP_TO_EDGE", 7 | "GL_COLOR_ATTACHMENT0", 8 | "GL_COLOR_BUFFER_BIT", 9 | "GL_COMPILE_STATUS", 10 | "GL_CONTEXT_LOST", 11 | "GL_DRAW_FRAMEBUFFER", 12 | "GL_DYNAMIC_ARRAY", 13 | "GL_DYNAMIC_DRAW", 14 | "GL_FALSE", 15 | "GL_FLOAT", 16 | "GL_FRAGMENT_SHADER", 17 | "GL_FRAMEBUFFER_COMPLETE", 18 | "GL_GEOMETRY_SHADER", 19 | "GL_INFO_LOG_LENGTH", 20 | "GL_INVALID_ENUM", 21 | "GL_INVALID_OPERATION", 22 | "GL_INVALID_VALUE", 23 | "GL_LINEAR", 24 | "GL_LINK_STATUS", 25 | "GL_MAX_TEXTURE_SIZE", 26 | "GL_NEAREST", 27 | "GL_NO_ERROR", 28 | "GL_OUT_OF_MEMORY", 29 | "GL_POINTS", 30 | "GL_RENDERER", 31 | "GL_RGBA", 32 | "GL_RGBA8", 33 | "GL_SHADING_LANGUAGE_VERSION", 34 | "GL_STACK_OVERFLOW", 35 | "GL_STACK_UNDERFLOW", 36 | "GL_TEXTURE0", 37 | "GL_TEXTURE_2D", 38 | "GL_TEXTURE_MAG_FILTER", 39 | "GL_TEXTURE_MIN_FILTER", 40 | "GL_TEXTURE_WRAP_S", 41 | "GL_TEXTURE_WRAP_T", 42 | "GL_UNSIGNED_BYTE", 43 | "GL_VENDOR", 44 | "GL_VERSION", 45 | "GL_VERTEX_SHADER" 46 | ], 47 | "Functions": [ 48 | "glActiveTexture", 49 | "glAttachShader", 50 | "glBindBuffer", 51 | "glBindFramebuffer", 52 | "glBindTexture", 53 | "glBindVertexArray", 54 | "glBufferData", 55 | "glBufferSubData", 56 | "glCheckFramebufferStatus", 57 | "glClear", 58 | "glClearColor", 59 | "glCompileShader", 60 | "glCreateProgram", 61 | "glCreateShader", 62 | "glDeleteBuffers", 63 | "glDeleteFramebuffers", 64 | "glDeleteProgram", 65 | "glDeleteShader", 66 | "glDeleteTextures", 67 | "glDeleteVertexArrays", 68 | "glDisable", 69 | "glDrawArrays", 70 | "glEnable", 71 | "glEnableVertexAttribArray", 72 | "glFlush", 73 | "glFramebufferTexture2D", 74 | "glGenBuffers", 75 | "glGenFramebuffers", 76 | "glGenTextures", 77 | "glGenVertexArrays", 78 | "glGetError", 79 | "glGetIntegerv", 80 | "glGetProgramInfoLog", 81 | "glGetProgramiv", 82 | "glGetShaderInfoLog", 83 | "glGetShaderiv", 84 | "glGetString", 85 | "glGetUniformLocation", 86 | "glLinkProgram", 87 | "glShaderSource", 88 | "glTexImage2D", 89 | "glTexParameteri", 90 | "glTexSubImage2D", 91 | "glUniform4f", 92 | "glUniform4fv", 93 | "glUniform4fv", 94 | "glUniformMatrix4fv", 95 | "glUseProgram", 96 | "glUseShader", 97 | "glVertexAttribPointer", 98 | "glViewport" 99 | ] 100 | } 101 | -------------------------------------------------------------------------------- /pkg/common/vector.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | // Zero values for reducing allocations 9 | var ( 10 | ZeroVector2F32 = Vector2[float32]{} 11 | ZeroVector2INT = Vector2[int]{} 12 | ) 13 | 14 | // We will use generics for vectors 15 | 16 | type Vector2[T Numbers] struct { 17 | X, Y T 18 | } 19 | 20 | func (v Vector2[T]) String() string { 21 | return fmt.Sprintf("Vector2(X: %v, Y: %v)", v.X, v.Y) 22 | } 23 | 24 | // just a shortcut 25 | func Vec2[T Numbers](X, Y T) Vector2[T] { 26 | return Vector2[T]{X: X, Y: Y} 27 | } 28 | 29 | func (v Vector2[T]) Width() T { 30 | return v.X 31 | } 32 | 33 | func (v Vector2[T]) Height() T { 34 | return v.Y 35 | } 36 | 37 | func (v Vector2[T]) Area() float32 { 38 | return float32(v.X * v.Y) 39 | } 40 | 41 | func (v Vector2[T]) ToInt() Vector2[int] { 42 | return Vector2[int]{ 43 | X: int(math.Floor(float64(v.X))), 44 | Y: int(math.Floor(float64(v.Y))), 45 | } 46 | } 47 | 48 | // Add two vectors 49 | func (v Vector2[T]) Add(v1 Vector2[T]) Vector2[T] { 50 | v.X += v1.X 51 | v.Y += v1.Y 52 | return v 53 | } 54 | 55 | // Subtract v1 from v 56 | func (v Vector2[T]) Sub(v1 Vector2[T]) Vector2[T] { 57 | v.X -= v1.X 58 | v.Y -= v1.Y 59 | return v 60 | } 61 | 62 | // Dot product of two vectors 63 | func (v Vector2[T]) Mul(v1 Vector2[T]) Vector2[T] { 64 | v.X *= v1.X 65 | v.Y *= v1.Y 66 | return v 67 | } 68 | 69 | // Multiplies the vector by a scalar 70 | func (v Vector2[T]) MulS(S T) Vector2[T] { 71 | v.X *= S 72 | v.Y *= S 73 | return v 74 | } 75 | 76 | // Divides v by v1 77 | func (v Vector2[T]) Div(v1 Vector2[T]) Vector2[T] { 78 | v.X /= v1.X 79 | v.Y /= v1.Y 80 | return v 81 | } 82 | 83 | // Divides the vector by a scalar 84 | func (v Vector2[T]) DivS(S T) Vector2[T] { 85 | v.X /= S 86 | v.Y /= S 87 | return v 88 | } 89 | 90 | func (v Vector2[T]) Length() float32 { 91 | return float32(math.Sqrt(float64(v.X*v.X + v.Y*v.Y))) 92 | } 93 | 94 | // Does not applies sqrt, faster 95 | func (v Vector2[T]) LengthSquared() float32 { 96 | return float32(v.X*v.X + v.Y*v.Y) 97 | } 98 | 99 | func (v Vector2[T]) Distance(v2 Vector2[T]) float32 { 100 | return v2.Sub(v).Length() 101 | } 102 | 103 | // Does not applies sqrt, faster 104 | func (v Vector2[T]) DistanceSquared(v2 Vector2[T]) float32 { 105 | return v2.Sub(v).LengthSquared() 106 | } 107 | 108 | func (v Vector2[T]) Normalized() Vector2[T] { 109 | return v.DivS(T(v.Length())) 110 | } 111 | 112 | // Returns the perpenicular vector of v 113 | func (v Vector2[T]) Perpendicular() Vector2[T] { 114 | v.X, v.Y = v.Y, -v.X 115 | return v 116 | } 117 | 118 | // Returns true if the vectors are equal 119 | func (v Vector2[T]) Equals(v1 Vector2[T]) bool { 120 | return v.X == v1.X && v.Y == v1.Y 121 | } 122 | 123 | // Returns true if the vector is horizontal 124 | func (v Vector2[T]) IsHorizontal() bool { 125 | return Abs(v.X) >= Abs(v.Y) 126 | } 127 | 128 | // Returns true if the vector is in given rectangle 129 | func (v Vector2[T]) IsInRect(rect Rectangle[T]) bool { 130 | return v.X >= rect.X && v.Y >= rect.Y && v.X < rect.X+rect.W && v.Y < rect.Y+rect.H 131 | } 132 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glReleaseShaderCompiler.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glReleaseShaderCompiler 14 | 3G 15 | 16 | 17 | glReleaseShaderCompiler 18 | release resources consumed by the implementation's shader compiler 19 | 20 | C Specification 21 | 22 | 23 | void glReleaseShaderCompiler 24 | void 25 | 26 | 27 | 28 | Description 29 | 30 | glReleaseShaderCompiler provides a hint to the implementation that it 31 | may free internal resources associated with its shader compiler. glCompileShader 32 | may subsequently be called and the implementation may at that time reallocate resources 33 | previously freed by the call to glReleaseShaderCompiler. 34 | 35 | 36 | Version Support 37 | 38 | 39 | 40 | 41 | 42 | glReleaseShaderCompiler 43 | 44 | 45 | 46 | 47 | 48 | 49 | See Also 50 | 51 | glCompileShader, 52 | glLinkProgram 53 | 54 | 55 | Copyright 56 | 57 | Copyright 2010-2014 Khronos Group. 58 | This material may be distributed subject to the terms and conditions set forth in 59 | the Open Publication License, v 1.0, 8 June 1999. 60 | http://opencontent.org/openpub/. 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /pkg/bench/bench_debug.go: -------------------------------------------------------------------------------- 1 | //go:build debug 2 | // +build debug 3 | 4 | package bench 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "io" 10 | "runtime" 11 | "sort" 12 | "sync" 13 | "time" 14 | 15 | "github.com/hismailbulut/Neoray/pkg/logger" 16 | "github.com/olekukonko/tablewriter" 17 | ) 18 | 19 | const BUILD_TYPE = logger.DebugBuild 20 | 21 | func IsDebugBuild() bool { return true } 22 | 23 | type funcBenchmark struct { 24 | calls int 25 | totalTime time.Duration 26 | maxTime time.Duration 27 | } 28 | 29 | var ( 30 | mutex sync.Mutex 31 | averages map[string]funcBenchmark 32 | initTime time.Time 33 | ) 34 | 35 | func init() { 36 | mutex.Lock() 37 | defer mutex.Unlock() 38 | averages = make(map[string]funcBenchmark) 39 | initTime = time.Now() 40 | } 41 | 42 | // Runtime benchmark, dont use in production because function itself is costly 43 | func Begin() func(name ...string) { 44 | before := time.Now() 45 | return func(name ...string) { 46 | elapsed := time.Since(before) 47 | mutex.Lock() 48 | defer mutex.Unlock() 49 | benchName := "unknown" 50 | if len(name) > 0 { 51 | benchName = name[0] 52 | } else { 53 | // get caller function name 54 | pc, _, _, ok := runtime.Caller(1) 55 | if ok { 56 | benchName = runtime.FuncForPC(pc).Name() 57 | } 58 | } 59 | val, ok := averages[benchName] 60 | if ok { 61 | val.calls++ 62 | val.totalTime += elapsed 63 | if elapsed > val.maxTime { 64 | val.maxTime = elapsed 65 | } 66 | averages[benchName] = val 67 | } else { 68 | averages[benchName] = funcBenchmark{ 69 | calls: 1, 70 | totalTime: elapsed, 71 | maxTime: elapsed, 72 | } 73 | } 74 | } 75 | } 76 | 77 | // This prints a table which has the measurement information of all functions. 78 | func PrintResults(out io.Writer) { 79 | mutex.Lock() 80 | defer mutex.Unlock() 81 | 82 | if len(averages) == 0 { 83 | return 84 | } 85 | 86 | type funcBenchmarkSummary struct { 87 | name string 88 | calls int 89 | time time.Duration 90 | average time.Duration 91 | max time.Duration 92 | percent float64 93 | } 94 | 95 | elapsedSeconds := time.Since(initTime).Seconds() 96 | 97 | list := []funcBenchmarkSummary{} 98 | for key, val := range averages { 99 | sum := funcBenchmarkSummary{} 100 | sum.name = key 101 | sum.calls = val.calls 102 | sum.time = val.totalTime 103 | sum.average = val.totalTime / time.Duration(val.calls) 104 | sum.max = val.maxTime 105 | sum.percent = sum.time.Seconds() / elapsedSeconds 106 | list = append(list, sum) 107 | } 108 | 109 | sort.Slice(list, func(i, j int) bool { 110 | return list[i].time > list[j].time 111 | }) 112 | 113 | var buf bytes.Buffer 114 | table := tablewriter.NewWriter(&buf) 115 | table.SetAutoWrapText(false) 116 | table.SetAlignment(tablewriter.ALIGN_CENTER) 117 | table.SetHeader([]string{ 118 | "NAME", "CALLS", "PERCENT", 119 | "TOTAL", "AVERAGE", "MAX", 120 | }) 121 | for _, r := range list { 122 | table.Append([]string{ 123 | r.name, 124 | fmt.Sprintf("%d", r.calls), 125 | fmt.Sprintf("%.4f", r.percent), 126 | r.time.String(), 127 | r.average.String(), 128 | r.max.String(), 129 | }) 130 | } 131 | table.Render() 132 | io.Copy(out, &buf) 133 | } 134 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glFinish.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | 2010-2014 13 | Khronos Group 14 | 15 | 16 | 17 | glFinish 18 | 3G 19 | 20 | 21 | glFinish 22 | block until all GL execution is complete 23 | 24 | C Specification 25 | 26 | 27 | void glFinish 28 | void 29 | 30 | 31 | 32 | Description 33 | 34 | glFinish does not return until the effects of all previously 35 | called GL commands are complete. 36 | Such effects include all changes to GL state, 37 | all changes to connection state, 38 | and all changes to the frame buffer contents. 39 | 40 | 41 | Notes 42 | 43 | glFinish requires a round trip to the server. 44 | 45 | 46 | Version Support 47 | 48 | 49 | 50 | 51 | 52 | glFinish 53 | 54 | 55 | 56 | 57 | 58 | 59 | See Also 60 | 61 | glFlush 62 | 63 | 64 | Copyright 65 | 66 | Copyright 1991-2006 Silicon Graphics, Inc. 67 | Copyright 2010-2014 Khronos Group. 68 | This document is licensed under the SGI Free Software B License. 69 | For details, see 70 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXWaitX.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXWaitX 13 | 3G 14 | 15 | 16 | glXWaitX 17 | complete X execution prior to subsequent GL calls 18 | 19 | C Specification 20 | 21 | 22 | void glXWaitX 23 | void 24 | 25 | 26 | 27 | 28 | Description 29 | 30 | X rendering calls made prior to glXWaitX are guaranteed to be 31 | executed before GL rendering calls made after glXWaitX. 32 | Although the same result can be achieved using XSync, 33 | glXWaitX does not require a round trip to the server, 34 | and it is therefore more efficient in cases where client and server 35 | are on separate machines. 36 | 37 | 38 | glXWaitX is ignored if there is no current GLX context. 39 | 40 | 41 | Notes 42 | 43 | glXWaitX may or may not flush the GL stream. 44 | 45 | 46 | Errors 47 | 48 | GLXBadCurrentWindow is generated if the drawable associated 49 | with the current context of the calling thread is a window, and that 50 | window is no longer valid. 51 | 52 | 53 | See Also 54 | 55 | glFinish, 56 | glFlush, 57 | glXWaitGL, 58 | XSync 59 | 60 | 61 | Copyright 62 | 63 | Copyright 1991-2006 64 | Silicon Graphics, Inc. This document is licensed under the SGI 65 | Free Software B License. For details, see 66 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXWaitGL.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXWaitGL 13 | 3G 14 | 15 | 16 | glXWaitGL 17 | complete GL execution prior to subsequent X calls 18 | 19 | C Specification 20 | 21 | 22 | void glXWaitGL 23 | void 24 | 25 | 26 | 27 | 28 | Description 29 | 30 | GL rendering calls made prior to glXWaitGL are guaranteed to be 31 | executed before X rendering calls made after glXWaitGL. 32 | Although this same result can be achieved using glFinish, 33 | glXWaitGL does not require a round trip to the server, 34 | and it is therefore more efficient in cases where client and server 35 | are on separate machines. 36 | 37 | 38 | glXWaitGL is ignored if there is no current GLX context. 39 | 40 | 41 | Notes 42 | 43 | glXWaitGL may or may not flush the X stream. 44 | 45 | 46 | Errors 47 | 48 | GLXBadCurrentWindow is generated if the drawable associated 49 | with the current context of the calling thread is a window, and that 50 | window is no longer valid. 51 | 52 | 53 | See Also 54 | 55 | glFinish, 56 | glFlush, 57 | glXWaitX, 58 | XSync 59 | 60 | 61 | Copyright 62 | 63 | Copyright 1991-2006 64 | Silicon Graphics, Inc. This document is licensed under the SGI 65 | Free Software B License. For details, see 66 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glResetHistogram.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glResetHistogram 13 | 3G 14 | 15 | 16 | glResetHistogram 17 | reset histogram table entries to zero 18 | 19 | C Specification 20 | 21 | 22 | void glResetHistogram 23 | GLenum target 24 | 25 | 26 | 27 | Parameters 28 | 29 | 30 | target 31 | 32 | 33 | Must be 34 | GL_HISTOGRAM. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glResetHistogram resets all the elements of the current histogram table to zero. 43 | 44 | 45 | Notes 46 | 47 | glResetHistogram is present only if ARB_imaging is returned when glGetString 48 | is called with an argument of GL_EXTENSIONS. 49 | 50 | 51 | Errors 52 | 53 | GL_INVALID_ENUM is generated if target is not GL_HISTOGRAM. 54 | 55 | 56 | GL_INVALID_OPERATION is generated if glResetHistogram is executed 57 | between the execution of glBegin and the corresponding 58 | execution of glEnd. 59 | 60 | 61 | See Also 62 | 63 | glHistogram 64 | 65 | 66 | Copyright 67 | 68 | Copyright 1991-2006 69 | Silicon Graphics, Inc. This document is licensed under the SGI 70 | Free Software B License. For details, see 71 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /pkg/fontkit/fontkit.go: -------------------------------------------------------------------------------- 1 | package fontkit 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/hismailbulut/Neoray/pkg/fontfinder" 7 | ) 8 | 9 | var ( 10 | // Private 11 | defaultFontKit *FontKit 12 | ) 13 | 14 | // FontKit is a struct that holds different styles of same font family 15 | // TODO: Maybe we should make this safe for concurrent usage, currently not 16 | type FontKit struct { 17 | regular *Font 18 | bold *Font 19 | italic *Font 20 | boldItalic *Font 21 | } 22 | 23 | func CreateKit(fontname string) (*FontKit, error) { 24 | info := fontfinder.Find(fontname) 25 | if info.Regular == "" && info.Bold == "" && info.Italic == "" && info.BoldItalic == "" { 26 | // This means we could not find any font file with this name 27 | return nil, fmt.Errorf("Couldn't find font %s", fontname) 28 | } 29 | fontkit := new(FontKit) 30 | // Load fonts 31 | var err error 32 | if info.Regular != "" { 33 | fontkit.regular, err = CreateFontFromFile(info.Regular) 34 | if err != nil { 35 | return nil, err 36 | } 37 | } 38 | if info.Bold != "" { 39 | fontkit.bold, err = CreateFontFromFile(info.Bold) 40 | if err != nil { 41 | return nil, err 42 | } 43 | } 44 | if info.Italic != "" { 45 | fontkit.italic, err = CreateFontFromFile(info.Italic) 46 | if err != nil { 47 | return nil, err 48 | } 49 | } 50 | if info.BoldItalic != "" { 51 | fontkit.boldItalic, err = CreateFontFromFile(info.BoldItalic) 52 | if err != nil { 53 | return nil, err 54 | } 55 | } 56 | return fontkit, nil 57 | } 58 | 59 | // This function must be called before any use of fontkit 60 | func SetDefaultFontData(regular, bold, italic, boldItalic []byte) { 61 | if defaultFontKit == nil { 62 | defaultFontKit = new(FontKit) 63 | defaultFontKit.regular, _ = CreateFontFromMem(regular) 64 | defaultFontKit.bold, _ = CreateFontFromMem(bold) 65 | defaultFontKit.italic, _ = CreateFontFromMem(italic) 66 | defaultFontKit.boldItalic, _ = CreateFontFromMem(boldItalic) 67 | } else { 68 | panic("Default font kit already created") 69 | } 70 | } 71 | 72 | // Returns default font kit, creates it if first time 73 | func Default() *FontKit { 74 | if defaultFontKit == nil { 75 | panic("Default font kit not created") 76 | } 77 | return defaultFontKit 78 | } 79 | 80 | func (fontkit *FontKit) Regular() *Font { 81 | return fontkit.regular 82 | } 83 | 84 | func (fontkit *FontKit) Bold() *Font { 85 | return fontkit.bold 86 | } 87 | 88 | func (fontkit *FontKit) Italic() *Font { 89 | return fontkit.italic 90 | } 91 | 92 | func (fontkit *FontKit) BoldItalic() *Font { 93 | return fontkit.boldItalic 94 | } 95 | 96 | // Returns first non nil font starting from regular 97 | func (fontkit *FontKit) DefaultFont() *Font { 98 | if fontkit.regular != nil { 99 | return fontkit.regular 100 | } 101 | if fontkit.bold != nil { 102 | return fontkit.bold 103 | } 104 | if fontkit.italic != nil { 105 | return fontkit.italic 106 | } 107 | if fontkit.boldItalic != nil { 108 | return fontkit.boldItalic 109 | } 110 | panic("all fonts are nil") 111 | } 112 | 113 | func (fontkit *FontKit) SuitableFont(bold, italic bool) *Font { 114 | if bold && italic && fontkit.boldItalic != nil { 115 | return fontkit.boldItalic 116 | } 117 | if italic && fontkit.italic != nil { 118 | return fontkit.italic 119 | } 120 | if bold && fontkit.bold != nil { 121 | return fontkit.bold 122 | } 123 | if fontkit.regular != nil { 124 | return fontkit.regular 125 | } 126 | return fontkit.DefaultFont() 127 | } 128 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glBlendBarrier.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2015 9 | Khronos Group 10 | 11 | 12 | 13 | glBlendBarrier 14 | 3G 15 | 16 | 17 | glBlendBarrier 18 | specifies a boundary between advanced blending passes 19 | 20 | 21 | C Specification 22 | 23 | 24 | void glBlendBarrier 25 | void 26 | 27 | 28 | 29 | Description 30 | 31 | glBlendBarrier specifies a boundary between passes when using advanced blend equations. 32 | Any command that causes the value of a sample to be modified using the 33 | framebuffer is considered to touch the sample, including clears, blended 34 | or unblended primitives, and BlitFramebuffer copies. Defined results are guaranteed only if each sample 35 | is touched no more than once in any single rendering pass. 36 | 37 | 38 | Associated Gets 39 | 40 | glGet with an argument of GL_BLEND_EQUATION_RGB 41 | 42 | 43 | 44 | API Version Support 45 | 46 | 47 | 48 | 49 | 50 | glBlendBarrier 51 | 52 | 53 | 54 | 55 | 56 | 57 | See Also 58 | 59 | glBlendEquation, 60 | glBlendEquationi, 61 | glGet 62 | 63 | 64 | Copyright 65 | 66 | Copyright 2015 Khronos Group. 67 | This document is licensed under the SGI Free Software B License. 68 | For details, see 69 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /cmd/neoray/input_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/go-gl/glfw/v3.3/glfw" 8 | "github.com/hismailbulut/Neoray/pkg/common" 9 | ) 10 | 11 | func TestMain(m *testing.M) { 12 | // We need to initialize glfw for GetKeyName function 13 | if glfw.Init() != nil { 14 | return 15 | } 16 | c := m.Run() 17 | glfw.Terminate() 18 | os.Exit(c) 19 | } 20 | 21 | func Test_parseCharInput(t *testing.T) { 22 | type args struct { 23 | char rune 24 | mods common.BitMask 25 | } 26 | tests := []struct { 27 | name string 28 | args args 29 | want string 30 | }{ 31 | { 32 | name: "Ctrl + AltGr + Backslash", 33 | args: args{ 34 | char: '\\', 35 | mods: ModControl | ModAltGr, 36 | }, 37 | want: "", 38 | }, 39 | { 40 | name: "Ctrl + Alt + AltGr + Bracket", 41 | args: args{ 42 | char: '}', 43 | mods: ModControl | ModAlt | ModAltGr, 44 | }, 45 | want: "", 46 | }, 47 | { 48 | name: "Ctrl + Alt + Sharp", 49 | args: args{ 50 | char: '#', 51 | mods: ModControl | ModAlt, 52 | }, 53 | want: "", // handled in key callback 54 | }, 55 | { 56 | name: "Shift + S", 57 | args: args{ 58 | char: 'S', 59 | mods: ModShift, 60 | }, 61 | want: "S", 62 | }, 63 | } 64 | for _, tt := range tests { 65 | t.Run(tt.name, func(t *testing.T) { 66 | if got := parseCharInput(tt.args.char, tt.args.mods); got != tt.want { 67 | t.Errorf("parseCharInput() = %v, want %v", got, tt.want) 68 | } 69 | }) 70 | } 71 | } 72 | 73 | func Test_parseKeyInput(t *testing.T) { 74 | type args struct { 75 | key glfw.Key 76 | scancode int 77 | mods common.BitMask 78 | } 79 | tests := []struct { 80 | name string 81 | args args 82 | want string 83 | }{ 84 | { 85 | name: "AltGr + Enter", 86 | args: args{ 87 | key: glfw.KeyEnter, 88 | mods: ModAltGr, 89 | }, 90 | want: "", 91 | }, 92 | { 93 | name: "Ctrl + Space", 94 | args: args{ 95 | key: glfw.KeySpace, 96 | mods: ModControl, 97 | }, 98 | want: "", 99 | }, 100 | { 101 | name: "Shift + AltGr + kp9", 102 | args: args{ 103 | key: glfw.KeyKP9, 104 | mods: ModAltGr | ModShift, 105 | }, 106 | want: "", 107 | }, 108 | { 109 | name: "Ctrl + Alt + h", 110 | args: args{ 111 | key: glfw.KeyH, 112 | mods: ModControl | ModAlt, 113 | }, 114 | want: "", 115 | }, 116 | { 117 | name: "Ctrl + Shift + Alt + Super + Home", 118 | args: args{ 119 | key: glfw.KeyHome, 120 | mods: ModControl | ModShift | ModAlt | ModSuper, 121 | }, 122 | want: "", // Yes neoray must send this 123 | }, 124 | { 125 | name: "g", // must handled in char callback 126 | args: args{ 127 | key: glfw.KeyG, 128 | mods: 0, 129 | }, 130 | want: "", 131 | }, 132 | { 133 | name: "AltGr + 1", // must handled in char callback 134 | args: args{ 135 | key: glfw.Key1, 136 | mods: ModAltGr, 137 | }, 138 | want: "", 139 | }, 140 | { 141 | name: "Shift + 1", // must handled in char callback 142 | args: args{ 143 | key: glfw.Key1, 144 | mods: ModShift, 145 | }, 146 | want: "", 147 | }, 148 | } 149 | for _, tt := range tests { 150 | t.Run(tt.name, func(t *testing.T) { 151 | if got := parseKeyInput(tt.args.key, tt.args.scancode, tt.args.mods); got != tt.want { 152 | t.Errorf("parseKeyInput() = %v, want %v", got, tt.want) 153 | } 154 | }) 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXDestroyGLXPixmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXDestroyGLXPixmap 13 | 3G 14 | 15 | 16 | glXDestroyGLXPixmap 17 | destroy a GLX pixmap 18 | 19 | C Specification 20 | 21 | 22 | void glXDestroyGLXPixmap 23 | Display * dpy 24 | GLXPixmap pix 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | pix 41 | 42 | 43 | Specifies the GLX pixmap to be destroyed. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | If the GLX pixmap pix is not current to any client, 52 | glXDestroyGLXPixmap destroys it immediately. 53 | Otherwise, 54 | pix is destroyed when it becomes not current to any client. 55 | In either case, the resource ID 56 | is freed immediately. 57 | 58 | 59 | Errors 60 | 61 | GLXBadPixmap is generated if pix is not a valid GLX pixmap. 62 | 63 | 64 | See Also 65 | 66 | glXCreateGLXPixmap, 67 | glXDestroyPixmap, 68 | glXMakeCurrent 69 | 70 | 71 | Copyright 72 | 73 | Copyright 1991-2006 74 | Silicon Graphics, Inc. This document is licensed under the SGI 75 | Free Software B License. For details, see 76 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXIsDirect.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXIsDirect 13 | 3G 14 | 15 | 16 | glXIsDirect 17 | indicate whether direct rendering is enabled 18 | 19 | C Specification 20 | 21 | 22 | Bool glXIsDirect 23 | Display * dpy 24 | GLXContext ctx 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | ctx 41 | 42 | 43 | Specifies the GLX context that is being queried. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | glXIsDirect returns True if ctx is a direct rendering context, 52 | False otherwise. 53 | Direct rendering contexts pass rendering commands directly from the calling 54 | process's address space to the rendering system, 55 | bypassing the X server. 56 | Nondirect rendering contexts pass all rendering commands to the X server. 57 | 58 | 59 | Errors 60 | 61 | GLXBadContext is generated if ctx is not a valid GLX context. 62 | 63 | 64 | See Also 65 | 66 | glXCreateContext, 67 | glXCreateNewContext 68 | 69 | 70 | Copyright 71 | 72 | Copyright 1991-2006 73 | Silicon Graphics, Inc. This document is licensed under the SGI 74 | Free Software B License. For details, see 75 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glListBase.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glListBase 13 | 3G 14 | 15 | 16 | glListBase 17 | set the display-list base for glCallLists 18 | 19 | C Specification 20 | 21 | 22 | void glListBase 23 | GLuint base 24 | 25 | 26 | 27 | Parameters 28 | 29 | 30 | base 31 | 32 | 33 | Specifies an integer offset that will be added to glCallLists 34 | offsets to generate display-list names. 35 | The initial value is 0. 36 | 37 | 38 | 39 | 40 | 41 | Description 42 | 43 | glCallLists specifies an array of offsets. 44 | Display-list names are generated by adding base to each offset. 45 | Names that reference valid display lists are executed; 46 | the others are ignored. 47 | 48 | 49 | Errors 50 | 51 | GL_INVALID_OPERATION is generated if glListBase 52 | is executed between the execution of glBegin 53 | and the corresponding execution of glEnd. 54 | 55 | 56 | Associated Gets 57 | 58 | glGet with argument GL_LIST_BASE 59 | 60 | 61 | See Also 62 | 63 | glCallLists 64 | 65 | 66 | Copyright 67 | 68 | Copyright 1991-2006 69 | Silicon Graphics, Inc. This document is licensed under the SGI 70 | Free Software B License. For details, see 71 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXDestroyContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXDestroyContext 13 | 3G 14 | 15 | 16 | glXDestroyContext 17 | destroy a GLX context 18 | 19 | C Specification 20 | 21 | 22 | void glXDestroyContext 23 | Display * dpy 24 | GLXContext ctx 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | ctx 41 | 42 | 43 | Specifies the GLX context to be destroyed. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | If the GLX rendering context ctx is not current to any thread, 52 | glXDestroyContext 53 | destroys it immediately. 54 | Otherwise, 55 | ctx is destroyed when it becomes not current to any thread. 56 | In either case, the resource ID 57 | referenced by ctx is freed immediately. 58 | 59 | 60 | Errors 61 | 62 | GLXBadContext is generated if ctx is not a valid GLX context. 63 | 64 | 65 | See Also 66 | 67 | glXCreateContext, 68 | glXCreateNewContext, 69 | glXMakeCurrent 70 | 71 | 72 | Copyright 73 | 74 | Copyright 1991-2006 75 | Silicon Graphics, Inc. This document is licensed under the SGI 76 | Free Software B License. For details, see 77 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glInitNames.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glInitNames 13 | 3G 14 | 15 | 16 | glInitNames 17 | initialize the name stack 18 | 19 | C Specification 20 | 21 | 22 | void glInitNames 23 | void 24 | 25 | 26 | 27 | Description 28 | 29 | The name stack is used during selection mode to allow sets of rendering 30 | commands to be uniquely identified. 31 | It consists of an ordered set of unsigned integers. 32 | glInitNames causes the name stack to be initialized to its default empty state. 33 | 34 | 35 | The name stack is always empty while the render mode is not GL_SELECT. 36 | Calls to glInitNames while the render mode is not GL_SELECT are ignored. 37 | 38 | 39 | Errors 40 | 41 | GL_INVALID_OPERATION is generated if glInitNames 42 | is executed between the execution of glBegin and the corresponding execution of 43 | glEnd. 44 | 45 | 46 | Associated Gets 47 | 48 | glGet with argument GL_NAME_STACK_DEPTH 49 | 50 | 51 | glGet with argument GL_MAX_NAME_STACK_DEPTH 52 | 53 | 54 | See Also 55 | 56 | glLoadName, 57 | glPushName, 58 | glRenderMode, 59 | glSelectBuffer 60 | 61 | 62 | Copyright 63 | 64 | Copyright 1991-2006 65 | Silicon Graphics, Inc. This document is licensed under the SGI 66 | Free Software B License. For details, see 67 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glCurrentPaletteMatrix.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 2003-2004 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glCurrentPaletteMatrix 13 | 3G 14 | 15 | 16 | 17 | glCurrentPaletteMatrix 18 | glCurrentPaletteMatrixOES 19 | 20 | defines which of the palette's matrices is affected by 21 | subsequent matrix operations 22 | 23 | 24 | 25 | 26 | C Specification 27 | 28 | 29 | 30 | void glCurrentPaletteMatrixOES 31 | GLuint index 32 | 33 | 34 | 35 | 36 | Parameters 37 | 38 | 39 | 40 | 41 | 42 | index 43 | 44 | 45 | 46 | specifies the index into the palette's matrices. 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Description 55 | 56 | 57 | glCurrentPaletteMatrixOES 58 | defines which of the palette's matrices is affected by 59 | subsequent matrix operations when the current matrix mode is 60 | GL_MATRIX_PALETTE_OES. 61 | 62 | 63 | 64 | 65 | Errors 66 | 67 | 68 | GL_INVALID_VALUE is generated if 69 | index is not between 70 | 0 and 71 | GL_MAX_PALETTE_MATRICES_OES - 1. 72 | 73 | 74 | 75 | See Also 76 | 77 | 78 | glLoadPaletteFromModelViewMatrix, 79 | glMatrixIndexPointer, 80 | glMatrixMode, 81 | glWeightPointer 82 | 83 | 84 | Copyright 85 | 86 | Copyright 2003-2004 87 | Silicon Graphics, Inc. This document is licensed under the SGI 88 | Free Software B License. For details, see 89 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glTextureBarrier.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 2014 7 | Khronos Group 8 | 9 | 10 | 11 | glTextureBarrier 12 | 3G 13 | 14 | 15 | glTextureBarrier 16 | controls the ordering of reads and writes to rendered fragments across drawing commands 17 | 18 | C Specification 19 | 20 | 21 | void glTextureBarrier 22 | void 23 | 24 | 25 | 26 | Description 27 | 28 | The values of rendered fragments are undefined when a shader 29 | stage fetches texels and the same texels are written via 30 | fragment shader outputs, even if the reads and writes are not in 31 | the same drawing command. To safely read the result of a written 32 | texel via a texel fetch in a subsequent drawing command, call 33 | glTextureBarrier between the two drawing 34 | commands to guarantee that writes have completed and caches have 35 | been invalidated before subsequent drawing commands are 36 | executed. 37 | 38 | 39 | Notes 40 | 41 | The situation described above is referred to as a 42 | rendering feedback loop and is discussed in 43 | more detail in section 9.3 of the OpenGL 4.5 Specification. 44 | 45 | 46 | Errors 47 | 48 | None. 49 | 50 | 51 | Version Support 52 | 53 | 54 | 55 | 56 | 57 | glTextureBarrier 58 | 59 | 60 | 61 | 62 | 63 | 64 | See Also 65 | 66 | glMemoryBarrier 67 | 68 | 69 | Copyright 70 | 71 | Copyright 2014 Khronos Group. 72 | This material may be distributed subject to the terms and conditions set forth in 73 | the Open Publication License, v 1.0, 8 June 1999. 74 | http://opencontent.org/openpub/. 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /pkg/opengl/opengl.go: -------------------------------------------------------------------------------- 1 | package opengl 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "unsafe" 7 | 8 | "github.com/hismailbulut/Neoray/pkg/common" 9 | "github.com/hismailbulut/Neoray/pkg/opengl/gl" 10 | ) 11 | 12 | type ContextInfo struct { 13 | Version string 14 | Vendor string 15 | Renderer string 16 | ShadingLanguageVersion string 17 | MaxTextureSize int32 18 | } 19 | 20 | type Context struct { 21 | shader *ShaderProgram // default shader for monospaced font rendering 22 | framebuffer uint32 // only for clearing textures 23 | } 24 | 25 | // Call per window 26 | func New(getProcAddress func(name string) unsafe.Pointer) (*Context, error) { 27 | // Initialize opengl 28 | err := gl.InitWithProcAddrFunc(getProcAddress) 29 | if err != nil { 30 | return nil, fmt.Errorf("Failed to initialize opengl: %s", err) 31 | } 32 | 33 | context := new(Context) 34 | 35 | // Init shaders 36 | vert := NewShaderFromSource(VERTEX_SHADER, ShaderSourceGridVert) 37 | geom := NewShaderFromSource(GEOMETRY_SHADER, ShaderSourceGridGeom) 38 | frag := NewShaderFromSource(FRAGMENT_SHADER, ShaderSourceGridFrag) 39 | context.shader = NewShaderProgram(vert, geom, frag) 40 | // Delete shaders because we don't need them after program creation 41 | vert.Delete() 42 | geom.Delete() 43 | frag.Delete() 44 | // TODO: When we start using multiple shaders this line will be deleted 45 | context.shader.Use() 46 | 47 | // Create framebuffer object 48 | // We dont need to bind framebuffer because we need it only when clearing texture 49 | gl.GenFramebuffers(1, &context.framebuffer) 50 | checkGLError() 51 | 52 | return context, nil 53 | } 54 | 55 | func (context *Context) Info() ContextInfo { 56 | info := ContextInfo{ 57 | Version: gl.GoStr(gl.GetString(gl.VERSION)), 58 | Vendor: gl.GoStr(gl.GetString(gl.VENDOR)), 59 | Renderer: gl.GoStr(gl.GetString(gl.RENDERER)), 60 | ShadingLanguageVersion: gl.GoStr(gl.GetString(gl.SHADING_LANGUAGE_VERSION)), 61 | } 62 | gl.GetIntegerv(gl.MAX_TEXTURE_SIZE, &info.MaxTextureSize) 63 | return info 64 | } 65 | 66 | func (context *Context) SetViewport(rect common.Rectangle[int]) { 67 | gl.Viewport(int32(rect.X), int32(rect.Y), int32(rect.W), int32(rect.H)) 68 | checkGLError() 69 | } 70 | 71 | func (context *Context) ClearScreen(c common.Color) { 72 | gl.ClearColor(c.R, c.G, c.B, c.A) 73 | checkGLError() 74 | gl.Clear(gl.COLOR_BUFFER_BIT) 75 | checkGLError() 76 | } 77 | 78 | func (context *Context) Flush() { 79 | // Since we are not using doublebuffering, we don't need to swap buffers, but we need to flush. 80 | gl.Flush() 81 | checkGLError() 82 | } 83 | 84 | func (context *Context) Destroy() { 85 | // Delete framebuffer 86 | gl.DeleteFramebuffers(1, &context.framebuffer) 87 | // Delete shaders 88 | context.shader.Destroy() 89 | } 90 | 91 | func checkGLError() { 92 | error_code := gl.GetError() 93 | if error_code == gl.NO_ERROR { 94 | return 95 | } 96 | var errorName string 97 | switch error_code { 98 | case gl.INVALID_ENUM: 99 | errorName = "INVALID_ENUM" 100 | case gl.INVALID_VALUE: 101 | errorName = "INVALID_VALUE" 102 | case gl.INVALID_OPERATION: 103 | errorName = "INVALID_OPERATION" 104 | case gl.STACK_OVERFLOW: 105 | errorName = "STACK_OVERFLOW" 106 | case gl.STACK_UNDERFLOW: 107 | errorName = "STACK_UNDERFLOW" 108 | case gl.OUT_OF_MEMORY: 109 | errorName = "OUT_OF_MEMORY" 110 | case gl.CONTEXT_LOST: 111 | errorName = "CONTEXT_LOST" 112 | default: 113 | errorName = fmt.Sprintf("#%.4x", error_code) 114 | } 115 | panic(fmt.Errorf("Opengl Error: %s", errorName)) 116 | } 117 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glResetMinmax.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glResetMinmax 13 | 3G 14 | 15 | 16 | glResetMinmax 17 | reset minmax table entries to initial values 18 | 19 | C Specification 20 | 21 | 22 | void glResetMinmax 23 | GLenum target 24 | 25 | 26 | 27 | Parameters 28 | 29 | 30 | target 31 | 32 | 33 | Must be 34 | GL_MINMAX. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glResetMinmax resets the elements of the current minmax table to their 43 | initial values: the ``maximum'' element receives the minimum possible 44 | component values, and the ``minimum'' element receives the maximum 45 | possible component values. 46 | 47 | 48 | Notes 49 | 50 | glResetMinmax is present only if ARB_imaging is returned when glGetString 51 | is called with an argument of GL_EXTENSIONS. 52 | 53 | 54 | Errors 55 | 56 | GL_INVALID_ENUM is generated if target is not GL_MINMAX. 57 | 58 | 59 | GL_INVALID_OPERATION is generated if glResetMinmax is executed 60 | between the execution of glBegin and the corresponding 61 | execution of glEnd. 62 | 63 | 64 | See Also 65 | 66 | glMinmax 67 | 68 | 69 | Copyright 70 | 71 | Copyright 1991-2006 72 | Silicon Graphics, Inc. This document is licensed under the SGI 73 | Free Software B License. For details, see 74 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsList.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glIsList 13 | 3G 14 | 15 | 16 | glIsList 17 | determine if a name corresponds to a display list 18 | 19 | C Specification 20 | 21 | 22 | GLboolean glIsList 23 | GLuint list 24 | 25 | 26 | 27 | Parameters 28 | 29 | 30 | list 31 | 32 | 33 | Specifies a potential display list name. 34 | 35 | 36 | 37 | 38 | 39 | Description 40 | 41 | glIsList returns GL_TRUE if list is the name 42 | of a display list and returns GL_FALSE if it is not, or if an error occurs. 43 | 44 | 45 | A name returned by glGenLists, but not yet associated with a display list 46 | by calling glNewList, is not the name of a display list. 47 | 48 | 49 | Errors 50 | 51 | GL_INVALID_OPERATION is generated if glIsList 52 | is executed between the execution of 53 | glBegin 54 | and the corresponding execution of glEnd. 55 | 56 | 57 | See Also 58 | 59 | glCallList, 60 | glCallLists, 61 | glDeleteLists, 62 | glGenLists, 63 | glNewList 64 | 65 | 66 | Copyright 67 | 68 | Copyright 1991-2006 69 | Silicon Graphics, Inc. This document is licensed under the SGI 70 | Free Software B License. For details, see 71 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetContextIDEXT.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetContextIDEXT 13 | 3G 14 | 15 | 16 | glXGetContextIDEXT 17 | get the XID for a context. 18 | 19 | C Specification 20 | 21 | 22 | GLXContextID glXGetContextIDEXT 23 | const GLXContext ctx 24 | 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | ctx 32 | 33 | 34 | Specifies a GLX rendering context. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glXGetContextIDEXT returns the XID associated with a GLXContext. 43 | 44 | 45 | No round trip is forced to the server; unlike most X calls that 46 | return a value, glXGetContextIDEXT does not flush any pending events. 47 | 48 | 49 | glXGetContextIDEXT is part of the 50 | GLX_EXT_import_context extension, not part of 51 | the core GLX command set. If 52 | GLX_EXT_import_context is included in the 53 | string returned by 54 | glXQueryExtensionsString, 55 | the extension is supported. 56 | 57 | 58 | Errors 59 | 60 | None is returned if 61 | ctx is NULL. 62 | Otherwise, if ctx does not refer to a 63 | valid context, undefined behavior results. 64 | 65 | 66 | See Also 67 | 68 | glXCreateContext, 69 | glXQueryVersion, 70 | glXQueryExtensionsString 71 | 72 | 73 | Copyright 74 | 75 | Copyright 1991-2006 76 | Silicon Graphics, Inc. This document is licensed under the SGI 77 | Free Software B License. For details, see 78 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glPauseTransformFeedback.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glPauseTransformFeedback 14 | 3G 15 | 16 | 17 | glPauseTransformFeedback 18 | pause transform feedback operations 19 | 20 | C Specification 21 | 22 | 23 | void glPauseTransformFeedback 24 | void 25 | 26 | 27 | 28 | Description 29 | 30 | glPauseTransformFeedback pauses transform feedback operations on the currently active transform feedback 31 | object. When transform feedback operations are paused, transform feedback is still considered active and changing most 32 | transform feedback state related to the object results in an error. However, a new transform feedback object may be bound 33 | while transform feedback is paused. 34 | 35 | 36 | Errors 37 | 38 | GL_INVALID_OPERATION is generated if the currently bound transform feedback object is not active or is paused. 39 | 40 | 41 | Version Support 42 | 43 | 44 | 45 | 46 | 47 | glPauseTransformFeedback 48 | 49 | 50 | 51 | 52 | 53 | 54 | See Also 55 | 56 | glGenTransformFeedbacks, 57 | glBindTransformFeedback, 58 | glBeginTransformFeedback, 59 | glResumeTransformFeedback, 60 | glEndTransformFeedback, 61 | glDeleteTransformFeedbacks 62 | 63 | 64 | Copyright 65 | 66 | Copyright 2010-2014 Khronos Group. 67 | This material may be distributed subject to the terms and conditions set forth in 68 | the Open Publication License, v 1.0, 8 June 1999. 69 | http://opencontent.org/openpub/. 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glResumeTransformFeedback.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glResumeTransformFeedback 14 | 3G 15 | 16 | 17 | glResumeTransformFeedback 18 | resume transform feedback operations 19 | 20 | C Specification 21 | 22 | 23 | void glResumeTransformFeedback 24 | void 25 | 26 | 27 | 28 | Description 29 | 30 | glResumeTransformFeedback resumes transform feedback operations on the currently active transform feedback 31 | object. When transform feedback operations are paused, transform feedback is still considered active and changing most 32 | transform feedback state related to the object results in an error. However, a new transform feedback object may be bound 33 | while transform feedback is paused. 34 | 35 | 36 | Errors 37 | 38 | GL_INVALID_OPERATION is generated if the currently bound transform feedback object is not active or is not paused. 39 | 40 | 41 | Version Support 42 | 43 | 44 | 45 | 46 | 47 | glResumeTransformFeedback 48 | 49 | 50 | 51 | 52 | 53 | 54 | See Also 55 | 56 | glGenTransformFeedbacks, 57 | glBindTransformFeedback, 58 | glBeginTransformFeedback, 59 | glPauseTransformFeedback, 60 | glEndTransformFeedback, 61 | glDeleteTransformFeedbacks 62 | 63 | 64 | Copyright 65 | 66 | Copyright 2010-2014 Khronos Group. 67 | This material may be distributed subject to the terms and conditions set forth in 68 | the Open Publication License, v 1.0, 8 June 1999. 69 | http://opencontent.org/openpub/. 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsSync.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glIsSync 14 | 3G 15 | 16 | 17 | glIsSync 18 | determine if a name corresponds to a sync object 19 | 20 | C Specification 21 | 22 | 23 | GLboolean glIsSync 24 | GLsync sync 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | sync 32 | 33 | 34 | Specifies a value that may be the name of a sync object. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glIsSync returns GL_TRUE if sync is currently the name of a sync object. 43 | If sync is not the name of a sync object, or if an error occurs, glIsSync returns 44 | GL_FALSE. Note that zero is not the name of a sync object. 45 | 46 | 47 | Notes 48 | 49 | glIsSync is available only if the GL version is 3.2 or greater. 50 | 51 | 52 | Version Support 53 | 54 | 55 | 56 | 57 | 58 | glIsSync 59 | 60 | 61 | 62 | 63 | 64 | 65 | See Also 66 | 67 | glFenceSync, 68 | glWaitSync, 69 | glClientWaitSync, 70 | glDeleteSync 71 | 72 | 73 | Copyright 74 | 75 | Copyright 2010-2014 Khronos Group. 76 | This material may be distributed subject to the terms and conditions set forth in 77 | the Open Publication License, v 1.0, 8 June 1999. 78 | http://opencontent.org/openpub/. 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXDestroyWindow.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXDestroyWindow 13 | 3G 14 | 15 | 16 | glXDestroyWindow 17 | destroy an on-screen rendering area 18 | 19 | C Specification 20 | 21 | 22 | void glXDestroyWindow 23 | Display * dpy 24 | GLXWindow win 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | win 41 | 42 | 43 | Specifies the GLXWindow to be destroyed. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | glXDestroyWindow destroys a GLXWindow created by glXCreateWindow. 52 | 53 | 54 | Notes 55 | 56 | glXDestroyWindow is available only if the GLX version is 1.3 or greater. 57 | 58 | 59 | If the GLX version is 1.1 or 1.0, the GL version must be 1.0. 60 | If the GLX version is 1.2, then the GL version must be 1.1. 61 | If the GLX version is 1.3, then the GL version must be 1.2. 62 | 63 | 64 | Errors 65 | 66 | GLXBadWindow is generated if win is not a valid 67 | GLXPixmap. 68 | 69 | 70 | See Also 71 | 72 | glXChooseFBConfig, 73 | glXCreateWindow, 74 | glXMakeContextCurrent 75 | 76 | 77 | Copyright 78 | 79 | Copyright 1991-2006 80 | Silicon Graphics, Inc. This document is licensed under the SGI 81 | Free Software B License. For details, see 82 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXDestroyPbuffer.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXDestroyPbuffer 13 | 3G 14 | 15 | 16 | glXDestroyPbuffer 17 | destroy an off-screen rendering area 18 | 19 | C Specification 20 | 21 | 22 | void glXDestroyPbuffer 23 | Display * dpy 24 | GLXPbuffer pbuf 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | pbuf 41 | 42 | 43 | Specifies the GLXPbuffer to be destroyed. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | glXDestroyPbuffer destroys a GLXPbuffer created by glXCreatePbuffer. 52 | 53 | 54 | Notes 55 | 56 | glXDestroyPbuffer is available only if the GLX version is 1.3 or greater. 57 | 58 | 59 | If the GLX version is 1.1 or 1.0, the GL version must be 1.0. 60 | If the GLX version is 1.2, then the GL version must be 1.1. 61 | If the GLX version is 1.3, then the GL version must be 1.2. 62 | 63 | 64 | Errors 65 | 66 | GLXBadPbuffer is generated if pbuf is not a valid 67 | GLXPbuffer. 68 | 69 | 70 | See Also 71 | 72 | glXChooseFBConfig, 73 | glXCreatePbuffer, 74 | glXMakeContextCurrent 75 | 76 | 77 | Copyright 78 | 79 | Copyright 1991-2006 80 | Silicon Graphics, Inc. This document is licensed under the SGI 81 | Free Software B License. For details, see 82 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /cmd/neoray/style.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | 7 | "github.com/hismailbulut/Neoray/pkg/common" 8 | "github.com/hismailbulut/Neoray/pkg/fontkit" 9 | "github.com/hismailbulut/Neoray/pkg/logger" 10 | ) 11 | 12 | const DEFAULT_FONT_SIZE = 12 13 | 14 | // neovim ui options 15 | type UIOptions struct { 16 | arabicshape bool 17 | ambiwidth string 18 | emoji bool 19 | guifont string 20 | guifontset string 21 | guifontwide string // TODO 22 | linespace int // TODO 23 | pumblend int // TODO 24 | showtabline int 25 | termguicolors bool 26 | mousehide bool // will be implemented soon, currently always true 27 | } 28 | 29 | func CreateUIOptions() UIOptions { 30 | return UIOptions{ 31 | mousehide: true, 32 | } 33 | } 34 | 35 | func (options *UIOptions) setGuiFont(guifont string) { 36 | // Load Font 37 | if guifont == options.guifont { 38 | return 39 | } 40 | options.guifont = guifont 41 | var size float64 = DEFAULT_FONT_SIZE 42 | // treat underlines like whitespaces 43 | guifont = strings.ReplaceAll(guifont, "_", " ") 44 | // parse font options 45 | fontOptions := strings.Split(guifont, ":") 46 | name := fontOptions[0] 47 | for _, opt := range fontOptions[1:] { 48 | if len(opt) > 1 && opt[0] == 'h' { 49 | // Font size 50 | tsize, err := strconv.ParseFloat(opt[1:], 32) 51 | if err == nil { 52 | size = tsize 53 | } 54 | } 55 | } 56 | if name == "" { 57 | // Set nil to disable font 58 | Editor.gridManager.SetGridFontKit(1, nil) 59 | Editor.contextMenu.SetFontKit(nil) 60 | } else { 61 | // Create and set font 62 | logger.Log(logger.TRACE, "Loading font", name) 63 | kit, err := fontkit.CreateKit(name) 64 | if err != nil { 65 | Editor.nvim.EchoError("Font %s not found", name) 66 | } else { 67 | // Log some info 68 | if kit.Regular() != nil { 69 | logger.Log(logger.TRACE, "Regular:", kit.Regular().FilePath()) 70 | } 71 | if kit.Bold() != nil { 72 | logger.Log(logger.TRACE, "Bold:", kit.Bold().FilePath()) 73 | } 74 | if kit.Italic() != nil { 75 | logger.Log(logger.TRACE, "Italic:", kit.Italic().FilePath()) 76 | } 77 | if kit.BoldItalic() != nil { 78 | logger.Log(logger.TRACE, "BoldItalic:", kit.BoldItalic().FilePath()) 79 | } 80 | // Set fonts 81 | Editor.gridManager.SetGridFontKit(1, kit) 82 | Editor.contextMenu.SetFontKit(kit) 83 | } 84 | } 85 | // Always set font size to default if user not set 86 | Editor.gridManager.SetGridFontSize(1, size) 87 | Editor.contextMenu.SetFontSize(size) 88 | } 89 | 90 | type HighlightAttribute struct { 91 | foreground common.Color 92 | background common.Color 93 | special common.Color 94 | reverse bool 95 | italic bool 96 | bold bool 97 | strikethrough bool 98 | underline bool 99 | // underlineline bool 100 | undercurl bool 101 | // underdot bool 102 | // underdash bool 103 | // blend int 104 | // TODO: Implement commented attributes 105 | } 106 | 107 | type ModeInfo struct { 108 | cursor_shape string 109 | cell_percentage int 110 | blinkwait int 111 | blinkon int 112 | blinkoff int 113 | attr_id int 114 | attr_id_lm int 115 | short_name string 116 | name string 117 | } 118 | 119 | type Mode struct { 120 | cursor_style_enabled bool 121 | mode_infos []ModeInfo 122 | current_mode_name string 123 | current_mode int 124 | } 125 | 126 | func (mode *Mode) Current() ModeInfo { 127 | if mode.current_mode < len(mode.mode_infos) { 128 | return mode.mode_infos[mode.current_mode] 129 | } 130 | return ModeInfo{} 131 | } 132 | 133 | func (mode *Mode) Clear() { 134 | mode.mode_infos = []ModeInfo{} 135 | } 136 | 137 | func (mode *Mode) Add(info ModeInfo) { 138 | mode.mode_infos = append(mode.mode_infos, info) 139 | } 140 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXDestroyPixmap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXDestroyPixmap 13 | 3G 14 | 15 | 16 | glXDestroyPixmap 17 | destroy an off-screen rendering area 18 | 19 | C Specification 20 | 21 | 22 | void glXDestroyPixmap 23 | Display * dpy 24 | GLXPixmap pixmap 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | pixmap 41 | 42 | 43 | Specifies the GLXPixmap to be destroyed. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | glXDestroyPixmap destroys a GLXPixmap created by glXCreatePixmap. 52 | 53 | 54 | Notes 55 | 56 | glXDestroyPixmap is available only if the GLX version is 1.3 or greater. 57 | 58 | 59 | If the GLX version is 1.1 or 1.0, the GL version must be 1.0. 60 | If the GLX version is 1.2, then the GL version must be 1.1. 61 | If the GLX version is 1.3, then the GL version must be 1.2. 62 | 63 | 64 | Errors 65 | 66 | GLXBadPixmap is generated if pixmap is not a valid 67 | GLXPixmap. 68 | 69 | 70 | See Also 71 | 72 | glXChooseFBConfig, 73 | glXCreatePixmap, 74 | glXDestroyGLXPixmap, 75 | glXMakeContextCurrent 76 | 77 | 78 | Copyright 79 | 80 | Copyright 1991-2006 81 | Silicon Graphics, Inc. This document is licensed under the SGI 82 | Free Software B License. For details, see 83 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsSampler.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glIsSampler 14 | 3G 15 | 16 | 17 | glIsSampler 18 | determine if a name corresponds to a sampler object 19 | 20 | C Specification 21 | 22 | 23 | GLboolean glIsSampler 24 | GLuint id 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | id 32 | 33 | 34 | Specifies a value that may be the name of a sampler object. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glIsSampler returns GL_TRUE if id is currently the name of a sampler object. 43 | If id is zero, or is a non-zero value that is not currently the 44 | name of a sampler object, or if an error occurs, glIsSampler returns GL_FALSE. 45 | 46 | 47 | A name returned by glGenSamplers, is the name of a sampler object. 48 | 49 | 50 | Notes 51 | 52 | glIsSampler is available only if the GL version is 3.3 or higher. 53 | 54 | 55 | Version Support 56 | 57 | 58 | 59 | 60 | 61 | glIsSampler 62 | 63 | 64 | 65 | 66 | 67 | 68 | See Also 69 | 70 | glGenSamplers, 71 | glBindSampler, 72 | glDeleteSamplers 73 | 74 | 75 | Copyright 76 | 77 | Copyright 2010-2014 Khronos Group. 78 | This material may be distributed subject to the terms and conditions set forth in 79 | the Open Publication License, v 1.0, 8 June 1999. 80 | http://opencontent.org/openpub/. 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXQueryExtensionsString.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXQueryExtensionsString 13 | 3G 14 | 15 | 16 | glXQueryExtensionsString 17 | return list of supported extensions 18 | 19 | C Specification 20 | 21 | 22 | const char * glXQueryExtensionsString 23 | Display * dpy 24 | int screen 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | screen 41 | 42 | 43 | Specifies the screen number. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | glXQueryExtensionsString returns a pointer to a string describing 52 | which GLX extensions are supported on the connection. The string 53 | is null-terminated and contains a space-separated list of 54 | extension names. (The extension names themselves never contain 55 | spaces.) If there are no extensions to GLX, then the empty string is 56 | returned. 57 | 58 | 59 | Notes 60 | 61 | glXQueryExtensionsString is available only if the GLX version is 1.1 or greater. 62 | 63 | 64 | glXQueryExtensionsString only returns information about GLX extensions. Call 65 | glGetString to get a list of GL extensions. 66 | 67 | 68 | See Also 69 | 70 | glGetString, 71 | glXQueryVersion, 72 | glXQueryServerString, 73 | glXGetClientString 74 | 75 | 76 | Copyright 77 | 78 | Copyright 1991-2006 79 | Silicon Graphics, Inc. This document is licensed under the SGI 80 | Free Software B License. For details, see 81 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /pkg/opengl/shader.go: -------------------------------------------------------------------------------- 1 | package opengl 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "strings" 7 | 8 | "github.com/hismailbulut/Neoray/pkg/opengl/gl" 9 | ) 10 | 11 | // Embedded shader sources 12 | var ( 13 | //go:embed shaders/grid.vert 14 | ShaderSourceGridVert string 15 | //go:embed shaders/grid.geom 16 | ShaderSourceGridGeom string 17 | //go:embed shaders/grid.frag 18 | ShaderSourceGridFrag string 19 | ) 20 | 21 | // for reducing gl.UseProgram calls 22 | var currentShaderProgramID uint32 23 | 24 | type ShaderType uint32 25 | 26 | const ( 27 | VERTEX_SHADER ShaderType = gl.VERTEX_SHADER 28 | GEOMETRY_SHADER ShaderType = gl.GEOMETRY_SHADER 29 | FRAGMENT_SHADER ShaderType = gl.FRAGMENT_SHADER 30 | ) 31 | 32 | func (st ShaderType) String() string { 33 | switch st { 34 | case VERTEX_SHADER: 35 | return "VERTEX_SHADER" 36 | case GEOMETRY_SHADER: 37 | return "GEOMETRY_SHADER" 38 | case FRAGMENT_SHADER: 39 | return "FRAGMENT_SHADER" 40 | } 41 | panic("unknown shader type") 42 | } 43 | 44 | type Shader struct { 45 | ID uint32 46 | Type ShaderType 47 | } 48 | 49 | func NewShaderFromSource(shader_type ShaderType, source string) *Shader { 50 | shader := &Shader{ 51 | ID: gl.CreateShader(uint32(shader_type)), 52 | Type: shader_type, 53 | } 54 | source_cstr, free := gl.Strs(source + "\x00") 55 | defer free() 56 | gl.ShaderSource(shader.ID, 1, source_cstr, nil) 57 | checkGLError() 58 | gl.CompileShader(shader.ID) 59 | checkGLError() 60 | var result int32 61 | gl.GetShaderiv(shader.ID, gl.COMPILE_STATUS, &result) 62 | if result == gl.FALSE { 63 | var logLength int32 64 | gl.GetShaderiv(shader.ID, gl.INFO_LOG_LENGTH, &logLength) 65 | log := string(make([]byte, logLength)) 66 | gl.GetShaderInfoLog(shader.ID, logLength, nil, gl.Str(log)) 67 | log = strings.Trim(log, "\x00") 68 | panic(fmt.Errorf("Shader %s compilation failed: %s\n", shader_type, log)) 69 | } 70 | return shader 71 | } 72 | 73 | func (shader *Shader) Delete() { 74 | gl.DeleteShader(shader.ID) 75 | shader.ID = 0 76 | shader.Type = 0 77 | } 78 | 79 | type ShaderProgram struct { 80 | ID uint32 81 | uniforms map[string]int32 82 | } 83 | 84 | // All shaders can be safely destroyed after program creation 85 | func NewShaderProgram(vert *Shader, geom *Shader, frag *Shader) *ShaderProgram { 86 | program := &ShaderProgram{ 87 | ID: gl.CreateProgram(), 88 | uniforms: make(map[string]int32), 89 | } 90 | if vert != nil { 91 | gl.AttachShader(program.ID, vert.ID) 92 | checkGLError() 93 | } 94 | if geom != nil { 95 | gl.AttachShader(program.ID, geom.ID) 96 | checkGLError() 97 | } 98 | if frag != nil { 99 | gl.AttachShader(program.ID, frag.ID) 100 | checkGLError() 101 | } 102 | gl.LinkProgram(program.ID) 103 | checkGLError() 104 | var status int32 105 | gl.GetProgramiv(program.ID, gl.LINK_STATUS, &status) 106 | if status == gl.FALSE { 107 | var logLength int32 108 | gl.GetProgramiv(program.ID, gl.INFO_LOG_LENGTH, &logLength) 109 | log := string(make([]byte, logLength)) 110 | gl.GetProgramInfoLog(program.ID, logLength, nil, gl.Str(log)) 111 | log = strings.Trim(log, "\x00") 112 | panic(fmt.Errorf("Failed to link shader program: %s", log)) 113 | } 114 | return program 115 | } 116 | 117 | func (program ShaderProgram) UniformLocation(name string) int32 { 118 | if location, ok := program.uniforms[name]; ok { 119 | return location 120 | } 121 | uniform_name := gl.Str(name + "\x00") 122 | loc := gl.GetUniformLocation(uint32(program.ID), uniform_name) 123 | if loc < 0 { 124 | panic(fmt.Errorf("Failed to find uniform: %s", name)) 125 | } 126 | program.uniforms[name] = loc 127 | return loc 128 | } 129 | 130 | func (program ShaderProgram) Use() { 131 | if program.ID != currentShaderProgramID { 132 | gl.UseProgram(program.ID) 133 | checkGLError() 134 | currentShaderProgramID = program.ID 135 | } 136 | } 137 | 138 | func (program ShaderProgram) Destroy() { 139 | gl.DeleteProgram(program.ID) 140 | program.ID = 0 141 | program.uniforms = nil 142 | } 143 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsVertexArray.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glIsVertexArray 14 | 3G 15 | 16 | 17 | glIsVertexArray 18 | determine if a name corresponds to a vertex array object 19 | 20 | C Specification 21 | 22 | 23 | GLboolean glIsVertexArray 24 | GLuint array 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | array 32 | 33 | 34 | Specifies a value that may be the name of a vertex array object. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glIsVertexArray returns GL_TRUE if array is currently the name of a vertex array 43 | object. If array is zero, or if array is not the name of a vertex array object, or if an error 44 | occurs, glIsVertexArray returns GL_FALSE. If array is a name returned by 45 | glGenVertexArrays, by that has not yet been bound through a call to 46 | glBindVertexArray, then the name is not a vertex array object and 47 | glIsVertexArray returns GL_FALSE. 48 | 49 | 50 | Version Support 51 | 52 | 53 | 54 | 55 | 56 | glIsVertexArray 57 | 58 | 59 | 60 | 61 | 62 | 63 | See Also 64 | 65 | glGenVertexArrays, 66 | glBindVertexArray, 67 | glDeleteVertexArrays 68 | 69 | 70 | Copyright 71 | 72 | Copyright 2010-2014 Khronos Group. 73 | This material may be distributed subject to the terms and conditions set forth in 74 | the Open Publication License, v 1.0, 8 June 1999. 75 | http://opencontent.org/openpub/. 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsFramebuffer.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glIsFramebuffer 14 | 3G 15 | 16 | 17 | glIsFramebuffer 18 | determine if a name corresponds to a framebuffer object 19 | 20 | C Specification 21 | 22 | 23 | GLboolean glIsFramebuffer 24 | GLuint framebuffer 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | framebuffer 32 | 33 | 34 | Specifies a value that may be the name of a framebuffer object. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glIsFramebuffer returns GL_TRUE if framebuffer is currently the name of a framebuffer 43 | object. If framebuffer is zero, or if framebuffer is not the name of a framebuffer object, or if an error 44 | occurs, glIsFramebuffer returns GL_FALSE. If framebuffer is a name returned by 45 | glGenFramebuffers, by that has not yet been bound through a call to 46 | glBindFramebuffer, then the name is not a framebuffer object and glIsFramebuffer 47 | returns GL_FALSE. 48 | 49 | 50 | Version Support 51 | 52 | 53 | 54 | 55 | 56 | glIsFramebuffer 57 | 58 | 59 | 60 | 61 | 62 | 63 | See Also 64 | 65 | glGenFramebuffers, 66 | glBindFramebuffer, 67 | glDeleteFramebuffers 68 | 69 | 70 | Copyright 71 | 72 | Copyright 2010-2014 Khronos Group. 73 | This material may be distributed subject to the terms and conditions set forth in 74 | the Open Publication License, v 1.0, 8 June 1999. 75 | http://opencontent.org/openpub/. 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXQueryExtension.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXQueryExtension 13 | 3G 14 | 15 | 16 | glXQueryExtension 17 | indicate whether the GLX extension is supported 18 | 19 | C Specification 20 | 21 | 22 | Bool glXQueryExtension 23 | Display * dpy 24 | int * errorBase 25 | int * eventBase 26 | 27 | 28 | 29 | 30 | Parameters 31 | 32 | 33 | dpy 34 | 35 | 36 | Specifies the connection to the X server. 37 | 38 | 39 | 40 | 41 | errorBase 42 | 43 | 44 | Returns the base error code of the GLX server extension. 45 | 46 | 47 | 48 | 49 | eventBase 50 | 51 | 52 | Returns the base event code of the GLX server extension. 53 | 54 | 55 | 56 | 57 | 58 | Description 59 | 60 | glXQueryExtension returns True if the X server of 61 | connection dpy supports the GLX extension, 62 | False otherwise. 63 | If True is returned, 64 | then errorBase and eventBase return the error base and event base of 65 | the GLX extension. These values should be added to the constant 66 | error and event values to determine the actual event or error values. 67 | Otherwise, errorBase and eventBase are unchanged. 68 | 69 | 70 | errorBase and eventBase do not return values if they are specified 71 | as NULL. 72 | 73 | 74 | See Also 75 | 76 | glXQueryVersion 77 | 78 | 79 | Copyright 80 | 81 | Copyright 1991-2006 82 | Silicon Graphics, Inc. This document is licensed under the SGI 83 | Free Software B License. For details, see 84 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glFlush.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | 2010-2014 13 | Khronos Group 14 | 15 | 16 | 17 | glFlush 18 | 3G 19 | 20 | 21 | glFlush 22 | force execution of GL commands in finite time 23 | 24 | C Specification 25 | 26 | 27 | void glFlush 28 | void 29 | 30 | 31 | 32 | Description 33 | 34 | Different GL implementations buffer commands in several different locations, 35 | including network buffers and the graphics accelerator itself. 36 | glFlush empties all of these buffers, 37 | causing all issued commands to be executed as quickly as 38 | they are accepted by the actual rendering engine. 39 | Though this execution may not be completed in any particular 40 | time period, 41 | it does complete in finite time. 42 | 43 | 44 | Because any GL program might be executed over a network, 45 | or on an accelerator that buffers commands, 46 | all programs should call glFlush whenever they count on having 47 | all of their previously issued commands completed. 48 | For example, 49 | call glFlush before waiting for user input that depends on 50 | the generated image. 51 | 52 | 53 | Notes 54 | 55 | glFlush can return at any time. 56 | It does not wait until the execution of all previously 57 | issued GL commands is complete. 58 | 59 | 60 | Version Support 61 | 62 | 63 | 64 | 65 | 66 | glFlush 67 | 68 | 69 | 70 | 71 | 72 | 73 | See Also 74 | 75 | glFinish 76 | 77 | 78 | Copyright 79 | 80 | Copyright 1991-2006 Silicon Graphics, Inc. 81 | Copyright 2010-2014 Khronos Group. 82 | This document is licensed under the SGI Free Software B License. 83 | For details, see 84 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsQuery.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2005 9 | Sams Publishing 10 | 11 | 12 | 2010-2014 13 | Khronos Group 14 | 15 | 16 | 17 | glIsQuery 18 | 3G 19 | 20 | 21 | glIsQuery 22 | determine if a name corresponds to a query object 23 | 24 | C Specification 25 | 26 | 27 | GLboolean glIsQuery 28 | GLuint id 29 | 30 | 31 | 32 | Parameters 33 | 34 | 35 | id 36 | 37 | 38 | Specifies a value that may be the name of a query object. 39 | 40 | 41 | 42 | 43 | 44 | Description 45 | 46 | glIsQuery returns GL_TRUE if id is currently the name of a query object. 47 | If id is zero, or is a non-zero value that is not currently the 48 | name of a query object, or if an error occurs, glIsQuery returns GL_FALSE. 49 | 50 | 51 | A name returned by glGenQueries, but not yet associated with a query object 52 | by calling glBeginQuery, is not the name of a query object. 53 | 54 | 55 | Version Support 56 | 57 | 58 | 59 | 60 | 61 | glIsQuery 62 | 63 | 64 | 65 | 66 | 67 | 68 | See Also 69 | 70 | glBeginQuery, 71 | glDeleteQueries, 72 | glEndQuery, 73 | glGenQueries 74 | 75 | 76 | Copyright 77 | 78 | Copyright 2005 Addison-Wesley. 79 | Copyright 2010-2014 Khronos Group. 80 | This material may be distributed subject to the terms and conditions set forth in 81 | the Open Publication License, v 1.0, 8 June 1999. 82 | http://opencontent.org/openpub/. 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsTransformFeedback.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glIsTransformFeedback 14 | 3G 15 | 16 | 17 | glIsTransformFeedback 18 | determine if a name corresponds to a transform feedback object 19 | 20 | C Specification 21 | 22 | 23 | GLboolean glIsTransformFeedback 24 | GLuint id 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | id 32 | 33 | 34 | Specifies a value that may be the name of a transform feedback object. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glIsTransformFeedback returns GL_TRUE if id is currently the name of a transform feedback 43 | object. If id is zero, or if id is not the name of a transform feedback object, or if an error 44 | occurs, glIsTransformFeedback returns GL_FALSE. If id is a name returned by 45 | glGenTransformFeedbacks, but that has not yet been bound through a call to 46 | glBindTransformFeedback, then the name is not a transform feedback object and glIsTransformFeedback 47 | returns GL_FALSE. 48 | 49 | 50 | Version Support 51 | 52 | 53 | 54 | 55 | 56 | glIsTransformFeedback 57 | 58 | 59 | 60 | 61 | 62 | 63 | See Also 64 | 65 | glGenTransformFeedbacks, 66 | glBindTransformFeedback, 67 | glDeleteTransformFeedbacks 68 | 69 | 70 | Copyright 71 | 72 | Copyright 2010-2014 Khronos Group. 73 | This material may be distributed subject to the terms and conditions set forth in 74 | the Open Publication License, v 1.0, 8 June 1999. 75 | http://opencontent.org/openpub/. 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetFBConfigs.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetFBConfigs 13 | 3G 14 | 15 | 16 | glXGetFBConfigs 17 | list all GLX frame buffer configurations for a given screen 18 | 19 | C Specification 20 | 21 | 22 | GLXFBConfig * glXGetFBConfigs 23 | Display * dpy 24 | int screen 25 | int * nelements 26 | 27 | 28 | 29 | 30 | Parameters 31 | 32 | 33 | dpy 34 | 35 | 36 | Specifies the connection to the X server. 37 | 38 | 39 | 40 | 41 | screen 42 | 43 | 44 | Specifies the screen number. 45 | 46 | 47 | 48 | 49 | nelements 50 | 51 | 52 | Returns the number of GLXFBConfigs returned. 53 | 54 | 55 | 56 | 57 | 58 | Description 59 | 60 | glXGetFBConfigs returns a list of all GLXFBConfigs available on the screen 61 | specified by screen. Use glXGetFBConfigAttrib to obtain attribute 62 | values from a specific GLXFBConfig. 63 | 64 | 65 | Notes 66 | 67 | glXGetFBConfigs is available only if the GLX version is 1.3 or greater. 68 | 69 | 70 | If the GLX version is 1.1 or 1.0, the GL version must be 1.0. 71 | If the GLX version is 1.2, then the GL version must be 1.1. 72 | If the GLX version is 1.3, then the GL version must be 1.2. 73 | 74 | 75 | See Also 76 | 77 | glXGetFBConfigAttrib, 78 | glXGetVisualFromFBConfig 79 | glXChooseFBConfig 80 | 81 | 82 | Copyright 83 | 84 | Copyright 1991-2006 85 | Silicon Graphics, Inc. This document is licensed under the SGI 86 | Free Software B License. For details, see 87 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /pkg/opengl/texture.go: -------------------------------------------------------------------------------- 1 | package opengl 2 | 3 | import ( 4 | "fmt" 5 | "image" 6 | "unsafe" 7 | 8 | "github.com/hismailbulut/Neoray/pkg/common" 9 | "github.com/hismailbulut/Neoray/pkg/logger" 10 | "github.com/hismailbulut/Neoray/pkg/opengl/gl" 11 | ) 12 | 13 | var boundTextureId uint32 14 | 15 | type Texture struct { 16 | id uint32 17 | width int 18 | height int 19 | fbo uint32 // this is like pointer to the framebuffer because framebuffer is in gpu memory 20 | } 21 | 22 | func (texture Texture) String() string { 23 | return fmt.Sprintf("Texture(ID: %d, Width: %d, Height: %d)", texture.id, texture.width, texture.height) 24 | } 25 | 26 | func (context *Context) CreateTexture(width, height int) Texture { 27 | texture := Texture{ 28 | fbo: context.framebuffer, 29 | } 30 | // NOTE: There can be multiple textures but only one can bind at a time 31 | gl.GenTextures(1, &texture.id) 32 | checkGLError() 33 | gl.BindTexture(gl.TEXTURE_2D, texture.id) 34 | checkGLError() 35 | boundTextureId = texture.id 36 | gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) 37 | checkGLError() 38 | gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) 39 | checkGLError() 40 | gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) 41 | checkGLError() 42 | gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) 43 | checkGLError() 44 | texture.Resize(width, height) 45 | logger.Log(logger.DEBUG, "Texture created:", texture) 46 | return texture 47 | } 48 | 49 | func (texture *Texture) Size() common.Vector2[int] { 50 | return common.Vec2(texture.width, texture.height) 51 | } 52 | 53 | // Texture must bound before resizing 54 | func (texture *Texture) Resize(width, height int) { 55 | if boundTextureId != texture.id { 56 | panic("texture must be bound before resize") 57 | } 58 | gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil) 59 | checkGLError() 60 | texture.width = width 61 | texture.height = height 62 | } 63 | 64 | func (texture *Texture) Clear() { 65 | // Bind framebuffer 66 | gl.BindFramebuffer(gl.DRAW_FRAMEBUFFER, texture.fbo) 67 | checkGLError() 68 | // Init framebuffer with texture 69 | gl.FramebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture.id, 0) 70 | checkGLError() 71 | // Check if the framebuffer is complete and ready for draw 72 | fbo_status := gl.CheckFramebufferStatus(gl.DRAW_FRAMEBUFFER) 73 | if fbo_status == gl.FRAMEBUFFER_COMPLETE { 74 | // Clear the texture 75 | gl.ClearColor(0, 0, 0, 0) 76 | checkGLError() 77 | gl.Clear(gl.COLOR_BUFFER_BIT) 78 | checkGLError() 79 | } else { 80 | panic(fmt.Errorf("Framebuffer is not complete: %d", fbo_status)) 81 | } 82 | // Unbind framebuffer 83 | gl.BindFramebuffer(gl.DRAW_FRAMEBUFFER, 0) 84 | checkGLError() 85 | } 86 | 87 | func (texture *Texture) Bind() { 88 | if boundTextureId == texture.id { 89 | return 90 | } 91 | gl.BindTexture(gl.TEXTURE_2D, texture.id) 92 | checkGLError() 93 | boundTextureId = texture.id 94 | } 95 | 96 | // Texture must bound before drawing 97 | func (texture *Texture) Draw(image *image.RGBA, dest common.Rectangle[int]) { 98 | if boundTextureId != texture.id { 99 | panic("texture must be bound before resize") 100 | } 101 | gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(dest.X), int32(dest.Y), int32(dest.W), int32(dest.H), gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&image.Pix[0])) 102 | checkGLError() 103 | } 104 | 105 | // Converts coordinates to opengl understandable coordinates, 0 to 1 106 | func (texture *Texture) Normalize(pos common.Rectangle[int]) common.Rectangle[float32] { 107 | return common.Rectangle[float32]{ 108 | X: float32(pos.X) / float32(texture.width), 109 | Y: float32(pos.Y) / float32(texture.height), 110 | W: float32(pos.W) / float32(texture.width), 111 | H: float32(pos.H) / float32(texture.height), 112 | } 113 | } 114 | 115 | func (texture *Texture) Delete() { 116 | gl.DeleteTextures(1, &texture.id) 117 | texture.id = 0 118 | texture.width = 0 119 | texture.height = 0 120 | texture.fbo = 0 121 | logger.Log(logger.DEBUG, "Texture deleted:", texture) 122 | } 123 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXFreeContextEXT.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXFreeContextEXT 13 | 3G 14 | 15 | 16 | glXFreeContextEXT 17 | free client-side memory for imported context 18 | 19 | C Specification 20 | 21 | 22 | void glXFreeContextEXT 23 | Display * dpy 24 | GLXContext ctx 25 | 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | ctx 41 | 42 | 43 | Specifies a GLX rendering context. 44 | 45 | 46 | 47 | 48 | 49 | Description 50 | 51 | glXFreeContextEXT frees the client-side part of a GLXContext that 52 | was created with glXImportContextEXT. glXFreeContextEXT does not 53 | free the server-side context information or the XID 54 | associated with the server-side context. 55 | 56 | 57 | glXFreeContextEXT is part of the 58 | GLX_EXT_import_context extension, not part of 59 | the core GLX command set. If 60 | GLX_EXT_import_context is included in the 61 | string returned by 62 | glXQueryExtensionsString, 63 | the extension is supported. 64 | 65 | 66 | Errors 67 | 68 | GLXBadContext is generated if ctx does not 69 | refer to a valid context. 70 | 71 | 72 | See Also 73 | 74 | glXCreateContext, 75 | glXQueryVersion, 76 | glXQueryExtensionsString, 77 | glXImportContextEXT 78 | 79 | 80 | Copyright 81 | 82 | Copyright 1991-2006 83 | Silicon Graphics, Inc. This document is licensed under the SGI 84 | Free Software B License. For details, see 85 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsBuffer.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2005 9 | Sams Publishing 10 | 11 | 12 | 2010-2014 13 | Khronos Group 14 | 15 | 16 | 17 | glIsBuffer 18 | 3G 19 | 20 | 21 | glIsBuffer 22 | determine if a name corresponds to a buffer object 23 | 24 | C Specification 25 | 26 | 27 | GLboolean glIsBuffer 28 | GLuint buffer 29 | 30 | 31 | 32 | Parameters 33 | 34 | 35 | buffer 36 | 37 | 38 | Specifies a value that may be the name of a buffer object. 39 | 40 | 41 | 42 | 43 | 44 | Description 45 | 46 | glIsBuffer returns GL_TRUE if buffer is currently the name of a buffer object. 47 | If buffer is zero, or is a non-zero value that is not currently the 48 | name of a buffer object, or if an error occurs, glIsBuffer returns GL_FALSE. 49 | 50 | 51 | A name returned by glGenBuffers, but not yet associated with a buffer object 52 | by calling glBindBuffer, is not the name of a buffer object. 53 | 54 | 55 | Version Support 56 | 57 | 58 | 59 | 60 | 61 | glIsBuffer 62 | 63 | 64 | 65 | 66 | 67 | 68 | See Also 69 | 70 | glBindBuffer, 71 | glDeleteBuffers, 72 | glGenBuffers, 73 | glGet 74 | 75 | 76 | Copyright 77 | 78 | Copyright 2005 Addison-Wesley. 79 | Copyright 2010-2014 Khronos Group. 80 | This material may be distributed subject to the terms and conditions set forth in 81 | the Open Publication License, v 1.0, 8 June 1999. 82 | http://opencontent.org/openpub/. 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glIsProgramPipeline.xml: -------------------------------------------------------------------------------- 1 | %mathent; ]> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 2010-2014 9 | Khronos Group 10 | 11 | 12 | 13 | glIsProgramPipeline 14 | 3G 15 | 16 | 17 | glIsProgramPipeline 18 | determine if a name corresponds to a program pipeline object 19 | 20 | C Specification 21 | 22 | 23 | GLboolean glIsProgramPipeline 24 | GLuint pipeline 25 | 26 | 27 | 28 | Parameters 29 | 30 | 31 | pipeline 32 | 33 | 34 | Specifies a value that may be the name of a program pipeline object. 35 | 36 | 37 | 38 | 39 | 40 | Description 41 | 42 | glIsProgramPipeline returns GL_TRUE if 43 | pipeline is currently the name of a program pipeline object. 44 | If pipeline is zero, or if pipeline is not the 45 | name of a program pipeline object, or if an error occurs, glIsProgramPipeline 46 | returns GL_FALSE. If pipeline is a name returned by 47 | glGenProgramPipelines, but that 48 | has not yet been bound through a call to glBindProgramPipeline, 49 | then the name is not a program pipeline object and glIsProgramPipeline 50 | returns GL_FALSE. 51 | 52 | 53 | Version Support 54 | 55 | 56 | 57 | 58 | 59 | glIsProgramPipeline 60 | 61 | 62 | 63 | 64 | 65 | 66 | See Also 67 | 68 | glGenProgramPipelines, 69 | glBindProgramPipeline, 70 | glDeleteProgramPipelines 71 | 72 | 73 | Copyright 74 | 75 | Copyright 2010-2014 Khronos Group. 76 | This material may be distributed subject to the terms and conditions set forth in 77 | the Open Publication License, v 1.0, 8 June 1999. 78 | http://opencontent.org/openpub/. 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /pkg/opengl/glow/xml/doc/glXGetSelectedEvent.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 1991-2006 9 | Silicon Graphics, Inc. 10 | 11 | 12 | glXGetSelectedEvent 13 | 3G 14 | 15 | 16 | glXGetSelectedEvent 17 | returns GLX events that are selected for a window or a GLX pixel buffer 18 | 19 | C Specification 20 | 21 | 22 | void glXGetSelectedEvent 23 | Display * dpy 24 | GLXDrawable draw 25 | unsigned long * event_mask 26 | 27 | 28 | 29 | Parameters 30 | 31 | 32 | dpy 33 | 34 | 35 | Specifies the connection to the X server. 36 | 37 | 38 | 39 | 40 | draw 41 | 42 | 43 | Specifies a GLX drawable. Must be a GLX pixel buffer or a window. 44 | 45 | 46 | 47 | 48 | event_mask 49 | 50 | 51 | Returns the events that are selected for draw. 52 | 53 | 54 | 55 | 56 | 57 | Description 58 | 59 | glXGetSelectedEvent returns in event_mask the events selected for draw. 60 | 61 | 62 | Notes 63 | 64 | glXGetSelectedEvent is available only if the GLX version is 1.3 or greater. 65 | 66 | 67 | If the GLX version is 1.1 or 1.0, the GL version must be 1.0. 68 | If the GLX version is 1.2, then the GL version must be 1.1. 69 | If the GLX version is 1.3, then the GL version must be 1.2. 70 | 71 | 72 | Errors 73 | 74 | GLXBadDrawable is generated if draw is not a valid window 75 | or a valid GLX pixel buffer. 76 | 77 | 78 | See Also 79 | 80 | glXSelectEvent, 81 | glXCreatePbuffer 82 | 83 | 84 | Copyright 85 | 86 | Copyright 1991-2006 87 | Silicon Graphics, Inc. This document is licensed under the SGI 88 | Free Software B License. For details, see 89 | https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt. 90 | 91 | 92 | 93 | --------------------------------------------------------------------------------