This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository direct3d.

View the commit online.

commit c01294fd3896960425e8385fd7fe949d6d222a90
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Thu Aug 17 13:36:07 2023 +0200

    update code
---
 src/d3d_2.c              | 109 ++++++++++++++-------------------
 src/d3d_3.c              |  37 +++---------
 src/d3d_4.c              | 154 ++++++-----------------------------------------
 src/d3d_5.c              |  46 ++------------
 src/{d3d_5.c => d3d_6.c} | 110 +++------------------------------
 src/shader_1.hlsl        |  33 ++++++++++
 src/win.c                |   6 +-
 7 files changed, 120 insertions(+), 375 deletions(-)

diff --git a/src/d3d_2.c b/src/d3d_2.c
index a2bf2ad..8e85352 100644
--- a/src/d3d_2.c
+++ b/src/d3d_2.c
@@ -3,6 +3,7 @@
  *
  * Display  pink triangle
  * Add HLSL code and compile it at runtime (sufficient for now)
+ * Computation of coordinates in CPU
  *
  * Compilation:
  *
@@ -31,6 +32,9 @@ do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
 do { } while (0)
 #endif
 
+#define XF(w,x) ((float)(2 * (x) - (w)) / (float)(w))
+#define YF(h,y) ((float)((h) - 2 * (y)) / (float)(h))
+
 struct D3d
 {
     /* DXGI */
@@ -45,7 +49,6 @@ struct D3d
     ID3D11RenderTargetView *d3d_render_target_view;
     ID3D11InputLayout *d3d_input_layout;
     ID3D11VertexShader *d3d_vertex_shader;
-    ID3D11Buffer *d3d_const_buffer;
     ID3D11RasterizerState *d3d_rasterizer_state;
     ID3D11PixelShader *d3d_pixel_shader;
     D3D11_VIEWPORT viewport;
@@ -54,16 +57,10 @@ struct D3d
 
 typedef struct
 {
-    UINT x;
-    UINT y;
+    FLOAT x;
+    FLOAT y;
 } Vertex;
 
-typedef struct
-{
-    float ivps[2]; /* inverse viewport size */
-    float dummy[2]; /* for 16 bytes padding */
-} Const_Buffer;
-
 typedef struct
 {
     ID3D11Buffer *vertex_buffer;
@@ -161,11 +158,10 @@ D3d *d3d_init(Window *win, int vsync)
 {
     D3D11_INPUT_ELEMENT_DESC desc_ie[] =
     {
-        { "POSITION", 0, DXGI_FORMAT_R32G32_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }
+        { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }
     };
     DXGI_SWAP_CHAIN_DESC1 desc_sw;
     DXGI_SWAP_CHAIN_FULLSCREEN_DESC desc_fs;
-    D3D11_BUFFER_DESC desc_buf;
     D3D11_RASTERIZER_DESC desc_rs;
     D3d *d3d;
     RECT r;
@@ -293,7 +289,7 @@ D3d *d3d_init(Window *win, int vsync)
     flags |= D3DCOMPILE_DEBUG;
 #endif
     vs_blob = NULL;
-    res = D3DCompileFromFile(L"shader_2.hlsl",
+    res = D3DCompileFromFile(L"shader_1.hlsl",
                              NULL,
                              D3D_COMPILE_STANDARD_FILE_INCLUDE,
                              "main_vs",
@@ -317,7 +313,7 @@ D3d *d3d_init(Window *win, int vsync)
 
     if (FAILED(res))
     {
-        printf(" * CreateVertexShader() failed\n");
+        printf(" * vs error : %s\n", (char *)ID3D10Blob_GetBufferPointer(err_blob));
         ID3D10Blob_Release(vs_blob);
         goto release_d3D_rasterizer;
     }
@@ -338,7 +334,7 @@ D3d *d3d_init(Window *win, int vsync)
 
     /* Pixel shader */
     ps_blob = NULL;
-    res = D3DCompileFromFile(L"shader_2.hlsl",
+    res = D3DCompileFromFile(L"shader_1.hlsl",
                              NULL,
                              D3D_COMPILE_STANDARD_FILE_INCLUDE,
                              "main_ps",
@@ -366,27 +362,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_input_layout;
     }
 
-    desc_buf.ByteWidth = sizeof(Const_Buffer);
-    desc_buf.Usage = D3D11_USAGE_DYNAMIC; /* because buffer is updated when the window has resized */
-    desc_buf.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
-    desc_buf.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    desc_buf.MiscFlags = 0;
-    desc_buf.StructureByteStride = 0;
-
-    res = ID3D11Device_CreateBuffer(d3d->d3d_device,
-                                    &desc_buf,
-                                    NULL,
-                                    &d3d->d3d_const_buffer);
-    if (FAILED(res))
-    {
-        printf(" * CreateBuffer() failed 0x%lx\n", res);
-        goto release_pixel_shader;
-    }
-
     return d3d;
 
-  release_pixel_shader:
-    ID3D11PixelShader_Release(d3d->d3d_pixel_shader);
   release_input_layout:
     ID3D11InputLayout_Release(d3d->d3d_input_layout);
   release_vertex_shader:
@@ -424,7 +401,6 @@ void d3d_shutdown(D3d *d3d)
     d3d_debug = d3d->d3d_debug;
 #endif
 
-    ID3D11Buffer_Release(d3d->d3d_const_buffer);
     ID3D11PixelShader_Release(d3d->d3d_pixel_shader);
     ID3D11InputLayout_Release(d3d->d3d_input_layout);
     ID3D11VertexShader_Release(d3d->d3d_vertex_shader);
@@ -446,30 +422,11 @@ void d3d_shutdown(D3d *d3d)
 void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
 {
     D3D11_RENDER_TARGET_VIEW_DESC desc_rtv;
-    D3D11_MAPPED_SUBRESOURCE mapped;
     ID3D11Texture2D *back_buffer;
     HRESULT res;
 
     FCT;
 
-    res = ID3D11DeviceContext_Map(d3d->d3d_device_ctx,
-                                  (ID3D11Resource *)d3d->d3d_const_buffer,
-                                  0U, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
-
-    if (FAILED(res))
-    {
-        printf("Map() failed\n");
-        fflush(stdout);
-        return;
-    }
-
-    ((Const_Buffer *)mapped.pData)->ivps[0] = 1.0f / (float)width;
-    ((Const_Buffer *)mapped.pData)->ivps[1] = 1.0f / (float)height;
-
-    ID3D11DeviceContext_Unmap(d3d->d3d_device_ctx,
-                              (ID3D11Resource *)d3d->d3d_const_buffer,
-                              0U);
-
     /* unset the render target view in the output merger */
     ID3D11DeviceContext_OMSetRenderTargets(d3d->d3d_device_ctx,
                                            0U, NULL, NULL);
@@ -542,6 +499,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
 /*** triangle ***/
 
 Object *triangle_new(D3d *d3d,
+                     int w, int h,
                      int x1, int y1,
                      int x2, int y2,
                      int x3, int y3)
@@ -557,12 +515,12 @@ Object *triangle_new(D3d *d3d,
     if (!o)
         return NULL;
 
-    vertices[0].x = x1;
-    vertices[0].y = y1;
-    vertices[1].x = x2;
-    vertices[1].y = y2;
-    vertices[2].x = x3;
-    vertices[2].y = y3;
+    vertices[0].x = XF(w, x1);
+    vertices[0].y = YF(h, y1);
+    vertices[1].x = XF(w, x2);
+    vertices[1].y = YF(h, y2);
+    vertices[2].x = XF(w, x3);
+    vertices[2].y = YF(h, y3);
 
     indices[0] = 0;
     indices[1] = 1;
@@ -630,9 +588,24 @@ void object_free(void *o)
 
 void d3d_scene_begin(D3d *d3d)
 {
+    DXGI_SWAP_CHAIN_DESC1 desc;
     Object *o;
+    HRESULT res;
+    int w;
+    int h;
+
+    res = IDXGISwapChain1_GetDesc1(d3d->dxgi_swapchain, &desc);
+    if (FAILED(res))
+        return;
+
+    w = desc.Width;
+    h = desc.Height;
+
+    printf(" * swapchain size : %d %d\n", w, h);
+    fflush(stdout);
 
     o = triangle_new(d3d,
+                     w, h,
                      320, 120,
                      480, 360,
                      160, 360);
@@ -650,11 +623,24 @@ void d3d_scene_end(void)
 void d3d_render(D3d *d3d)
 {
     DXGI_PRESENT_PARAMETERS pp;
+    DXGI_SWAP_CHAIN_DESC1 desc;
     const FLOAT color[4] = { 0.10f, 0.18f, 0.24f, 1.0f };
     HRESULT res;
+    int w;
+    int h;
 
     FCT;
 
+    res = IDXGISwapChain1_GetDesc1(d3d->dxgi_swapchain, &desc);
+    if (FAILED(res))
+        return;
+
+    w = desc.Width;
+    h = desc.Height;
+
+    printf(" * swapchain size : %d %d\n", w, h);
+    fflush(stdout);
+
     /* clear render target */
     ID3D11DeviceContext_ClearRenderTargetView(d3d->d3d_device_ctx,
                                               d3d->d3d_render_target_view,
@@ -670,10 +656,6 @@ void d3d_render(D3d *d3d)
                                     d3d->d3d_vertex_shader,
                                     NULL,
                                     0);
-    ID3D11DeviceContext_VSSetConstantBuffers(d3d->d3d_device_ctx,
-                                             0,
-                                             1,
-                                             &d3d->d3d_const_buffer);
 
     /*
      * Rasterizer Stage
@@ -706,6 +688,7 @@ void d3d_render(D3d *d3d)
                                          objects[0]->index_buffer,
                                          DXGI_FORMAT_R32_UINT,
                                          0);
+
     /* draw */
     ID3D11DeviceContext_DrawIndexed(d3d->d3d_device_ctx,
                                     objects[0]->index_count,
diff --git a/src/d3d_3.c b/src/d3d_3.c
index 8910819..d9d8bf4 100644
--- a/src/d3d_3.c
+++ b/src/d3d_3.c
@@ -1,7 +1,9 @@
 /*
  * Tutorial part 3
  *
- * Specify color of the triangle
+ * Display  pink triangle
+ * Add HLSL code and compile it at runtime (sufficient for now)
+ * Computation of coordinates in GPU
  *
  * Compilation:
  *
@@ -55,10 +57,6 @@ typedef struct
 {
     UINT x;
     UINT y;
-    BYTE r;
-    BYTE g;
-    BYTE b;
-    BYTE a;
 } Vertex;
 
 typedef struct
@@ -164,8 +162,7 @@ D3d *d3d_init(Window *win, int vsync)
 {
     D3D11_INPUT_ELEMENT_DESC desc_ie[] =
     {
-        { "POSITION", 0, DXGI_FORMAT_R32G32_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
-        { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 2 * sizeof(UINT), D3D11_INPUT_PER_VERTEX_DATA, 0 }
+        { "POSITION", 0, DXGI_FORMAT_R32G32_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }
     };
     DXGI_SWAP_CHAIN_DESC1 desc_sw;
     DXGI_SWAP_CHAIN_FULLSCREEN_DESC desc_fs;
@@ -297,7 +294,7 @@ D3d *d3d_init(Window *win, int vsync)
     flags |= D3DCOMPILE_DEBUG;
 #endif
     vs_blob = NULL;
-    res = D3DCompileFromFile(L"shader_3.hlsl",
+    res = D3DCompileFromFile(L"shader_2.hlsl",
                              NULL,
                              D3D_COMPILE_STANDARD_FILE_INCLUDE,
                              "main_vs",
@@ -342,7 +339,7 @@ D3d *d3d_init(Window *win, int vsync)
 
     /* Pixel shader */
     ps_blob = NULL;
-    res = D3DCompileFromFile(L"shader_3.hlsl",
+    res = D3DCompileFromFile(L"shader_2.hlsl",
                              NULL,
                              D3D_COMPILE_STANDARD_FILE_INCLUDE,
                              "main_ps",
@@ -548,11 +545,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
 Object *triangle_new(D3d *d3d,
                      int x1, int y1,
                      int x2, int y2,
-                     int x3, int y3,
-                     unsigned char r,
-                     unsigned char g,
-                     unsigned char b,
-                     unsigned char a)
+                     int x3, int y3)
 {
     Vertex vertices[3];
     unsigned int indices[3];
@@ -567,22 +560,10 @@ Object *triangle_new(D3d *d3d,
 
     vertices[0].x = x1;
     vertices[0].y = y1;
-    vertices[0].r = r;
-    vertices[0].g = g;
-    vertices[0].b = b;
-    vertices[0].a = a;
     vertices[1].x = x2;
     vertices[1].y = y2;
-    vertices[1].r = r;
-    vertices[1].g = g;
-    vertices[1].b = b;
-    vertices[1].a = a;
     vertices[2].x = x3;
     vertices[2].y = y3;
-    vertices[2].r = r;
-    vertices[2].g = g;
-    vertices[2].b = b;
-    vertices[2].a = a;
 
     indices[0] = 0;
     indices[1] = 1;
@@ -655,8 +636,7 @@ void d3d_scene_begin(D3d *d3d)
     o = triangle_new(d3d,
                      320, 120,
                      480, 360,
-                     160, 360,
-                     255, 255, 0, 255); /* r, g, b, a */
+                     160, 360);
     objects[0] = o;
 }
 
@@ -727,6 +707,7 @@ void d3d_render(D3d *d3d)
                                          objects[0]->index_buffer,
                                          DXGI_FORMAT_R32_UINT,
                                          0);
+
     /* draw */
     ID3D11DeviceContext_DrawIndexed(d3d->d3d_device_ctx,
                                     objects[0]->index_count,
diff --git a/src/d3d_4.c b/src/d3d_4.c
index be17237..4433079 100644
--- a/src/d3d_4.c
+++ b/src/d3d_4.c
@@ -1,7 +1,7 @@
 /*
  * Tutorial part 4
  *
- * Add rectangle
+ * Specify color of the triangle
  *
  * Compilation:
  *
@@ -76,7 +76,7 @@ typedef struct
     UINT index_count;
 } Object;
 
-static Object *objects[2];
+static Object *objects[1];
 
 /************************** D3D11 **************************/
 
@@ -638,115 +638,6 @@ Object *triangle_new(D3d *d3d,
     return o;
 }
 
-/*** rectangle ***/
-
-Object *rectangle_new(D3d *d3d,
-                      int x, int y,
-                      int w, int h,
-                      unsigned char r,
-                      unsigned char g,
-                      unsigned char b,
-                      unsigned char a)
-{
-    Vertex vertices[4];
-    unsigned int indices[6];
-    D3D11_BUFFER_DESC desc;
-    D3D11_SUBRESOURCE_DATA sr_data;
-    Object *o;
-    HRESULT res;
-
-    o = (Object *)malloc(sizeof(Object));
-    if (!o)
-        return NULL;
-
-    /* vertex upper left */
-    vertices[0].x = x;
-    vertices[0].y = y;
-    vertices[0].r = r;
-    vertices[0].g = g;
-    vertices[0].b = b;
-    vertices[0].a = a;
-    /* vertex upper right*/
-    vertices[1].x = x + w;
-    vertices[1].y = y;
-    vertices[1].r = r;
-    vertices[1].g = g;
-    vertices[1].b = b;
-    vertices[1].a = a;
-    /* vertex bottom right*/
-    vertices[2].x = x + w;
-    vertices[2].y = y + h;
-    vertices[2].r = r;
-    vertices[2].g = g;
-    vertices[2].b = b;
-    vertices[2].a = a;
-    /* vertex bottom left*/
-    vertices[3].x = x;
-    vertices[3].y = y + h;
-    vertices[3].r = r;
-    vertices[3].g = g;
-    vertices[3].b = b;
-    vertices[3].a = a;
-
-    /* triangle upper left */
-    indices[0] = 0;
-    indices[1] = 1;
-    indices[2] = 3;
-    /* triangle bottom right */
-    indices[3] = 1;
-    indices[4] = 2;
-    indices[5] = 3;
-
-    o->stride = sizeof(Vertex);
-    o->offset = 0U;
-    o->index_count = 6U;
-
-    desc.ByteWidth = sizeof(vertices);
-    desc.Usage = D3D11_USAGE_DYNAMIC;
-    desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
-    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    desc.MiscFlags = 0U;
-    desc.StructureByteStride = 0U;
-
-    sr_data.pSysMem = vertices;
-    sr_data.SysMemPitch = 0U;
-    sr_data.SysMemSlicePitch = 0U;
-
-    res =ID3D11Device_CreateBuffer(d3d->d3d_device,
-                                   &desc,
-                                   &sr_data,
-                                   &o->vertex_buffer);
-    if (FAILED(res))
-    {
-        free(o);
-        return NULL;
-    }
-
-    desc.ByteWidth = sizeof(indices);
-    desc.Usage = D3D11_USAGE_DYNAMIC;
-    desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
-    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    desc.MiscFlags = 0U;
-    desc.StructureByteStride = 0U;
-
-    sr_data.pSysMem = indices;
-    sr_data.SysMemPitch = 0U;
-    sr_data.SysMemSlicePitch = 0U;
-
-    res =ID3D11Device_CreateBuffer(d3d->d3d_device,
-                                   &desc,
-                                   &sr_data,
-                                   &o->index_buffer);
-    if (FAILED(res))
-    {
-        ID3D11Buffer_Release(o->vertex_buffer);
-        free(o);
-        return NULL;
-    }
-
-    return o;
-}
-
 void object_free(void *o)
 {
     if (!o)
@@ -767,12 +658,6 @@ void d3d_scene_begin(D3d *d3d)
                      160, 360,
                      255, 255, 0, 255); /* r, g, b, a */
     objects[0] = o;
-
-    o = rectangle_new(d3d,
-                      520, 120,
-                      200, 100,
-                      0, 0, 255, 255); /* r, g, b, a */
-    objects[1] = o;
 }
 
 void d3d_scene_end(void)
@@ -787,7 +672,6 @@ void d3d_render(D3d *d3d)
 {
     DXGI_PRESENT_PARAMETERS pp;
     const FLOAT color[4] = { 0.10f, 0.18f, 0.24f, 1.0f };
-    size_t i;
     HRESULT res;
 
     FCT;
@@ -832,25 +716,21 @@ void d3d_render(D3d *d3d)
      * OMSetRenderTargets() called in the resize() callback
      */
 
-
-    for (i = 0; i < sizeof(objects) / sizeof(Object *); i++)
-    {
-        /* Input Assembler (IA) stage */
-        ID3D11DeviceContext_IASetVertexBuffers(d3d->d3d_device_ctx,
-                                               0,
-                                               1,
-                                               &objects[i]->vertex_buffer,
-                                               &objects[i]->stride,
-                                               &objects[i]->offset);
-        ID3D11DeviceContext_IASetIndexBuffer(d3d->d3d_device_ctx,
-                                             objects[i]->index_buffer,
-                                             DXGI_FORMAT_R32_UINT,
-                                             0);
-        /* draw */
-        ID3D11DeviceContext_DrawIndexed(d3d->d3d_device_ctx,
-                                        objects[i]->index_count,
-                                        0, 0);
-    }
+    /* Input Assembler (IA) stage */
+    ID3D11DeviceContext_IASetVertexBuffers(d3d->d3d_device_ctx,
+                                           0,
+                                           1,
+                                           &objects[0]->vertex_buffer,
+                                           &objects[0]->stride,
+                                           &objects[0]->offset);
+    ID3D11DeviceContext_IASetIndexBuffer(d3d->d3d_device_ctx,
+                                         objects[0]->index_buffer,
+                                         DXGI_FORMAT_R32_UINT,
+                                         0);
+    /* draw */
+    ID3D11DeviceContext_DrawIndexed(d3d->d3d_device_ctx,
+                                    objects[0]->index_count,
+                                    0, 0);
 
     /*
      * present frame, that is, flip the back buffer and the front buffer
diff --git a/src/d3d_5.c b/src/d3d_5.c
index 525bc4e..b2abc50 100644
--- a/src/d3d_5.c
+++ b/src/d3d_5.c
@@ -1,7 +1,7 @@
 /*
  * Tutorial part 5
  *
- * Manage rotation (still, bug of 1 pixel with 90 and 270 deg)
+ * Add rectangle
  *
  * Compilation:
  *
@@ -63,9 +63,8 @@ typedef struct
 
 typedef struct
 {
-    int rotation[2][4];
-    float ivps[2];
-    float dummy[2];
+    float ivps[2]; /* inverse viewport size */
+    float dummy[2]; /* for 16 bytes padding */
 } Const_Buffer;
 
 typedef struct
@@ -298,7 +297,7 @@ D3d *d3d_init(Window *win, int vsync)
     flags |= D3DCOMPILE_DEBUG;
 #endif
     vs_blob = NULL;
-    res = D3DCompileFromFile(L"shader_5.hlsl",
+    res = D3DCompileFromFile(L"shader_3.hlsl",
                              NULL,
                              D3D_COMPILE_STANDARD_FILE_INCLUDE,
                              "main_vs",
@@ -343,7 +342,7 @@ D3d *d3d_init(Window *win, int vsync)
 
     /* Pixel shader */
     ps_blob = NULL;
-    res = D3DCompileFromFile(L"shader_5.hlsl",
+    res = D3DCompileFromFile(L"shader_3.hlsl",
                              NULL,
                              D3D_COMPILE_STANDARD_FILE_INCLUDE,
                              "main_ps",
@@ -468,41 +467,6 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
         return;
     }
 
-    switch (rot)
-    {
-        case 0:
-            ((Const_Buffer *)mapped.pData)->rotation[0][0] = 1;
-            ((Const_Buffer *)mapped.pData)->rotation[0][1] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[0][2] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[1][0] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[1][1] = 1;
-            ((Const_Buffer *)mapped.pData)->rotation[1][2] = 0;
-            break;
-        case 1:
-            ((Const_Buffer *)mapped.pData)->rotation[0][0] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[0][1] = -1;
-            ((Const_Buffer *)mapped.pData)->rotation[0][2] = width - 1;
-            ((Const_Buffer *)mapped.pData)->rotation[1][0] = 1;
-            ((Const_Buffer *)mapped.pData)->rotation[1][1] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[1][2] = 0;
-            break;
-        case 2:
-            ((Const_Buffer *)mapped.pData)->rotation[0][0] = -1;
-            ((Const_Buffer *)mapped.pData)->rotation[0][1] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[0][2] = width - 1;
-            ((Const_Buffer *)mapped.pData)->rotation[1][0] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[1][1] = -1;
-            ((Const_Buffer *)mapped.pData)->rotation[1][2] = height - 1;
-            break;
-        case 3:
-            ((Const_Buffer *)mapped.pData)->rotation[0][0] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[0][1] = 1;
-            ((Const_Buffer *)mapped.pData)->rotation[0][2] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[1][0] = -1;
-            ((Const_Buffer *)mapped.pData)->rotation[1][1] = 0;
-            ((Const_Buffer *)mapped.pData)->rotation[1][2] = height - 1;
-            break;
-    }
     ((Const_Buffer *)mapped.pData)->ivps[0] = 1.0f / (float)width;
     ((Const_Buffer *)mapped.pData)->ivps[1] = 1.0f / (float)height;
 
diff --git a/src/d3d_5.c b/src/d3d_6.c
similarity index 90%
copy from src/d3d_5.c
copy to src/d3d_6.c
index 525bc4e..4a35576 100644
--- a/src/d3d_5.c
+++ b/src/d3d_6.c
@@ -1,11 +1,11 @@
 /*
- * Tutorial part 5
+ * Tutorial part 6
  *
  * Manage rotation (still, bug of 1 pixel with 90 and 270 deg)
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_5 d3d_5.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_6 d3d_6.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
  */
 
 #include <stdlib.h> /* calloc() free() malloc() */
@@ -71,7 +71,7 @@ typedef struct
 typedef struct
 {
     ID3D11Buffer *vertex_buffer;
-    ID3D11Buffer *index_buffer; /* not useful for a single triangle */
+    ID3D11Buffer *index_buffer;
     UINT stride;
     UINT offset;
     UINT index_count;
@@ -579,101 +579,6 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
                                        1U, &d3d->viewport);
 }
 
-/*** triangle ***/
-
-Object *triangle_new(D3d *d3d,
-                     int x1, int y1,
-                     int x2, int y2,
-                     int x3, int y3,
-                     unsigned char r,
-                     unsigned char g,
-                     unsigned char b,
-                     unsigned char a)
-{
-    Vertex vertices[3];
-    unsigned int indices[3];
-    D3D11_BUFFER_DESC desc;
-    D3D11_SUBRESOURCE_DATA sr_data;
-    Object *o;
-    HRESULT res;
-
-    o = (Object *)malloc(sizeof(Object));
-    if (!o)
-        return NULL;
-
-    vertices[0].x = x1;
-    vertices[0].y = y1;
-    vertices[0].r = r;
-    vertices[0].g = g;
-    vertices[0].b = b;
-    vertices[0].a = a;
-    vertices[1].x = x2;
-    vertices[1].y = y2;
-    vertices[1].r = r;
-    vertices[1].g = g;
-    vertices[1].b = b;
-    vertices[1].a = a;
-    vertices[2].x = x3;
-    vertices[2].y = y3;
-    vertices[2].r = r;
-    vertices[2].g = g;
-    vertices[2].b = b;
-    vertices[2].a = a;
-
-    indices[0] = 0;
-    indices[1] = 1;
-    indices[2] = 2;
-
-    o->stride = sizeof(Vertex);
-    o->offset = 0U;
-    o->index_count = 3U;
-
-    desc.ByteWidth = sizeof(vertices);
-    desc.Usage = D3D11_USAGE_DYNAMIC;
-    desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
-    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    desc.MiscFlags = 0U;
-    desc.StructureByteStride = 0U;
-
-    sr_data.pSysMem = vertices;
-    sr_data.SysMemPitch = 0U;
-    sr_data.SysMemSlicePitch = 0U;
-
-    res =ID3D11Device_CreateBuffer(d3d->d3d_device,
-                                   &desc,
-                                   &sr_data,
-                                   &o->vertex_buffer);
-    if (FAILED(res))
-    {
-        free(o);
-        return NULL;
-    }
-
-    desc.ByteWidth = sizeof(indices);
-    desc.Usage = D3D11_USAGE_DYNAMIC;
-    desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
-    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
-    desc.MiscFlags = 0U;
-    desc.StructureByteStride = 0U;
-
-    sr_data.pSysMem = indices;
-    sr_data.SysMemPitch = 0U;
-    sr_data.SysMemSlicePitch = 0U;
-
-    res =ID3D11Device_CreateBuffer(d3d->d3d_device,
-                                   &desc,
-                                   &sr_data,
-                                   &o->index_buffer);
-    if (FAILED(res))
-    {
-        ID3D11Buffer_Release(o->vertex_buffer);
-        free(o);
-        return NULL;
-    }
-
-    return o;
-}
-
 /*** rectangle ***/
 
 Object *rectangle_new(D3d *d3d,
@@ -797,11 +702,10 @@ void d3d_scene_begin(D3d *d3d)
 {
     Object *o;
 
-    o = triangle_new(d3d,
-                     320, 120,
-                     480, 360,
-                     160, 360,
-                     255, 255, 0, 255); /* r, g, b, a */
+    o = rectangle_new(d3d,
+                      220, 20,
+                      203, 101,
+                      0, 0, 255, 255); /* r, g, b, a */
     objects[0] = o;
 
     o = rectangle_new(d3d,
diff --git a/src/shader_1.hlsl b/src/shader_1.hlsl
new file mode 100644
index 0000000..6b4e7a4
--- /dev/null
+++ b/src/shader_1.hlsl
@@ -0,0 +1,33 @@
+struct vs_input
+{
+    float2 position : POSITION;
+};
+
+struct ps_input
+{
+    float4 position : SV_POSITION;
+};
+
+/*
+ * vertex shater program
+ *
+ * @param input the 2 coordinates of a vertex, got from CPU
+ * @return the 4D position of the pixel corresponding to the vertex in GPU
+ */
+ps_input main_vs(vs_input input )
+{
+    ps_input output;
+    output.position = float4(input.position, 0.0f, 1.0f);
+    return output;
+}
+
+/*
+ * pixel shater program
+ *
+ * @param input the 4D coordinates of a pixel
+ * @return the color of the pixel in RGBA colorspace, here pink
+ */
+float4 main_ps(ps_input input) : SV_TARGET
+{
+    return float4(1.0f, 0.0f, 1.0f, 1.0f);
+}
diff --git a/src/win.c b/src/win.c
index 8d57371..6e58a78 100644
--- a/src/win.c
+++ b/src/win.c
@@ -181,7 +181,7 @@ Window *window_new(int x, int y, int w, int h)
                             0U))
         goto unregister_class;
 
-    printf("window new : %d %d %ld %ld", w, h, r.right - r.left, r.bottom - r.top);
+    printf("window new : %d %d %ld %ld\n", w, h, r.right - r.left, r.bottom - r.top);
     fflush(stdout);
 
     win->win = CreateWindowEx(0U,
@@ -198,7 +198,7 @@ Window *window_new(int x, int y, int w, int h)
     return win;
 
   unregister_class:
-    UnregisterClass("D2D", win->instance);
+    UnregisterClass("D3D", win->instance);
   free_library:
     FreeLibrary(win->instance);
   free_win:
@@ -213,7 +213,7 @@ void window_del(Window *win)
         return;
 
     DestroyWindow(win->win);
-    UnregisterClass("D2D", win->instance);
+    UnregisterClass("D3D", win->instance);
     FreeLibrary(win->instance);
     free(win);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to