Précédent   Forum des professionnels en informatique > Applications > Développement 2D, 3D et Jeux > API graphiques > DirectX
DirectX Forum d'entraide sur le développement avec DirectX. Avant de poster -> FAQ DirectX
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 13/06/2011, 22h18   #1
Invité régulier
 
Homme Quentin Ventura
Inscription : juin 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Quentin Ventura
Localisation : Canada

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2011
Messages : 30
Points : 8
Points : 8
Par défaut Faible résolution de texture

Bonjour à tous,

J'ai un petit problème avec le logiciel que je développe, qui je pense est liée à la résolution de mon panel ...

Déjà voila à quoi ça ressemble:



Le fond: C'est un carré, texturé avec une image jpg de 1024*1024 représentant un plan.
Le "truc" au dessus, c'est supposé être un tracé, j'y fais aucun traitement dans le Vertex Shader / Pixel Shader, ce qui explique que ce soit si moche, mais on peut voir que les pixels sont relativement gros ...

Maintenant mon code ... (Je précise, c'est SlimDX et DirectX10, en C#)

J'ai une classe GPUDevice qui instancie mon device, et qui contient une liste de Panels qui utiliseront ce device.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlimDX;
using SlimDX.Direct3D10;
 
using Device = SlimDX.Direct3D10.Device;
 
namespace PrototypeV4.GraphicEngine
{
 
    static class GPUDevice
    {
        private static SlimDX.Direct3D10.Device gpuDevice;
        private static List<PrototypeV4.GUI.ViewPanel> listOfPanels;
        static GPUDevice()
        {
            gpuDevice = new SlimDX.Direct3D10.Device(DriverType.Hardware, DeviceCreationFlags.Debug);
            listOfPanels = new List<GUI.ViewPanel>();
        }
 
        public static SlimDX.Direct3D10.Device GpuDevice
        {
            get
            {
                return gpuDevice;
            }
        }
 
        public static List<GUI.ViewPanel> ListOfPanelsToRender
        {
            get
            {
                return listOfPanels;
            }
        }
 
        public static void addPanelToRender(GUI.ViewPanel vp)
        {
            listOfPanels.Add(vp);
        }
 
 
        public static void clear()
        {
            gpuDevice.Dispose();
        }
    }
}
J'ai une classe MapView, qui donc elle hérite de Panel, créée mes différents modeles (M_XX), créé mes objets chargés du dessin (D_XX), et surtout, créé la swapChain relative à ce panel, le ViewPort et le RenderTargetView ...

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlimDX;
using SlimDX.Direct3D10;
using SlimDX.DXGI;
using SlimDX.Windows;
using SlimDX.D3DCompiler;
using System.Windows.Forms;
using System.Runtime.InteropServices;
 
namespace PrototypeV4.GUI
{
    class MapView : ViewPanel
    {
        SlimDX.Direct3D10.Device gpuDevice;
 
        private Modele.M_Map modeleMap;
        private Modele.M_Path modelePath;
 
        private Draw.D_Map drawMap;
        private Draw.D_Path drawPath;
 
        private MapViewContainer parent;
        private Color4 backColor = new Color4(new Vector3(1.0f, 1.0f, 1.0f));
 
        public MapView(MapViewContainer parent)
            : base()
        {
 
            this.parent = parent;
            modeleMap = parent.CurrentMap;
            modelePath = new Modele.M_Path();
 
            this.Dock = System.Windows.Forms.DockStyle.Fill;
            gpuDevice = GraphicEngine.GPUDevice.GpuDevice;
 
            initCamera();
 
            initView();
 
 
            drawMap = new Draw.D_Map(this, modeleMap);
 
            DateTime now = DateTime.Now;
 
            modelePath.add(new Modele.M_Point(0.2f, 0.2f, now));
            modelePath.add(new Modele.M_Point(0.4f, 0.3f, now.AddSeconds(10)));
            modelePath.add(new Modele.M_Point(0.4f, 0.7f, now.AddSeconds(20)));
            modelePath.add(new Modele.M_Point(0.2f, 0.6f, now.AddSeconds(30)));
            modelePath.add(new Modele.M_Point(0.3f, 0.9f, now.AddSeconds(40)));
            modelePath.add(new Modele.M_Point(0.5f, 0.10f, now.AddSeconds(50)));
            modelePath.add(new Modele.M_Point(0.8f, 0.10f, now.AddSeconds(60)));
            modelePath.add(new Modele.M_Point(0.10f, 0.8f, now.AddSeconds(70)));
            modelePath.add(new Modele.M_Point(0.9f, 0.6f, now.AddSeconds(80)));
            modelePath.add(new Modele.M_Point(0.5f, 0.7f, now.AddSeconds(90)));
            modelePath.add(new Modele.M_Point(0.3f, 0.5f, now.AddSeconds(100)));
 
            drawPath = new Draw.D_Path(this, modelePath);
 
            drawMap.init();
            drawPath.init();
        }
 
        public void initView()
        {
 
            Factory factory;
            SlimDX.Direct3D10.Resource resource;
 
            var description = new SwapChainDescription()
            {
                BufferCount = 2,
                Usage = Usage.RenderTargetOutput,
                OutputHandle = Handle,
                IsWindowed = true,
                ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags = SwapChainFlags.AllowModeSwitch,
                SwapEffect = SwapEffect.Discard
            };
 
 
            factory = new Factory();
            factory.SetWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
 
            swapChain = new SwapChain(factory, gpuDevice, description);
 
            viewport = new Viewport(0, 0, this.Width, this.Height);
 
            resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0);
 
            renderTarget = new RenderTargetView(gpuDevice, resource);
 
            gpuDevice.OutputMerger.SetTargets(renderTarget);
            gpuDevice.Rasterizer.SetViewports(viewport);
 
            factory.Dispose();
            resource.Dispose();
        }
 
        public void initCamera()
        {
            // Initialisation de la caméra
            camera = new Utilities.Camera(
                new Vector3(0.0f, 0.0f, -100.0f),   // Location
                new Vector3(0.0f, 0.0f, 0.0f),  // Target
                new Vector3(0.0f, 1.0f, 0.0f),  // Up
                0.1f,
                100.0f,
                (float)(Math.PI * 0.5f),
                this.Width / this.Height);
           camera.build();
        }
 
        public override void run()
        {
            gpuDevice.ClearRenderTargetView(renderTarget, backColor);
            gpuDevice.OutputMerger.SetTargets(renderTarget);
 
            drawMap.run();
            drawPath.run();
 
            swapChain.Present(0, PresentFlags.None);
        }
 
        public void reinit()
        {
            drawMap.reinit();
        }
 
        public override void clear()
        {
            swapChain.Dispose();
            renderTarget.Dispose();
        }
 
        public MapViewContainer Parent
        {
            get
            {
                return Parent;
            }
        }
 
        public Modele.M_Map Map
        {
            set 
            { 
                modeleMap = value;
                reinit();
            }
        }
 
    }
}
Et ensuite ma class D_Map qui elle s'occupe de dessiner la map ...
Cette classe a pas grand chose de spécial je pense, c'est juste les "techniques" habituelle pour appliquer une texture ... Mais je dois faire une erreur quelque part ...

