├── .github
└── FUNDING.yml
├── .gitignore
├── .gitmodules
├── .vscode
└── c_cpp_properties.json
├── DamagedHelmet_gltf.jpg
├── LICENSE
├── README.md
├── include
└── gk
│ ├── accessor.h
│ ├── animation-keyframe.h
│ ├── animation.h
│ ├── bbox.h
│ ├── buffer.h
│ ├── camera.h
│ ├── clear.h
│ ├── color.h
│ ├── common.h
│ ├── context.h
│ ├── controller.h
│ ├── coord.h
│ ├── geom-types.h
│ ├── geom.h
│ ├── gk.h
│ ├── gpu_state.h
│ ├── image.h
│ ├── light.h
│ ├── material.h
│ ├── mouse.h
│ ├── node.h
│ ├── opt.h
│ ├── pass.h
│ ├── plane.h
│ ├── platform.h
│ ├── prims
│ ├── builtin-prim.h
│ ├── cube.h
│ └── prims.h
│ ├── program.h
│ ├── render.h
│ ├── renderpath.h
│ ├── scene.h
│ ├── shader.h
│ ├── shadows.h
│ ├── texture.h
│ ├── time.h
│ ├── trackball.h
│ ├── transform.h
│ ├── transparent.h
│ ├── type.h
│ ├── uniform.h
│ ├── value.h
│ └── vertex.h
└── src
├── accessor.c
├── anim
├── animatable.c
├── animatable.h
├── basic
│ ├── basic.c
│ └── transform.c
└── keyframe
│ ├── interp.c
│ ├── kf.c
│ ├── kf.h
│ └── tangent.c
├── backend
└── gl
│ ├── buff.c
│ └── buff.h
├── bbox.c
├── bbox
├── scene_bbox.c
└── scene_bbox.h
├── camera.c
├── clear
└── gradient.c
├── common.h
├── coord
└── coord_orig.c
├── culling
├── frustum_culler.c
└── frustum_culler.h
├── default
├── def_effect.c
├── def_effect.h
├── def_light.c
├── def_light.h
├── def_prog.c
├── def_prog.h
├── opt.c
├── shader
│ ├── def_shader.c
│ ├── def_shader.h
│ ├── gk_cube.frag
│ ├── gk_cube.vert
│ ├── gk_default.frag
│ ├── gk_default.vert
│ ├── gk_drawbone.fs
│ └── gk_drawbone.vs
├── transform.c
└── transform.h
├── error
├── err.c
├── err.h
└── gpu
│ ├── err.c
│ └── err.h
├── fs_utils.c
├── fs_utils.h
├── gk.c
├── image.c
├── lib.c
├── light.c
├── light
├── transform.c
└── uniform_single.c
├── material
├── colortex_uniform.c
├── colortex_uniform.h
├── material.c
└── material_uniform.c
├── model.c
├── model.h
├── morph
└── load.c
├── node.c
├── pass
├── clear.c
├── output
│ └── output.c
├── pass.c
└── target
│ ├── depth.c
│ └── target.c
├── platform
└── ak_platform_info.c
├── prim
└── prim.c
├── prims
├── builtin_prims.c
├── cube.c
├── prims.c
└── quad.c
├── program
├── program.c
├── program.h
├── uniform.c
├── uniform.h
├── uniform_cache.c
├── uniform_cache.h
├── vertex_input.c
└── vertex_input.h
├── rect.c
├── render
├── queue
│ └── queue.c
└── realtime
│ ├── animator.c
│ ├── animator.h
│ ├── builtin
│ ├── builtin.c
│ └── builtin.h
│ ├── light.c
│ ├── light.h
│ ├── material.c
│ ├── material.h
│ ├── model.c
│ ├── node.c
│ ├── pass.c
│ ├── pass.h
│ ├── prim.c
│ ├── prim.h
│ ├── scene.c
│ ├── texture.c
│ ├── texture.h
│ ├── transp.c
│ └── transp.h
├── scene
└── scene.c
├── shader.c
├── shader
├── builtin_shader.c
├── builtin_shader.h
├── cmn_material.c
├── cmn_material.h
├── glsl
│ ├── frag
│ │ ├── blinn.glsl
│ │ ├── clr_grad_circ.glsl
│ │ ├── common.glsl
│ │ ├── constant.glsl
│ │ ├── constants.glsl
│ │ ├── depth.glsl
│ │ ├── lambert.glsl
│ │ ├── lights.glsl
│ │ ├── normal.glsl
│ │ ├── pbr_common.glsl
│ │ ├── pbr_metalrough.glsl
│ │ ├── pbr_specgloss.glsl
│ │ ├── phong.glsl
│ │ ├── rtt.glsl
│ │ ├── shadowmap.glsl
│ │ ├── shadows.glsl
│ │ ├── transp.glsl
│ │ └── wboit_compos.glsl
│ ├── lib
│ │ └── funcs
│ │ │ ├── colorspace.glsl
│ │ │ ├── lerp.glsl
│ │ │ └── max.glsl
│ └── vert
│ │ ├── common.glsl
│ │ ├── plain.glsl
│ │ ├── rtt.glsl
│ │ ├── shadowmap.glsl
│ │ └── target.glsl
├── shader.c
└── shader.h
├── shadows
├── builtin
│ ├── basic.c
│ ├── basic.h
│ ├── csm.c
│ └── csm.h
├── render.c
├── render.h
├── shad_common.h
├── shadows.c
├── shadows.h
└── visualize.c
├── skin
├── draw.c
├── draw.h
└── load.c
├── state
├── aux
│ └── bind_prim.c
├── gpu.h
└── gpu
│ ├── apply.c
│ ├── apply.h
│ ├── common.c
│ ├── common.h
│ ├── default.c
│ ├── default.h
│ ├── stack.c
│ └── states
│ ├── blend.c
│ ├── common.h
│ ├── depth.c
│ ├── face.c
│ ├── fbuff.c
│ └── texture.c
├── tball
├── mouse.c
├── mouse.h
├── tball.c
└── tball.h
├── texture.c
├── transform.c
├── transp
├── builtin
│ └── oit
│ │ ├── weighted_blended.c
│ │ └── weighted_blended.h
├── transp.c
├── transp.h
└── transp_common.h
├── types
├── impl_camera.h
├── impl_node.h
├── impl_scene.h
└── impl_transform.h
├── value
├── value.c
└── value_util.c
├── vertex.c
└── vertex.h
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [recp]
4 | patreon: recp
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.xcodeproj
2 | *.xcworkspace
3 | *.sln
4 | *.vcxproj
5 | *.vcxproj.*
6 | *.suo
7 | *.sdf
8 | *.opensdf
9 | ipch/
10 | Debug/
11 | Release/
12 | .DS_Store
13 | .vs
14 | *.nupkg
15 | *.opendb
16 | packages.config
17 | /aclocal.m4
18 | /ar-lib
19 | /autom4te.cache/
20 | /compile
21 | /config.guess
22 | /config.log
23 | /config.status
24 | /config.sub
25 | /configure
26 | /depcomp
27 | /install-sh
28 | /ltmain.sh
29 | /missing
30 | /libtool
31 | /.libs/
32 | .deps/
33 | *.[oa]
34 | *.l[oa]
35 | Makefile
36 | Makefile.in
37 | m4/*.m4
38 | .buildstamp
39 | .dirstamp
40 | packages/
41 | .anjuta/*
42 | *.anjuta*
43 | config.h.*
44 | config.h
45 | stamp*
46 | COPYING
47 | .idea/*
48 | *.VC.db
49 | cscope.files
50 | cscope.in.out
51 | cscope.out
52 | cscope.po.out
53 | build/
54 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "deps/cglm"]
2 | path = deps/cglm
3 | url = https://github.com/recp/cglm.git
4 | [submodule "deps/ds"]
5 | path = deps/ds
6 | url = https://github.com/recp/ds.git
7 | [submodule "deps/tm"]
8 | path = deps/tm
9 | url = https://github.com/recp/tm.git
10 | [submodule "deps/gpu"]
11 | path = deps/gpu
12 | url = https://github.com/recp/gpu.git
13 | [submodule "deps/im"]
14 | path = deps/im
15 | url = https://github.com/recp/im.git
16 |
--------------------------------------------------------------------------------
/.vscode/c_cpp_properties.json:
--------------------------------------------------------------------------------
1 | {
2 | "configurations": [
3 | {
4 | "name": "Mac",
5 | "includePath": [
6 | "${workspaceFolder}/**"
7 | ],
8 | "defines": [],
9 | "macFrameworkPath": [
10 | "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks"
11 | ],
12 | "compilerPath": "/usr/bin/clang",
13 | "cStandard": "c11",
14 | "cppStandard": "c++17",
15 | "intelliSenseMode": "clang-x64"
16 | }
17 | ],
18 | "version": 4
19 | }
--------------------------------------------------------------------------------
/DamagedHelmet_gltf.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/recp/gkern/9ca47fe38b4875fc225e054219745d9027fcfc66/DamagedHelmet_gltf.jpg
--------------------------------------------------------------------------------
/include/gk/accessor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_accessor_h
20 | #define gk_accessor_h
21 |
22 | #include "common.h"
23 |
24 | typedef struct GkGPUAccessor {
25 | struct GkGPUBuffer *buffer;
26 |
27 | void *min;
28 | void *max;
29 |
30 | uint32_t itemCount;
31 | uint32_t itemSize;
32 | GkType itemType;
33 |
34 | size_t filledSize;
35 | size_t byteOffset;
36 | size_t byteStride;
37 | uint32_t count;
38 |
39 | uint32_t gpuTarget;
40 | bool normalized;
41 | } GkGPUAccessor;
42 |
43 | GK_EXPORT
44 | bool
45 | gkAccessorIsInteger(GkGPUAccessor * __restrict acc);
46 |
47 | #endif /* gk_accessor_h */
48 |
--------------------------------------------------------------------------------
/include/gk/bbox.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_bbox_h
20 | #define gk_bbox_h
21 |
22 | #include "common.h"
23 | #include
24 |
25 | struct GkTransform;
26 |
27 | typedef vec3 GkBBox[2];
28 |
29 | void
30 | gkTransformAABB(struct GkTransform * __restrict trans,
31 | GkBBox bbox[2]);
32 |
33 | #endif /* gk_bbox_h */
34 |
--------------------------------------------------------------------------------
/include/gk/buffer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef buffer_h
20 | #define buffer_h
21 |
22 | #include "common.h"
23 | #include "type.h"
24 |
25 | typedef enum GkEnumType {
26 | GK_NONE = 0,
27 | GK_ARRAY = 1,
28 | GK_INDEX = 2,
29 | GK_UNIFORM = 3,
30 |
31 | GK_STATIC_DRAW = 4,
32 | GK_STATIC_READ = 5,
33 | GK_DYNAMIC_DRAW = 6,
34 | GK_DYNAMIC_READ = 7
35 | } GkEnumType;
36 |
37 | typedef struct GkGPUBuffer {
38 | struct GkGPUBuffer *prev;
39 | struct GkGPUBuffer *next;
40 | GLuint vbo;
41 | GLsizei size;
42 | GLenum usage;
43 | GLenum target;
44 | } GkGpuBuffer;
45 |
46 | typedef struct GkBuffer {
47 | void *data;
48 | size_t len;
49 | size_t count;
50 | size_t stride;
51 | } GkBuffer;
52 |
53 | GK_EXPORT
54 | GkGpuBuffer*
55 | gkGpuBufferNew(struct GkContext * __restrict ctx,
56 | GkEnumType type,
57 | size_t size);
58 |
59 | GK_EXPORT
60 | void
61 | gkGpuBufferFeed(GkGpuBuffer * __restrict gbuff,
62 | GkEnumType usage,
63 | const void * __restrict data);
64 |
65 | #endif /* buffer_h */
66 |
--------------------------------------------------------------------------------
/include/gk/clear.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_clear_h
20 | #define gk_clear_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 |
27 | struct GkScene;
28 |
29 | typedef enum GkClearEffect {
30 | GK_CLEAR_EFFECT_NONE = 0,
31 | GK_CLEAR_EFFECT_GRADIENT = 1
32 | } GkClearEffect;
33 |
34 | GK_EXPORT
35 | void
36 | gkClearEffect(GkScene *scene, GkPipeline *pip);
37 |
38 | GK_EXPORT
39 | void
40 | gkSetClearEffect(GkScene *scene, GkClearEffect effect);
41 |
42 | #ifdef __cplusplus
43 | }
44 | #endif
45 | #endif /* gk_clear_h */
46 |
--------------------------------------------------------------------------------
/include/gk/color.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_color_h
20 | #define gk_color_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include
26 |
27 | typedef struct GkColorRGBA {
28 | float R;
29 | float G;
30 | float B;
31 | float A;
32 | } GkColorRGBA;
33 |
34 | typedef union GkColor {
35 | GkColorRGBA rgba;
36 | vec4 vec;
37 | } GkColor;
38 |
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 | #endif /* gk_color_h */
43 |
--------------------------------------------------------------------------------
/include/gk/context.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef context_h
20 | #define context_h
21 |
22 | #include "common.h"
23 |
24 | struct RBTree;
25 | struct GkPipeline;
26 | struct FList;
27 | struct GkGPUStates;
28 | struct FList;
29 |
30 | typedef struct GkContext {
31 | struct FList *states; /* GPU state caches */
32 | struct RBTree *mdltree;
33 | struct GkGPUStates *currState;
34 | struct FList *samplers; /* private */
35 | uint32_t availTexUnit;
36 | } GkContext;
37 |
38 | GK_EXPORT
39 | GkContext*
40 | gkAllocContext(void);
41 |
42 | void
43 | gkContextFree(GkContext *ctx);
44 |
45 | #endif /* context_h */
46 |
--------------------------------------------------------------------------------
/include/gk/coord.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_coord_h
20 | #define gk_coord_h
21 |
22 | #include "common.h"
23 | #include
24 |
25 | void
26 | gk_moveOrigin(vec3 position,
27 | vec3 orig,
28 | vec3 out);
29 |
30 | #endif /* gk_coord_h */
31 |
--------------------------------------------------------------------------------
/include/gk/geom-types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_geom_types_h
20 | #define gk_geom_types_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 |
27 | typedef struct GkPoint {
28 | float x;
29 | float y;
30 | } GkPoint;
31 |
32 | typedef struct GkSize {
33 | float w;
34 | float h;
35 | } GkSize;
36 |
37 | typedef struct GkRect {
38 | GkPoint origin;
39 | GkSize size;
40 | } GkRect;
41 |
42 | #ifdef __OBJC__
43 | CG_INLINE
44 | GkPoint
45 | gkPointCGPoint(CGPoint point) {
46 | GkPoint p; p.x = point.x; p.y = point.y; return p;
47 | }
48 |
49 | CG_INLINE
50 | GkSize
51 | gkSizeCGSize(CGSize size) {
52 | GkSize s; s.w = size.width; s.h = size.height; return s;
53 | }
54 |
55 | CG_INLINE
56 | GkRect
57 | gkRectCGRect(CGRect rect) {
58 | GkRect r;
59 | r.origin.x = rect.origin.x;
60 | r.origin.y = rect.origin.y;
61 | r.size.w = rect.size.width;
62 | r.size.h = rect.size.height;
63 | return r;
64 | }
65 |
66 | CG_INLINE
67 | void
68 | gkViewportCGRect(CGRect rect, vec4 viewport) {
69 | viewport[0] = rect.origin.x;
70 | viewport[1] = rect.origin.y;
71 | viewport[2] = rect.size.width;
72 | viewport[3] = rect.size.height;
73 | }
74 |
75 | #endif
76 |
77 | GkPoint
78 | gk_rect_center(GkRect rect);
79 |
80 | #ifdef __cplusplus
81 | }
82 | #endif
83 | #endif /* gk_geom_types_h */
84 |
--------------------------------------------------------------------------------
/include/gk/gk.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_h
20 | #define gk_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 | #include "context.h"
27 | #include "shader.h"
28 | #include "program.h"
29 | #include "light.h"
30 | #include "material.h"
31 | #include "bbox.h"
32 | #include "geom-types.h"
33 | #include "image.h"
34 | #include "geom.h"
35 | #include "node.h"
36 | #include "transform.h"
37 | #include "camera.h"
38 | #include "scene.h"
39 | #include "render.h"
40 |
41 | #include
42 |
43 | #include
44 | #include
45 |
46 | #define GK_DRAW_ELEMENTS (1 << 0)
47 | #define GK_DRAW_ARRAYS (1 << 1)
48 | #define GK_COMPLEX (1 << 2)
49 |
50 | void
51 | gkReshape(GkScene *scene, GkRect rect);
52 |
53 | GK_EXPORT
54 | void
55 | gkGetDepthForPoint(vec3 point);
56 |
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 | #endif /* gk_h */
61 |
--------------------------------------------------------------------------------
/include/gk/image.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /* more or less red books's image structure is used here */
20 |
21 | #ifndef gk_image_h
22 | #define gk_image_h
23 |
24 | #include "common.h"
25 |
26 | typedef struct GkImageMip {
27 | struct GkImageMip *next;
28 | GLvoid *data;
29 | GLsizei width;
30 | GLsizei height;
31 | GLsizei depth;
32 | GLsizeiptr mipStride;
33 | GLuint level;
34 | } GkImageMip;
35 |
36 | typedef struct GkImage {
37 | GkImageMip mips;
38 | GLenum format; /* RGB, RGBA... */
39 | GLenum type; /* GL_UNSIGNED_BYTE, GL_FLOAT...*/
40 | GLsizei mipLevels;
41 | GLsizei slices;
42 | GLsizeiptr sliceStride;
43 | size_t totalsize;
44 | } GkImage;
45 |
46 | #endif /* gk_image_h */
47 |
--------------------------------------------------------------------------------
/include/gk/mouse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_mouse_h
20 | #define gk_mouse_h
21 |
22 | #include "common.h"
23 | #include "geom-types.h"
24 |
25 | typedef enum GkMouseState {
26 | GK_MOUSE_DOWN = 1,
27 | GK_MOUSE_UP = 2,
28 | GK_MOUSE_MOVE = 3
29 | } GkMouseState;
30 |
31 | typedef enum GkMouseButton {
32 | GK_MOUSE_LEFT = 1,
33 | GK_MOUSE_RIGHT = 2,
34 | GK_MOUSE_MIDDLE = 3
35 | } GkMouseButton;
36 |
37 | typedef struct GkMouseEventStruct {
38 | void *sender;
39 | GkScene *scene;
40 | GkMouseButton button;
41 | GkMouseState state;
42 | GkPoint point;
43 | } GkMouseEventStruct;
44 |
45 | typedef void (*GkMouseEvent)(void *sender,
46 | GkScene *scene,
47 | GkMouseButton button,
48 | GkMouseState state,
49 | GkPoint point);
50 |
51 | typedef void (*GkMouseEventWithStruct)(GkMouseEventStruct *event);
52 |
53 | #endif /* gk_mouse_h */
54 |
--------------------------------------------------------------------------------
/include/gk/node.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_node_h
20 | #define gk_node_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 | #include "light.h"
27 | #include "bbox.h"
28 | #include "geom.h"
29 | #include "camera.h"
30 | #include "transform.h"
31 | #include "controller.h"
32 |
33 | #include
34 | #include
35 |
36 | struct GkScene;
37 | struct GkAnimatable;
38 | struct GkControllerInst;
39 |
40 | typedef enum GkNodeFlags {
41 | GK_NODEF_NONE = 0,
42 | GK_NODEF_NODE = 1,
43 | GK_NODEF_HAVE_TRANSFORM = 2,
44 | GK_NODEF_JOINT = 3
45 | } GkNodeFlags;
46 |
47 | typedef struct GkNode {
48 | struct GkNode *parent;
49 | struct GkNode *next;
50 | struct GkNode *chld;
51 |
52 | struct GkAnimatable *anim;
53 | GkTransform *trans;
54 |
55 | GkGeometryInst *geom;
56 | GkLight *light;
57 | GkCamera *camera;
58 | GkControllerInst *controller;
59 | GkInstanceMorph *morpher;
60 |
61 | GkNodeFlags flags;
62 | } GkNode;
63 |
64 | GkNode*
65 | gkAllocNode(struct GkScene * __restrict scene);
66 |
67 | void
68 | gkMakeNodeTransform(struct GkScene * __restrict scene,
69 | GkNode * __restrict node);
70 |
71 | GK_EXPORT
72 | void
73 | gkApplyTransform(struct GkScene * __restrict scene,
74 | GkNode * __restrict node);
75 |
76 | GK_EXPORT
77 | void
78 | gkApplyView(struct GkScene * __restrict scene,
79 | GkNode * __restrict node);
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 | #endif /* gk_node_h */
85 |
--------------------------------------------------------------------------------
/include/gk/opt.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_options_h
20 | #define gk_options_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 |
27 | typedef enum GkOption {
28 | GK_OPT_LIGHT_DIR = 0, /* 0, 0, -1 */
29 | GK_OPT_LIGHT_UP = 1 /* 0, 1, 0 */
30 | } GkOption;
31 |
32 | GK_EXPORT
33 | void
34 | gk_opt_set(GkOption option, uintptr_t value);
35 |
36 | GK_EXPORT
37 | uintptr_t
38 | gk_opt(GkOption option);
39 |
40 | #ifdef __cplusplus
41 | }
42 | #endif
43 | #endif /* gk_options_h */
44 |
45 |
--------------------------------------------------------------------------------
/include/gk/plane.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef plane_h
20 | #define plane_h
21 |
22 | #include
23 |
24 | typedef enum GkPlaneIndex {
25 | GK_PLANE_LEFT = 0,
26 | GK_PLANE_RIGHT = 1,
27 | GK_PLANE_BOTTOM = 2,
28 | GK_PLANE_TOP = 3,
29 | GK_PLANE_NEAR = 4,
30 | GK_PLANE_FAR = 5
31 | } GkPlaneIndex;
32 |
33 | typedef vec4 GkPlane;
34 |
35 | #endif /* plane_h */
36 |
--------------------------------------------------------------------------------
/include/gk/platform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_platform_h
20 | #define gk_platform_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include
26 |
27 | /* this caches common queries */
28 | typedef enum GkPlatformInfo {
29 | GK_PLI_MAX_TEX_UNITS = 0
30 | } GkPlatformInfo;
31 |
32 | GLint
33 | gkPlatfomInfo(GkPlatformInfo pi);
34 |
35 | void
36 | gkSetGLContext(void *glcontext);
37 |
38 | #ifdef __cplusplus
39 | }
40 | #endif
41 | #endif /* gk_platform_h */
42 |
--------------------------------------------------------------------------------
/include/gk/prims/builtin-prim.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef builtin_prim_h
20 | #define builtin_prim_h
21 |
22 | #include "../common.h"
23 |
24 | struct GkScene;
25 | struct GkPrimitive;
26 |
27 | typedef enum GkPrimType {
28 | GK_PRIM_CUBE = 1,
29 | GK_PRIM_TEXQUAD = 2
30 | } GkPrimType;
31 |
32 | GK_EXPORT
33 | struct GkPrimitive*
34 | gkGetBuiltinPrim(GkPrimType primType);
35 |
36 | GK_EXPORT
37 | struct GkPrimitive*
38 | gkPrimGetTexQuad(void);
39 |
40 | GK_EXPORT
41 | struct GkPrimitive*
42 | gkGetBuiltinPrim(GkPrimType primType);
43 |
44 | GK_EXPORT
45 | void
46 | gkRenderBuiltinPrim(struct GkScene *scene,
47 | GkPrimType primType);
48 |
49 | #endif /* builtin_prim_h */
50 |
--------------------------------------------------------------------------------
/include/gk/prims/cube.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_cube_h
20 | #define gk_cube_h
21 |
22 | #include "../common.h"
23 | #include "../geom.h"
24 |
25 | struct GkScene;
26 |
27 | void
28 | gkDrawBBox(struct GkScene * __restrict scene,
29 | GkBBox bbox,
30 | mat4 world);
31 |
32 | void
33 | gkInitCube(void);
34 |
35 | void
36 | gkReleaseCube(void);
37 |
38 | #endif /* gk_cube_h */
39 |
--------------------------------------------------------------------------------
/include/gk/prims/prims.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_prims_h
20 | #define gk_prims_h
21 |
22 | #include "../common.h"
23 | #include "cube.h"
24 |
25 | void
26 | gkReleasePrims(void);
27 |
28 | #endif /* gk_prims_h */
29 |
--------------------------------------------------------------------------------
/include/gk/render.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_render_h
20 | #define gk_render_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 |
27 | struct GkLight;
28 |
29 | void
30 | gkPrepMaterial(GkScene *scene,
31 | GkGeometryInst *modelInst);
32 |
33 | void
34 | gkPrepModel(GkScene *scene,
35 | GkGeometryInst *modelInst,
36 | GkTransform *ptr);
37 |
38 | void
39 | gkRenderModel(GkScene *scene,
40 | GkGeometryInst *modelInst);
41 |
42 | void
43 | gkRnModelNoMatOPass(GkScene *scene,
44 | GkGeometryInst *modelInst);
45 |
46 | void
47 | gkPrepNode(GkScene *scene,
48 | GkNode *node,
49 | GkTransform *ptr);
50 |
51 | void
52 | gkRenderNode(GkScene *scene,
53 | GkNode *node,
54 | GkTransform *ptr);
55 |
56 | void
57 | gkRenderScene(GkScene * scene);
58 |
59 | GK_EXPORT
60 | void
61 | gkRenderShadows(GkScene * __restrict scene,
62 | struct GkLight * __restrict light);
63 |
64 | GK_EXPORT
65 | void
66 | gkScenePerLightRenderPath(GkScene * __restrict scene);
67 |
68 | GK_EXPORT
69 | void
70 | gkModelPerLightRenderPath(GkScene * __restrict scene);
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 | #endif /* gk_render_h */
76 |
--------------------------------------------------------------------------------
/include/gk/renderpath.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef render_path_h
20 | #define render_path_h
21 |
22 | #include "common.h"
23 |
24 | struct GkScene;
25 |
26 | typedef void (*GkRenderPathFn) (struct GkScene * __restrict scene);
27 |
28 | typedef enum GkRenderPathType {
29 | GK_RNPATH_MODEL_PERLIGHT = 1,
30 | GK_RNPATH_SCENE_PERLIGHT = 2 /* for shadowmaps */
31 | } GkRenderPathType;
32 |
33 | GK_EXPORT
34 | void
35 | gkSetRenderPath(struct GkScene * __restrict scene,
36 | GkRenderPathType rpath);
37 |
38 | #endif /* render_path_h */
39 |
--------------------------------------------------------------------------------
/include/gk/shader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_shader_h
20 | #define gk_shader_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 | #include
27 | #include
28 | #include
29 |
30 | typedef struct GkShader {
31 | struct GkShader *next;
32 | GLuint shaderId;
33 | GLuint shaderType;
34 | GLboolean isValid;
35 | } GkShader;
36 |
37 | GLuint
38 | gkShaderLoadFromFile(GLenum shaderType,
39 | const char * __restrict path);
40 |
41 | int
42 | gkShaderLoadFromFolder(const char * __restrict path,
43 | GkShader ** __restrict dest);
44 |
45 | GLuint
46 | gkShaderLoad(GLenum shaderType,
47 | const char * __restrict source);
48 |
49 | GLuint
50 | gkShaderLoadN(GLenum shaderType,
51 | char *source[],
52 | size_t count);
53 |
54 | void
55 | gkAttachShaders(GLuint program,
56 | GkShader * __restrict shaders);
57 |
58 | void
59 | gkShaderLogInfo(GLuint shaderId,
60 | FILE * __restrict file);
61 |
62 | void
63 | gkUniformMat4(GLint location, mat4 matrix);
64 |
65 | GkShader*
66 | gkShaderByName(const char *name);
67 |
68 | void
69 | gkShaderSetName(GkShader *shader, const char *name);
70 |
71 | #ifdef __cplusplus
72 | }
73 | #endif
74 | #endif /* gk_shader_h */
75 |
--------------------------------------------------------------------------------
/include/gk/shadows.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef shadows_h
20 | #define shadows_h
21 |
22 | #include "common.h"
23 |
24 | struct GkScene;
25 | struct GkOutput;
26 |
27 | /* Shadow technique type */
28 |
29 | typedef enum GkShadowTechnType {
30 | GK_SHADOW_AUTO = 0,
31 | GK_SHADOW_DISABLED = 1,
32 | GK_SHADOW_BASIC_SHADOWMAP = 1,
33 | GK_SHADOW_CSM = 2,
34 | GK_SHADOW_COLORED_STOCHASTIC = 3,
35 | GK_SHADOW_DEFAULT = GK_SHADOW_DISABLED
36 | } GkShadowTechnType;
37 |
38 | GK_EXPORT
39 | void
40 | gkSetShadowTechn(GkShadowTechnType techn);
41 |
42 | GK_EXPORT
43 | GkShadowTechnType
44 | gkShadowTechn(void);
45 |
46 | GK_EXPORT
47 | uint32_t
48 | gkShadowSplit(void);
49 |
50 | GK_EXPORT
51 | void
52 | gkSetShadowSplit(uint32_t splitCount);
53 |
54 | void
55 | gkRenderShadowMapTo(GkScene * __restrict scene,
56 | struct GkOutput * __restrict output);
57 |
58 | #endif /* transparency_h */
59 |
--------------------------------------------------------------------------------
/include/gk/time.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_timer_h
20 | #define gk_timer_h
21 |
22 | GK_EXPORT
23 | double
24 | gkGetTime(void);
25 |
26 | #endif /* gk_timer_h */
27 |
--------------------------------------------------------------------------------
/include/gk/trackball.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_trackball_h
20 | #define gk_trackball_h
21 |
22 | #include "common.h"
23 | #include "geom-types.h"
24 | #include "mouse.h"
25 |
26 | #include
27 | #include
28 |
29 | struct GkScene;
30 | struct GkTrackball;
31 | struct GkNode;
32 |
33 | typedef enum GkTrackballEventType {
34 | GK_TRACKBALL_EVENT_BEGIN = 0,
35 | GK_TRACKBALL_EVENT_END = 1
36 | } GkTrackballEventType;
37 |
38 | typedef void (*GkTrackballEventCb)(struct GkTrackball *tball,
39 | GkTrackballEventType event);
40 |
41 | typedef struct GkTrackball {
42 | void *data;
43 | struct GkScene *scene;
44 | struct GkNode *node;
45 | vec3 *bbox; /* attached node's bounding box */
46 | GkTransform *nodeTrans; /* attached node's transform */
47 | GkMouseEvent mouse;
48 | GkMouseEventWithStruct mouse2;
49 | GkTrackballEventCb cb;
50 | GkPoint start;
51 | vec3 from;
52 | float *center;
53 | mat4 trans;
54 | float velocity;
55 | bool enabled;
56 | bool moving;
57 | bool moved;
58 | } GkTrackball;
59 |
60 | GkTrackball*
61 | gkTrackballAlloc(void);
62 |
63 | void
64 | gkTrackballAttach(GkTrackball * __restrict tball,
65 | GkScene * __restrict scene,
66 | GkNode * __restrict node,
67 | vec3 pivot);
68 |
69 | void
70 | gkTrackballFree(GkTrackball *tball);
71 |
72 | #endif /* gk_trackball_h */
73 |
--------------------------------------------------------------------------------
/include/gk/transparent.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef transparency_h
20 | #define transparency_h
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | #include "common.h"
26 |
27 | struct GkScene;
28 |
29 | /* Transparent technique type */
30 |
31 | typedef enum GkTranspTechnType {
32 | GK_TRANSP_AUTO = 0,
33 | GK_TRANSP_DISABLED = 1,
34 | GK_TRANSP_ALPHA_BLENDED = 2, /* ordering is required */
35 | GK_TRANSP_WEIGHTED_BLENDED = 3,
36 | GK_TRANSP_PHENOMENOLOGICAL = 4,
37 |
38 | GK_TRANSP_DEFAULT = GK_TRANSP_WEIGHTED_BLENDED
39 | } GkTranspTechnType;
40 |
41 | GK_EXPORT
42 | void
43 | gkSetTranspTechn(GkTranspTechnType techn);
44 |
45 | GK_EXPORT
46 | GkTranspTechnType
47 | gkTranspTechn(void);
48 |
49 | GK_EXPORT
50 | void
51 | gkEnableTransp(GkScene * __restrict scene);
52 |
53 | GK_EXPORT
54 | void
55 | gkDisableTransp(GkScene * __restrict scene);
56 |
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 | #endif /* transparency_h */
61 |
--------------------------------------------------------------------------------
/include/gk/type.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef type_h
20 | #define type_h
21 |
22 | #include "common.h"
23 |
24 | typedef enum GkType {
25 | GKT_UNKNOWN = 0,
26 | GKT_INT32 = 1,
27 | GKT_UINT32 = 2,
28 | GKT_INT16 = 3,
29 | GKT_UINT16 = 4,
30 | GKT_INT8 = 5,
31 | GKT_UINT8 = 6,
32 | GKT_FLOAT = 7,
33 | GKT_DOUBLE = 8,
34 | GKT_FLOAT3 = 9,
35 | GKT_FLOAT4 = 10,
36 | GKT_FLOAT3x3 = 11,
37 | GKT_FLOAT4x4 = 12
38 | } GkType;
39 |
40 | #endif /* type_h */
41 |
--------------------------------------------------------------------------------
/include/gk/uniform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef uniform_h
20 | #define uniform_h
21 |
22 | #include "common.h"
23 |
24 | struct GkPipeline;
25 |
26 | GK_EXPORT
27 | void
28 | gkUniform1i(struct GkPipeline * __restrict prog,
29 | const char * __restrict name,
30 | GLint val);
31 |
32 | GK_EXPORT
33 | void
34 | gkUniform1ui(struct GkPipeline * __restrict prog,
35 | const char * __restrict name,
36 | GLuint val);
37 |
38 | GK_EXPORT
39 | void
40 | gkUniform1f(struct GkPipeline * __restrict prog,
41 | const char * __restrict name,
42 | float val);
43 |
44 | GK_EXPORT
45 | void
46 | gkUniform2f(struct GkPipeline * __restrict prog,
47 | const char * __restrict name,
48 | float val[2]);
49 |
50 | #endif /* uniform_h */
51 |
--------------------------------------------------------------------------------
/include/gk/vertex.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_vertex_h
20 | #define gk_vertex_h
21 |
22 | #include "common.h"
23 | #include "program.h"
24 | #include "type.h"
25 | #include "accessor.h"
26 |
27 | typedef struct GkVertexInput {
28 | struct GkVertexInput *next;
29 | const char *name;
30 | GkGPUAccessor *accessor;
31 | int32_t refc;
32 | } GkVertexInput;
33 |
34 | GK_EXPORT
35 | GkVertexInput*
36 | gkMakeVertexInput(const char *name, GkType type, int32_t len);
37 |
38 | GK_EXPORT
39 | int
40 | gkVertexInputCmp(void *key1, void *key2);
41 |
42 | GK_EXPORT
43 | int32_t
44 | gkAddVertexInput(GkPipeline *prog, GkVertexInput *input);
45 |
46 | GK_EXPORT
47 | void
48 | gkRemoveVertexInput(GkPipeline *prog, GkVertexInput *input);
49 |
50 | GK_EXPORT
51 | int32_t
52 | gkIndexOfVertexInput(GkPipeline *prog, GkVertexInput *input);
53 |
54 | GK_EXPORT
55 | const char*
56 | gkShortNameOfVertexInput(const char *name);
57 |
58 | GK_EXPORT
59 | const char*
60 | gkSetShortNameOfVertexInput(const char *name, const char *shortName);
61 |
62 | GK_EXPORT
63 | void
64 | gk_bindInputTo(GkPrimitive * __restrict prim,
65 | GkVertexInput * __restrict inp);
66 |
67 | GK_EXPORT
68 | void
69 | gk_attachInputTo(GkPrimInst * __restrict primInst,
70 | GkVertexAttachment * __restrict va,
71 | GkVertexInput * __restrict inp);
72 |
73 | #endif /* gk_vertex_h */
74 |
--------------------------------------------------------------------------------
/src/accessor.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "../include/gk/accessor.h"
21 |
22 | GK_EXPORT
23 | bool
24 | gkAccessorIsInteger(GkGPUAccessor * __restrict acc) {
25 | switch ((int)acc->itemType) {
26 | case GL_INT:
27 | case GL_UNSIGNED_INT:
28 | case GL_SHORT:
29 | case GL_UNSIGNED_SHORT:
30 | case GL_BYTE:
31 | case GL_UNSIGNED_BYTE: return true;
32 | default:
33 | return false;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/anim/animatable.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Recep Aslantas.
3 | * Full license can be found in the LICENSE file
4 | */
5 |
6 | #include "animatable.h"
7 |
8 | GkAnimatable*
9 | gkAnimatable(void *object) {
10 | GkAnimatable *anima;
11 | anima = malloc(sizeof(*anima));
12 | anima->animations = flist_new(NULL);
13 | return anima;
14 | }
15 |
16 | GK_EXPORT
17 | void
18 | gkAddAnimation(GkScene *scene,
19 | GkNode *node,
20 | GkAnimation *anim) {
21 | GkSceneImpl *sceneImpl;
22 |
23 | sceneImpl = (GkSceneImpl *)scene;
24 | anim->scene = scene;
25 |
26 | if (node) {
27 | anim->node = node;
28 | flist_insert(node->anim->animations, anim);
29 | }
30 |
31 | flist_sp_insert(&sceneImpl->anims, anim);
32 | }
33 |
--------------------------------------------------------------------------------
/src/anim/animatable.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Recep Aslantas.
3 | * Full license can be found in the LICENSE file
4 | */
5 |
6 | #ifndef animatable_h
7 | #define animatable_h
8 |
9 | #include "../common.h"
10 | #include "../../include/gk/gk.h"
11 | #include "../../include/gk/animation.h"
12 |
13 | typedef struct GkAnimatable {
14 | FList *animations;
15 | } GkAnimatable;
16 |
17 | GkAnimatable*
18 | gkAnimatable(void *object);
19 |
20 | GK_EXPORT
21 | void
22 | gkAddAnimation(GkScene *scene,
23 | GkNode *node,
24 | GkAnimation *anim);
25 |
26 | #endif /* animatable_h */
27 |
--------------------------------------------------------------------------------
/src/anim/basic/basic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "../../../include/gk/gk.h"
21 | #include "../../../include/gk/animation.h"
22 | #include
23 |
24 | GK_EXPORT
25 | GkAnimation*
26 | gkBasicAnimation(const char *path,
27 | GkValue *from,
28 | GkValue *to,
29 | double duration) {
30 | return NULL;
31 | }
32 |
--------------------------------------------------------------------------------
/src/anim/keyframe/kf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "../../../include/gk/animation.h"
21 |
22 | void
23 | gkRunKFAnim(GkKeyFrameAnimation *kfa, float ease);
24 |
25 | GK_EXPORT
26 | void
27 | gkChannelSetTargetTo(GkChannel * __restrict ch,
28 | GkFloatOrPointer * __restrict to);
29 |
30 | GK_EXPORT
31 | void
32 | gkPrepChannel(GkAnimation *anim, GkChannel *ch);
33 |
34 | GK_EXPORT
35 | void
36 | gkPrepChannelKey(GkKeyFrameAnimation *anim, GkChannel *ch);
37 |
--------------------------------------------------------------------------------
/src/backend/gl/buff.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "buff.h"
20 |
21 | static
22 | GLenum
23 | gk__gl_buffType(GkEnumType type);
24 |
25 | static
26 | GLenum
27 | gk__gl_usage(GkEnumType type);
28 |
29 | static
30 | GLenum
31 | gk__gl_buffType(GkEnumType type) {
32 | switch (type) {
33 | case GK_ARRAY: return GL_ARRAY_BUFFER;
34 | case GK_INDEX: return GL_ELEMENT_ARRAY_BUFFER;
35 | case GK_UNIFORM: return GL_UNIFORM_BUFFER;
36 | default: return 0;
37 | }
38 | }
39 |
40 | static
41 | GLenum
42 | gk__gl_usage(GkEnumType type) {
43 | switch (type) {
44 | case GK_STATIC_DRAW: return GL_STATIC_DRAW;
45 | case GK_STATIC_READ: return GL_STATIC_READ;
46 | case GK_DYNAMIC_DRAW: return GL_DYNAMIC_DRAW;
47 | case GK_DYNAMIC_READ: return GL_DYNAMIC_READ;
48 | default: return 0;
49 | }
50 | }
51 |
52 | GK_EXPORT
53 | GkGpuBuffer*
54 | gkGpuBufferNew(GkContext * __restrict ctx,
55 | GkEnumType type,
56 | size_t size) {
57 | GkGpuBuffer *gbuff;
58 |
59 | gbuff = calloc(1, sizeof(*gbuff));
60 | gbuff->size = (GLsizei)size;
61 | gbuff->usage = GL_STATIC_DRAW;
62 | gbuff->target = gk__gl_buffType(type);
63 |
64 | glGenBuffers(1, &gbuff->vbo);
65 |
66 | return gbuff;
67 | }
68 |
69 | GK_EXPORT
70 | void
71 | gkGpuBufferFeed(GkGpuBuffer * __restrict gbuff,
72 | GkEnumType usage,
73 | const void * __restrict data) {
74 | gbuff->usage = gk__gl_usage(usage);
75 |
76 | /* TODO: get from state manager */
77 | glBindBuffer(gbuff->target, gbuff->vbo);
78 | glBufferData(gbuff->target, gbuff->size, data, gbuff->usage);
79 | }
80 |
--------------------------------------------------------------------------------
/src/backend/gl/buff.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_backend_gl_buff_h
20 | #define src_backend_gl_buff_h
21 |
22 | #include "../../common.h"
23 | #include "../../../include/gk/buffer.h"
24 |
25 | #endif /* src_backend_gl_buff_h */
26 |
--------------------------------------------------------------------------------
/src/bbox.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "../include/gk/bbox.h"
21 | #include "../include/gk/scene.h"
22 |
23 | #include
24 |
25 | void
26 | gkTransformAABB(GkTransform * __restrict trans,
27 | GkBBox bbox[2]) {
28 | glm_aabb_transform(bbox[0], trans->world, bbox[1]);
29 | }
30 |
31 | GK_EXPORT
32 | bool
33 | gkSceneIs2D(GkScene *scene) {
34 | return glm_eq(scene->bbox[1][0] - scene->bbox[0][0], 0.0f)
35 | || glm_eq(scene->bbox[1][1] - scene->bbox[0][1], 0.0f)
36 | || glm_eq(scene->bbox[1][2] - scene->bbox[0][2], 0.0f);
37 | }
38 |
--------------------------------------------------------------------------------
/src/bbox/scene_bbox.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Recep Aslantas.
3 | * Full license can be found in the LICENSE file
4 | */
5 |
6 | #include "scene_bbox.h"
7 |
8 | GK_EXPORT
9 | void
10 | gkUpdateSceneAABB(GkScene * __restrict scene, GkBBox bbox) {
11 | glm_aabb_merge(scene->bbox, bbox, scene->bbox);
12 | }
13 |
--------------------------------------------------------------------------------
/src/bbox/scene_bbox.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Recep Aslantas.
3 | * Full license can be found in the LICENSE file
4 | */
5 |
6 | #ifndef src_scene_bbox_h
7 | #define src_scene_bbox_h
8 |
9 | #include "../common.h"
10 |
11 | GK_EXPORT
12 | void
13 | gkUpdateSceneAABB(GkScene * __restrict scene, GkBBox bbox);
14 |
15 | #endif /* src_scene_bbox_h */
16 |
--------------------------------------------------------------------------------
/src/clear/gradient.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../include/gk/gk.h"
20 | #include "../../include/gk/clear.h"
21 | #include "../../include/gk/pass.h"
22 | #include "../../include/gk/gpu_state.h"
23 | #include "../../include/gk/prims/builtin-prim.h"
24 | #include "../types/impl_scene.h"
25 | #include "../shader/builtin_shader.h"
26 |
27 | GK_EXPORT
28 | void
29 | gkClearEffect(GkScene *scene, GkPipeline *pip) {
30 | GkContext *ctx;
31 | vec2 size;
32 |
33 | ctx = gkContextOf(scene);
34 | size[0] = scene->viewport[2] * scene->backingScale;
35 | size[1] = scene->viewport[3] * scene->backingScale;
36 |
37 | gkPushState(ctx);
38 | gkUseProgram(ctx, pip);
39 | gkUniform2f(pip, "uSize", size);
40 | gkRenderBuiltinPrim(scene, GK_PRIM_TEXQUAD);
41 | gkPopState(ctx);
42 | }
43 |
44 | GK_EXPORT
45 | void
46 | gkSetClearEffect(GkScene *scene, GkClearEffect effect) {
47 | GkSceneImpl *sceneImpl;
48 |
49 | sceneImpl = (GkSceneImpl *)scene;
50 |
51 | sceneImpl->clearPipeline = gkBuiltinProg(GK_BUILTIN_PROG_CLR_GRAD_CIRC);
52 | }
53 |
--------------------------------------------------------------------------------
/src/common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_src_common_h
20 | #define gk_src_common_h
21 |
22 | #define GK_INTERN
23 |
24 | #ifdef _MSC_VER
25 | # define WIN32_LEAN_AND_MEAN
26 | # include
27 |
28 | # define strncasecmp _strnicmp
29 | # define strcasecmp _stricmp
30 | #endif
31 |
32 | #ifdef __GNUC__
33 | # define GK_DESTRUCTOR __attribute__((destructor))
34 | # define GK_CONSTRUCTOR __attribute__((constructor))
35 | #else
36 | # define GK_DESTRUCTOR
37 | # define GK_CONSTRUCTOR
38 | #endif
39 |
40 | #define GK__UNUSED(X) (void)X
41 |
42 | #include "types/impl_transform.h"
43 | #include "types/impl_scene.h"
44 | #include "error/gpu/err.h"
45 |
46 | #endif /* gk_src_common_h */
47 |
--------------------------------------------------------------------------------
/src/coord/coord_orig.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/gk.h"
21 | #include "../../include/gk/coord.h"
22 |
23 | void
24 | gk_moveOrigin(vec3 position,
25 | vec3 orig,
26 | vec3 out) {
27 | glm_vec3_sub(orig, position, out);
28 | }
29 |
--------------------------------------------------------------------------------
/src/culling/frustum_culler.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef frustum_culler_h
20 | #define frustum_culler_h
21 |
22 | #include "../../include/gk/gk.h"
23 |
24 | bool
25 | gkPrimIsInFrustum(GkScene * __restrict scene,
26 | GkCamera * __restrict cam,
27 | GkPrimitive * __restrict prim);
28 |
29 | #endif /* frustum_culler_h */
30 |
--------------------------------------------------------------------------------
/src/default/def_effect.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_def_effect_h
20 | #define gk_def_effect_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/material.h"
24 |
25 | GkMaterial*
26 | gk_def_material(void);
27 |
28 | GkTechnique*
29 | gk_def_material_phong(void);
30 |
31 | GkTechnique*
32 | gk_def_material_blinn(void);
33 |
34 | GkTechnique*
35 | gk_def_material_lambert(void);
36 |
37 | GkTechnique*
38 | gk_def_material_constant(void);
39 |
40 | GkMetalRough*
41 | gk_def_material_mtlrough(void);
42 |
43 | GkSpecGloss*
44 | gk_def_material_specgloss(void);
45 |
46 | #endif /* gk_def_effect_h */
47 |
--------------------------------------------------------------------------------
/src/default/def_light.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "def_light.h"
21 | #include "../../include/gk/material.h"
22 | #include
23 |
24 | GkDirectionalLight gkdef_light_directional = {
25 | .base = {
26 | .name = "directional",
27 | .ref = {NULL, NULL},
28 | .next = NULL,
29 | .node = NULL,
30 | .dir = {0.0f, 0.0f, -1.0f},
31 | .defdir = {0.0f, 0.0f, -1.0f},
32 | .type = GK_LIGHT_TYPE_DIRECTIONAL,
33 | .color = { 1.0, 1.0, 1.0, 1.0 },
34 | .index = -1,
35 | .isvalid = false,
36 | .flags = 0
37 | }
38 | };
39 |
40 | GkLight*
41 | gk_def_lights() {
42 | return &gkdef_light_directional.base;
43 | }
44 |
--------------------------------------------------------------------------------
/src/default/def_light.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef ak_def_light_h
20 | #define ak_def_light_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/light.h"
24 |
25 | GkLight*
26 | gk_def_lights(void);
27 |
28 | #endif /* ak_def_light_h */
29 |
--------------------------------------------------------------------------------
/src/default/def_prog.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_def_prog_h
20 | #define gk_def_prog_h
21 |
22 | #include "../../include/gk/gk.h"
23 |
24 | GkPipeline*
25 | gk_prog_cube(void);
26 |
27 | GkPipeline*
28 | gk_prog_drawbone(void);
29 |
30 | #endif /* gk_def_prog_h */
31 |
--------------------------------------------------------------------------------
/src/default/opt.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/opt.h"
21 |
22 | vec3 gk__light_dir = {0.0f, 0.0f, -1.0f};
23 | vec3 gk__light_up = {0.0f, 1.0f, 0.0f};
24 |
25 | uintptr_t GK_OPTIONS[] =
26 | {
27 | (uintptr_t)&gk__light_dir,
28 | (uintptr_t)&gk__light_up
29 | };
30 |
31 | GK_EXPORT
32 | void
33 | gk_opt_set(GkOption option, uintptr_t value) {
34 | GK_OPTIONS[option] = value;
35 | }
36 |
37 | GK_EXPORT
38 | uintptr_t
39 | gk_opt(GkOption option) {
40 | return GK_OPTIONS[option];
41 | }
42 |
--------------------------------------------------------------------------------
/src/default/shader/def_shader.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "def_shader.h"
21 |
22 | const char*
23 | gk_def_shader_vert(GK_DEF_SHADER shader) {
24 |
25 | switch (shader) {
26 | case GK_DEF_SHADER_CUBE:
27 | return
28 | #include "gk_cube.vert"
29 | ;
30 | break;
31 | case GK_DEF_SHADER_DRAWBONE:
32 | return
33 | #include "gk_drawbone.vs"
34 | ;
35 | break;
36 | default:
37 | return
38 | #include "gk_default.vert"
39 | ;
40 | }
41 | }
42 |
43 | const char*
44 | gk_def_shader_frag(GK_DEF_SHADER shader) {
45 | switch (shader) {
46 | case GK_DEF_SHADER_CUBE:
47 | return
48 | #include "gk_cube.frag"
49 | ;
50 | break;
51 | case GK_DEF_SHADER_DRAWBONE:
52 | return
53 | #include "gk_drawbone.fs"
54 | ;
55 | break;
56 | default:
57 | return
58 | #include "gk_default.frag"
59 | ;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/default/shader/def_shader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_def_shader_h
20 | #define gk_def_shader_h
21 |
22 | #include "../../../include/gk/gk.h"
23 |
24 | typedef enum GK_DEF_SHADER {
25 | GK_DEF_SHADER_DEFAULT = 0,
26 | GK_DEF_SHADER_CUBE = 1,
27 | GK_DEF_SHADER_DRAWBONE = 2
28 | } GK_DEF_SHADER;
29 |
30 | const char*
31 | gk_def_shader_vert(GK_DEF_SHADER shader);
32 |
33 | const char*
34 | gk_def_shader_frag(GK_DEF_SHADER shader);
35 |
36 | #endif /* gk_def_shader_h */
37 |
--------------------------------------------------------------------------------
/src/default/shader/gk_cube.frag:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | \n#version 410 \n
21 |
22 | out vec4 fragColor;
23 |
24 | void main() {
25 | fragColor = vec4(1.0, 0.0, 0.0, 1.0);
26 | }
27 | )
28 |
--------------------------------------------------------------------------------
/src/default/shader/gk_cube.vert:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | \n#version 410 \n
21 |
22 | uniform mat4 MVP; // Projection * View * Model matrix
23 |
24 | layout(location = 0) in vec3 POSITION;
25 |
26 | void main() {
27 | gl_Position = MVP * vec4(POSITION, 1.0);
28 | }
29 | )
30 |
--------------------------------------------------------------------------------
/src/default/shader/gk_default.vert:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | \n#version 410 \n
21 |
22 | uniform mat4 MVP; // Projection * View * Model matrix
23 | uniform mat4 MV; // View * Model Matrix
24 | uniform mat4 NM; // Normal matrix
25 | uniform int NMU; // Use normal matrix
26 |
27 | layout(location = 0) in vec3 POSITION;
28 | layout(location = 1) in vec3 NORMAL;
29 |
30 | out vec3 vPos;
31 | out vec3 vNormal;
32 | out vec3 vEye;
33 |
34 | void main() {
35 | vec4 pos4 = vec4(POSITION, 1.0);
36 |
37 | vPos = vec3(MV * pos4);
38 | vEye = normalize(-vPos);
39 |
40 | if (NMU == 1)
41 | vNormal = normalize(vec3(NM * vec4(NORMAL, 0.0)));
42 | else
43 | vNormal = normalize(vec3(MV * vec4(NORMAL, 0.0)));
44 |
45 | gl_Position = MVP * pos4;
46 | }
47 | )
48 |
--------------------------------------------------------------------------------
/src/default/shader/gk_drawbone.fs:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | \n#version 410 \n
21 |
22 | out vec4 fragColor;
23 |
24 | void main() {
25 | fragColor = vec4(1.0, 0.0, 0.0, 1.0);
26 | }
27 | )
28 |
--------------------------------------------------------------------------------
/src/default/shader/gk_drawbone.vs:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | \n#version 410 \n
21 |
22 | uniform mat4 VP;
23 | layout(std140) uniform JointBlock {
24 | mat4 uJoints[255];
25 | };
26 |
27 | void main() {
28 | gl_Position = VP * uJoints[gl_VertexID] * vec4(1.0, 0.0, 0.0, 1.0);
29 | }
30 | )
31 |
--------------------------------------------------------------------------------
/src/default/transform.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "transform.h"
21 | #include "../types/impl_transform.h"
22 |
23 | GkTransformImpl gkdef_idmat = {
24 | .pub = {
25 | GLM_MAT4_IDENTITY_INIT,
26 | GLM_MAT4_IDENTITY_INIT,
27 | GK_TRANSF_LOCAL_ISVALID,
28 | NULL
29 | },
30 | 0,
31 | 0,
32 | NULL
33 | };
34 |
35 | GkTransform *
36 | gk_def_idmat() {
37 | return &gkdef_idmat.pub;
38 | }
39 |
--------------------------------------------------------------------------------
/src/default/transform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_def_transform_h
20 | #define gk_def_transform_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/material.h"
24 |
25 | GkTransform *
26 | gk_def_idmat(void);
27 |
28 | #endif /* gk_def_transform_h */
29 |
--------------------------------------------------------------------------------
/src/error/err.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "err.h"
20 |
--------------------------------------------------------------------------------
/src/error/err.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_err_err_h
20 | #define src_err_err_h
21 |
22 | #include
23 |
24 | #endif /* src_err_err_h */
25 |
--------------------------------------------------------------------------------
/src/error/gpu/err.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "err.h"
20 | #include
21 |
22 | /* TODO: log and raise warning/errors */
23 |
24 | void
25 | gkGPUAssertOnError() {
26 | GLenum err;
27 | err = glGetError();
28 | assert(err != GL_INVALID_OPERATION);
29 | }
30 |
31 | void
32 | gkGPUFrameBuffAssertOnError() {
33 | assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
34 | }
35 |
--------------------------------------------------------------------------------
/src/error/gpu/err.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_err_gpu_err_h
20 | #define src_err_gpu_err_h
21 |
22 | #include "../../common.h"
23 |
24 | GK_EXPORT
25 | void
26 | gkGPUAssertOnError(void);
27 |
28 | GK_EXPORT
29 | void
30 | gkGPUFrameBuffAssertOnError(void);
31 |
32 | #ifdef DEBUG
33 | # define GK_DEBUG_GPU_ASSERT_ONERROR() gkGPUAssertOnError()
34 | # define GK_DEBUG_GPU_FRAMEBUFF_ASSERT_ONERROR() gkGPUFrameBuffAssertOnError()
35 | # else
36 | # define GK_DEBUG_GPU_ASSERT_ONERROR()
37 | # define GK_DEBUG_GPU_FRAMEBUFF_ASSERT_ONERROR()
38 | #endif
39 |
40 | #endif /* src_err_gpu_err_h */
41 |
--------------------------------------------------------------------------------
/src/fs_utils.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "fs_utils.h"
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | int
28 | fsReadfile(const char * __restrict file,
29 | const char * __restrict modes,
30 | char ** __restrict dest) {
31 | FILE * infile = fopen(file, modes);
32 | int infile_no = fileno(infile);
33 |
34 | struct stat infile_st;
35 | if (fstat(infile_no, &infile_st) != 0)
36 | goto err;
37 |
38 | blksize_t blksize = infile_st.st_blksize;
39 | off_t fsize = infile_st.st_size;
40 |
41 | size_t fcontents_size = sizeof(char) * fsize;
42 | *dest = malloc(fcontents_size + 1);
43 | memset(*dest + fcontents_size, '\0', 1);
44 |
45 | size_t total_read = 0;
46 | size_t nread = 0;
47 | do {
48 | nread = fread(*dest + total_read,
49 | sizeof(**dest),
50 | blksize,
51 | infile);
52 |
53 | total_read += nread;
54 | } while (nread > 0 && total_read < fsize);
55 |
56 | fclose(infile);
57 |
58 | return 0;
59 | err:
60 | return -1;
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/src/fs_utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef fs_utils_h
20 | #define fs_utils_h
21 |
22 | #include
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | int
29 | fsReadfile(const char * __restrict file,
30 | const char * __restrict modes,
31 | char ** __restrict dest);
32 |
33 | #ifdef __cplusplus
34 | }
35 |
36 | #endif
37 |
38 | #endif /* fs_utils_h */
39 |
--------------------------------------------------------------------------------
/src/lib.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "model.h"
21 | #include "common.h"
22 |
23 | #include "shader/shader.h"
24 | #include "program/program.h"
25 | #include "program/vertex_input.h"
26 |
27 | #include "vertex.h"
28 |
29 | void
30 | GK_CONSTRUCTOR
31 | gk__init(void);
32 |
33 | void
34 | GK_DESTRUCTOR
35 | gk__cleanup(void);
36 |
37 | void
38 | GK_CONSTRUCTOR
39 | gk__init() {
40 | gk_verta_init();
41 | gk_vertinp_init();
42 | gk_shaders_init();
43 | gk_prog_init();
44 | }
45 |
46 | void
47 | GK_DESTRUCTOR
48 | gk__cleanup() {
49 | gk_prog_deinit();
50 | gk_shaders_deinit();
51 | gk_vertinp_deinit();
52 | gk_verta_deinit();
53 | }
54 |
--------------------------------------------------------------------------------
/src/material/colortex_uniform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_colortex_uniform_h
20 | #define gk_colortex_uniform_h
21 |
22 | #include "../../include/gk/gk.h"
23 |
24 | void
25 | gkUniformColor(GkColor * __restrict color,
26 | char * __restrict name,
27 | GkPipeline * __restrict prog);
28 |
29 | void
30 | gkUniformTex(GkContext * __restrict ctx,
31 | GkMaterial * __restrict mat,
32 | GkTexture * __restrict tex,
33 | char * __restrict name,
34 | GkPipeline * __restrict prog);
35 |
36 | void
37 | gkUniformColorDesc(GkContext * __restrict ctx,
38 | GkMaterial * __restrict mat,
39 | GkColorDesc * __restrict crtx,
40 | char * __restrict name,
41 | GkPipeline * __restrict prog);
42 |
43 | void
44 | gkUniformColorBuff(GkColor * __restrict color,
45 | char * __restrict buf,
46 | char * __restrict name,
47 | GkPipeline * __restrict prog);
48 |
49 | void
50 | gkUniformColorDescBuff(GkContext * __restrict ctx,
51 | GkMaterial * __restrict mat,
52 | GkColorDesc * __restrict crtx,
53 | char * __restrict buf,
54 | char * __restrict name,
55 | GkPipeline * __restrict prog);
56 |
57 | #endif /* gk_colortex_uniform_h */
58 |
--------------------------------------------------------------------------------
/src/material/material.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/gk.h"
21 | #include "../../include/gk/material.h"
22 | #include
23 |
24 | #include "../default/def_effect.h"
25 |
26 | GkTechnique*
27 | gkMaterialNewPhong() {
28 | GkTechnique *phong;
29 | phong = malloc(sizeof(*phong));
30 | memcpy(phong,
31 | gk_def_material_phong(),
32 | sizeof(*phong));
33 | return phong;
34 | }
35 |
36 | GkTechnique*
37 | gkMaterialNewBlinn() {
38 | GkTechnique *blinn;
39 | blinn = malloc(sizeof(*blinn));
40 | memcpy(blinn,
41 | gk_def_material_blinn(),
42 | sizeof(*blinn));
43 | return blinn;
44 | }
45 |
46 | GkTechnique*
47 | gkMaterialNewLambert() {
48 | GkTechnique *lambert;
49 | lambert = malloc(sizeof(*lambert));
50 | memcpy(lambert,
51 | gk_def_material_lambert(),
52 | sizeof(*lambert));
53 | return lambert;
54 | }
55 |
56 | GkTechnique*
57 | gkMaterialNewConstant() {
58 | GkTechnique *constant;
59 | constant = malloc(sizeof(*constant));
60 | memcpy(constant,
61 | gk_def_material_constant(),
62 | sizeof(*constant));
63 | return constant;
64 | }
65 |
66 | GkMetalRough*
67 | gkMaterialNewMetalRough() {
68 | GkMetalRough *mtlrough;
69 | mtlrough = malloc(sizeof(*mtlrough));
70 | memcpy(mtlrough,
71 | gk_def_material_mtlrough(),
72 | sizeof(*mtlrough));
73 | return mtlrough;
74 | }
75 |
76 | GkSpecGloss*
77 | gkMaterialNewSpecGloss() {
78 | GkSpecGloss *specGloss;
79 | specGloss = malloc(sizeof(*specGloss));
80 | memcpy(specGloss,
81 | gk_def_material_specgloss(),
82 | sizeof(*specGloss));
83 | return specGloss;
84 | }
85 |
--------------------------------------------------------------------------------
/src/model.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "model.h"
21 | #include
22 |
23 | void
24 | gk_geom_add(GkContext * __restrict ctx,
25 | GkGeometry * __restrict geom,
26 | void * __restrict source) {
27 | rb_insert(ctx->mdltree, source, geom);
28 | }
29 |
30 | GkGeometry*
31 | gk_geom_find(GkContext * __restrict ctx,
32 | void * __restrict source) {
33 | return rb_find(ctx->mdltree, source);
34 | }
35 |
--------------------------------------------------------------------------------
/src/model.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_src_model_h
20 | #define gk_src_model_h
21 |
22 | #include "../include/gk/gk.h"
23 |
24 | void
25 | gk_mdl_init(void);
26 |
27 | void
28 | gk_mdl_deinit(void);
29 |
30 | #endif /* gk_src_model_h */
31 |
--------------------------------------------------------------------------------
/src/pass/clear.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/pass.h"
21 |
22 | GK_EXPORT
23 | void
24 | gkClearColor(GkColorOutput *colorOutput) {
25 | if (colorOutput->clear->color) {
26 | glClearBufferfv(GL_COLOR,
27 | colorOutput->drawIndex,
28 | *colorOutput->clear->color);
29 | return;
30 | }
31 |
32 | /* TODO: add this to state manager */
33 | glClearBufferfv(GL_COLOR, colorOutput->drawIndex, GLM_VEC4_ZERO);
34 | }
35 |
36 | GK_EXPORT
37 | void
38 | gkClearColorAt(GkOutput *output, int32_t buffIndex) {
39 | GkColorOutput *color;
40 | int32_t i;
41 |
42 | color = output->color;
43 | for (i = 0; i < buffIndex && color; i++)
44 | color = color->next;
45 |
46 | if (color && i == buffIndex)
47 | gkClearColor(color);
48 | }
49 |
50 | GK_EXPORT
51 | void
52 | gkClearColors(GkOutput *output) {
53 | GkColorOutput *color;
54 |
55 | color = output->color;
56 | while (color) {
57 | gkClearColor(color);
58 | color = color->next;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/platform/ak_platform_info.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/gk.h"
21 | #include "../../include/gk/platform.h"
22 |
23 | /* Default expected values */
24 | GLint GK_PLI[] =
25 | {
26 | 16 /* 0: _MAX_TEX_UNIT */
27 | };
28 |
29 | void *gk_glcontext = NULL;
30 | GLint *gk_glcontextPLI = NULL;
31 |
32 | void
33 | gk_pl_fetchPLI(void);
34 |
35 | GLint
36 | gkPlatfomInfo(GkPlatformInfo pli) {
37 | if (gk_glcontext) {
38 | #ifdef DEBUG
39 | assert((uint32_t)pli < GK_ARRAY_LEN(gk_glcontextPLI));
40 | #endif
41 | return gk_glcontextPLI[pli];
42 | }
43 |
44 | #ifdef DEBUG
45 | assert((uint32_t)pli < GK_ARRAY_LEN(GK_PLI));
46 | #endif
47 | return GK_PLI[pli];
48 | }
49 |
50 | void
51 | gk_pl_fetchPLI() {
52 | if (!gk_glcontext)
53 | return;
54 |
55 | glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &gk_glcontextPLI[0]);
56 | }
57 |
58 | void
59 | gkSetGLContext(void *glcontext) {
60 | if (gk_glcontext) {
61 | free(gk_glcontextPLI);
62 |
63 | gk_glcontextPLI = NULL;
64 | gk_glcontext = NULL;
65 | }
66 |
67 | if (glcontext) {
68 | gk_glcontext = glcontext;
69 | gk_glcontextPLI = calloc(GK_ARRAY_LEN(GK_PLI), sizeof(GLint));
70 | gk_pl_fetchPLI();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/prims/builtin_prims.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/prims/builtin-prim.h"
21 | #include "../../include/gk/gk.h"
22 | #include
23 |
24 | GK_EXPORT
25 | GkPrimitive*
26 | gkGetBuiltinPrim(GkPrimType primType) {
27 | switch (primType) {
28 | case GK_PRIM_TEXQUAD:
29 | return gkPrimGetTexQuad();
30 | default:
31 | return NULL;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/prims/prims.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/prims/prims.h"
21 |
22 | void
23 | gkReleasePrims() {
24 | gkReleaseCube();
25 | }
26 |
--------------------------------------------------------------------------------
/src/program/program.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_program_h
20 | #define src_program_h
21 |
22 | void
23 | gk_prog_init(void);
24 |
25 | void
26 | gk_prog_deinit(void);
27 |
28 | #endif /* src_program_h */
29 |
--------------------------------------------------------------------------------
/src/program/uniform.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "uniform.h"
21 | #include "uniform_cache.h"
22 |
23 | GK_EXPORT
24 | void
25 | gkUniform1i(GkPipeline * __restrict prog,
26 | const char * __restrict name,
27 | GLint val) {
28 | glUniform1i(gkUniformLoc(prog, name), val);
29 | }
30 |
31 | GK_EXPORT
32 | void
33 | gkUniform1ui(GkPipeline * __restrict prog,
34 | const char * __restrict name,
35 | GLuint val) {
36 | glUniform1ui(gkUniformLoc(prog, name), val);
37 | }
38 |
39 | GK_EXPORT
40 | void
41 | gkUniform1f(GkPipeline * __restrict prog,
42 | const char * __restrict name,
43 | float val) {
44 | glUniform1f(gkUniformLoc(prog, name), val);
45 | }
46 |
47 | GK_EXPORT
48 | void
49 | gkUniform2f(GkPipeline * __restrict prog,
50 | const char * __restrict name,
51 | float val[2]) {
52 | glUniform2f(gkUniformLoc(prog, name), val[0], val[1]);
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/src/program/uniform.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_uniform_h
20 | #define src_uniform_h
21 |
22 | #include "../../include/gk/program.h"
23 | #include "../../include/gk/uniform.h"
24 | #include "../../include/gk/gk.h"
25 |
26 | #endif /* src_uniform_h */
27 |
--------------------------------------------------------------------------------
/src/program/uniform_cache.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "uniform_cache.h"
21 | #include
22 |
23 | GK_EXPORT
24 | GLint
25 | gkUniformLoc(GkPipeline *prog, const char *name) {
26 | void *found;
27 | GLint loc;
28 |
29 | if (!prog->uniforms)
30 | prog->uniforms = hash_new_str(8);
31 |
32 | if ((found = hash_get(prog->uniforms, (void *)name)))
33 | return ((GLint)(uintptr_t)found) - 1;
34 |
35 | loc = glGetUniformLocation(prog->progId, name);
36 | hash_set(prog->uniforms,
37 | (void *)strdup(name),
38 | (void *)(uintptr_t)(loc + 1));
39 |
40 | return loc;
41 | }
42 |
43 | GLint
44 | gkUniformLocBuff(GkPipeline * __restrict prog,
45 | char * __restrict name,
46 | char * __restrict buf) {
47 | char *pBuf;
48 | size_t attrlen;
49 | GLint loc;
50 |
51 | if (!buf)
52 | return gkUniformLoc(prog, name);
53 |
54 | pBuf = strrchr(buf, '.') + 1;
55 | strcpy(pBuf, name);
56 |
57 | attrlen = strlen(pBuf);
58 | loc = gkUniformLoc(prog, buf);
59 | memset((buf + strlen(buf)) - attrlen, '\0', attrlen);
60 | return loc;
61 | }
62 |
--------------------------------------------------------------------------------
/src/program/uniform_cache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_uniform_cache_h
20 | #define src_uniform_cache_h
21 |
22 | #include "../../include/gk/program.h"
23 | #include "../../include/gk/gk.h"
24 |
25 | GK_EXPORT
26 | GLint
27 | gkUniformLoc(GkPipeline *prog, const char *name);
28 |
29 | GLint
30 | gkUniformLocBuff(GkPipeline * __restrict prog,
31 | char * __restrict name,
32 | char * __restrict buf);
33 |
34 | #endif /* src_uniform_cache_h */
35 |
36 |
--------------------------------------------------------------------------------
/src/program/vertex_input.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef vertex_input_h
20 | #define vertex_input_h
21 |
22 | void
23 | gk_vertinp_init(void);
24 |
25 | void
26 | gk_vertinp_deinit(void);
27 |
28 | #endif /* vertex_input_h */
29 |
--------------------------------------------------------------------------------
/src/rect.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "../include/gk/gk.h"
21 | #include "../include/gk/geom-types.h"
22 |
23 | GkPoint
24 | gk_rect_center(GkRect rect) {
25 | GkPoint p;
26 |
27 | p.x = rect.origin.x + rect.size.w * 0.5f;
28 | p.y = rect.origin.y + rect.size.h * 0.5f;
29 |
30 | return p;
31 | }
32 |
--------------------------------------------------------------------------------
/src/render/queue/queue.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | GkRenderItem*
4 | gkAllocRenderQueue(int32_t count) {
5 | GkRenderItem* itemList;
6 |
7 | itemList = malloc(sizeof(*itemList) * count);
8 | return itemList;
9 | }
10 |
11 |
12 | void
13 | gkLinearizeScene(GkScene * __restrict scene) {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/render/realtime/animator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef rn_anim_h
20 | #define rn_anim_h
21 |
22 | #include "../../../include/gk/gk.h"
23 | #include "../../types/impl_scene.h"
24 |
25 | void
26 | gkRunAnim(GkSceneImpl *sceneImpl);
27 |
28 | #endif /* rn_anim_h */
29 |
--------------------------------------------------------------------------------
/src/render/realtime/builtin/builtin.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../../common.h"
20 | #include "../../../../include/gk/prims/builtin-prim.h"
21 |
22 | #include "builtin.h"
23 | #include "prim.h"
24 |
25 | void
26 | gkRenderBuiltinPrim(GkScene *scene,
27 | GkPrimType primType) {
28 | GkPrimitive *prim;
29 | prim = gkGetBuiltinPrim(primType);
30 |
31 | glBindVertexArray(prim->vao);
32 | gkRenderPrim(scene, prim);
33 | }
34 |
--------------------------------------------------------------------------------
/src/render/realtime/builtin/builtin.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef rn_builtin_h
20 | #define rn_builtin_h
21 |
22 | #include "../../../../include/gk/gk.h"
23 | #include "../../../../include/gk/prims/prims.h"
24 |
25 | #endif /* rn_builtin_h */
26 |
--------------------------------------------------------------------------------
/src/render/realtime/light.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef render_light_h
20 | #define render_light_h
21 |
22 | #include "../../../include/gk/gk.h"
23 |
24 | void
25 | gkRenderPrimForLight(GkScene * __restrict scene,
26 | GkTransform * __restrict trans,
27 | GkPrimitive * __restrict prim,
28 | GkPipeline * __restrict prog);
29 |
30 | void
31 | gkRenderPrimPerLight(GkScene * __restrict scene,
32 | GkPrimitive * __restrict prim,
33 | GkPipeline * __restrict prog);
34 |
35 | void
36 | gkRenderTranspPrimPerLight(GkScene * __restrict scene,
37 | GkPrimitive * __restrict prim,
38 | GkPipeline * __restrict prog);
39 |
40 | #endif /* render_light_h */
41 |
--------------------------------------------------------------------------------
/src/render/realtime/material.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef material_h
20 | #define material_h
21 |
22 | void
23 | gkApplyMaterial(GkScene * __restrict scene,
24 | GkPrimInst * __restrict primInst);
25 |
26 | void
27 | gkApplyMaterials(GkScene * __restrict scene,
28 | GkPrimInst * __restrict primInst);
29 |
30 | #endif /* material_h */
31 |
--------------------------------------------------------------------------------
/src/render/realtime/pass.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "../../../include/gk/prims/builtin-prim.h"
21 | #include "../../../include/gk/gpu_state.h"
22 | #include "../../shader/builtin_shader.h"
23 | #include "../../program/uniform_cache.h"
24 | #include "../../state/gpu.h"
25 |
26 | #include "light.h"
27 | #include "material.h"
28 | #include "pass.h"
29 | #include "prim.h"
30 |
31 | void
32 | gkRenderPass(GkScene * __restrict scene,
33 | GkPrimInst * __restrict primInst,
34 | GkPass * __restrict pass) {
35 | GkContext *ctx;
36 | GkPipeline *prog;
37 | GkSceneImpl *sceneImpl;
38 | GkTransform *trans;
39 | GkPrimitive *prim;
40 | GkMaterial *material;
41 |
42 | if (!(prog = pass->prog))
43 | return;
44 |
45 | sceneImpl = (GkSceneImpl *)scene;
46 | ctx = gkContextOf(scene);
47 | prim = primInst->prim;
48 | trans = primInst->trans;
49 | material = primInst->activeMaterial;
50 |
51 | gkUseProgram(ctx, prog);
52 |
53 | if (!pass->noMaterials) {
54 | gkUniformMaterial(ctx, prog, material);
55 | gkToggleDoubleSided(ctx, material->doubleSided);
56 | }
57 |
58 | gkUniformTransform(prog, trans, scene->camera);
59 |
60 | if (!pass->noLights) {
61 | switch (sceneImpl->rpath) {
62 | case GK_RNPATH_MODEL_PERLIGHT:
63 | if (material->technique
64 | && !material->technique->transparent)
65 | gkRenderPrimPerLight(scene, prim, prog);
66 | else
67 | gkRenderTranspPrimPerLight(scene, prim, prog);
68 | break;
69 | case GK_RNPATH_SCENE_PERLIGHT:
70 | gkRenderPrimForLight(scene, trans, prim, prog);
71 | break;
72 | default: break;
73 | }
74 | } else {
75 | gkRenderPrim(scene, prim);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/render/realtime/pass.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef pass_h
20 | #define pass_h
21 |
22 | #include "../../../include/gk/gk.h"
23 | #include "../../../include/gk/material.h"
24 | #include "../../../include/gk/pass.h"
25 |
26 | void
27 | gkRenderPass(GkScene * __restrict scene,
28 | GkPrimInst * __restrict primInst,
29 | GkPass * __restrict pass);
30 |
31 | #endif /* pass_h */
32 |
--------------------------------------------------------------------------------
/src/render/realtime/prim.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "prim.h"
21 | #include "material.h"
22 | #include "../../../include/gk/prims/cube.h"
23 |
24 | void
25 | gkRenderPrim(GkScene * __restrict scene,
26 | GkPrimitive * __restrict prim) {
27 | if (prim->flags & GK_DRAW_ELEMENTS)
28 | glDrawElements(prim->mode,
29 | prim->count,
30 | GL_UNSIGNED_INT, /* TODO: ? */
31 | NULL);
32 | else if (prim->flags & GK_DRAW_ARRAYS)
33 | glDrawArrays(prim->mode, 0, prim->count);
34 | }
35 |
36 | void
37 | gkRenderPrimInst(GkScene * __restrict scene,
38 | GkPrimInst * __restrict primInst) {
39 | GkPrimitive *prim;
40 |
41 | prim = primInst->prim;
42 |
43 | glBindVertexArray(prim->vao);
44 | gkApplyMaterial(scene, primInst);
45 |
46 | if ((scene->flags & GK_SCENEF_DRAW_PRIM_BBOX))
47 | gkDrawBBox(scene,
48 | primInst->bbox,
49 | primInst->trans->world);
50 | }
51 |
--------------------------------------------------------------------------------
/src/render/realtime/prim.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef rn_prim_h
20 | #define rn_prim_h
21 |
22 | #include "../../../include/gk/gk.h"
23 |
24 | void
25 | gkRenderPrim(GkScene * __restrict scene,
26 | GkPrimitive * __restrict prim);
27 |
28 | void
29 | gkRenderPrimInst(GkScene * __restrict scene,
30 | GkPrimInst * __restrict primInst);
31 |
32 | GK_INLINE
33 | void
34 | gkRenderPrims(GkScene * __restrict scene,
35 | GkRenderList * __restrict rnlist) {
36 | GkPrimInst **prims;
37 | size_t i, primc;
38 |
39 | primc = rnlist->count;
40 | prims = rnlist->items;
41 |
42 | for (i = 0; i < primc; i++) {
43 | if (!scene->renderPrimFunc)
44 | gkRenderPrimInst(scene, prims[i]);
45 | else
46 | scene->renderPrimFunc(scene, prims[i]);
47 | }
48 | }
49 |
50 | #endif /* rn_prim_h */
51 |
--------------------------------------------------------------------------------
/src/render/realtime/texture.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "prim.h"
21 | #include "texture.h"
22 | #include "../../shader/builtin_shader.h"
23 | #include "../../state/gpu.h"
24 | #include "../../../include/gk/prims/builtin-prim.h"
25 |
26 | void
27 | gkRenderTexture(GkScene * __restrict scene, GkPass * __restrict pass) {
28 | GkPipeline *prog;
29 | GkContext *ctx;
30 |
31 | ctx = gkContextOf(scene);
32 | prog = gkBuiltinProg(GK_BUILTIN_PROG_RTT);
33 |
34 | gkPushState(ctx);
35 | gkDisableDepthTest(ctx);
36 |
37 | gkUseProgram(gkContextOf(scene), prog);
38 | gkBindRenderTargetTo(scene, pass, 0, prog, 0, "uColorTex");
39 | gkRenderBuiltinPrim(scene, GK_PRIM_TEXQUAD);
40 |
41 | gkPopState(ctx);
42 | }
43 |
44 | void
45 | gkBlit(GkScene * __restrict scene,
46 | GkOutput * __restrict src,
47 | GkOutput * __restrict dst,
48 | int32_t colorIndex) {
49 | float w, h;
50 |
51 | w = scene->viewport[2] * scene->backingScale;
52 | h = scene->viewport[3] * scene->backingScale;
53 |
54 | glBindFramebuffer(GL_READ_FRAMEBUFFER, src->fbo);
55 | glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIndex);
56 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dst->fbo);
57 |
58 | glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
59 | }
60 |
--------------------------------------------------------------------------------
/src/render/realtime/texture.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef rn_texture_h
20 | #define rn_texture_h
21 |
22 | #include "../../../include/gk/gk.h"
23 | #include "../../../include/gk/pass.h"
24 |
25 | void
26 | gkRenderTexture(GkScene * __restrict scene, GkPass * __restrict pass);
27 |
28 | void
29 | gkBlit(GkScene * __restrict scene,
30 | GkOutput * __restrict src,
31 | GkOutput * __restrict dst,
32 | int32_t colorIndex);
33 |
34 | #endif /* rn_texture_h */
35 |
--------------------------------------------------------------------------------
/src/render/realtime/transp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef rn_transp_h
20 | #define rn_transp_h
21 |
22 | #include "../../../include/gk/gk.h"
23 |
24 | bool
25 | gkPrimIsTransparent(GkScene * __restrict scene,
26 | GkGeometryInst * __restrict modelInst,
27 | GkPrimInst * __restrict primInst);
28 |
29 | bool
30 | gkIsTransparent(GkScene * __restrict scene,
31 | GkMaterial * __restrict mat);
32 |
33 | #endif /* rn_transp_h */
34 |
--------------------------------------------------------------------------------
/src/scene/scene.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/gk.h"
21 | #include "../../include/gk/scene.h"
22 | #include "../types/impl_scene.h"
23 |
24 | #include
25 | #include
26 |
27 | GK_EXPORT
28 | GkScene*
29 | gkAllocScene(GkContext * __restrict context) {
30 | GkSceneImpl *sceneImpl;
31 | sceneImpl = calloc(1, sizeof(*sceneImpl));
32 |
33 | sceneImpl->transfCacheSlots = flist_new(NULL);
34 |
35 | sceneImpl->pub.flags = GK_SCENEF_INIT | GK_SCENEF_ONCE;
36 | sceneImpl->pub.backingScale = 1.0f;
37 | sceneImpl->pub.internalFormat = GL_RGBA;
38 | sceneImpl->pub.ctx = context;
39 |
40 | return &sceneImpl->pub;
41 | }
42 |
43 | GK_EXPORT
44 | void
45 | gkSceneSetOnClear(GkScene * __restrict scene,
46 | GkRenderAfterClearFunc onClear,
47 | void * __restrict obj) {
48 | GkSceneImpl *sceneImpl;
49 |
50 | sceneImpl = (GkSceneImpl *)scene;
51 | sceneImpl->onClear = onClear;
52 | sceneImpl->onClearObj = obj;
53 | }
54 |
--------------------------------------------------------------------------------
/src/shader/builtin_shader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef builtin_shader_h
20 | #define builtin_shader_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/shader.h"
24 |
25 | typedef enum GkBuiltinProg {
26 | GK_BUILTIN_PROG_RTT = 1,
27 | GK_BUILTIN_PROG_DEPTH = 2,
28 | GK_BUILTIN_PROG_SHADOWMAP = 3,
29 |
30 | /* weighted-blended transparency */
31 | GK_BUILTIN_PROG_WEIGBL_COMPOS = 4,
32 |
33 | /* Clear Effects */
34 | GK_BUILTIN_PROG_CLR_GRAD_CIRC = 5
35 | } GkBuiltinProg;
36 |
37 | GkPipeline*
38 | gkBuiltinProg(GkBuiltinProg progtype);
39 |
40 | #endif /* builtin_shader_h */
41 |
--------------------------------------------------------------------------------
/src/shader/cmn_material.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef cmn_material_h
20 | #define cmn_material_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/material.h"
24 |
25 | size_t
26 | gkShaderNameFor(GkScene * __restrict scene,
27 | GkLight * __restrict light,
28 | GkPrimInst * __restrict primInst,
29 | GkMaterial * __restrict mat,
30 | char * __restrict nameBuff);
31 |
32 | void
33 | gkShaderFlagsFor(GkScene * __restrict scene,
34 | GkLight * __restrict light,
35 | GkPrimInst * __restrict primInst,
36 | GkMaterial * __restrict mat,
37 | char ** __restrict vertFlags,
38 | char ** __restrict fragFlags);
39 |
40 | GkShader*
41 | gkShadersFor(GkScene * __restrict scene,
42 | GkLight * __restrict light,
43 | GkPrimInst * __restrict primInst,
44 | GkMaterial * __restrict mat);
45 |
46 | GkPipeline*
47 | gkGetPiplineForCmnMat(GkScene * __restrict scene,
48 | GkLight * __restrict light,
49 | GkPrimInst * __restrict primInst,
50 | GkMaterial * __restrict mat);
51 |
52 | #endif /* cmn_material_h */
53 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/clr_grad_circ.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /*
20 | References:
21 | [0] https://github.com/SFML/SFML/wiki/Source:-Radial-Gradient-Shader
22 | */
23 |
24 | GK_STRINGIFY(
25 |
26 | out vec4 fragColor;
27 |
28 | uniform vec2 uSize;
29 |
30 | /* TODO: maybe uniform */
31 | vec4 bgcolor1 = vec4(0.1, 0.1, 0.1, 1.0);
32 | vec4 bgcolor2 = vec4(0.19803921569, 0.2137254902, 0.2490196078, 1.0);
33 |
34 | void main() {
35 | vec2 centerFlipped = uSize * 0.5;
36 | float radius = centerFlipped.y;
37 |
38 | vec2 center = vec2(centerFlipped.x, uSize.y - centerFlipped.y);
39 | vec2 p = (gl_FragCoord.xy - center) / radius;
40 | float r = sqrt(dot(p, p));
41 |
42 | fragColor = mix(bgcolor2, bgcolor1, r);
43 | }
44 | )
45 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/constant.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.glsl"
20 |
21 | GK_STRINGIFY(
22 |
23 | void main() {
24 | vec4 clr;
25 | \n#ifdef SHADOWMAP\n
26 | float shadow = shadowCoef();
27 | \n#endif\n
28 |
29 | \n#ifdef TRANSP\n
30 | lightAttn = 1.0;
31 | \n#endif\n
32 |
33 | clr =
34 | \n#ifdef SHADOWMAP\n
35 | shadow * (
36 | \n#endif\n
37 |
38 | \n#ifdef EMISSION_TEX\n
39 | texture(uEmissionTex, EMISSION_TEXCOORD)
40 | \n#elif defined(EMISSION_COLOR)\n
41 | uEmission
42 | \n#else\n
43 | vec4(0, 0, 0, 0)
44 | \n#endif\n
45 |
46 | \n#ifdef AMBIENT_TEX\n
47 | + texture(uAmbientTex, AMBIENT_TEXCOORD) * uIAmbient
48 | \n#elif defined(AMBIENT_COLOR)\n
49 | + uAmbient * uIAmbient
50 | \n#endif\n
51 |
52 | \n#ifdef SHADOWMAP\n
53 | )
54 | \n#endif\n
55 | ;
56 |
57 | write(clr);
58 | }
59 | )
60 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/constants.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | const float cPI = 3.141592653589793;
21 | const float cMinRough = 0.04;
22 | const vec3 cDielectricSpecular = vec3(0.04);
23 | const vec3 cBlack = vec3(0.0);
24 | )
25 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/depth.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | uniform sampler2D uColorTex;
21 | uniform float uNear;
22 | uniform float uFar;
23 |
24 | in vec2 vTexCoord;
25 |
26 | layout(location = 0) out vec4 color;
27 |
28 | void main() {
29 | /* linearize depth */
30 | float depth = texture(uColorTex, vTexCoord).x;
31 | float c = (2.0 * uNear) / (uFar + uNear - depth * (uFar - uNear));
32 | color = vec4(c, c, c, 1);
33 | }
34 | )
35 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/lambert.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.glsl"
20 | #include "normal.glsl"
21 |
22 | GK_STRINGIFY(
23 |
24 | void main() {
25 | vec4 clr, lightc;
26 | vec3 L, N;
27 | float a, Ld;
28 |
29 | \n#ifdef SHADOWMAP\n
30 | float shadow = shadowCoef();
31 | \n#endif\n
32 |
33 | a = getLight(L);
34 |
35 | \n#ifdef TRANSP\n
36 | lightAttn = a;
37 | \n#endif\n
38 |
39 | lightc = vec4(light.color.rgb, 1.0) * a;
40 | N = normal();
41 |
42 | \n#ifndef TRANSP\n
43 | Ld = max(0.0, dot(N, L));
44 | \n#else\n
45 | N = N * sign(dot(N, L));
46 | Ld = max(0.0, dot(N, L));
47 | \n#endif\n
48 |
49 | clr =
50 | \n#ifdef SHADOWMAP\n
51 | shadow * (
52 | \n#endif\n
53 |
54 | \n#ifdef DIFFUSE_TEX\n
55 | lightc * texture(uDiffuseTex, DIFFUSE_TEXCOORD) * Ld
56 | \n#elif defined(DIFFUSE_COLOR)\n
57 | lightc * uDiffuse * Ld
58 | \n#else\n
59 | lightc * vec4(1, 1, 1, 1) * Ld
60 | \n#endif\n
61 |
62 | \n#ifdef AMBIENT_TEX\n
63 | + texture(uAmbientTex, AMBIENT_TEXCOORD) * uIAmbient
64 | \n#elif defined(AMBIENT_COLOR)\n
65 | + uAmbient * uIAmbient
66 | \n#endif\n
67 |
68 | \n#ifdef EMISSION_TEX\n
69 | + texture(uEmissionTex, EMISSION_TEXCOORD)
70 | \n#elif defined(EMISSION_COLOR)\n
71 | + uEmission
72 | \n#endif\n
73 |
74 | \n#ifdef SHADOWMAP\n
75 | )
76 | \n#endif\n
77 |
78 | ;
79 |
80 | write(clr);
81 | }
82 | )
83 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/lights.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 |
21 | float
22 | point(inout vec3 L) {
23 | float dist;
24 | L = light.position - vPos;
25 | dist = length(L);
26 | L = L / dist;
27 | return 1.0 / (light.constAttn
28 | + light.linAttn * dist
29 | + light.quadAttn * dist * dist);
30 | }
31 |
32 | float
33 | spot(inout vec3 L) {
34 | float dist;
35 | float spotCos;
36 |
37 | L = light.position - vPos;
38 | dist = length(L);
39 | L = L / dist;
40 |
41 | spotCos = dot(light.direction, -L);
42 | if (spotCos < light.cutoffCos)
43 | return 0.0;
44 |
45 | return pow(spotCos, light.cutoffExp) / (light.constAttn
46 | + light.linAttn * dist
47 | + light.quadAttn * dist * dist);
48 | }
49 |
50 | float
51 | directional(inout vec3 L) {
52 | L = -light.direction;
53 | return 1.0;
54 | }
55 |
56 | float
57 | getLight(inout vec3 L) {
58 | float a;
59 |
60 | switch (lightType) {
61 | case SpotLight:
62 | a = spot(L);
63 | break;
64 | case PointLight:
65 | a = point(L);
66 | break;
67 | case DirectionalLight:
68 | a = directional(L);
69 | break;
70 | case AmbientLight:
71 | L = vec3(0);
72 | a = 1.0;
73 | break;
74 | default:
75 | a = 1.0;
76 | }
77 |
78 | return a;
79 | }
80 |
81 | )
82 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/normal.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /*
20 | References:
21 | [1] https://github.com/KhronosGroup/glTF-WebGL-PBR/blob/master/shaders/pbr-frag.glsl
22 | */
23 |
24 | /*
25 | TODO: this will upadated later
26 | */
27 |
28 | GK_STRINGIFY(
29 | vec3 normal() {
30 |
31 | \n#if !defined(HAS_TANGENTS) && defined(NORMAL_TEX)\n
32 | vec3 pdx = dFdx(vPos);
33 | vec3 pdy = dFdy(vPos);
34 | vec3 tdx = dFdx(vec3(NORMAL_TEXCOORD, 0.0));
35 | vec3 tdy = dFdy(vec3(NORMAL_TEXCOORD, 0.0));
36 | vec3 t = (tdy.t * pdx - tdx.t * pdy) / (tdx.s * tdy.t - tdy.s * tdx.t);
37 |
38 | \n#ifdef HAS_NORMALS\n
39 | vec3 ng = normalize(vNormal);
40 | \n#else\n
41 | vec3 ng = cross(pdx, pdy);
42 | \n#endif\n
43 |
44 | t = normalize(t - ng * dot(ng, t));
45 | vec3 b = normalize(cross(ng, t));
46 | mat3 tbn = mat3(t, b, ng);
47 | \n#elif defined(HAS_TBN)\n
48 | mat3 tbn = vTBN;
49 | \n#endif\n
50 |
51 | \n#ifdef NORMAL_TEX\n
52 | vec3 n = texture(uNormalTex, NORMAL_TEXCOORD).rgb;
53 | n = normalize(tbn * ((2.0 * n - 1.0) * vec3(uNormalScale, uNormalScale, 1.0)));
54 | \n#elif defined(HAS_TBN)\n
55 | // The tbn matrix is linearly interpolated, so we need to re-normalize
56 | vec3 n = normalize(tbn[2].xyz);
57 | \n#else\n
58 | vec3 n = normalize(vNormal);
59 | \n#endif\n
60 |
61 | if (gl_FrontFacing)
62 | return n;
63 |
64 | return -n;
65 | }
66 | )
67 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/phong.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.glsl"
20 | #include "normal.glsl"
21 |
22 | GK_STRINGIFY(
23 | void main() {
24 | vec4 clr, lightc;
25 | vec3 L, N;
26 | float a, Ld, Ls;
27 |
28 | \n#ifdef SHADOWMAP\n
29 | float shadow = shadowCoef();
30 | \n#endif\n
31 |
32 | a = getLight(L);
33 |
34 | \n#ifdef TRANSP\n
35 | lightAttn = a;
36 | \n#endif\n
37 |
38 | lightc = vec4(light.color.rgb, 1.0) * a;
39 | N = normal();
40 |
41 | \n#ifndef TRANSP\n
42 | Ld = max(0.0, dot(N, L));
43 | if (Ld == 0.0)
44 | Ls = 0.0;
45 | else
46 | Ls = pow(max(0.0, dot(reflect(-L, N), vEye)), uShininess);
47 | \n#else\n
48 | N = N * sign(dot(N, L));
49 | Ld = max(0.0, dot(N, L));
50 | if (Ld == 0.0)
51 | Ls = 0.0;
52 | else
53 | Ls = pow(max(0.0, dot(reflect(-L, N), vEye)), uShininess);
54 | \n#endif\n
55 |
56 | clr =
57 | \n#ifdef SHADOWMAP\n
58 | shadow * (
59 | \n#endif\n
60 |
61 | \n#ifdef DIFFUSE_TEX\n
62 | lightc * texture(uDiffuseTex, DIFFUSE_TEXCOORD) * Ld
63 | \n#elif defined(DIFFUSE_COLOR)\n
64 | lightc * uDiffuse * Ld
65 | \n#else\n
66 | lightc * vec4(1, 1, 1, 1) * Ld
67 | \n#endif\n
68 |
69 | \n#ifdef AMBIENT_TEX\n
70 | + texture(uAmbientTex, AMBIENT_TEXCOORD) * uIAmbient
71 | \n#elif defined(AMBIENT_COLOR)\n
72 | + uAmbient * uIAmbient
73 | \n#endif\n
74 |
75 | \n#ifdef EMISSION_TEX\n
76 | + texture(uEmissionTex, EMISSION_TEXCOORD)
77 | \n#elif defined(EMISSION_COLOR)\n
78 | + uEmission
79 | \n#endif\n
80 |
81 | \n#ifdef SPECULAR_TEX\n
82 | + lightc * texture(uSpecularTex, SPECULAR_TEXCOORD) * Ls
83 | \n#elif defined(SPECULAR_COLOR)\n
84 | + lightc * uSpecular * Ls
85 | \n#else\n
86 | + lightc * vec4(1, 1, 1, 1) * Ls
87 | \n#endif\n
88 |
89 | \n#ifdef SHADOWMAP\n
90 | )
91 | \n#endif\n
92 | ;
93 |
94 | write(clr);
95 | }
96 | )
97 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/rtt.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 |
21 | out vec4 fragColor;
22 |
23 | uniform sampler2D uColorTex;
24 |
25 | in vec2 vTexCoord;
26 |
27 | void main() {
28 | fragColor = texture(uColorTex, vTexCoord);
29 | }
30 | )
31 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/shadowmap.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | layout(location = 0) out float depth;
21 | void main() {
22 | depth = gl_FragCoord.z;
23 | }
24 | )
25 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/shadows.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 |
21 | \n#ifdef SHADOWMAP\n
22 | \n#ifndef SHAD_SPLIT\n
23 |
24 | \n#ifdef SHAD_CUBE\n
25 | uniform samplerCubeShadow uShadMap;
26 | uniform vec2 uFarNear;
27 |
28 | float depthValue(const in vec3 v) {
29 | vec3 absv = abs(v);
30 | float z = max(absv.x, max(absv.y, absv.z));
31 | return uFarNear.x + uFarNear.y / z;
32 | }
33 |
34 | \n#else\n
35 | uniform sampler2DShadow uShadMap;
36 | in vec4 vShadCoord;
37 | \n#endif\n
38 |
39 | float shadowCoef() {
40 | \n#ifdef SHAD_CUBE\n
41 | vec3 L;
42 | float d;
43 |
44 | L = vPosWS - light.position_ws;
45 | d = depthValue(L);
46 |
47 | return texture(uShadMap, vec4(L, d));
48 | \n#else\n
49 | return textureProj(uShadMap, vShadCoord);
50 | \n#endif\n
51 | }
52 |
53 | \n#else\n
54 |
55 | uniform sampler2DArrayShadow uShadMap;
56 | uniform mat4 uShadMVP[SHAD_SPLIT];
57 | uniform float uShadDist[SHAD_SPLIT];
58 |
59 | float shadowCoef() {
60 | vec4 shadCoord;
61 | int i;
62 |
63 | for (i = 0; i < SHAD_SPLIT; i++) {
64 | if (gl_FragCoord.z < uShadDist[i])
65 | break;
66 | }
67 |
68 | shadCoord = uShadMVP[i] * vPosMS;
69 | shadCoord.xyw = (shadCoord / shadCoord.w).xyz;
70 | shadCoord.z = float(i);
71 |
72 | return texture(uShadMap, shadCoord);
73 | }
74 |
75 | \n#endif\n
76 | \n#endif\n
77 |
78 | )
79 |
--------------------------------------------------------------------------------
/src/shader/glsl/frag/wboit_compos.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /*
20 | http://casual-effects.blogspot.com.tr/2015/03/implemented-weighted-blended
21 | -order.html
22 | */
23 |
24 | GK_STRINGIFY(
25 | uniform sampler2D uAccum; /* sum(rgb * a, a) */
26 | uniform sampler2D uReveal; /* prod(1 - a) */
27 |
28 | float max4(vec4 v) {
29 | return max(max(v.x, v.y), max(v.z, v.w));
30 | }
31 |
32 | layout(location = 0) out vec4 fragcolor;
33 |
34 | void main() {
35 | float revealage;
36 | vec4 accum;
37 | vec3 averageColor;
38 | ivec2 C;
39 |
40 | C = ivec2(gl_FragCoord.xy);
41 | revealage = texelFetch(uReveal, C, 0).r;
42 |
43 | /* Save the blending and color texture fetch cost */
44 | if (revealage >= 1.0)
45 | discard;
46 |
47 | accum = texelFetch(uAccum, C, 0);
48 |
49 | /* Suppress overflow */
50 | if (isinf(max4(abs(accum))))
51 | accum.rgb = vec3(accum.a);
52 |
53 | averageColor = accum.rgb / max(accum.a, 0.00001);
54 |
55 | fragcolor = vec4(averageColor, revealage);
56 | }
57 | )
58 |
--------------------------------------------------------------------------------
/src/shader/glsl/lib/funcs/colorspace.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 |
21 | const float gamma = 2.2;
22 |
23 | float
24 | toLinear(float v) {
25 | return pow(v, gamma);
26 | }
27 |
28 | vec2
29 | toLinear(vec2 v) {
30 | return pow(v, vec2(gamma));
31 | }
32 |
33 | vec3
34 | toLinear(vec3 v) {
35 | return pow(v, vec3(gamma));
36 | }
37 |
38 | vec4
39 | toLinear(vec4 v) {
40 | return vec4(toLinear(v.rgb), v.a);
41 | }
42 |
43 | float
44 | toSRGB(float v) {
45 | return pow(v, 1.0 / gamma);
46 | }
47 |
48 | vec2
49 | toSRGB(vec2 v) {
50 | return pow(v, vec2(1.0 / gamma));
51 | }
52 |
53 | vec3
54 | toSRGB(vec3 v) {
55 | return pow(v, vec3(1.0 / gamma));
56 | }
57 |
58 | vec4
59 | toSRGB(vec4 v) {
60 | return vec4(toSRGB(v.rgb), v.a);
61 | }
62 |
63 | )
64 |
--------------------------------------------------------------------------------
/src/shader/glsl/lib/funcs/lerp.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 |
21 | vec3
22 | lerp(vec3 x, vec3 y, vec3 s) {
23 | return x + s * (y - x);
24 | }
25 |
26 | vec3
27 | lerp(vec3 x, vec3 y, float s) {
28 | return x + s * (y - x);
29 | }
30 |
31 | float
32 | lerp(float x, float y, float s) {
33 | return x + s * (y - x);
34 | }
35 |
36 | )
37 |
--------------------------------------------------------------------------------
/src/shader/glsl/lib/funcs/max.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 |
21 | float
22 | max(vec3 v) {
23 | return max(max(v.x, v.y), v.z);
24 | }
25 |
26 | )
27 |
--------------------------------------------------------------------------------
/src/shader/glsl/vert/plain.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | layout(location = 0) in vec3 POSITION;
21 | void main() {
22 | gl_Position = vec4(POSITION, 1.0);
23 | }
24 | )
25 |
--------------------------------------------------------------------------------
/src/shader/glsl/vert/rtt.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | layout(location = 0) in vec2 POSITION;
21 | layout(location = 1) in vec2 TEXCOORD;
22 |
23 | out vec2 vTexCoord;
24 | void main() {
25 | vTexCoord = TEXCOORD;
26 | gl_Position = vec4(POSITION, 0.0, 1.0);
27 | }
28 | )
29 |
--------------------------------------------------------------------------------
/src/shader/glsl/vert/shadowmap.glsl:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | GK_STRINGIFY(
20 | uniform mat4 MVP;
21 | layout(location = 0) in vec3 POSITION;
22 | void main() {
23 | gl_Position = MVP * vec4(POSITION, 1.0);
24 | }
25 | )
26 |
--------------------------------------------------------------------------------
/src/shader/shader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_shader_h
20 | #define src_shader_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/shader.h"
24 |
25 | typedef enum GkShaderFlags {
26 | GK_SHADER_FLAG_MVP = 1,
27 | GK_SHADER_FLAG_MV = 2,
28 | GK_SHADER_FLAG_NM = 3,
29 | GK_SHADER_FLAG_NMU = 4,
30 | GK_SHADER_FLAG_VP = 5,
31 | GK_SHADER_FLAG_BUILTIN = GK_SHADER_FLAG_MVP
32 | | GK_SHADER_FLAG_MV
33 | | GK_SHADER_FLAG_NM
34 | | GK_SHADER_FLAG_NMU
35 | } GkShaderFlags;
36 |
37 | GkPipeline*
38 | gkGetOrCreatProgByName(const char *commonName,
39 | const char *shaderSources[],
40 | GLenum shaderTypes[],
41 | uint32_t shaderCount,
42 | GkShaderFlags flags);
43 |
44 | void
45 | gk_shaders_init(void);
46 |
47 | void
48 | gk_shaders_deinit(void);
49 |
50 | #endif /* src_shader_h */
51 |
--------------------------------------------------------------------------------
/src/shadows/builtin/basic.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef basic_h
20 | #define basic_h
21 |
22 | #include "../../../include/gk/gk.h"
23 | #include "../../../include/gk/scene.h"
24 |
25 | #include "../shadows.h"
26 |
27 | GkShadowMap*
28 | gkSetupBasicShadowMap(GkScene * __restrict scene,
29 | GkLight * __restrict light);
30 |
31 | void
32 | gkRenderBasicShadowMap(GkScene * __restrict scene,
33 | GkLight * __restrict light);
34 |
35 | #endif /* basic_h */
36 |
--------------------------------------------------------------------------------
/src/shadows/builtin/csm.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef csm_h
20 | #define csm_h
21 |
22 | #include "../../../include/gk/gk.h"
23 | #include "../../../include/gk/scene.h"
24 |
25 | #include "../shadows.h"
26 |
27 | GkShadowMap*
28 | gkSetupShadowMapCSM(GkScene * __restrict scene,
29 | GkLight * __restrict light);
30 |
31 | void
32 | gkRenderShadowMapCSM(GkScene * __restrict scene,
33 | GkLight * __restrict light);
34 |
35 | #endif /* csm_h */
36 |
--------------------------------------------------------------------------------
/src/shadows/render.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "shadows.h"
21 | #include "render.h"
22 | #include "../render/realtime/prim.h"
23 |
24 | void
25 | gkRenderShadowMap(GkScene * __restrict scene,
26 | GkShadowMap * __restrict sm,
27 | GkPrimInst * __restrict primInst,
28 | GkPipeline * __restrict prog,
29 | int split) {
30 | mat4 mvp;
31 | vec4 *world;
32 | GkPrimitive *prim;
33 |
34 | world = primInst->trans->world;
35 | prim = primInst->prim;
36 |
37 | glm_mul(sm->viewProj[split], world, mvp);
38 | gkUniformMat4(prog->mvpi, mvp);
39 |
40 | glBindVertexArray(prim->vao);
41 | gkRenderPrim(scene, prim);
42 |
43 | /* reset the state */
44 | glBindVertexArray(0);
45 | }
46 |
--------------------------------------------------------------------------------
/src/shadows/render.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_shad_render_h
20 | #define src_shad_render_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/shadows.h"
24 | #include "../../include/gk/pass.h"
25 |
26 | void
27 | gkRenderShadowMap(GkScene * __restrict scene,
28 | GkShadowMap * __restrict sm,
29 | GkPrimInst * __restrict primInst,
30 | GkPipeline * __restrict prog,
31 | int split);
32 |
33 | #endif /* src_shad_render_h */
34 |
35 |
--------------------------------------------------------------------------------
/src/shadows/shadows.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_shadows_h
20 | #define src_shadows_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/shadows.h"
24 | #include "../../include/gk/pass.h"
25 |
26 | typedef struct GkShadowMap {
27 | GkPass *pass;
28 | GkLight *currLight;
29 | float *distances;
30 | mat4 *viewProj;
31 | int splitc;
32 | float near;
33 | float far;
34 | GkSize size;
35 | } GkShadowMap;
36 |
37 | typedef GkShadowMap* (*gkSetupShadowsFunc)(GkScene * __restrict scene,
38 | GkLight * __restrict light);
39 | typedef void (*gkRenderShadowsFunc)(GkScene * __restrict scene,
40 | GkLight * __restrict light);
41 |
42 | GkShadowMap*
43 | gkSetupShadows(GkScene * __restrict scene,
44 | GkLight * __restrict light);
45 |
46 | void
47 | gkRenderShadows(GkScene * __restrict scene,
48 | GkLight * __restrict light);
49 |
50 | #endif /* src_shadows_h */
51 |
--------------------------------------------------------------------------------
/src/shadows/visualize.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../common.h"
20 | #include "../../include/gk/prims/builtin-prim.h"
21 |
22 | #include "shadows.h"
23 | #include "../shader/builtin_shader.h"
24 | #include "../program/uniform_cache.h"
25 | #include "../state/gpu.h"
26 |
27 | void
28 | gkRenderShadowMapTo(GkScene * __restrict scene,
29 | GkOutput * __restrict output) {
30 | GkContext *ctx;
31 | GkSceneImpl *sceneImpl;
32 | GkShadowMap *sm;
33 | GkCamera *cam;
34 | GkPipeline *depthProg;
35 | int32_t texUnit;
36 | float near, far;
37 |
38 | sceneImpl = (GkSceneImpl *)scene;
39 | sm = sceneImpl->shadows;
40 | if (!sm->currLight || !(cam = sm->currLight->camera))
41 | return;
42 |
43 | ctx = gkContextOf(scene);
44 |
45 | gkPushState(ctx);
46 | gkBindOutput(scene, output);
47 |
48 | texUnit = (int32_t)ctx->samplers->count;
49 | depthProg = gkBuiltinProg(GK_BUILTIN_PROG_DEPTH);
50 |
51 | glm_persp_decomp_z(cam->proj, &near, &far);
52 |
53 | gkUseProgram(gkContextOf(scene), depthProg);
54 | gkBindTextureTo(ctx, texUnit, GL_TEXTURE_2D, sm->pass->output->depth);
55 | gkUniform1i(depthProg, "uColorTex", texUnit);
56 | gkUniform1f(depthProg, "uNear", near);
57 | gkUniform1f(depthProg, "uFar", far);
58 |
59 | gkRenderBuiltinPrim(scene, GK_PRIM_TEXQUAD);
60 | gkPopState(ctx);
61 | }
62 |
--------------------------------------------------------------------------------
/src/skin/draw.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_draw_h
20 | #define src_draw_h
21 |
22 | #include "../../include/gk/gk.h"
23 |
24 | #endif /* src_draw_h */
25 |
--------------------------------------------------------------------------------
/src/state/aux/bind_prim.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../../include/gk/gk.h"
20 | #include "../../../include/gk/gpu_state.h"
21 |
22 | GK_EXPORT
23 | void
24 | gkBindPrimitive(GkPrimitive * __restrict prim) {
25 | if (!prim)
26 | return;
27 |
28 | glBindVertexArray(prim->vao);
29 | }
30 |
31 | GK_EXPORT
32 | void
33 | gkBindPrimInst(GkPrimInst * __restrict primInst) {
34 | GkPrimitive *prim;
35 |
36 | if (!primInst || !(prim = primInst->prim))
37 | return;
38 |
39 | glBindVertexArray(prim->vao);
40 | }
41 |
--------------------------------------------------------------------------------
/src/state/gpu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_state_gpu_common_h
20 | #define src_state_gpu_common_h
21 |
22 | #include "gpu/common.h"
23 | #include "gpu/default.h"
24 |
25 | #endif /* src_state_gpu_common_h */
26 |
--------------------------------------------------------------------------------
/src/state/gpu/apply.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_gpu_state_impl_h
20 | #define src_gpu_state_impl_h
21 |
22 | #include "../../../include/gk/gk.h"
23 | #include "../../../include/gk/gpu_state.h"
24 |
25 | #include "common.h"
26 |
27 | #define GK_GPU_APPLY_ST_FN(NAME) \
28 | _gk_hide void NAME(GkContext * __restrict, GkStateBase * __restrict);
29 |
30 | GK_GPU_APPLY_ST_FN(gkApplyDepthState);
31 | GK_GPU_APPLY_ST_FN(gkApplyBlendState);
32 | GK_GPU_APPLY_ST_FN(gkApplyTexState);
33 | GK_GPU_APPLY_ST_FN(gkApplyOutputState);
34 | GK_GPU_APPLY_ST_FN(gkApplyCullFaceState);
35 | GK_GPU_APPLY_ST_FN(gkApplyFrameBuffState);
36 |
37 | #endif /* src_gpu_state_impl_h */
38 |
--------------------------------------------------------------------------------
/src/state/gpu/default.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "default.h"
21 | #include "common.h"
22 | #include
23 |
24 | #define GK__STATE_BASE(T) \
25 | .base = { \
26 | .prev = NULL, \
27 | .next = NULL, \
28 | .type = T, \
29 | .index = 0, \
30 | .indexed = false \
31 | }
32 |
33 | GkTextureState gk__deftexst = {
34 | GK__STATE_BASE(GK_GPUSTATE_TEXTURE),
35 | .texunit = 0,
36 | .target = GL_TEXTURE_2D,
37 | .texid = 0
38 | };
39 |
40 | GkGPUStates gk__defstate = {
41 | .depth = &(GkDepthState){
42 | GK__STATE_BASE(GK_GPUSTATE_DEPTH),
43 | .test = true,
44 | .func = GL_LESS,
45 | .mask = GL_TRUE,
46 | },
47 |
48 | .face = &(GkFaceState){
49 | GK__STATE_BASE(GK_GPUSTATE_CULLFACE),
50 | .cull = false,
51 | .face = GL_BACK,
52 | .frontFace = GL_CCW
53 | },
54 |
55 | .blend = &(GkBlendState){
56 | GK__STATE_BASE(GK_GPUSTATE_BLEND),
57 | .blend = false,
58 | .eq = GL_FUNC_ADD,
59 | .src = GL_ONE,
60 | .dst = GL_ZERO
61 | },
62 |
63 | .output = &(GkOutputState){
64 | GK__STATE_BASE(GK_GPUSTATE_OUTPUT),
65 | .output = NULL
66 | },
67 |
68 | .tex = NULL,
69 | .activeTex = 0,
70 | .prog = NULL
71 | };
72 |
73 | _gk_hide
74 | void
75 | gkInitStates(GkContext * __restrict ctx) {
76 | if (ctx->currState)
77 | return;
78 |
79 | ctx->currState = calloc(1, sizeof(*ctx->currState));
80 |
81 | memcpy(ctx->currState, &gk__defstate, sizeof(gk__defstate));
82 | ctx->currState->tex = hash_new(NULL,
83 | ds_hashfn_ui32p,
84 | ds_cmp_ui32p, 8);
85 | }
86 |
--------------------------------------------------------------------------------
/src/state/gpu/default.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef default_h
20 | #define default_h
21 |
22 | #include "common.h"
23 |
24 | _gk_hide
25 | void
26 | gkInitStates(GkContext * __restrict ctx);
27 |
28 | #endif /* default_h */
29 |
--------------------------------------------------------------------------------
/src/state/gpu/stack.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "../../common.h"
20 | #include "../../../include/gk/gk.h"
21 | #include "../../../include/gk/gpu_state.h"
22 |
23 | #include "common.h"
24 | #include "apply.h"
25 |
26 | #include
27 | #include
28 |
29 | GkGPUApplyStateFn gk__stateFuncs[] = {
30 | NULL,
31 | gkApplyDepthState,
32 | gkApplyBlendState,
33 | gkApplyTexState,
34 | gkApplyOutputState,
35 | gkApplyCullFaceState,
36 | gkApplyFrameBuffState
37 | };
38 |
39 | GK_EXPORT
40 | void
41 | gkPushState(GkContext * __restrict ctx) {
42 | GkStatesItem *newst;
43 |
44 | if (!ctx->states || !ctx->states->last)
45 | return;
46 |
47 | /* save space! */
48 | if (((GkStatesItem *)flist_last(ctx->states))->isempty)
49 | return;
50 |
51 | newst = calloc(1, sizeof(*newst));
52 | newst->isempty = true;
53 |
54 | flist_append(ctx->states, newst);
55 | }
56 |
57 | GK_EXPORT
58 | void
59 | gkPopState(GkContext * __restrict ctx) {
60 | GkStatesItem *curr;
61 | FListItem *curri;
62 | GkStateBase *prevst, *currst;
63 |
64 | curr = flist_pop(ctx->states);
65 | if (!curr)
66 | return;
67 |
68 | if (!(curri = curr->states))
69 | goto fr;
70 |
71 | /* revert each state to previous */
72 | do {
73 | currst = curri->data;
74 | prevst = currst->prev;
75 |
76 | #ifdef DEBUG
77 | assert(prevst != currst);
78 | assert(prevst);
79 | #endif
80 |
81 | gk__stateFuncs[prevst->type](ctx, prevst);
82 |
83 | free(currst);
84 | } while ((curri = curri->next));
85 |
86 | fr:
87 | /* we are no longer need to current state */
88 | free(curr);
89 | }
90 |
--------------------------------------------------------------------------------
/src/state/gpu/states/common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_gpustate_states_common_h
20 | #define src_gpustate_states_common_h
21 |
22 | #include "../../../common.h"
23 | #include "../../../../include/gk/gk.h"
24 | #include "../../../../include/gk/gpu_state.h"
25 |
26 | #include "../common.h"
27 | #include "../apply.h"
28 |
29 | #endif /* src_gpustate_states_common_h */
30 |
--------------------------------------------------------------------------------
/src/state/gpu/states/depth.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 |
21 | GK_EXPORT
22 | void
23 | gkEnableDepthTest(GkContext * __restrict ctx) {
24 | GkDepthState *state;
25 |
26 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_DEPTH);
27 | if (state->test)
28 | return;
29 |
30 | state->test = true;
31 |
32 | glEnable(GL_DEPTH_TEST);
33 | }
34 |
35 | GK_EXPORT
36 | void
37 | gkDisableDepthTest(GkContext * __restrict ctx) {
38 | GkDepthState *state;
39 |
40 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_DEPTH);
41 | if (!state->test)
42 | return;
43 |
44 | state->test = false;
45 |
46 | glDisable(GL_DEPTH_TEST);
47 | }
48 |
49 | GK_EXPORT
50 | void
51 | gkDepthMask(GkContext * __restrict ctx, GLboolean flag) {
52 | GkDepthState *state;
53 |
54 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_DEPTH);
55 | if (state->mask == flag)
56 | return;
57 |
58 | state->mask = flag;
59 |
60 | glDepthMask(flag);
61 | }
62 |
63 | GK_EXPORT
64 | void
65 | gkDepthFunc(GkContext * __restrict ctx, GLenum func) {
66 | GkDepthState *state;
67 |
68 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_DEPTH);
69 | if (state->func == func)
70 | return;
71 |
72 | state->func = func;
73 |
74 | glDepthFunc(func);
75 | }
76 |
--------------------------------------------------------------------------------
/src/state/gpu/states/face.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 |
21 | GK_EXPORT
22 | void
23 | gkEnableCullFace(GkContext * __restrict ctx) {
24 | GkFaceState *state;
25 |
26 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_CULLFACE);
27 | if (state->cull)
28 | return;
29 |
30 | state->cull = true;
31 |
32 | glEnable(GL_CULL_FACE);
33 | }
34 |
35 | GK_EXPORT
36 | void
37 | gkDisableCullFace(GkContext * __restrict ctx) {
38 | GkFaceState *state;
39 |
40 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_CULLFACE);
41 | if (!state->cull)
42 | return;
43 |
44 | state->cull = false;
45 |
46 | glDisable(GL_CULL_FACE);
47 | }
48 |
49 | GK_EXPORT
50 | void
51 | gkToggleDoubleSided(GkContext * __restrict ctx, bool doubleSided) {
52 | if (!doubleSided) {
53 | gkEnableCullFace(ctx);
54 | return;
55 | }
56 |
57 | gkDisableCullFace(ctx);
58 | }
59 |
60 | GK_EXPORT
61 | void
62 | gkCullFace(GkContext * __restrict ctx, GLenum face) {
63 | GkFaceState *state;
64 |
65 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_CULLFACE);
66 |
67 | state->face = face;
68 |
69 | glCullFace(face);
70 | }
71 |
72 | GK_EXPORT
73 | void
74 | gkFrontFace(GkContext * __restrict ctx, GLenum face) {
75 | GkFaceState *state;
76 |
77 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_CULLFACE);
78 |
79 | state->frontFace = face;
80 |
81 | glFrontFace(face);
82 | }
83 |
--------------------------------------------------------------------------------
/src/state/gpu/states/fbuff.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 |
21 | GK_EXPORT
22 | void
23 | gkSrcBuff(GkContext * __restrict ctx, GLenum buff) {
24 | GkFramebuffState *state;
25 |
26 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_BLEND);
27 | if (state->readbuff == buff)
28 | return;
29 |
30 | state->readbuff = buff;
31 |
32 | glReadBuffer(buff);
33 | }
34 |
35 | GK_EXPORT
36 | void
37 | gkDstBuff(GkContext * __restrict ctx, GLenum buff) {
38 | GkFramebuffState *state;
39 |
40 | state = gkGetOrCreatState(ctx, GK_GPUSTATE_BLEND);
41 | if (state->drawbuff == buff)
42 | return;
43 |
44 | state->drawbuff = buff;
45 |
46 | glDrawBuffer(buff);
47 | }
48 |
--------------------------------------------------------------------------------
/src/state/gpu/states/texture.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 |
21 | GK_EXPORT
22 | void
23 | gkActiveTexture(GkContext * __restrict ctx,
24 | uint32_t unit) {
25 | GkGPUStates *ast;
26 |
27 | ast = ctx->currState;
28 | if (ast->activeTex == unit)
29 | return;
30 |
31 | ast->activeTex = unit;
32 | glActiveTexture(GL_TEXTURE0 + unit);
33 | }
34 |
35 | GK_EXPORT
36 | void
37 | gkBindTextureTo(GkContext * __restrict ctx,
38 | uint32_t unit,
39 | uint32_t target,
40 | uint32_t texid) {
41 | GkTextureState *state;
42 | GkGPUStates *ast;
43 |
44 | ast = ctx->currState;
45 | state = gkGetOrCreatTexState(ctx, unit, target);
46 |
47 | if (ast->activeTex != unit)
48 | gkActiveTexture(ctx, unit);
49 |
50 | if (state->texid != texid)
51 | gkBindTexture(ctx, target, texid);
52 | }
53 |
54 | GK_EXPORT
55 | void
56 | gkBindTexture(GkContext * __restrict ctx,
57 | uint32_t target,
58 | uint32_t texid) {
59 | GkTextureState *state;
60 | GkGPUStates *ast;
61 |
62 | ast = ctx->currState;
63 |
64 | state = gkGetOrCreatTexState(ctx, ast->activeTex, target);
65 | if (state->texid == texid)
66 | return;
67 |
68 | state->texid = texid;
69 | glBindTexture(target, texid);
70 | }
71 |
--------------------------------------------------------------------------------
/src/tball/mouse.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_tball_mouse_h
20 | #define gk_tball_mouse_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/trackball.h"
24 |
25 | void
26 | gkTrackballMouseWs(GkMouseEventStruct *event);
27 |
28 | void
29 | gkTrackballMouse(void *sender,
30 | GkScene *scene,
31 | GkMouseButton button,
32 | GkMouseState state,
33 | GkPoint point);
34 |
35 | #endif /* gk_tball_mouse_h */
36 |
--------------------------------------------------------------------------------
/src/tball/tball.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef gk_tball_h
20 | #define gk_tball_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/trackball.h"
24 | #include "../../include/gk/geom-types.h"
25 |
26 | void
27 | gkTrackballVec(GkTrackball * __restrict tball,
28 | GkPoint p,
29 | vec3 vec);
30 |
31 | #endif /* gk_tball_h */
32 |
--------------------------------------------------------------------------------
/src/transp/builtin/oit/weighted_blended.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef transp_weighted_blended_h
20 | #define transp_weighted_blended_h
21 |
22 | #include "../../../../include/gk/gk.h"
23 | #include "../../../../include/gk/pass.h"
24 | #include "../../transp_common.h"
25 |
26 | typedef struct GkTranspWeightedBlended {
27 | GkTranspBase base;
28 | GkPass *opaquePass;
29 | GkPass *transpPass;
30 | GkPass *composPass;
31 | GkPipeline *composProg;
32 | } GkTranspWeightedBlended;
33 |
34 | void
35 | gkTranspWeightedBlendedInit(GkScene * __restrict scene);
36 |
37 | void
38 | gkTranspWeightedBlended(GkScene * __restrict scene);
39 |
40 | #endif /* transp_weighted_blended_h */
41 |
--------------------------------------------------------------------------------
/src/transp/transp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_transp_h
20 | #define src_transp_h
21 |
22 | typedef void (*GkTranspTechnInitFunc)(GkScene * __restrict scene);
23 | typedef void (*GkTranspTechnRenderFunc)(GkScene * __restrict scene);
24 |
25 | #endif /* src_transp_h */
26 |
--------------------------------------------------------------------------------
/src/transp/transp_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_transp_common_h
20 | #define src_transp_common_h
21 |
22 | #include "../../include/gk/gk.h"
23 | #include "../../include/gk/transparent.h"
24 | #include "../../include/gk/prims/builtin-prim.h"
25 |
26 | typedef struct GkTranspBase {
27 | GkTranspTechnType type;
28 | } GkTranspBase;
29 |
30 | _gk_hide
31 | GkRenderPathFn
32 | gkTranpRenderFunc(void);
33 |
34 | #endif /* src_transp_common_h */
35 |
--------------------------------------------------------------------------------
/src/types/impl_camera.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef impl_camera_h
20 | #define impl_camera_h
21 |
22 | #include "../../include/gk/camera.h"
23 |
24 | #include
25 |
26 | typedef struct GkCameraImpl {
27 | GkCamera pub;
28 | uint32_t transfSlot;
29 | float lastZoomDist;
30 | } GkCameraImpl;
31 |
32 | #endif /* impl_camera_h */
33 |
--------------------------------------------------------------------------------
/src/types/impl_node.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef impl_node_h
20 | #define impl_node_h
21 |
22 | #include "../../include/gk/gk.h"
23 |
24 | typedef struct GkNodePage {
25 | struct GkNodePage *next;
26 | uint32_t size;
27 | uint32_t count;
28 | GkNode nodes[];
29 | } GkNodePage;
30 |
31 | #endif /* impl_node_h */
32 |
--------------------------------------------------------------------------------
/src/types/impl_scene.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef impl_scene_h
20 | #define impl_scene_h
21 |
22 | #include "../../include/gk/scene.h"
23 | #include "../../include/gk/node.h"
24 | #include "../../include/gk/animation.h"
25 | #include "impl_node.h"
26 |
27 | #include
28 | #include
29 |
30 | typedef struct GkSceneImpl {
31 | GkScene pub;
32 | struct FListItem *transpPrims;
33 | struct GkLight *forLight;
34 | void *shadows;
35 | void *transp;
36 | struct GkPass *overridePass; /* override all passes */
37 | struct GkMaterial *overrideMaterial; /* override all materials */
38 | FList *transfCacheSlots;
39 |
40 | GkNodePage *nodePages;
41 | GkNodePage *lastPage;
42 | FListItem *anims;
43 |
44 | FListItem *instSkins;
45 | FListItem *instMorphs;
46 | GkPipeline *clearPipeline;
47 | GkRenderAfterClearFunc onClear;
48 | void * onClearObj;
49 |
50 | GkRenderPathFn rp;
51 | GkRenderPathFn renderFunc;
52 | GkRenderPathFn lightIterFunc;
53 | GkRenderPathType rpath;
54 | int32_t internalFormat;
55 | size_t centercount;
56 | float backingScale;
57 | bool transpPass;
58 | } GkSceneImpl;
59 |
60 | #endif /* impl_scene_h */
61 |
--------------------------------------------------------------------------------
/src/value/value_util.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c), Recep Aslantas.
3 | * Full license can be found in the LICENSE file
4 | */
5 |
6 | #include "../common.h"
7 | #include "../../include/gk/value.h"
8 |
9 | GK_EXPORT
10 | void
11 | gkValueLerp(GkValue *from, GkValue *to, float t, GkValue *dest) {
12 | if (dest->rowc == 1) {
13 | dest->val.floatValue = glm_lerp(from->val.floatValue,
14 | to->val.floatValue,
15 | t);
16 | } else {
17 | float *fv, *tv, *dv;
18 | int i;
19 |
20 | if (!dest->val.p)
21 | dest->val.p = malloc(from->itemSize * from->colc * from->rowc);
22 |
23 | fv = from->val.p;
24 | tv = to->val.p;
25 | dv = dest->val.p;
26 |
27 | for (i = 0; i < from->rowc; i++)
28 | dv[i] = glm_lerp(fv[i], tv[i], t);
29 | }
30 |
31 | dest->type = to->type;
32 | }
33 |
34 | GK_EXPORT
35 | void
36 | gkValueCopy(GkValue *src, GkValue *dest) {
37 | if (dest->rowc == 1) {
38 | dest->val.floatValue =src->val.floatValue;
39 | } else {
40 | float *fv, *dv;
41 | int i;
42 |
43 | if (!dest->val.p)
44 | dest->val.p = malloc(src->itemSize * src->colc * src->rowc);
45 |
46 | fv = src->val.p;
47 | dv = dest->val.p;
48 |
49 | for (i = 0; i < src->rowc; i++)
50 | dv[i] = fv[i];
51 | }
52 |
53 | dest->type = src->type;
54 | }
55 |
56 | GK_EXPORT
57 | void
58 | gkValueSub(GkValue *a, GkValue *b, GkValue *dest) {
59 | if (!b || (b->type != GKT_FLOAT && !b->val.p)) {
60 | gkValueCopy(a, dest);
61 | return;
62 | }
63 |
64 | if (dest->rowc == 1) {
65 | dest->val.floatValue = a->val.floatValue - b->val.floatValue;
66 | } else {
67 | float *av, *bv, *dv;
68 | int i;
69 |
70 | if (!dest->val.p)
71 | dest->val.p = malloc(a->itemSize * a->colc * a->rowc);
72 |
73 | av = a->val.p;
74 | bv = b->val.p;
75 | dv = dest->val.p;
76 |
77 | for (i = 0; i < a->rowc; i++)
78 | dv[i] = av[i] - bv[i];
79 | }
80 |
81 | dest->type = a->type;
82 | }
83 |
84 | GK_EXPORT
85 | void
86 | gkVectorSubf(float * __restrict a,
87 | float * __restrict b,
88 | float * __restrict dest,
89 | int count) {
90 | while (count-- > 0)
91 | dest[count] = a[count] - b[count];
92 | }
93 |
94 | GK_EXPORT
95 | void
96 | gkValueFree(GkValue *a) {
97 | if (a->val.p)
98 | free(a->val.p);
99 |
100 | free(a);
101 | }
102 |
--------------------------------------------------------------------------------
/src/vertex.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "common.h"
20 | #include "vertex.h"
21 |
22 | #include "../include/gk/gk.h"
23 | #include "../include/gk/vertex.h"
24 | #include
25 |
26 | #include
27 |
28 | static RBTree *gk__vertAttrShortNames;
29 |
30 | static const size_t gk__vertAttribNamesCount = 13;
31 | static const char *gk__attribNames[] = {
32 | "POSITION",
33 | "NORMAL",
34 | "TEXCOORD",
35 | "TEXCOORD0", "TEXCOORD1", "TEXCOORD2", "TEXCOORD3", "TEXCOORD4",
36 | "TEXCOORD5", "TEXCOORD6", "TEXCOORD7", "TEXCOORD8", "TEXCOORD9"
37 | };
38 |
39 | static const char *gk_attribShortNames[] = {
40 | "P", "N",
41 | "T0", "T0", "T1", "T2", "T3", "T4", "T5", "T6", "T7", "T8", "T9"
42 | };
43 |
44 | GK_EXPORT
45 | const char*
46 | gkShortNameOfVertexInput(const char *name) {
47 | return rb_find(gk__vertAttrShortNames, (void *)name);
48 | }
49 |
50 | GK_EXPORT
51 | const char*
52 | gkSetShortNameOfVertexInput(const char *name, const char *shortName) {
53 | return rb_find(gk__vertAttrShortNames,
54 | strdup(shortName));
55 | }
56 |
57 | void
58 | gk_verta_init() {
59 | int32_t i;
60 |
61 | gk__vertAttrShortNames = rb_newtree_str();
62 |
63 | for (i = 0; i < gk__vertAttribNamesCount; i++) {
64 | rb_insert(gk__vertAttrShortNames,
65 | (void *)gk__attribNames[i],
66 | (void *)gk_attribShortNames[i]);
67 | }
68 | }
69 |
70 | void
71 | gk_verta_deinit() {
72 | rb_destroy(gk__vertAttrShortNames);
73 | }
74 |
--------------------------------------------------------------------------------
/src/vertex.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the gk project (https://github.com/recp/gk)
3 | * Copyright (c) Recep Aslantas.
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #ifndef src_vertex_h
20 | #define src_vertex_h
21 |
22 | void
23 | gk_verta_init(void);
24 |
25 | void
26 | gk_verta_deinit(void);
27 |
28 | #endif /* src_vertex_h */
29 |
--------------------------------------------------------------------------------