I'm using the 11.2 compatible build of SharpDX and have rendering going up well so far, however i'm starting to test things out with large textures and would need mipmaping to avoid the ugly artifacts of higher than screen resolution textures.
From what i understand if i want the full set of mipmap levels i need to set MipLevels to 0 in my texture creation, however, changing the MipLevels parameter from 1 (what it was and works) to 0 (my goal) causes an exception with invalid parameter on the texture instantiation line.
The error has to be at that point or before (crashed before it reaches any rendering and at the step of declaration).
Here's how i'm declaring my texture state :
new SharpDX.Direct3D11.Texture2DDescription()
{
Width = bitmapSource.Size.Width,
Height = bitmapSource.Size.Height,
ArraySize = 1,
BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource,
Usage = SharpDX.Direct3D11.ResourceUsage.Immutable,
CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
MipLevels = 1, // This works, but if i change it to 0, i get an argument invalid exception
OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
}
Since the texture is immutable and being created with a full MIP chain you need to provide initial data for every mip in the chain. I assume you are only providing data for mip 0?
EDIT:
A similar question is asked here: http://www.gamedev.net/topic/605521-mipmap-dx11/
You have a few different options:
1) Generate the mips offline (perhaps store your textures in a DDS, which supports mips) and provide an array of DataRectangles, one for each mip.
2) Remove the Immutable usage flag, use Default instead, don't provide any initial data but instead use something like Map or UpdateSubresource to fill in Mip 0 after it has been created. Once mip 0 is populated, you can call GenerateMips on the DeviceContext so long as the texture was created with the D3D11_RESOURCE_MISC_GENERATE_MIPS MiscFlag, this will populate all other mips with the correct downsampled data.
3) A third approach would be to do something similar to Option 2, but instead you could provide a dummy set of data for all but the first mip and thus avoid the need to call Map or UpdateSubresource. However you will still have to call GenerateMips on the DeviceContext.
Related
I have two meshes, containing same material template but with different paramters. I want to draw these two meshes one by one. For example, the pseudocode likes
BeginRenderPass
BindPipeline
for(auto& mesh : meshes)
{
BindVertexBuffers(mesh.vertexBuffer)
AddUniformBufferDescriptorSet(mesh.material)
UpdateDescriptorSets
BindIndexBuffer(mesh.indexBuffer)
DrawIndexed(mesh.indexCount, 1, 0, 0, 0)
}
vkCmdEndRenderPass
I bind vertex buffers of all mesh to same binding index, and use same descriptor set for all uniform object. There are some validation errors:
validation layer: Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidCommandBuffer-VkDescriptorSet ] Object 0: handle = 0x40b43c0000000049, type = VK_OBJECT_TYPE_DESCRIPTOR_SET; Object 1: handle = 0x1c40e53df48, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xe8616bf2 | You are adding vkCmdBindVertexBuffers() to VkCommandBuffer 0x1c40e53df48[] that is invalid because bound VkDescriptorSet 0x40b43c0000000049[] was destroyed or updated.
How can I implement the above pseudocode ?
There is my finding(WRONG). ~~First, the conclusion is I can not implment mulitple draw calls like the above pseudocode.~~ Because, according to vkUpdateDescriptorSets , it will invalid the command buffer used to bind the descriptor sets, which will disenable record next call. Therefore, the validation error appears.
What I can implement to draw multiple meshes with seperate material parameters.
There are two ways:
Use push_constant in shader to config material parameters, and set the corresponding parameter values by vkCmdPushConstants before draw call.
Use uniform buffer array in shader, where each element is a set of material parameters. Add an additional input attribute named “material id” to index the corresponding uniform buffer. Then update the uniform buffer array in one call of vkUpdateDescriptorSets. The current command buffer still can record next draw call command.
The first way is inspired by Sascha_Willems, the second way is what I have successfully implemented.
Supplement(CORRECTION)
I also try to update and bind the corresponding descriptor set before each of two draw calls insider one render pass. Finally, it works. Note that two seperate descriptor sets with same layout bindings need to be created, but the graphics pipeline need to be decleared to contain only one descriptor set.
Essential, due to crappy circumstances, I need to do this in native Twig if possible: (I know this shouldn't be done in a VIEW template language)
loop over object.key
object.key["key1"] = ["val1","val2-a"]
object.key["key2"] = ["val1","val2-b"]
object.key["key3"] = ["val1","val2-c"]
manipulate as needed, into a new array or object or whatever and get
object.key["key1"] = ["val2-a"]
object.key["key2"] = ["val2-b"]
object.key["key3"] = ["val2-c"]
As you can see, I need to reduce duplicates values across different keys.
I'm having hard time finding a way to do this with out adding a custom filter or changing some architecture in the back-end that, basically, a deadline doesn't have time for. Any thoughts?
For several years I have been using the CGridCellCombo class. It is designed to be used with the CGridCtrl.
Several years ago I did make a request in the comments section for an enhancement but I got no replies.
The basic concept of the CGridCellCombo is that it works with the text value of the cell. Thus, when you present the drop list it will have that value selected. Under normal circumstances this is fine.
But I have places where I am using the combo as a droplist. In some situations it is perfectly fine to continue to use the text value as the go-between.
But is some situations it would have been ideal to know the actual selected index of the combo. When I have a droplist and it is translated into 30 languages, and I need to know the index, I have no choice but to load the possible options for that translation and then examine the cell value and based on the value found in the array I know the index.
It works, but is not very elegant. I did spend a bit of time trying to keep track of the selected index by adding a variable to CInPlaceList and setting it but. I then added a wrapper method to the CGridCellCombo to return that value. But it didn't work.
I wondered if anyone here has a good understanding of the CGridCellCombo class and might be able to advise me in exposing the CComboCell::GetCurSel value.
I know that the CGridCtrl is very old but I am not away of another flexible grid control that is designed for MFC.
The value that is transfered back to the CGridCtrl is choosen in CInPlaceList::EndEdit. The internal message GVN_ENDLABELEDIT is used, and this message always use a text to set it into the grid.
The value is taken here via GetWindowText from the control. Feel free to overwrite this behaviour.
The handler CGridCtrl::OnEndInPlaceEdit again calls OnEndEditCell. All take a string send from GVN_ENDLABELEDIT.
When you want to make a difference between the internal value and the selected value you have to manage this via rewriting the Drawing and selecting. The value in the grid is the GetCurSel value and you have to show something different... There isn't much handling about this in the current code to change.
More information
The key is CInPlaceList::EndEdit(). There is a call to GetWindowText (CInPlaceList is derived from CComboBox), just get the index here. Also in CGridCellCombo::EndEdit you have access to the m_pEditWnd, that is the CInPlaceList object and derived from CComboBox, so you have access here too.
I have found this to be the simplest solution:
int CGridCellCombo::GetSelectedIndex()
{
int iSelectedIndex = CB_ERR;
CString strText = GetText();
for (int iOption = 0; iOption < m_Strings.GetSize(); iOption++)
{
if (strText.CollateNoCase(m_Strings[iOption]) == 0) // Match
{
iSelectedIndex = iOption;
break;
}
}
return iSelectedIndex;
}
I'm not sure of the underlying implementation of the texture atlases, so my question is - what is the correct way to deal with pulling textures out of them? I need to loop through various atlases and pull out 64 random textures.
Create a static atlas and reuse the reference to pull out textures?
static SKTextureAtlas *monsterAtlas;
static int monsterCount;
monsterAtlas = [SKTextureAtlas atlasNamed:#"monsters"];
monsterCount = [monsterAtlas textureNames].count;
//pull out a random texture
NSString* textureName = [[monsterAtlas textureNames] objectAtIndex: arc4random()%monsterCount];
SKTexture* texture = [monsterAtlas textureNamed:textureName];
-OR-
create a new atlas every time I need a texture?
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:#"monster"];
SKTexture *f1 = [atlas textureNamed:#"monster-walk1.png"];
The reason i'm asking is that with the first approach, my code may be quite unweildy, as I would have 10+ atlas references created. Will this use too much memory?
With the second approach I'm concerned that I will be doing a lot of extra work creating an atlas each time I execute a loop iteration. How should I do this?
Create each atlas once and keep a reference to it.
It's not unweildy if you write a class that manages atlases and gives you access to individual textures.
I am making a game in Game Maker right now and cannot figure out how to get an objects exact position and have another object move to that position. Can someone please help me?
To get an object's position simply use
xpos = instance.x;
ypos = instance.y;
where instance is the instance id (gained through some method, object id can be used if the instance is the only instantiation of the object).
To start moving towards a position you should set the speed & direction:
direction = point_direction(x,y, instance.x, instance.y);
speed = WANTEDSPEED;
The object position are two variables (x,y)
You can access them as you would do with any other variable (objectName.variable)
So these two would be, as paul23 said:
object.x
object.y
To make the object move towards a point you can better use this built-in function:
move_towards_point(object.x,object.y,speed)
It'll move by speed pixels every time it's executed so you may want to put it in the Step event.