summaryrefslogtreecommitdiff
path: root/Source/modules/asura-framework/scripts/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'Source/modules/asura-framework/scripts/graphics')
-rw-r--r--Source/modules/asura-framework/scripts/graphics/animation.lua15
-rw-r--r--Source/modules/asura-framework/scripts/graphics/animator.lua33
-rw-r--r--Source/modules/asura-framework/scripts/graphics/camera.lua21
-rw-r--r--Source/modules/asura-framework/scripts/graphics/canvas.lua34
-rw-r--r--Source/modules/asura-framework/scripts/graphics/default_shaders.lua5
-rw-r--r--Source/modules/asura-framework/scripts/graphics/image.lua40
-rw-r--r--Source/modules/asura-framework/scripts/graphics/material.lua48
-rw-r--r--Source/modules/asura-framework/scripts/graphics/material_manager.lua3
-rw-r--r--Source/modules/asura-framework/scripts/graphics/mesh2d.lua9
-rw-r--r--Source/modules/asura-framework/scripts/graphics/mesh2d_renderer.lua13
-rw-r--r--Source/modules/asura-framework/scripts/graphics/particle_system.lua20
-rw-r--r--Source/modules/asura-framework/scripts/graphics/renderer.lua19
-rw-r--r--Source/modules/asura-framework/scripts/graphics/shader.lua75
-rw-r--r--Source/modules/asura-framework/scripts/graphics/shaderHelper.lua14
-rw-r--r--Source/modules/asura-framework/scripts/graphics/shape.lua12
-rw-r--r--Source/modules/asura-framework/scripts/graphics/shape_renderer.lua13
-rw-r--r--Source/modules/asura-framework/scripts/graphics/sprite.lua10
-rw-r--r--Source/modules/asura-framework/scripts/graphics/sprite_batch_renderer.lua9
-rw-r--r--Source/modules/asura-framework/scripts/graphics/sprite_renderer.lua17
19 files changed, 410 insertions, 0 deletions
diff --git a/Source/modules/asura-framework/scripts/graphics/animation.lua b/Source/modules/asura-framework/scripts/graphics/animation.lua
new file mode 100644
index 0000000..285adaa
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/animation.lua
@@ -0,0 +1,15 @@
+AsuraEngine.Animation = AsuraEngine.Asset.Extend("Animation")
+
+local Animation = AsuraEngine.Animation
+
+local Frame = AsuraEngine.Class("Frame")
+
+function Frame.Ctor(self)
+
+end
+
+function Animation.Ctor(self)
+
+end
+
+return Animation \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/animator.lua b/Source/modules/asura-framework/scripts/graphics/animator.lua
new file mode 100644
index 0000000..fd2f979
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/animator.lua
@@ -0,0 +1,33 @@
+local Component = AsuraEngine.Framework.Require("component")
+
+AsuraEngine.Animator = Component.Extend("Animator")
+
+local Animator = AsuraEngine.Animator
+
+-- Animator inspector variables.
+Animator.spriteRenderer = AsuraEngine.Type.SpriteRenderer
+Animator.animation = AsuraEngine.Type.Animation
+
+function Animator:Ctor(entity, animation)
+ self.base(entity)
+ self.spriteRenderer = entity:GetSpriteRenderer()
+ self.animation = animation
+end
+
+function Animator:SetAnimation(animation)
+ self.animation = animation
+end
+
+function Animator:GetAnimation()
+ return self.animation
+end
+
+function Animator:OnUpdate(dt)
+
+end
+
+function Animator:OnRender()
+
+end
+
+return Animator \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/camera.lua b/Source/modules/asura-framework/scripts/graphics/camera.lua
new file mode 100644
index 0000000..a989de6
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/camera.lua
@@ -0,0 +1,21 @@
+AsuraEngine.Camera = AsuraEngine.Component.Extend("Camera")
+
+local Camera = AsuraEngine.Camera
+
+Camera.isCulling = AsuraEngine.Type.Bool
+Camera.isOnScreen = AsuraEngine.Type.Bool
+
+function Camera.Ctor(self)
+ self.isCulling = false
+ self.isOnScreen = false
+end
+
+function Camera.OnUpdate(dt)
+
+end
+
+function Camera.OnRender()
+
+end
+
+return Camera \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/canvas.lua b/Source/modules/asura-framework/scripts/graphics/canvas.lua
new file mode 100644
index 0000000..ce2ca20
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/canvas.lua
@@ -0,0 +1,34 @@
+AsuraEngine.Canvas = AsuraEngine.Component.Extend("Canvas")
+
+local Canvas = AsuraEngine.Canvas
+
+function Canvas.Ctor(self, width, height)
+ self.simCanvas = AsuraEngine.SimCanvas.New(width, height)
+ self.width = width
+ self.height = height
+end
+
+function Canvas.GetWidth(self)
+ return self.width
+end
+
+function Canvas.GetHeight(self)
+ return self.height
+end
+
+function Canvas.GetSize(self)
+ return self.width, self.height
+end
+
+function Canvas.OnEnable(self)
+ if self.simCanvas == nil then
+ return
+ end
+ self.simCanvas:Begin()
+end
+
+function Canvas.OnDisable(self)
+
+end
+
+return Canvas \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/default_shaders.lua b/Source/modules/asura-framework/scripts/graphics/default_shaders.lua
new file mode 100644
index 0000000..bd54cb9
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/default_shaders.lua
@@ -0,0 +1,5 @@
+--[[
+õshaders.
+]]
+
+
diff --git a/Source/modules/asura-framework/scripts/graphics/image.lua b/Source/modules/asura-framework/scripts/graphics/image.lua
new file mode 100644
index 0000000..f5ebaa2
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/image.lua
@@ -0,0 +1,40 @@
+-- 图片资源
+AsuraEngine.Image = AsuraEngine.Asset.Extend("Image")
+
+local Image = AsuraEngine.Image
+
+function Image.Ctor(self, path)
+ local simImage = AsuraEngine.SimImage.New(path)
+ local w, h = simImage:GetSize()
+ self.simImage = simImage
+ self.width = w
+ self.height = h
+end
+
+function Image.GetWidth(self)
+ return self.simImage.GetWidth()
+end
+
+function Image.GetHeight(self)
+ return self.simImage.GetHeight()
+end
+
+function Image.GetSize(self)
+ return self.simImage.GetSize()
+end
+
+--获得x,y位置的颜色值
+function Image.GetColor(self, x, y)
+ return self.simImage.GetColor(x, y)
+end
+
+--获得所有像素,返回到一个table里
+function Image.GetPixels(self)
+ return self.simImage:GetPixels()
+end
+
+--image不可再编辑器编辑,所以没有ToAsset方法
+--function Image.ToAsset()
+--end
+
+return Image \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/material.lua b/Source/modules/asura-framework/scripts/graphics/material.lua
new file mode 100644
index 0000000..032c913
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/material.lua
@@ -0,0 +1,48 @@
+--material是shader的代理啊,保存对shader uniforms的设置
+AsuraEngine.Material = AsuraEngine.Asset.Extend("Material")
+
+local Material = AsuraEngine.Material
+
+function Material.Ctor(self)
+ self.uniforms = {} --uniform变量和值
+ self.shader = nil
+ self.isShared = false
+end
+
+function Material.Clone(self)
+
+end
+
+function Material:ToAsset()
+
+end
+
+function Material:GetUniform(name)
+
+end
+
+function Material:SetFloat(uniform, value)
+
+end
+
+function Material:SetTexture(uniform, tex)
+
+end
+
+function Material:SetInteger(unifrom, value)
+
+end
+
+function Material:SetVec2(uniform, value)
+
+end
+
+function Material:SetMat44(uniform, value)
+
+end
+
+function Material:GetUniformID()
+
+end
+
+return Material \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/material_manager.lua b/Source/modules/asura-framework/scripts/graphics/material_manager.lua
new file mode 100644
index 0000000..086a5db
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/material_manager.lua
@@ -0,0 +1,3 @@
+local MaterialManager = AsuraEngine.Manager.New()
+
+return MaterialManager \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/mesh2d.lua b/Source/modules/asura-framework/scripts/graphics/mesh2d.lua
new file mode 100644
index 0000000..05b2e2e
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/mesh2d.lua
@@ -0,0 +1,9 @@
+AsuraEngine.Mesh2D = AsuraEngine.Asset.Extend("Mesh2D")
+
+local Mesh2D = AsuraEngine.Mesh2D
+
+function Mesh2D.Ctor(self)
+
+end
+
+return Mesh2D \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/mesh2d_renderer.lua b/Source/modules/asura-framework/scripts/graphics/mesh2d_renderer.lua
new file mode 100644
index 0000000..09c8c98
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/mesh2d_renderer.lua
@@ -0,0 +1,13 @@
+AsuraEngine.Mesh2DRenderer = AsuraEngine.Renderer.Extend("Mesh2DRenderer")
+
+local Mesh2DRenderer = AsuraEngine.Mesh2DRenderer
+
+function Mesh2DRenderer.Ctor(self, material)
+ self.base(material)
+end
+
+function Mesh2DRenderer.OnRender(self)
+
+end
+
+return Mesh2DRenderer \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/particle_system.lua b/Source/modules/asura-framework/scripts/graphics/particle_system.lua
new file mode 100644
index 0000000..065a845
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/particle_system.lua
@@ -0,0 +1,20 @@
+require "graphics.sprite_renderer"
+
+AsuraEngine.ParticleSystem = AsuraEngine.Component.Extend("ParticleSystem")
+
+local ParticleSystem = AsuraEngine.ParticleSystem
+
+function ParticleSystem.Ctor(self, entity, def)
+ self.base(entity)
+ self.spriteRenderer = AsuraEngine.SpriteRenderer.New()
+end
+
+function ParticleSystem.OnRenderer()
+
+end
+
+function ParticleSystem.OnUpdate(dt)
+
+end
+
+return ParticleSystem \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/renderer.lua b/Source/modules/asura-framework/scripts/graphics/renderer.lua
new file mode 100644
index 0000000..92a6409
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/renderer.lua
@@ -0,0 +1,19 @@
+local Renderer = AsuraEngine.Component.Extend("Renderer")
+AsuraEngine.Renderer = Renderer
+
+function Renderer.Ctor(self)
+ self.materials = {}
+ self.material = nil
+ self.isMultiMaterials = false
+end
+
+--取材质,如果是shared,那么从此材质clone一个
+function Renderer.GetMaterial(self)
+
+end
+
+function Renderer.IsMultiMaterials(self)
+ return self.isMultiMaterials
+end
+
+return Renderer \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/shader.lua b/Source/modules/asura-framework/scripts/graphics/shader.lua
new file mode 100644
index 0000000..c411619
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/shader.lua
@@ -0,0 +1,75 @@
+AsuraEngine.Shader = AsuraEngine.Asset.Extend("Shader")
+
+local helper = AsuraEngine.Framework.Require("graphics/shaderHelper")
+
+local Shader = AsuraEngine.Shader
+
+function Shader.Ctor(self)
+ self.simShader = nil
+ self.uniforms = {} -- 映射uniform name到location
+end
+
+--编译shader
+function Shader.Load(self, vert, frag)
+ self.uniforms = {}
+ if self.simShader == nil then
+ self.simShader = AsuraEngine.SimShader.New(vert, frag)
+ else
+ self.simShader:Load(vert, frag)
+ end
+ if self.simShader == nil then
+ --shader编译错误
+ return
+ end
+ --在编译的时候就获得所有的uniform和loc
+ local uniforms = helper.GetUniforms(vert, frag)
+ if uniforms == nil then
+ return
+ end
+ for _, uniform in uniforms do
+ self.uniforms[uniform] = self.simShader:GetUniformLocation(uniform)
+ end
+end
+
+function Shader.GetUniformLocation(self, name)
+ if self.uniforms then
+ local id = self.uniforms[name]
+ return id
+ end
+ return 0
+end
+
+function Shader.SendVec2(self, name, vec2)
+ local id = self:GetUniformLocation(name)
+ self.simShader:SendUniformVector2(name, vec2)
+end
+
+function Shader.SendVec3(self, name, vec3)
+
+end
+
+function Shader.SendVec4(self, name, vec4)
+
+end
+
+function Shader.SendTexture(self, name, tex)
+
+end
+
+function Shader.SendFloat(self, name, number)
+
+end
+
+function Shader.SendInteger(self, name, integer)
+
+end
+
+function Shader.SendColor(self, name, color)
+
+end
+
+function Shader.SendMat44(self, name, mat44)
+
+end
+
+return Shader \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/shaderHelper.lua b/Source/modules/asura-framework/scripts/graphics/shaderHelper.lua
new file mode 100644
index 0000000..b1b42a6
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/shaderHelper.lua
@@ -0,0 +1,14 @@
+--[[
+解析vertex shader和 fragment shader,并取得两个shader里面定义的uniforms
+]]
+local helper = {}
+
+function helper.GetUniforms(vert, frag)
+
+end
+
+function helper.TryCompileShader(vert, frag)
+
+end
+
+return helper \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/shape.lua b/Source/modules/asura-framework/scripts/graphics/shape.lua
new file mode 100644
index 0000000..51ea8c3
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/shape.lua
@@ -0,0 +1,12 @@
+--
+-- 2D图形
+--
+AsuraEngine.Shape = AsuraEngine.Asset.Extend("Shape")
+
+local Shape = AsuraEngine.Shape
+
+function Shape.Ctor(self)
+
+end
+
+return Shape \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/shape_renderer.lua b/Source/modules/asura-framework/scripts/graphics/shape_renderer.lua
new file mode 100644
index 0000000..80b48b8
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/shape_renderer.lua
@@ -0,0 +1,13 @@
+AsuraEngine.ShapeRenderer = AsuraEngine.Component.Extend("ShapeRenderer")
+
+local ShapeRenderer = AsuraEngine.ShapeRenderer
+
+function ShapeRenderer.OnRenderer()
+
+end
+
+function ShapeRenderer.OnUpdate(dt)
+
+end
+
+return ShapeRenderer \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/sprite.lua b/Source/modules/asura-framework/scripts/graphics/sprite.lua
new file mode 100644
index 0000000..9bf05f4
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/sprite.lua
@@ -0,0 +1,10 @@
+local Sprite = AsuraEngine.Asset.Extend("Sprite")
+AsuraEngine.Sprite = Sprite
+
+function Sprite.Ctor(self, image)
+ self.image = image
+end
+
+function Sprite.ToAsset(self)
+
+end \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/sprite_batch_renderer.lua b/Source/modules/asura-framework/scripts/graphics/sprite_batch_renderer.lua
new file mode 100644
index 0000000..9ec73d2
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/sprite_batch_renderer.lua
@@ -0,0 +1,9 @@
+AsuraEngine.SpriteBatchRenderer = AsuraEngine.Component.Extend("SpriteBatchRenderer")
+
+local SpriteBatchRenderer = AsuraEngine.SpriteBatchRenderer
+
+function SpriteBatchRenderer.Ctor(self)
+
+end
+
+return SpriteBatchRenderer \ No newline at end of file
diff --git a/Source/modules/asura-framework/scripts/graphics/sprite_renderer.lua b/Source/modules/asura-framework/scripts/graphics/sprite_renderer.lua
new file mode 100644
index 0000000..cdf4901
--- /dev/null
+++ b/Source/modules/asura-framework/scripts/graphics/sprite_renderer.lua
@@ -0,0 +1,17 @@
+require "graphics.renderer"
+
+-- ֻrenderersлᴴvertex bufferindex bufferһobject û
+-- rendererûбҪGPU
+
+local SpriteRenderer = AsuraEngine.Renderer.Extend("Spriterenderer")
+AsuraEngine.SpriteRenderer = SpriteRenderer
+
+function SpriteRenderer.Ctor(self)
+ self.materials = {}
+end
+
+function SpriteRenderer:OnRender()
+
+end
+
+return SpriteRenderer \ No newline at end of file