Skip to content

Commit

Permalink
Added graphics classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
codescapade committed Sep 12, 2024
1 parent 3c22867 commit 57f5750
Show file tree
Hide file tree
Showing 20 changed files with 2,780 additions and 5 deletions.
17 changes: 17 additions & 0 deletions build/Build.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,33 @@ import jume.events.FocusEvent;
import jume.events.ResizeEvent;
// graphics
import jume.graphics.Color;
import jume.graphics.DefaultShaders;
import jume.graphics.Graphics;
import jume.graphics.Image;
import jume.graphics.Pipeline;
import jume.graphics.RenderTarget;
import jume.graphics.Shader;
import jume.graphics.ShaderType;
// graphics.animation
import jume.graphics.animation.Animation;
import jume.graphics.animation.AnimationMode;
// graphics.atlas
import jume.graphics.atlas.Atlas;
import jume.graphics.atlas.AtlasFrame;
// graphics.bitmapFont
import jume.graphics.bitmapFont.BitmapFont;
import jume.graphics.bitmapFont.FontData;
// graphics.gl
import jume.graphics.gl.BlendMode;
import jume.graphics.gl.BlendOperation;
import jume.graphics.gl.Context;
import jume.graphics.gl.MipmapFilter;
import jume.graphics.gl.TextureFilter;
import jume.graphics.gl.TextureWrap;
// graphics.renderers
import jume.graphics.renderers.BaseRenderer;
import jume.graphics.renderers.ImageRenderer;
import jume.graphics.renderers.ShapeRenderer;
// math
import jume.math.Mat4;
import jume.math.MathUtils;
Expand Down
2 changes: 1 addition & 1 deletion checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"type": "ParameterNumber",
"props": {
"severity": "WARNING",
"max": 4,
"max": 5,
"ignoreOverriddenMethods": false
}
},
Expand Down
121 changes: 121 additions & 0 deletions src/jume/graphics/DefaultShaders.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package jume.graphics;

/**
* These are the default shape and image shaders.
*/
class DefaultShaders {
public static inline function shapeVert(gl1: Bool): String {
return gl1 ? SHAPE_VERT_GL1 : SHAPE_VERT;
}

public static inline function shapeFrag(gl1: Bool): String {
return gl1 ? SHAPE_FRAG_GL1 : SHAPE_FRAG;
}

public static inline function imageVert(gl1: Bool): String {
return gl1 ? IMAGE_VERT_GL1 : IMAGE_VERT;
}

public static inline function imageFrag(gl1: Bool): String {
return gl1 ? IMAGE_FRAG_GL1 : IMAGE_FRAG;
}

static final SHAPE_VERT = [
'#version 300 es',
'in vec3 vertexPosition;',
'in vec4 vertexColor;',
'uniform mat4 projectionMatrix;',
'out vec4 fragmentColor;',
'void main() {',
' gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);',
' fragmentColor = vertexColor;',
'}',
].join('\n');

static final SHAPE_FRAG = [
'#version 300 es',
'precision mediump float;',
'in vec4 fragmentColor;',
'out vec4 FragColor;',
'void main() {',
' FragColor = fragmentColor;',
'}',
].join('\n');

static final SHAPE_VERT_GL1 = [
'#version 100',
'attribute vec3 vertexPosition;',
'attribute vec4 vertexColor;',
'uniform mat4 projectionMatrix;',
'varying vec4 fragColor;',
'void main() {',
' gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);',
' fragColor = vertexColor;',
'}',
].join('\n');

static final SHAPE_FRAG_GL1 = [
'#version 100',
'precision mediump float;',
'varying vec4 fragColor;',
'void main() {',
' gl_FragColor = fragColor;',
'}',
].join('\n');

static final IMAGE_VERT = [
'#version 300 es',
'in vec3 vertexPosition;',
'in vec4 vertexColor;',
'in vec2 vertexUV;',
'uniform mat4 projectionMatrix;',
'out vec2 fragUV;',
'out vec4 fragColor;',
'void main() {',
' gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);',
' fragUV = vertexUV;',
' fragColor = vertexColor;',
'}',
].join('\n');

static final IMAGE_FRAG = [
'#version 300 es',
'precision mediump float;',
'uniform sampler2D tex;',
'in vec2 fragUV;',
'in vec4 fragColor;',
'out vec4 FragColor;',
'void main() {',
' vec4 texcolor = texture(tex, fragUV) * fragColor;',
' texcolor.rgb *= fragColor.a;',
' FragColor = texcolor;',
'}',
].join('\n');

static final IMAGE_VERT_GL1 = [
'#version 100',
'attribute vec3 vertexPosition;',
'attribute vec4 vertexColor;',
'attribute vec2 vertexUV;',
'uniform mat4 projectionMatrix;',
'varying vec4 fragColor;',
'varying vec2 fragUV;',
'void main() {',
' gl_Position = projectionMatrix * vec4(vertexPosition, 1.0);',
' fragColor = vertexColor;',
' fragUV = vertexUV;',
'}',
].join('\n');

static final IMAGE_FRAG_GL1 = [
'#version 100',
'uniform sampler2D tex;',
'varying vec4 fragColor;',
'varying vec2 fragUV;',
'void main() {',
' vec4 texColor = texture2D(tex, fragUV) * fragColor;',
' texColor.rgb *= fragColor.a;',
' gl_FragColor = texColor;',
'}',
].join('\n');
}
Loading

0 comments on commit 57f5750

Please sign in to comment.