Пример #1
0
    def onCreate(self):
        #Heightmap.
        #self.heightmap = d3d11x.HeightMap(self.device, None, (64, 64), heightCallback, (2, 1, 2), (8, 8), False)
        self.heightmap = d3d11x.HeightMap(
            self.device, d3d11x.getResourceDir("Textures", "heightmap.dds"),
            (64, 64), heightCallback, (2, 1, 2), (8, 8), False)

        self.heightmap.textureView = self.loadTextureView("ground-marble.dds")

        #Sphere mesh.
        meshPath = d3d11x.getResourceDir("Mesh", "sphere.obj")
        self.sphere = d3d11x.Mesh(self.device, meshPath)
        self.sphere.textureView = self.loadTextureView("misc-white.bmp")
def compute():
    #Create two input buffers and one for the output.
    buffer1, buffer1srv = createBufferAndView()
    buffer2, buffer2srv = createBufferAndView()
    bufferOut, bufferOutUav = createBufferAndView()
    bufferOut.resize(NUMITEMS)

    #Staging buffer which will be used to copy data
    #between GPU and CPU.
    stager = createStagingBuffer(INPUTDATA, CPU_ACCESS_WRITE | CPU_ACCESS_READ)
    buffer1.copy(stager)
    buffer2.copy(stager)

    #Load the effect and set buffers.
    effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "Compute.fx"))
    effect.set("buffer1", buffer1srv)
    effect.set("buffer2", buffer2srv)
    effect.set("bufferOut", bufferOutUav)
    effect.set("bufferSize", NUMITEMS)
    effect.apply(0, 0)

    compStart = time.clock()
    #Start the compute operation.
    device.dispatch(NUMITEMS, 1, 1)

    #Copy data back for CPU access.
    stager.copy(bufferOut)
    outputData = []
    with d3d11x.Mapper(stager, MAP_READ):
        outputData = stager[:]

    print("Compute shader took %f seconds" % (time.clock() - compStart))

    verifyResults(outputData)
Пример #3
0
    def onCreate(self):
        #Add a macro and replace the default effect with our own.
        d3d11x.Mesh.effectMacros["BLOB_COUNT"] = str(BLOB_COUNT)
        d3d11x.Mesh.effectName = "SampleBlobs.fx"

        self.mesh = d3d11x.Mesh(self.device,
                                d3d11x.getResourceDir("Mesh", "sphere.obj"))

        #Blob data.
        self.blobs = []
        self.pos = [
            d3d11.Vector(-1.5, 6.0, -4.0),
            d3d11.Vector(1.5, 0.0, -4.0),
            d3d11.Vector(6.5, 7.0, -4.0),
            d3d11.Vector(-6.5, 7.0, -4.0)
        ]

        #GUI stuff.
        self.manager = d3d11gui.Manager(self.device, self.window)

        main = d3d11gui.Window(self.manager, d3d11x.Rect(10, 50, 200, 120))
        main.text = "Choose the technique:"

        choice = d3d11gui.Choice(main, d3d11x.Rect(5, 30, 150, 25))
        choice.onChoice = self.onChoiceTech
        choice.add("Merge")
        choice.add("Meta")
        choice.add("Wobble")
        choice.add("Avoid")
        choice.add("No effect")

        self.tech = 0
Пример #4
0
 def onClickLaunchSample(self, event):
     pyPath = d3d11x.getResourceDir(event.sender.pyname + ".py")
     self.window.show(SW_HIDE)
     try:
         subprocess.call('"%s" "%s"' % (sys.executable, pyPath))
     except:
         pass
     self.window.show(SW_SHOW)
Пример #5
0
 def build(self):
     effectName = self.effecName
     if not self.effecName:
         effectName = "marker.fx"
     effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
     self.effect = d3d11.Effect(effectPath)
     #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
     #the pass's input signature is compatible with that combination.
     self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)
Пример #6
0
 def onCreate(self):
     
     #Sphere mesh.
     meshPath = d3d11x.getResourceDir("Mesh", "sphere.obj")
     self.sphere = d3d11x.Mesh(self.device, meshPath)
     self.sphere.textureView = self.loadTextureView("misc-white.bmp")
     
     #User controlled camera.
     self.camera = d3d11x.Camera((0, 0, -40), (0, 1, 0), 1.0)
