Worklog for DavidSimon
A.B.E ( Alpha.Beta.Engine )
Return to Worklogs
| ||
With news that BlitzMax finally has the most wonderful of wonderful
things, Threading support, I begun work on my first BlitzMax Project in a
while(I had moved onto to C#/XNA years ago, dabbling with max here and
there) That project is, (Drumroll) A.B.E - My attempt at a multi-threaded, dare I say it, advanced, software 3D Engine. What is a software 3D Engine? Answer:It's like a hardware 3D Engine, only it performs all rendering calculations on the cpu, meaning even it's most beautiful of beautiful fx, will work on even the lowest of low gpus. Why for blitz? Why now? Why not? --- Just to give a taste of it, here is a code excerpt from today's coding. it's very early in so i'm not giving anything away. anyone could do this in a couple of hours, but you can at least see where it is heading. not all code is included. [code] [/code' '--[ Alpha.Beta.Engine ]--(or ABE for short.) ' '(c)TechniColor DreamCode 2008 ' ' ' SuperStrict Framework Brl.glmax2d Import brl.max2d Import brl.polledinput Import pub.freejoy Import brl.random Import brl.audio Import brl.glmax2d Import brl.retro Import pub.opengl Import pub.threads Import "aMaths.bmx" Include "aThreading.bmx" Type Vertex Field Pos:Vector3 Field Normal:Vector3 Field Tangent:Vector3 Field BiNormal:Vector3 Field TexCoord0:Vector3 Field TexCoord1:Vector3 Field Color:Vector4 Function CreateCoord:Vertex(x:Float,y:Float,z:Float,u:Float,v:Float,w:Float = 0) Local r:Vertex = New Vertex r.Pos = Vector3.Create(x,y,z) r.TexCoord0 = Vector3.Create(u,v,w) r.TexCoord1 = Vector3.Zero r.BiNormal = Vector3.Zero r.Tangent = Vector3.Zero r.Normal = Vector3.Zero r.Color = Vector4.One Return r End Function End Type Type Triangle Field v0:Int,v1:Int,v2:Int Function Create:Triangle(v0%,v1%,v2%) Local r:Triangle = New Triangle r.v0 = v0;r.v1 = v1;r.v2 = v2 Return r End Function End Type Type ModelSurface Field mVertices:TList = CreateList() Field mIndices:TList = CreateList() Field mLock:AMutex = New AMutex Method AddVertex:Int(v:Vertex) mVertices.AddLast(v) Return mVertices.Count()-1 End Method Method AddTriangle(t:Triangle) mIndices.addLast( t ) End Method End Type Type Model Extends Entity Field mSurfaces:TList = CreateList() End Type Type Entity End Type Type ModelFactory Function Quad:Model(w:Float,h:Float) Local m:Model = New Model Local s:ModelSurface = New ModelSurface m.mSurfaces.AddLast( s ) Local v0:Vertex,v1:Vertex,v2:Vertex,v3:Vertex v0 = Vertex.CreateCoord( -w,-h,0,0,0) v1 = Vertex.CreateCoord( w,-h,0,1,0) v2 = Vertex.CreateCoord( w,h,0,1,1) v3 = Vertex.CreateCoord( -w,h,0,0,1 ) s.AddVertex( v0 ) s.AddVertex( v1 ) s.AddVertex( v2 ) s.AddVertex( v3 ) s.AddTriangle( Triangle.Create(0,1,2) ) s.AddTriangle( Triangle.Create(2,3,0) ) Return m End Function End Type Type Viewport Field X:Float Field Y:Float Field Width:Float Field Height:Float Field Near:Float,Far:Float Field Aspect# Function Create:Viewport(x:Float,y:Float,w:Float,h:Float,far:Float = 1000) Local r:Viewport = New Viewport r.Init(x,y,w,h,1,far) Return r End Function Method Init(xv#,yv#,wv#,hv#,nearv#,farv#) x = xv;y=yv width=wv;height=hv; aspect = width/height near = nearv;far = farv End Method Field ProjX# Field ProjY# Method Project(xv#,yv#,zv#) ProjX = xv*Far/zv; ProjY = y*Far/zv; ProjX = ProjX + width/2.0; ProjY = ProjY*aspect + height/2.0; End Method End Type Type DataBufferObject Field mBytes:Byte Ptr Field mSize:Int Method Delete() MemFree mbytes End Method Method CreateBuffer(bytes:Int) mBytes = MemAlloc(bytes) mSize = bytes End Method Method FillBuffer( dat:Byte Ptr,size:Int ) Local index:Int = 0 Local findex:Int = 0 While index<mSize mBytes[index]=dat[findex] findex:+1 If findex=size findex=0 EndIf index:+1 Wend End Method End Type Type Color Field r%,g%,b%,a% Function Create:Color(r%,g%,b%,a%) Local ret:Color = New color ret.r = r ret.g = g ret.b = b ret.a = a Return ret End Function End Type Type DepthBuffer Extends DataBufferObject Function Create:DepthBuffer(w%,h%) Local r:DepthBuffer = New DepthBuffer r.CreateBuffer(w*h) Return r End Function End Type Type GraphicsBuffer Extends DataBufferObject Field mHasAlpha:Int = False Field mDepthMap:DepthBuffer = Null Function Create:GraphicsBuffer(w%,h%,alpha:Int=True,isPrimary:Int=False) Local r:GraphicsBuffer = New GraphicsBuffer If alpha r.CreateBuffer(w*h*4) r.mHasAlpha = True Else r.createBuffer(w*h*3) EndIf If isPrimary r.mDepthMap = DepthBuffer.Create(w,h) End If Return r End Function Method Clear(ClrCol:Color,clearDepth:Int = True) Local buf:Byte Ptr = MemAlloc(4) buf[0] = clrcol.r buf[1] = clrcol.g buf[2] = clrcol.b buf[3] = clrcol.a FillBuffer( buf,4 ) End Method End Type Type GraphicDevice Function Create:GraphicDevice(w:Int,h:Int,full:Int=False) Local r:GraphicDevice = New Graphicdevice SetGraphicsDriver GLMax2DDriver() Graphics(w,h,0) Return r End Function End Type Local device:GraphicDevice = GraphicDevice.Create(512,512,False) While Not KeyDown(Key_Escape) Wend |