Package d3d11.core

Examples of d3d11.core.ID3D11DeviceContext


  /**
   * @param args
   */
  public static void main(String[] args) {
    D3D11_SAMPLER_DESC desc = new D3D11_SAMPLER_DESC();
    desc.AddressU(D3D11_TEXTURE_ADDRESS_MODE.D3D11_TEXTURE_ADDRESS_MIRROR);
    desc.MaxLOD(654.0f);
    desc.MaxAnisotropy(16);
   
    long start = System.currentTimeMillis();
    int hash = desc.hashCode();
    System.out.println(System.currentTimeMillis() - start);
   
    System.out.println(hash);
  }
View Full Code Here


    // Compiling for vertex shader and input layout
    ID3D10Blob code = D3DCompile(shaders, null, null, null, "VS", "vs_5_0", 0, 0);
   
    // Create input layout
    D3D11_INPUT_ELEMENT_DESC layoutDesc = new D3D11_INPUT_ELEMENT_DESC("POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0);
    final ID3D11InputLayout layout = device.CreateInputLayout(new D3D11_INPUT_ELEMENT_DESC[] { layoutDesc }, code);
    immediateContext.IASetInputLayout(layout);
   
    // Creating vertex shader
    final ID3D11VertexShader vs = device.CreateVertexShader(code, null);
    code.Release();
   
    // Creating pixel shader
    code = D3DCompile(shaders, null, null, null, "PS", "ps_5_0", 0, 0);
    final ID3D11PixelShader ps = device.CreatePixelShader(code, null);
    code.Release();
   
    // Create vertex buffer
    D3D11_BUFFER_DESC bufferDesc = new D3D11_BUFFER_DESC(D3D11_BIND_VERTEX_BUFFER,
                               D3D11_USAGE_DEFAULT,
                               D3D11_CPU_ACCESS_NONE,
                               0,
                               (int)(9 * sizeOf(Float.class)));
    D3D11_SUBRESOURCE_DATA initData = new D3D11_SUBRESOURCE_DATA();
    initData.pSysMem(pointerToFloats(0.0f, 1.0f, 0.5f, 1f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f));
    initData.SysMemPitch(0).SysMemSlicePitch(0);
    final ID3D11Buffer vertexBuffer = device.CreateBuffer(bufferDesc, initData);
    delete(initData)// Delete data of regain memory
   
    // Create constant buffer (size must be multiple of 16)
    bufferDesc.BindFlags(D3D11_BIND_CONSTANT_BUFFER);
    bufferDesc.Usage(D3D11_USAGE_DYNAMIC);
    bufferDesc.CPUAccessFlags(D3D11_CPU_ACCESS_WRITE);
    bufferDesc.ByteWidth((int) sizeOf(D3DXMATRIX.class));
    final ID3D11Buffer constBuffer = device.CreateBuffer(bufferDesc, null);
   
    final AtomicInteger angle = new AtomicInteger(0);
    final D3DXMATRIX mat = new D3DXMATRIX();
    D3DXMatrixIdentity(pointerTo(mat));
   
    JNIEnv env = JAWTUtils.getJNIEnv();
    JAWT jawt = JAWTUtils.getJAWT(env);
    while(frame.isEnabled()) {

      if(frame.isVisible())
       
        /*
         * Drawing shall occur inside this methods, to prevent deadlock between
         * Java drawing and native drawing
         */
        JAWTUtils.withLockedSurface(env, jawt, frame, new LockedComponentRunnable() {
         
          @Override
          public void run(Component comp, long peer) {
            // Clear screen
            immediateContext.ClearRenderTargetView(pointerTo(rtView), pointerToFloats(0.0f, 0.125f, 0.3f, 1.0f));
           
            // Set vertex buffer
            int stride = (int) (sizeOf(Float.class) * 3);
            immediateContext.IASetVertexBuffers(0, 1, pointerToPointer(pointerTo(vertexBuffer)), pointerToInt(stride), pointerToInt(0));
           
            // Set shaders and input layout
            immediateContext.IASetInputLayout(layout);
            immediateContext.VSSetShader(pointerTo(vs), null, 0);
            immediateContext.PSSetShader(pointerTo(ps), null, 0);
           
            // Update rotation matrix for triangle
            D3DXMatrixRotationZ(pointerTo(mat), angle.addAndGet(1) * 0.01f);
            D3D11_MAPPED_SUBRESOURCE mappedData = immediateContext.Map(constBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0);
            pointerTo(mat).copyTo(mappedData.pData());
            immediateContext.Unmap(constBuffer, 0);
            immediateContext.VSSetConstantBuffers(0, 1, pointerToPointer(pointerTo(constBuffer)));
           
            // Set primitive topology and draw
            immediateContext.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
            immediateContext.Draw(3, 0);
           
            // Present to screen
            swapChain.Present(0, 0);
          }
        });
   
      try {
        Thread.sleep(5);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
   
    vs.Release();
    ps.Release();
    layout.Release();
    vertexBuffer.Release();
    swapChain.Release();
    device.Release();
  }
View Full Code Here

    // Compiling for vertex shader and input layout
    ID3D10Blob code = D3DCompile(shaders, null, null, null, "VS", "vs_5_0", 0, 0);
   
    // Create input layout
    D3D11_INPUT_ELEMENT_DESC layoutDesc = new D3D11_INPUT_ELEMENT_DESC("POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0);
    final ID3D11InputLayout layout = device.CreateInputLayout(new D3D11_INPUT_ELEMENT_DESC[] { layoutDesc }, code);
    immediateContext.IASetInputLayout(layout);
   
    // Creating vertex shader
    final ID3D11VertexShader vs = device.CreateVertexShader(code, null);
    code.Release();
   
    // Creating pixel shader
    code = D3DCompile(shaders, null, null, null, "PS", "ps_5_0", 0, 0);
    final ID3D11PixelShader ps = device.CreatePixelShader(code, null);
    code.Release();
   
    // Create vertex buffer
    D3D11_BUFFER_DESC bufferDesc = new D3D11_BUFFER_DESC(D3D11_BIND_VERTEX_BUFFER,
                               D3D11_USAGE_DEFAULT,
                               D3D11_CPU_ACCESS_NONE,
                               0,
                               (int)(9 * sizeOf(Float.class)));
    D3D11_SUBRESOURCE_DATA initData = new D3D11_SUBRESOURCE_DATA();
    initData.pSysMem(pointerToFloats(0.0f, 1.0f, 0.5f, 1f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f));
    initData.SysMemPitch(0).SysMemSlicePitch(0);
    final ID3D11Buffer vertexBuffer = device.CreateBuffer(bufferDesc, initData);
   
    JNIEnv env = JAWTUtils.getJNIEnv();
    JAWT jawt = JAWTUtils.getJAWT(env);
    while(frame.isEnabled()) {

      if(frame.isVisible())
        JAWTUtils.withLockedSurface(env, jawt, frame, new LockedComponentRunnable() {
          @Override
          public void run(Component comp, long peer) {
            immediateContext.ClearRenderTargetView(pointerTo(rtView), pointerToFloats(0.0f, 0.125f, 0.3f, 1.0f));
           
            int stride = (int) (sizeOf(Float.class) * 3);
            immediateContext.IASetVertexBuffers(0, 1, pointerToPointer(pointerTo(vertexBuffer)), pointerToInt(stride), pointerToInt(0));
           
            immediateContext.IASetInputLayout(layout);
            immediateContext.VSSetShader(pointerTo(vs), null, 0);
            immediateContext.PSSetShader(pointerTo(ps), null, 0);
           
            immediateContext.IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
            immediateContext.Draw(3, 0);
           
            swapChain.Present(0, 0);
          }
        });
   
      try {
        Thread.sleep(5);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
   
    vs.Release();
    ps.Release();
    layout.Release();
    vertexBuffer.Release();
    swapChain.Release();
    device.Release();
  }
View Full Code Here

TOP

Related Classes of d3d11.core.ID3D11DeviceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.