Пример #7
0
	def build(self):
		effectName = self.effecName
		if not self.effecName:
			effectName = "marker.fx"
		effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
		self.effect = d3d11.Effect(effectPath)
		#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
		#the pass's input signature is compatible with that combination.
		self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)
    def onCreate(self):
        self.renderTarget = None
        self.renderTargetView = None

        meshPath = d3d11x.getResourceDir("Mesh", "barrel.obj")
        self.mesh = d3d11x.Mesh(self.device, meshPath)
        self.mesh.textureView = self.loadTextureView("static-barrel.dds")

        self.skyBox = d3d11x.SkyBox(self.device)
        self.skyBox.textureView = self.loadTextureView("skybox-clear.dds")

        effectPath = d3d11x.getResourceDir("Effects", "SamplePostProcess.fx")
        self.postEffect = d3d11.Effect(effectPath)
        self.postInputLayout = d3d11.InputLayout(vertexLayoutDesc,
                                                 self.postEffect, 0, 0)

        #Vertex buffer for 2D stuff.
        self.vertexBuffer = d3d11.Buffer(vertexLayoutDesc, 32,
                                         BIND_VERTEX_BUFFER, USAGE_DYNAMIC,
                                         CPU_ACCESS_WRITE)
Пример #9
0
	def setDesc(self, desc):
		self.desc = desc

		effectPath = d3d11x.getResourceDir(".", self.desc.effect)
		self.effect = d3d11.Effect(effectPath)
		self.vertexDesc = self.desc.vtdesc

		print self.desc.effect, self.vertexDesc
		print self.effect
		#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
		#the pass's input signature is compatible with that combination.
		self.inputLayout = d3d11.InputLayout(self.vertexDesc, self.effect, 0, 0)
Пример #10
0
    def setDesc(self, desc):
        self.desc = desc

        effectPath = d3d11x.getResourceDir(".", self.desc.effect)
        self.effect = d3d11.Effect(effectPath)
        self.vertexDesc = self.desc.vtdesc

        print self.desc.effect, self.vertexDesc
        print self.effect
        #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
        #the pass's input signature is compatible with that combination.
        self.inputLayout = d3d11.InputLayout(self.vertexDesc, self.effect, 0,
                                             0)
    def onCreate(self):
        #Heightmap.
        self.heightmap = d3d11x.HeightMap(
            self.device, d3d11x.getResourceDir("Textures", "heightmap.dds"),
            (64, 64), heightCallback, (1.5, 0.1, 1.5), (8, 8), True)
        self.heightmap.textureView = self.loadTextureView("ground-moss.dds")

        #Skybox.
        self.skybox = d3d11x.SkyBox(self.device)
        self.skybox.textureView = self.loadTextureView("skybox-clear.dds")

        #User controlled camera.
        self.camera = d3d11x.Camera((0, 20, -80), (0, 10, 0), 1.0)