Pour termine,r mon fichier .fx, qui la aussi est classique:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Texture2D texture2d;
matrix World;
matrix View;
matrix Projection;
 
 
SamplerState linearSampler
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};
 
struct VS_IN
{
	float4 position : POSITION;
	float4 color : COLOR;
	float2 UV: TEXCOORD;
};
 
struct PS_IN
{
	float4 position : SV_POSITION;
	float4 color : COLOR;
	float2 UV: TEXCOORD;
};
 
PS_IN VS( VS_IN vertexShaderIn )
{
	PS_IN vertexShaderOut = (PS_IN)0;
 
	vertexShaderOut.position = mul( vertexShaderIn.position, World );
	vertexShaderOut.position = mul( vertexShaderOut.position, View );
	vertexShaderOut.position = mul( vertexShaderOut.position, Projection );
 
	vertexShaderOut.color = vertexShaderIn.color;
	vertexShaderOut.UV = vertexShaderIn.UV;
 
	return vertexShaderOut;
}
 
float4 PS( PS_IN pixelShaderIn ) : SV_Target
{
	float4 finalColor = texture2d.Sample( linearSampler, pixelShaderIn.UV );
	return finalColor;
}
 
technique10 Render
{
	pass P0
	{
		SetGeometryShader( 0 );
		SetVertexShader( CompileShader( vs_4_0, VS() ) );
		SetPixelShader( CompileShader( ps_4_0, PS() ) );
	}
}
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using PrototypeV4.Modele;
using PrototypeV4.GUI;
 
using SlimDX;
using SlimDX.DXGI;
using SlimDX.Windows;
using SlimDX.D3DCompiler;
using SlimDX.Direct3D10;
 
