2011-10-19 2 views
1

저는 XNA와 함께 작동하는 라이브러리를 작성하고 있습니다. 저는 프리미티브를위한 기본 클래스를 가지고 있습니다.이 클래스로부터 Planes, Cubes 및 기타 원시 타입을 작성할 계획입니다. 이상적으로 사용 된 정점 유형에 관계없이 내 기본 클래스에서 렌더링을 수행하고 싶습니다.일반 기본 클래스에서 DrawUserIndexedPrimitives <> 사용

관련 코드 : 이제

public abstract class Primitive<VT> where VT : IVertexType 
{ 
    private void Draw(GraphicsDevice graphics) 
    { 
      graphics.DrawUserIndexedPrimitives<VT>(primitiveType_, 
                vertices_, 
                0, 
                vertices_.Length, 
                indices_, 
                0, 
                primitiveCount_); 
    }  
} 

, 적절한 정점 타입의 사용이에서 파생 이외의 클래스 : 문제는

public abstract class Plane<VT> : Primitive<VT> where VT : IVertextTpye { ... } 
public class PlaneColored : Primitive<VertexPositionColor> { .... } 
public class PlaneTextured : Primitive<VertexPositionTexture> { .... } 

, 내가 DrawUserIndexPrimitives <에 컴파일 오류를 > 전화 :

Error 1 The type 'VT' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawUserIndexedPrimitives<T>(Microsoft.Xna.Framework.Graphics.PrimitiveType, T[], int, int, short[], int, int)' C:\dev\Projects\2010\XNAParts\XNAParts\Parts\Primitive.cs 88 

그리고 구성을 struct 그렇지 않으면 DrawUserIndexPrimitives의 제네릭 매개 변수가 작동하지 않습니다 (구조체가 아니므로).

이 문제가 발생합니까?

미리 감사드립니다.

+0

좋은 질문이지만 제목에 null 제약 조건이있는 실제 문제가 설명되어 있지 않습니다. –

답변

1

단지 Primitive을 변경하면 어떨까요? VT은 구조체입니까?

public abstract class Primitive<VT> where VT : struct, IVertexType 

와 유사

public abstract class Plane<VT> : Primitive<VT> where VT : struct, IVertexType 

당신은 "(이 구조체가 아니라으로) DrawUserIndexPrimitives 일반적인 매개 변수가 작동하지 않습니다"하지만 당신이 무슨 뜻인지 명확하지 않다 주장한다. 어떤 매개 변수? I 용의자 위 내용은 원하는 내용이지만 실제로는 명확하지 않습니다.

+0

감사합니다. 구조체와 IVertextType을 모두 사용할 수 있다는 것을 완전히 잊었습니다! –

관련 문제