Пример #12
0
    def build(self):
        effectName = self.effecName
        if not self.effecName:
            effectName = "marker.fx"
        effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
        self.effect = d3d11.Effect(effectPath)
        #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
        #the pass's input signature is compatible with that combination.
        self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)

        vertexData = []
        for i in xrange(self.gridx + 1):
            if i % 2 == 0:
                vertexData.append((0, 0, i * self.gridsize, 1, 1, 1, 1))
                vertexData.append(
                    (self.width, 0, i * self.gridsize, 1, 1, 1, 1))
            else:
                vertexData.append(
                    (self.width, 0, i * self.gridsize, 1, 1, 1, 1))
                vertexData.append((0, 0, i * self.gridsize, 1, 1, 1, 1))

        for i in xrange(self.gridy + 1):
            if self.height % 2 == 0:
                if i % 2 == 0:
                    vertexData.append(
                        (i * self.gridsize, 0, self.height, 1, 1, 1, 1))
                    vertexData.append((i * self.gridsize, 0, 0, 1, 1, 1, 1))
                else:
                    vertexData.append((i * self.gridsize, 0, 0, 1, 1, 1, 1))
                    vertexData.append(
                        (i * self.gridsize, 0, self.height, 1, 1, 1, 1))
            else:
                if i % 2 == 0:
                    vertexData.append(((self.width - i) * self.gridsize, 0,
                                       self.height, 1, 1, 1, 1))
                    vertexData.append(
                        ((self.width - i) * self.gridsize, 0, 0, 1, 1, 1, 1))
                else:
                    vertexData.append(
                        ((self.width - i) * self.gridsize, 0, 0, 1, 1, 1, 1))
                    vertexData.append(((self.width - i) * self.gridsize, 0,
                                       self.height, 1, 1, 1, 1))

        self.vertexBuffer = d3d11.Buffer(
            g_vertexDesc,
            vertexData,  # D3D11_SUBRESOURCE_DATA
            BIND_VERTEX_BUFFER,  # D3D11_BUFFER_DESC.BinadFlags
            USAGE_DYNAMIC,  # D3D11_BUFFER_DESC.Usage
            CPU_ACCESS_WRITE,  # D3D11_BUFFER_DESC.CPUAccessFlags
        )
    def __init__(self, parent, id, title, pos, size=(800, 600)):
        wx.Frame.__init__(self, parent, id, title, pos, size)

        self.mainpanel = wx.Panel(self, -1, size=(800, 600))
        self.mainpanel.SetAutoLayout(True)

        self.leftwindow = wx.Panel(self.mainpanel, -1, (10, 10), (380, 450))
        self.leftwindow.SetBackgroundColour(wx.WHITE)
        self.leftwindow.SetConstraints(
            anchors.LayoutAnchors(self.leftwindow, True, True, True, True))

        self.rightwindow = wx.Panel(self.mainpanel, -1, (400, 10), (380, 450))
        self.rightwindow.SetBackgroundColour(wx.WHITE)
        self.rightwindow.SetConstraints(
            anchors.LayoutAnchors(self.rightwindow, False, True, True, True))

        playvideo = wx.Button(self.mainpanel, -1,
                              "Play media on this window...", (500, 500))
        playvideo.SetConstraints(
            anchors.LayoutAnchors(playvideo, False, False, True, True))
        self.Bind(wx.EVT_BUTTON, self.playVideo, playvideo)

        #Create a DirectPython window from an existing wxPython window.
        tempWindow = d3d11.Window(handle=self.leftwindow.GetHandle())

        #Create our resources. Note that if the size of the window
        #changes, you should call self.device.reset().
        self.device = d3d11.Device(tempWindow, DRIVER_TYPE_WARP)
        self.effect = d3d11.Effect(
            d3d11x.getResourceDir("Effects", "Tutorial2.fx"))
        self.inputLayout = d3d11.InputLayout(vertexDesc, self.effect, 0, 0)
        self.vertexBuffer = d3d11.Buffer(vertexDesc, triangle,
                                         BIND_VERTEX_BUFFER)

        #We need to detach() the window. This means that it is up to
        #us (or wxPython) to mange the window from now on.
        tempWindow.detach()

        self.media = None

        self.Bind(wx.EVT_PAINT, self.onPaint)
        self.Bind(wx.EVT_TIMER, self.onTimer)
        self.Bind(wx.EVT_IDLE, self.onIdle)
        self.leftwindow.Bind(wx.EVT_SIZE, self.onSize)

        #Use a timer for rendering. It is not a very smooth
        #solution, you might want to tweak the time interval
        #or do something else, now it is jerky.
        self.timer = wx.Timer(self)
        self.timer.Start(10)
