[Agate-svn-commit] SF.net SVN: agate:[930] branches/agate3d-3.2
Status: Alpha
Brought to you by:
kanato
|
From: <ka...@us...> - 2009-05-01 07:34:25
|
Revision: 930
http://agate.svn.sourceforge.net/agate/?rev=930&view=rev
Author: kanato
Date: 2009-05-01 07:34:20 +0000 (Fri, 01 May 2009)
Log Message:
-----------
Update AgateMDX with vertex/index buffer support. Not working right yet.
Modified Paths:
--------------
branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs
branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs
branches/agate3d-3.2/Tests/Display3D/Matrices.cs
Added Paths:
-----------
branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
Modified: branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/AgateLib/DisplayLib/IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -17,13 +17,63 @@
public void WriteIndices(short[] indices)
{
+ if (impl.IndexType == IndexBufferType.Int32)
+ {
+ WriteIndices(ConvertToInt32(indices));
+ return;
+ }
+
impl.WriteIndices(indices);
}
public void WriteIndices(int[] indices)
{
+ if (impl.IndexType == IndexBufferType.Int16)
+ {
+ WriteIndices(ConvertToInt16(indices));
+ return;
+ }
+
impl.WriteIndices(indices);
}
+ private short[] ConvertToInt16(int[] indices)
+ {
+ short[] retval = new short[indices.Length];
+
+ int i = 0;
+
+ try
+ {
+ checked
+ {
+ for (i = 0; i < retval.Length; i++)
+ {
+ retval[i] = (short)indices[i];
+ }
+ }
+ }
+ catch (OverflowException ex)
+ {
+ throw new AgateLib.AgateException(ex, string.Format(
+ "A 16 bit index buffer cannot contain values greater than {0}, " +
+ "but there is a value of {1} at index {2}.",
+ short.MaxValue, indices[i], i));
+ }
+
+ return retval;
+ }
+ private int[] ConvertToInt32(short[] indices)
+ {
+ int[] retval = new int[indices.Length];
+
+ for (int i = 0; i < retval.Length; i++)
+ {
+ retval[i] = (short)indices[i];
+ }
+
+ return retval;
+ }
+
public int Count
{
get { return impl.Count; }
Modified: branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/D3DDevice.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -32,7 +32,7 @@
public class D3DDevice : IDisposable
{
private Device mDevice;
- private Texture mLastTexture;
+ private Texture[] mLastTexture = new Texture[8];
private MDX1_IRenderTarget mRenderTarget;
private DrawBuffer mDrawBuffer;
@@ -46,6 +46,7 @@
private int mMaxLightsUsed = 0;
+
//VertexBuffer mSurfaceVB;
//const int NumVertices = 1000;
//int mSurfaceVBPointer = 0;
@@ -256,13 +257,16 @@
public void SetDeviceStateTexture(Texture texture)
{
-
- if (texture == mLastTexture)
+ SetDeviceStateTexture(texture, 0);
+ }
+ public void SetDeviceStateTexture(Texture texture, int index)
+ {
+ if (texture == mLastTexture[index])
return;
- mDevice.SetTexture(0, texture);
+ mDevice.SetTexture(index, texture);
- mLastTexture = texture;
+ mLastTexture[index] = texture;
if (texture != null)
{
@@ -349,7 +353,7 @@
mDevice.RenderState.AmbientMaterialSource = ColorSource.Color1;
mDevice.RenderState.AmbientColor = lights.Ambient.ToArgb();
-
+
//Material mat = new Material();
//mat.Diffuse = System.Drawing.Color.White;
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Display.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -53,6 +53,10 @@
private bool mVSync = true;
+ private bool mHasDepth , mHasStencil;
+ private float mDepthClear = 0;
+ private int mStencilClear = 0;
+
#endregion
#region --- Creation / Destruction ---
@@ -96,20 +100,55 @@
if (caps.DeviceCaps.SupportsPureDevice)
flags |= Direct3D.CreateFlags.PureDevice;
- Device device = new Device
- (0, dtype, window.RenderTarget.TopLevelControl.Handle,
- flags, present);
+ Device device = new Device(0, dtype,
+ window.RenderTarget.TopLevelControl.Handle,
+ flags, present);
+ try
+ {
+ DepthFormat f = (DepthFormat)device.DepthStencilSurface.Description.Format;
+ SetHaveDepthStencil(f);
+ }
+ catch
+ {
+ mHasDepth = false;
+ mHasStencil = false;
+ }
+
device.DeviceLost += new EventHandler(mDevice_DeviceLost);
device.DeviceReset += new EventHandler(mDevice_DeviceReset);
mDevice = new D3DDevice(device);
+
// create primitive objects
mLine = new Direct3D.Line(device);
- //CreateSurfaceVB();
+ }
+ private void SetHaveDepthStencil(DepthFormat depthFormat)
+ {
+ switch (depthFormat)
+ {
+ case DepthFormat.D24X4S4:
+ case DepthFormat.D24S8:
+ case DepthFormat.D15S1:
+ mHasStencil = true;
+ mHasDepth = true;
+ break;
+
+ case DepthFormat.D24X8:
+ case DepthFormat.D32:
+ case DepthFormat.D16:
+ mHasStencil = false;
+ mHasDepth = true;
+ break;
+
+ default:
+ mHasDepth = false;
+ mHasStencil = false;
+ break;
+ }
}
public override void Dispose()
@@ -195,15 +234,6 @@
#region --- Creation of objects ---
- //public override DisplayWindowImpl CreateDisplayWindow(string title, int clientWidth, int clientHeight,
- // string iconFile, bool startFullScreen, bool allowResize)
- //{
- // return new MDX1_DisplayWindow(title, clientWidth, clientHeight, iconFile, startFullScreen, allowResize);
- //}
- //public override DisplayWindowImpl CreateDisplayWindow(System.Windows.Forms.Control renderTarget)
- //{
- // return new MDX1_DisplayWindow(renderTarget);
- //}
public override DisplayWindowImpl CreateDisplayWindow(CreateWindowParams windowParams)
{
return new MDX1_DisplayWindow(windowParams);
@@ -252,12 +282,10 @@
while (mClipRects.Count > 0)
PopClipRect();
-
mRenderTarget.EndRender();
}
-
#endregion
#region --- Clip Rect stuff ---
@@ -295,6 +323,9 @@
mDevice.Device.Viewport = view;
mCurrentClipRect = newClipRect;
+
+ mDevice.Device.RenderState.StencilEnable = false;
+ mDevice.Device.RenderState.ZBufferEnable = false;
SetOrthoProjection(newClipRect);
}
@@ -307,9 +338,7 @@
{
if (mClipRects.Count == 0)
{
-#if DEBUG
throw new Exception("You have popped the cliprect too many times.");
-#endif
}
else
{
@@ -323,11 +352,23 @@
#endregion
#region --- Methods for drawing to the back buffer ---
+ ClearFlags ClearFlags
+ {
+ get
+ {
+ ClearFlags retval = ClearFlags.Target;
+
+ if (mHasDepth) retval |= ClearFlags.ZBuffer;
+ if (mHasStencil) retval |= ClearFlags.Stencil;
+
+ return retval;
+ }
+ }
public override void Clear(Color color)
{
mDevice.DrawBuffer.Flush();
- mDevice.Clear(ClearFlags.Target, color.ToArgb(), 1.0f, 0);
+ mDevice.Clear(ClearFlags, color.ToArgb(), mDepthClear, mStencilClear);
}
public override void Clear(Color color, Rectangle rect)
{
@@ -336,7 +377,7 @@
System.Drawing.Rectangle[] rects = new System.Drawing.Rectangle[1];
rects[0] = Interop.Convert(rect);
- mDevice.Clear(ClearFlags.Target, color.ToArgb(), 1.0f, 0, rects);
+ mDevice.Clear(ClearFlags, color.ToArgb(), mDepthClear, mStencilClear, rects);
}
@@ -504,22 +545,12 @@
private PresentParameters CreateFullScreenPresentParameters(MDX1_DisplayWindow displayWindow,
int width, int height, int bpp)
{
- PresentParameters present = new PresentParameters();
+ PresentParameters present = CreateBasePresentParams(displayWindow);
- present.AutoDepthStencilFormat = DepthFormat.Unknown;
- present.EnableAutoDepthStencil = false;
- present.DeviceWindowHandle = displayWindow.RenderTarget.Handle;
- present.BackBufferWidth = width;
- present.BackBufferHeight = height;
present.SwapEffect = SwapEffect.Flip;
present.Windowed = false;
present.PresentFlag = PresentFlag.None;
- if (VSync)
- present.PresentationInterval = PresentInterval.Default;
- else
- present.PresentationInterval = PresentInterval.Immediate;
-
SelectBestDisplayMode(present, bpp);
return present;
@@ -528,16 +559,23 @@
private PresentParameters CreateWindowedPresentParameters(MDX1_DisplayWindow displayWindow,
int width, int height)
{
+ PresentParameters present = CreateBasePresentParams(displayWindow);
+
+ return present;
+ }
+
+ private PresentParameters CreateBasePresentParams(MDX1_DisplayWindow displayWindow)
+ {
PresentParameters present = new PresentParameters();
present.BackBufferCount = 1;
- present.AutoDepthStencilFormat = DepthFormat.Unknown;
- present.EnableAutoDepthStencil = false;
+ present.AutoDepthStencilFormat = GetDepthFormat(Format.A8R8G8B8);
+ present.EnableAutoDepthStencil = true;
present.DeviceWindowHandle = displayWindow.RenderTarget.Handle;
- present.BackBufferWidth = width;
- present.BackBufferHeight = height;
+ present.BackBufferWidth = displayWindow.Width;
+ present.BackBufferHeight = displayWindow.Height;
present.BackBufferFormat = Format.Unknown;
- present.SwapEffect = SwapEffect.Copy;
+ present.SwapEffect = SwapEffect.Discard;
present.Windowed = true;
present.PresentFlag = PresentFlag.LockableBackBuffer;
@@ -548,6 +586,52 @@
return present;
}
+ private DepthFormat GetDepthFormat(Format backbufferFormat)
+ {
+ DepthFormat[] formats = new DepthFormat[]
+ {
+ DepthFormat.D24S8,
+ DepthFormat.D24X4S4,
+ DepthFormat.D24X8,
+ DepthFormat.D15S1,
+ DepthFormat.D32,
+ DepthFormat.D16,
+ };
+
+ var adapter = Manager.Adapters.Default.Adapter;
+ Format deviceFormat = GetDeviceFormat(backbufferFormat);
+
+ foreach (var f in formats)
+ {
+ if (Manager.CheckDeviceFormat(adapter, DeviceType.Hardware, deviceFormat,
+ Usage.DepthStencil, ResourceType.Surface, f) == false)
+ {
+ continue;
+ }
+ if (Manager.CheckDepthStencilMatch(adapter, DeviceType.Hardware,
+ deviceFormat, backbufferFormat, f) == false)
+ {
+ continue;
+ }
+
+ return f;
+ }
+
+ return DepthFormat.Unknown;
+ }
+ private Format GetDeviceFormat(Format backbufferFormat)
+ {
+ switch (backbufferFormat)
+ {
+ case Format.A8R8G8B8: return Format.X8R8G8B8;
+ case Format.A8B8G8R8: return Format.X8B8G8R8;
+ case Format.A1R5G5B5: return Format.X1R5G5B5;
+
+ default:
+ return backbufferFormat;
+ }
+ }
+
public override ScreenMode[] EnumScreenModes()
{
List<ScreenMode> modes = new List<ScreenMode>();
@@ -839,11 +923,15 @@
Matrix4 world = Matrix4.Identity;
Matrix4 view = Matrix4.Identity;
- // TODO: Fix this
- protected override VertexBufferImpl CreateVertexBuffer(VertexLayout layout, int vertexCount)
+ protected override VertexBufferImpl CreateVertexBuffer(
+ AgateLib.Geometry.VertexTypes.VertexLayout layout, int vertexCount)
{
- return new MDX1_VertexBuffer(this);
+ return new MDX1_VertexBuffer(this, layout, vertexCount);
}
+ protected override IndexBufferImpl CreateIndexBuffer(IndexBufferType type, int size)
+ {
+ return new MDX1_IndexBuffer(this, type, size);
+ }
private Matrix TransformAgateMatrix(Matrix4 value)
{
Added: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs (rev 0)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using AgateLib.DisplayLib;
+using AgateLib.ImplementationBase;
+using Direct3D = Microsoft.DirectX.Direct3D;
+
+namespace AgateMDX
+{
+ class MDX1_IndexBuffer : IndexBufferImpl
+ {
+ MDX1_Display mDisplay;
+ IndexBufferType mType;
+ int mCount;
+ Direct3D.IndexBuffer mBuffer;
+
+ public MDX1_IndexBuffer(MDX1_Display disp, IndexBufferType type, int count)
+ {
+ mDisplay = disp;
+ mType = type;
+ mCount = count;
+
+ CreateIndexBuffer();
+ }
+
+ private void CreateIndexBuffer()
+ {
+ int indexSize = 2;
+
+ if (IndexType == IndexBufferType.Int32)
+ indexSize = 4;
+
+ mBuffer = new Microsoft.DirectX.Direct3D.IndexBuffer(
+ mDisplay.D3D_Device.Device,
+ mCount * indexSize,
+ Microsoft.DirectX.Direct3D.Usage.WriteOnly,
+ Microsoft.DirectX.Direct3D.Pool.Managed,
+ IndexType == IndexBufferType.Int16);
+ }
+
+ public override int Count
+ {
+ get { return mCount; }
+ }
+
+ public override AgateLib.DisplayLib.IndexBufferType IndexType
+ {
+ get { return mType; }
+ }
+
+ public override void WriteIndices(int[] indices)
+ {
+ mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ }
+
+ public override void WriteIndices(short[] indices)
+ {
+ mBuffer.SetData(indices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
+ }
+ }
+}
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_Surface.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -65,6 +65,11 @@
#endregion
+ public Texture D3dTexture
+ {
+ get { return mTexture.Value; }
+ }
+
#region --- TextureCoordinates structure ---
struct TextureCoordinates
Modified: branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateMDX/MDX1_VertexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Text;
using AgateLib;
+using AgateLib.DisplayLib;
using AgateLib.Geometry;
+using AgateLib.Geometry.VertexTypes;
using AgateLib.ImplementationBase;
using Direct3D = Microsoft.DirectX.Direct3D;
@@ -11,50 +13,209 @@
class MDX1_VertexBuffer : VertexBufferImpl
{
MDX1_Display mDisplay;
+ Direct3D.VertexBuffer mBuffer;
+ Direct3D.VertexDeclaration mDeclaration;
+ Direct3D.VertexFormats mFormats;
+ int mCount;
- public MDX1_VertexBuffer(MDX1_Display display)
+ public MDX1_VertexBuffer(MDX1_Display display, VertexLayout layout, int vertexCount)
{
mDisplay = display;
+ mCount = vertexCount;
+
+ mDeclaration = CreateVertexDeclaration(layout);
+ mFormats = CreateVertexFormats(layout);
+
+ mBuffer = new Microsoft.DirectX.Direct3D.VertexBuffer(
+ mDisplay.D3D_Device.Device,
+ vertexCount * layout.VertexSize,
+ Microsoft.DirectX.Direct3D.Usage.WriteOnly,
+ mFormats,
+ Direct3D.Pool.Managed);
}
+ private Direct3D.VertexFormats CreateVertexFormats(VertexLayout layout)
+ {
+ Direct3D.VertexFormats retval = Microsoft.DirectX.Direct3D.VertexFormats.None;
- public override void WriteNormalData(Vector3[] data)
- {
- throw new NotImplementedException();
+ foreach (var element in layout)
+ {
+ switch (element.ElementType)
+ {
+ case VertexElement.Position:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Position;
+ break;
+
+ case VertexElement.Texture:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture0;
+ break;
+
+ case VertexElement.Texture1:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture1;
+ break;
+
+ case VertexElement.Texture2:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture2;
+ break;
+
+ case VertexElement.Texture3:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Texture3;
+ break;
+
+ case VertexElement.Color:
+ retval |= Microsoft.DirectX.Direct3D.VertexFormats.Diffuse;
+ break;
+ }
+ }
+
+ return retval;
}
- public override void WriteTextureCoords(Vector2[] texCoords)
+ private Direct3D.VertexDeclaration CreateVertexDeclaration(VertexLayout layout)
{
- throw new NotImplementedException();
+ List<Direct3D.VertexElement> formats = new List<Microsoft.DirectX.Direct3D.VertexElement>();
+
+ for (int i = 0; i < layout.Count; i++)
+ {
+ var element = layout[i];
+ short loc = 0;
+ int size;
+
+ Direct3D.VertexElement d3d_element = ConvertElement(element, out size);
+ d3d_element.Offset = loc;
+ loc += (short)size;
+ }
+
+ formats.Add(Direct3D.VertexElement.VertexDeclarationEnd);
+
+ return new Direct3D.VertexDeclaration(
+ mDisplay.D3D_Device.Device, formats.ToArray());
}
- public override void WriteVertexData(Vector3[] data)
+ private Direct3D.VertexElement ConvertElement(VertexElementDesc element, out int size)
{
- throw new NotImplementedException();
+ Direct3D.DeclarationType declType;
+ Direct3D.DeclarationMethod declMethod = Microsoft.DirectX.Direct3D.DeclarationMethod.Default;
+ Direct3D.DeclarationUsage declUsage;
+
+ switch(element.DataType)
+ {
+ case VertexElementDataType.Float1:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float1;
+ break;
+ case VertexElementDataType.Float2:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float2;
+ break;
+ case VertexElementDataType.Float3:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float3;
+ break;
+ case VertexElementDataType.Float4:
+ declType = Microsoft.DirectX.Direct3D.DeclarationType.Float4;
+ break;
+ default:
+ throw new NotImplementedException(
+ element.DataType.ToString() + " not implemented.");
+ }
+
+ size = VertexLayout.SizeOf(element.DataType);
+
+ switch(element.ElementType)
+ {
+ case VertexElement.Position:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Position;
+ break;
+ case VertexElement.Texture:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.TextureCoordinate;
+ break;
+ case VertexElement.Normal:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Normal;
+ break;
+ case VertexElement.Tangent:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Tangent;
+ break;
+ case VertexElement.Color:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.Color;
+ break;
+ case VertexElement.Bitangent:
+ declUsage = Microsoft.DirectX.Direct3D.DeclarationUsage.BiNormal;
+ break;
+ default:
+ throw new NotImplementedException(
+ element.ElementType.ToString() + " not implemented.");
+ }
+
+ return new Direct3D.VertexElement(0, 0, declType, declMethod, declUsage, 0);
}
- public override void WriteIndices(short[] indices)
+
+ private Direct3D.PrimitiveType GetPrimitiveType(ref int vertexCount)
{
- throw new NotImplementedException();
+ switch (this.PrimitiveType)
+ {
+ case PrimitiveType.TriangleFan:
+ vertexCount = vertexCount - 2;
+ return Microsoft.DirectX.Direct3D.PrimitiveType.TriangleFan;
+ case PrimitiveType.TriangleList:
+ vertexCount /= 3;
+ return Microsoft.DirectX.Direct3D.PrimitiveType.TriangleList;
+ case PrimitiveType.TriangleStrip:
+ vertexCount = vertexCount - 2;
+ return Microsoft.DirectX.Direct3D.PrimitiveType.TriangleStrip;
+ default:
+ throw new NotImplementedException(this.PrimitiveType.ToString() + " not implemented.");
+ }
}
- public override void Draw(int vertexStart, int vertexCount)
+ public override void Draw(int start, int count)
{
- throw new NotImplementedException();
+ int primitiveCount = count;
+
+ // after calling GetPrimitiveType, primitiveCount is the number of primitives
+ // instead of the number of vertices.
+ Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount);
+
+ SetTextures();
+
+ mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
+ mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
+ mDisplay.D3D_Device.Device.DrawPrimitives(primType, start, primitiveCount);
}
+ public override void DrawIndexed(IndexBuffer indexbuffer, int start, int count)
+ {
+ int primitiveCount = count;
- public override int IndexCount
+ // after calling GetPrimitiveType, count is the number of primitives
+ // instead of the number of vertices.
+ Direct3D.PrimitiveType primType = GetPrimitiveType(ref primitiveCount);
+
+ SetTextures();
+
+ mDisplay.D3D_Device.Device.SetStreamSource(0, mBuffer, 0);
+ mDisplay.D3D_Device.Device.VertexDeclaration = mDeclaration;
+ mDisplay.D3D_Device.Device.DrawIndexedPrimitives(primType, start, 0, count, 0, primitiveCount);
+ }
+
+ private void SetTextures()
{
- get { return 0; }
+ for (int i = 0; i < Textures.Count; i++)
+ {
+ if (Textures[i] == null)
+ mDisplay.D3D_Device.SetDeviceStateTexture(null, i);
+ else
+ {
+ MDX1_Surface surf = (MDX1_Surface)Textures[i].Impl;
+
+ mDisplay.D3D_Device.SetDeviceStateTexture(surf.D3dTexture, i);
+ }
+ }
}
public override int VertexCount
{
- get { return 0; }
+ get { return mCount; }
}
-
- public override void WriteAttributeData(string attributeName, Vector3[] data)
+ public override void Write<T>(T[] vertices)
{
- throw new NotImplementedException();
+ mBuffer.SetData(vertices, 0, Microsoft.DirectX.Direct3D.LockFlags.Discard);
}
}
}
Modified: branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs
===================================================================
--- branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Drivers/AgateOTK/GL_IndexBuffer.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -46,33 +46,6 @@
GL.BindBuffer(BufferTarget.ElementArrayBuffer, mBufferID);
}
- private short[] ConvertToInt16(int[] indices)
- {
- short[] retval = new short[indices.Length];
-
- int i = 0;
-
- try
- {
- checked
- {
- for (i = 0; i < retval.Length; i++)
- {
- retval[i] = (short)indices[i];
- }
- }
- }
- catch (OverflowException ex)
- {
- throw new AgateLib.AgateException(ex, string.Format(
- "A 16 bit index buffer cannot contain values greater than {0}, " +
- "but there is a value of {1} at index {2}.",
- short.MaxValue, indices[i], i));
- }
-
- return retval;
- }
-
unsafe public override void WriteIndices(int[] indices)
{
if (indices.Length != Count)
@@ -80,10 +53,8 @@
"The size of the passed array must match the size of the index buffer.");
if (mType == IndexBufferType.Int16)
- {
- WriteIndices(ConvertToInt16(indices));
- return;
- }
+ throw new ArgumentException(
+ "Cannot write 32-bit data to a 16-bit buffer.");
Bind();
Modified: branches/agate3d-3.2/Tests/Display3D/Matrices.cs
===================================================================
--- branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-01 02:16:20 UTC (rev 929)
+++ branches/agate3d-3.2/Tests/Display3D/Matrices.cs 2009-05-01 07:34:20 UTC (rev 930)
@@ -30,6 +30,7 @@
}
#endregion
+
static int matrixIndex = 1;
static int move, turn;
@@ -58,6 +59,7 @@
cube.Location = new Vector3(cube.Length / 2, cube.Length / 2, 0);
cube.CreateVertexBuffer();
+ IndexBuffer indices = cube.IndexBuffer;
VertexBuffer b = cube.VertexBuffer;
b.Textures[0] = surf;
@@ -111,7 +113,7 @@
break;
case 1:
- myproj = Matrix4.Projection(45, wind.Width / (float)wind.Height, 1f, 1000);
+ myproj = Matrix4.Projection(45, wind.Width / (float)wind.Height, 1f, 1000f);
myview = Matrix4.LookAt(position, lookTarget,
new Vector3(0, 0, 1));
@@ -136,7 +138,7 @@
Display.MatrixWorld = Matrix4.Translation(0, 0, 0);
m[0].Position = position;
- m.DoLighting();
+ //m.DoLighting();
// draw a weird checkerboard
for (int x = 0; x < 8; x += 2)
@@ -152,7 +154,7 @@
Display.DrawRect(new Rectangle(0, 0, 8, 8), Color.Black);
- b.Draw();
+ b.DrawIndexed(indices);
Display.EndFrame();
Core.KeepAlive();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|