using System.Runtime.InteropServices;
 
namespace PrototypeV4.Draw
{
    [StructLayout(LayoutKind.Sequential)]
    struct VertexMap
    {
        public Vector4 PositionRhw;
        public Vector4 Color;
        public Vector2 UV;
    }
 
    class D_Map
    {
        private ViewPanel target;
        private M_Map modele;
 
        private Effect effect;
        protected EffectTechnique technique;
        protected EffectPass pass;
 
        private List<Vector4> vertexPositions;
        private List<Vector2> textureCoords;
        private List<Vector4> vertexColors;
        private SlimDX.Direct3D10.Buffer vertices;
 
        private InputLayout layout;
 
        private float mapWidth;
        private float mapHeight;
 
        private EffectMatrixVariable worldVariable = null,
                                     viewVariable = null,
                                     projectionVariable = null;
 
        private Matrix world;
 
        private SlimDX.Direct3D10.Device gpuDevice;
 
        public D_Map(ViewPanel target, M_Map modele)
        {
            this.target = target;
            this.modele = modele;
            mapHeight = modele.Height;
            mapWidth = modele.Width;
            gpuDevice= PrototypeV4.GraphicEngine.GPUDevice.GpuDevice;
            world = Matrix.Identity;
 
 
        }
 
        public void init()
        {
            vertexPositions = new List<Vector4>();
            textureCoords = new List<Vector2>();
            vertexColors = new List<Vector4>();
 
            effect = Effect.FromFile(gpuDevice, "fx/D_Map.fx", "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null);
            technique = effect.GetTechniqueByIndex(0);
            pass = technique.GetPassByIndex(0);
 
            worldVariable = effect.GetVariableByName("World").AsMatrix();
            viewVariable = effect.GetVariableByName("View").AsMatrix();
            projectionVariable = effect.GetVariableByName("Projection").AsMatrix();
 
            Texture2D texture = Texture2D.FromFile(gpuDevice, modele.FilePath);
 
 
            EffectResourceVariable shaderTexture = effect.GetVariableByName("texture2d").AsResource();
            ShaderResourceView textureView = new ShaderResourceView(gpuDevice, texture);
            shaderTexture.SetResource(textureView);
 
            InputElement[] inputElements = new InputElement[]
					{
						new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
						new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 16, 0),
                        new InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 32, 0)
					};
            layout = new InputLayout(gpuDevice, pass.Description.Signature, inputElements);
 
            float ratio = 1 / (mapHeight / mapWidth);
            ratio = 100;
 
            vertexPositions.Add(new Vector4(-1.0f * ratio, -1.0f * ratio, 0.0f, 1.0f));
            vertexPositions.Add(new Vector4(-1.0f * ratio, 1.0f * ratio, 0.0f, 1.0f));
            vertexPositions.Add(new Vector4(1.0f * ratio, -1.0f * ratio, 0.0f, 1.0f));
            vertexPositions.Add(new Vector4(1.0f * ratio, 1.0f * ratio, 0.0f, 1.0f));
 
 
            textureCoords.Add(new Vector2(0.0f, 1.0f));
            textureCoords.Add(new Vector2(0.0f, 0.0f));
            textureCoords.Add(new Vector2(1.0f, 1.0f));
            textureCoords.Add(new Vector2(1.0f, 0.0f));
 
            vertexColors.Add(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
            vertexColors.Add(new Vector4(0.0f, 1.0f, 0.0f, 1.0f));
            vertexColors.Add(new Vector4(0.0f, 0.0f, 1.0f, 1.0f));
            vertexColors.Add(new Vector4(1.0f, 0.0f, 1.0f, 1.0f));
 
            DataStream stream = new DataStream(vertexPositions.Count * Marshal.SizeOf(typeof(VertexMap)), true, true);
            for (int i = 0; i < vertexPositions.Count; i++)
            {
                stream.Write(vertexPositions[i]);
                stream.Write(vertexColors[i]);
                stream.Write(textureCoords[i]);
            }
 
            stream.Position = 0;
 
            BufferDescription bufferDescription = new BufferDescription();
            bufferDescription.BindFlags = BindFlags.VertexBuffer;
            bufferDescription.CpuAccessFlags = CpuAccessFlags.None;
            bufferDescription.OptionFlags = ResourceOptionFlags.None;
            bufferDescription.SizeInBytes = vertexPositions.Count * Marshal.SizeOf(typeof(VertexMap));
            bufferDescription.Usage = ResourceUsage.Default;
 
            vertices = new SlimDX.Direct3D10.Buffer(gpuDevice, stream, bufferDescription);
 
            stream.Close();
 
            // create the vertex layout and buffer
            // configure the Input Assembler portion of the pipeline with the vertex data
        }
 