Пример #14
0
	def build(self):
		effectName = self.effecName
		if not self.effecName:
			effectName = "marker.fx"
		effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
		self.effect = d3d11.Effect(effectPath)
		#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
		#the pass's input signature is compatible with that combination.
		self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)

		vertexData = []
		for i in xrange(self.gridx+1):
			if i%2 == 0:
				vertexData.append( (0, 0, i*self.gridsize, 1, 1, 1, 1) )
				vertexData.append( (self.width, 0, i*self.gridsize, 1, 1, 1, 1) )
			else:
				vertexData.append( (self.width, 0, i*self.gridsize, 1, 1, 1, 1) )
				vertexData.append( (0, 0, i*self.gridsize, 1, 1, 1, 1) )

		for i in xrange(self.gridy+1):
			if self.height%2 == 0:
				if i%2 == 0:
					vertexData.append( (i*self.gridsize, 0, self.height, 1, 1, 1, 1) )
					vertexData.append( (i*self.gridsize, 0, 0, 1, 1, 1, 1) )
				else:
					vertexData.append( (i*self.gridsize, 0, 0, 1, 1, 1, 1) )
					vertexData.append( (i*self.gridsize, 0, self.height, 1, 1, 1, 1) )
			else:
				if i%2 == 0:
					vertexData.append( ( (self.width-i)*self.gridsize, 0, self.height, 1, 1, 1, 1) )
					vertexData.append( ( (self.width-i)*self.gridsize, 0, 0, 1, 1, 1, 1) )
				else:
					vertexData.append( ( (self.width-i)*self.gridsize, 0, 0, 1, 1, 1, 1) )
					vertexData.append( ( (self.width-i)*self.gridsize, 0, self.height, 1, 1, 1, 1) )

		self.vertexBuffer = d3d11.Buffer(
				g_vertexDesc,
				vertexData,				# D3D11_SUBRESOURCE_DATA
				BIND_VERTEX_BUFFER,		# D3D11_BUFFER_DESC.BinadFlags
				USAGE_DYNAMIC,			# D3D11_BUFFER_DESC.Usage
				CPU_ACCESS_WRITE,		# D3D11_BUFFER_DESC.CPUAccessFlags
		)
Пример #15
0
    def onCreate(self):
        self.heightmap = d3d11x.HeightMap(self.device, None, (32, 32),
                                          heightFunc, (2, 1, 2), (10, 10),
                                          False)
        self.heightmap.textureView = self.loadTextureView("ground-marble.dds")

        effectPath = d3d11x.getResourceDir("Effects", "SampleSprites.fx")
        self.spriteEffect = d3d11.Effect(effectPath)
        self.spriteInputLayout = d3d11.InputLayout(spriteLayoutDesc,
                                                   self.spriteEffect, 0, 0)
        self.spriteTexture = self.loadTextureView("misc-particle.dds")

        self.camera = d3d11x.Camera()

        #Create a dynamic vertex buffer for our sprites. Double the
        #size for shadow sprites.
        self.spriteBuffer = d3d11.Buffer(spriteLayoutDesc, POINT_COUNT * 2,
                                         BIND_VERTEX_BUFFER, USAGE_DYNAMIC,
                                         CPU_ACCESS_WRITE)

        self.points = []
Пример #16
0
    def onCreate(self):
        self.window.show(SW_HIDE)

        textureName = d3d11x.getResourceDir("Textures", "static-barrel.dds")

        #Warm the filesystem cache.
        dummy = d3d11.Texture(textureName)

        COUNT = 10
        #Force format conversion, heavy work for the CPU.
        FORMAT = FORMAT_R8G8B8A8_UNORM

        #Normal loading.
        normalStart = time.clock()
        for x in range(COUNT):
            t = d3d11.Texture(textureName, (0, 0, 1, 0), FORMAT)
        normalTime = time.clock() - normalStart

        #Threaded loading.
        threadStart = time.clock()
        loader = d3d11x.ThreadedLoader()
        for x in range(COUNT):
            loader.addJob(self, "t", d3d11.Texture, textureName, (0, 0, 1, 0),
                          FORMAT)
        #loader.wait()
        loader.join()
        threadTime = time.clock() - threadStart

        comp = normalTime / threadTime
        result = "faster"
        if comp < 1.0:
            result = "slower"

        d3d11.messageBox(self.window,
                         message % (normalTime, threadTime, comp, result),
                         "Results", 0)

        self.exit()
Пример #17
0
    #This is functionally same as above, only easier to read. I use the complex one now
    #so that you don't get confused when you encounter it in samples.
    #("POSITION", 0, FORMAT_R32G32B32_FLOAT),
    #("COLOR", 0, FORMAT_R32G32B32A32_FLOAT),
]

#Our triangle - three vertices with position and color. The layout must match 'vertexDesc'.
triangle = [
    (-5, 0, 0) + (1, 0, 0, 1),  #Red vertex.
    (0, 10, 0) + (0, 1, 0, 1),  #Green vertex.
    (5, 0, 0) + (0, 0, 1, 1),  #Blue vertex.
]

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "Tutorial2.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, triangle, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1:
Пример #18
0
    #("COLOR", 0, FORMAT_R32G32B32A32_FLOAT),
]

#Our triangle - three vertices with position and color. The layout must match 'vertexDesc'.
triangle = [
    (-5, 0, 0) + (1, 0, 0, 1), #Red vertex.
    (0, 10, 0) + (0, 1, 0, 1), #Green vertex.
    (5, 0, 0)  + (0, 0, 1, 1), #Blue vertex.
]

vertices = []
for p in cdata.Box:
	vertices.append((p[0], p[1], p[2], 1, 1, 1, 1))

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "simple.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, vertices, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))

def mainloop():
    while 1:
        #Check all new messages.
Пример #19
0
    def onCreate(self):
        self.manager = gui.Manager(self.device, self.window)

        root = gui.Window(self.manager, d3d11x.Rect(250, 100, 500, 400))
        root.title = "Window 1"

        root2 = gui.Window(self.manager, d3d11x.Rect(10, 10, 400, 450))

        text = gui.Label(root2, d3d11x.Rect(10, 10, 300, 100))
        text.setAnchor((10, None, 10, None))
        text.titleColor = (1, 1, 0, 1)
        text.title = "This is a sample"
        text.text = "This control has an anchor attached and will be resized horizontally if the parent window is resized."

        edit = gui.TextBox(root2, d3d11x.Rect(10, 140, 300, 250))
        edit.text = "You can edit the contents of this text box in many ways.\n\nPress the right mouse key on an empty space to open a menu."

        image = gui.Image(root, d3d11x.Rect(300, 50, 1, 1),
                          d3d11x.getResourceDir("Textures", "misc-moon.png"),
                          (50, 50))
        image.text = "Image"
        image.textColor = (1, 0, 0, 0.75)

        button = gui.Button(root, d3d11x.Rect(10, 20, 100, 35), "Hello")
        button.onClick = self.onHello

        #You can store custom objects into some widgets. Anything
        #which can be converted to a string is OK.
        class Dummy:
            def __init__(self, i):
                self.i = i

            def __str__(self):
                return "Item %i" % self.i

        choices = gui.Choice(root, d3d11x.Rect(10, 60, 200, 30))
        choices.onChoice = self.onChoice
        for x in range(5):
            choices.add(Dummy(x))

        group = gui.CheckBoxGroup(root, d3d11x.Rect(10, 120, 150, 200))
        group.onCheck = self.onCheck
        for x in range(3):
            group.add(Dummy(x))
        group.check(1, True)

        radio = gui.RadioGroup(root, d3d11x.Rect(200, 120, 150, 200))
        radio.onSelect = self.onSelect
        for x in range(3):
            radio.add(Dummy(x))
        radio.select(2)

        slider = gui.Slider(root, d3d11x.Rect(20, 250, 200, 8))
        slider.range = 100
        slider.drawConnectors = 1
        slider.addSelector(gui.Selector(0, 50))
        slider.addSelector(gui.Selector(49, 100, 99))
        slider.onSlide = self.onSlide

        slider2 = gui.Slider(root, d3d11x.Rect(250, 250, 100, 8))
        slider2.range = 50
        slider2.addSelector()

        scrollBar = gui.ScrollBar(root, d3d11x.Rect(0, 0, 100, 100))
        scrollBar.setScrollData(gui.ScrollData(20, 10, gui.SCROLL_X))
        scrollBar.setScrollData(gui.ScrollData(10, 10, gui.SCROLL_Y))

        progress = gui.ProgressBar(root, d3d11x.Rect(10, 300, 200, 25))
        progress.throbber = True
Пример #20
0
    #("COLOR", 0, FORMAT_R32G32B32A32_FLOAT),
]

#Our triangle - three vertices with position and color. The layout must match 'vertexDesc'.
triangle = [
    (-5, 0, 0) + (1, 0, 0, 1),  #Red vertex.
    (0, 10, 0) + (0, 1, 0, 1),  #Green vertex.
    (5, 0, 0) + (0, 0, 1, 1),  #Blue vertex.
]

vertices = []
for p in cdata.Box:
    vertices.append((p[0], p[1], p[2], 1, 1, 1, 1))

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "simple.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, vertices, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1:
Пример #21
0
 def onClickHelp(self, event):
     helpIndex = d3d11x.getResourceDir("..", "Docs", "index.html")
     os.startfile(helpIndex)