        public void run()
        {
 
            worldVariable.SetMatrix(world);
            viewVariable.SetMatrix(target.Camera.ViewMatrix);
            projectionVariable.SetMatrix(target.Camera.ProjectionMatrix);
 
            gpuDevice.InputAssembler.SetInputLayout(layout);
            gpuDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
            gpuDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, Marshal.SizeOf(typeof(VertexMap)), 0));
 
            for (int p = 0; p < technique.Description.PassCount; p++)
            {
                pass.Apply();
                gpuDevice.Draw(4, 0);
            }
        }
 
        public void reinit()
        {
            Texture2D texture = Texture2D.FromFile(gpuDevice, modele.FilePath);
            EffectResourceVariable shaderTexture = effect.GetVariableByName("texture2d").AsResource();
            ShaderResourceView textureView = new ShaderResourceView(gpuDevice, texture);
            shaderTexture.SetResource(textureView);
        }
    }
}
Voila, j'ai pas mis tout le code, seulement ce qui, je pense, peut être utile ... J'pense que j'ai fait une erreur de débutant assez grossière quelque part, mais je sais pas ou

Bref, toute aide me serait utile Et toute critique aussi ! Parce que j'ai très peu de connaissance théoriques sur le sujet, donc j'ai un peu construit mon logiciel au "feeling" sans appliquer les bonnes pratiques ...

Ps: Si quelqu'un a un titre plus approprié pour mon problème aussi je suis preneur
qventura est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 16h31   #2
Invité régulier
 
Homme Quentin Ventura
Inscription : juin 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Quentin Ventura
Localisation : Canada

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2011
Messages : 30
Points : 8
Points : 8
Plop coup de pied au cul de sujet
qventura est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 18h52   #3
Membre Expert
 
Inscription : février 2006
Messages : 1 393
Détails du profil
Informations forums :
Inscription : février 2006
Messages : 1 393
Points : 2 057
Points : 2 057
je dirai bonne question, mais là j'ai pas spécialement le temps d'écrire une appli pour tester ton code.
stardeath est déconnecté   Envoyer un message privé Réponse avec citation 01
Vieux 15/06/2011, 18h54   #4
Invité régulier
 
Homme Quentin Ventura
Inscription : juin 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Quentin Ventura
Localisation : Canada

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2011
Messages : 30
Points : 8
Points : 8
Haha !
Tu viens de me donner une idée, je vais créer un projet plus simple pour tester, avec uniquement le panel en question !
Merci
Je posterais ici le projet si j'arrive pas à trouver la solution comme ça
qventura est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/06/2011, 19h32   #5
Membre habitué
 
Avatar de ShadowTzu
 
Inscription : juin 2005
Messages : 182
Détails du profil
Informations personnelles :
Âge : 28

Informations forums :
Inscription : juin 2005
Messages : 182
Points : 133
Points : 133
Je ne connais que Dx9 mais, est-ce que cela ne serait pas plutôt un problème lors du chargement de la texture:

Texture2D texture = Texture2D.FromFile(gpuDevice, modele.FilePath);

tu dois pouvoir renseigner plus d'argument comme par exemple la taille de la texture (0 ou 1024 à testé juste pour voir) le format (A8R8G8B8) et les filtres (none, point, box, linear,...)
__________________
Tzu3D: Mon Moteur 3D DirectX9 en VB.NET
ShadowTzu est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/06/2011, 19h37   #6
Invité régulier
 
Homme Quentin Ventura
Inscription : juin 2011
Messages : 30
Détails du profil
Informations personnelles :
Nom : Homme Quentin Ventura
Localisation : Canada

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2011
Messages : 30
Points : 8
Points : 8
En fait le problème est reglé
C'est du a un mauvais ordonnancement des instanciations en gros ...
Quand je créais le viewport avec ClientSize, le panel était pas encore instancié, et donc sa taille vallait 200 / 100 ... Après ca avait lieux la mise à l'échelle d'ou l'étirement de l'image !
Bon au final ma solution est toujours un peu dégueulasse mais ca marche

J'vais quand même regarder pour les paramètres, mais avec SlimDX/DX10 y'en a pas besoin a priori ! Merci
qventura est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h05.


 
 
 
 
Partenaires

Hébergement Web