Related
I’m somewhat new to Swiftui programming and probably making all kinds of beginner mistakes. That said, I’m trying to learn the language by grinding my teeth on a number of small programs and in this one, can’t seem to get the ContentView to update for numPlayers and numRows when returning from Sheet but the two Bool variables (showRowIndicators and showColumnIndicators) update correctly in ContentView.
Any help would be appreciated! :)
import SwiftUI
struct Player: Identifiable, Hashable {
var id: Int = 0
var name: String = ""
}
struct ContentView: View {
#State var players = [
Player(id: 0, name: "Player1"),
Player(id: 1, name: "Player2"),
Player(id: 2, name: "Player3"),
Player(id: 3, name: "Player4"),
Player(id: 4, name: "Player5"),
Player(id: 5, name: "Player6"),
Player(id: 6, name: "Player7"),
Player(id: 7, name: "Player8"),
Player(id: 8, name: "Player9"),
Player(id: 9, name: "Player10"),
]
#State var numbers = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
]
#AppStorage("numRows") var numRows: Int = 10
#AppStorage("numPlayers") var numPlayers: Int = 4
#AppStorage("showRowIndicators") var showRowIndicators: Bool = false
#AppStorage("showColumnIndicators") var showColumnIndicators: Bool = false
#State var backgroundColor: Color = Color.green
#State var showSheet: Bool = false
var rowOddBColor: Color = Color.white.opacity(0.2)
var rowEvenBColor: Color = Color.green.opacity(0.2)
var maxRows = 20
let boxWidth = 65.0
let boxHeight = 22.0
let boxPadH = 2.0
let HSspace = 7.0
let boxBackColor = Color(#colorLiteral(red: 0.8993894458, green: 0.8753863573, blue: 0.7580057979, alpha: 1))
let boxForeColor = Color(#colorLiteral(red: 0, green: 0, blue: 0, alpha: 1))
let totalBackColor = Color(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1))
let topScoreBackColor = Color(#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1))
var winningPlayer: Int = 0
var isTopScore: Int = 0
var body: some View {
ZStack {
//background
backgroundColor
.ignoresSafeArea()
//content
DisplayColumnGuides(numPlayers: $numPlayers, showColumnIndicators: $showColumnIndicators, backgroundColor: $backgroundColor, HSspace: HSspace, boxWidth: boxWidth)
ScrollView(.vertical) {
VStack(spacing: 0) {
HStack {
Image(systemName: "gear")
.font(.largeTitle)
.frame(width: 50, alignment: .leading)
.onTapGesture {
showSheet.toggle()
}
Spacer()
}
DisplayPlayerNames(players: $players, numPlayers: $numPlayers, HSspace: HSspace, boxWidth: boxWidth, boxHeight: boxHeight)
let rowCount: Int = (numRows <= maxRows ? numRows : maxRows)
ForEach(0..<rowCount) { row in
ZStack {
Text("\(row+1)")
.font(.footnote)
.foregroundColor(.white)
.frame(maxWidth: .infinity, alignment: .leading)
HStack(spacing: HSspace) {
ForEach(0..<numPlayers) { column in
TextField("", value: self.$numbers[row][column], format: .number)
.foregroundColor(boxForeColor)
.font(.title3)
.multilineTextAlignment(.center)
.keyboardType(.numbersAndPunctuation)
.frame(width: boxWidth, height: boxHeight)
// .background(boxBackColor)
.cornerRadius(5.0)
// .border(.black, width: 0.2)
}
}
.frame(maxWidth: .infinity)
.frame(height: boxHeight+5)
.background(
showRowIndicators
? ( isNumberEven(number: row)
? rowEvenBColor
: rowOddBColor
)
: nil
)
}
}
VStack(spacing: 10) {
ZStack {
Text("Total")
// .bold()
.font(.footnote)
.foregroundColor(Color.blue)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.top, 5)
HStack(spacing: HSspace) {
ForEach(0..<numPlayers) { player in
let playerScore = addScore(playerNumber: player)
let topPlayer = getTopPlayer()
Text("\(playerScore)")
.font(.title3)
.foregroundColor(boxForeColor)
.bold()
.frame(width: boxWidth, height: boxHeight+5)
.background(topPlayer == player ? topScoreBackColor : totalBackColor)
// .border(.black)
.cornerRadius(10.0)
}
}
.padding(.top, 5)
}
}
Spacer()
}
}
.sheet(isPresented: $showSheet) {
OptionsView()
}
}
.onTapGesture {
//--- Hide Keyboard ---
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
.gesture(
DragGesture(minimumDistance: 0, coordinateSpace: .local).onEnded({ gesture in
//--- Hide keyboard on swipe down ---
if gesture.translation.height > 0 {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}))
}
func isNumberEven(number: Int) -> Bool {
return (number % 2 == 0)
}
func getTopPlayer() -> Int {
var topScore: Int = 0
var topPlayer: Int = -1
for p in 0..<players.count {
let tPlayer = addScore(playerNumber: p)
if tPlayer > topScore {
topScore = tPlayer
topPlayer = p
}
}
return topPlayer
}
func addScore(playerNumber: Int) -> Int {
let rowCount = maxRows
var playerTotal: Int = 0
for row in 0..<rowCount {
playerTotal += numbers[row][playerNumber]
}
return playerTotal
}
}
struct OptionsView: View {
#Environment(\.presentationMode) var presentationMode
#AppStorage("numRows") var numRows: Int?
#AppStorage("numPlayers") var numPlayers: Int = 4
#AppStorage("showRowIndicators") var showRowIndicators: Bool = false
#AppStorage("showColumnIndicators") var showColumnIndicators: Bool = false
var body: some View {
ZStack {
Color.brown.opacity(0.3)
VStack {
Text("Settings")
.font(.largeTitle)
.underline()
.padding(.vertical)
// Button(action: {
// presentationMode.wrappedValue.dismiss()
// }, label: {
// Image(systemName: "xmark")
// .foregroundColor(.red)
// .font(.title)
// .padding(10)
// })
// .frame(maxWidth: .infinity, alignment: .leading)
HStack {
Text("Enter # score rows (max 20)")
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
TextField("Enter # rows", value: $numRows, format: .number)
.keyboardType(.numberPad)
.multilineTextAlignment(.center)
.frame(width: 100)
.background(Color.white)
.cornerRadius(10.0)
}
.padding(.horizontal)
HStack {
Text("Enter # players (max 10)")
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
TextField("Enter # players", value: $numPlayers, format: .number)
.keyboardType(.numberPad)
.multilineTextAlignment(.center)
.frame(width: 100, alignment: .center)
.background(Color.white)
.cornerRadius(10.0)
}
.padding(.horizontal)
Toggle(isOn: $showRowIndicators, label: {
Text("Show row guides")
})
.padding(.horizontal)
.padding(.top, 20)
Toggle(isOn: $showColumnIndicators, label: {
Text("Show column guides")
})
.padding(.horizontal)
.padding(.top, 5)
Button(action: {
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Close")
.foregroundColor(.blue)
.font(.title)
.frame(width: 100, height: 40.0)
.background(Color.white)
.cornerRadius(25)
.padding(10)
})
.padding(.top, 40)
Spacer()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
// OptionsView()
}
}
struct DisplayColumnGuides: View {
#Binding var numPlayers: Int
#Binding var showColumnIndicators: Bool
#Binding var backgroundColor: Color
var HSspace: Double
var boxWidth: Double
var body: some View {
HStack(spacing: HSspace) {
ForEach(0..<numPlayers) { player in
Rectangle()
.fill(
showColumnIndicators
? Color.blue.opacity(0.2)
: backgroundColor
)
.frame(width: boxWidth, alignment: .center)
}
}
.padding(.vertical, 5)
}
}
struct DisplayPlayerNames: View {
#Binding var players: [Player]
#Binding var numPlayers: Int
var HSspace: Double
var boxWidth: Double
var boxHeight: Double
var body: some View {
HStack(spacing: HSspace) {
ForEach(0..<numPlayers) { player in
TextField("", text: self.$players[player].name)
// .underline()
.multilineTextAlignment(.center)
.frame(width: boxWidth, height: boxHeight, alignment: .center)
}
}
.padding(.vertical, 5)
}
}
I am try to display a billboardjs bubble chart using javascript and html.
I included the lib in my index.html file as:
src="/lib/billboard.pkgd.js"
The codes are very simple but when ran, I got the "NaN" error.
this.d3Chart = bb.generate({
bindto: "#d3bubbleChart",
data: {
type: "bubble",
label: false,
xs: {
data1: "x1",
data2: "x2"
},
columns: [,
["x1", 10, 20, 50, 100, 50],
["x2", 30, 40, 90, 100, 170],
["data1", [20, 50], [30, 10], [50, 28], [60, 70], [100, 80]],
["data2", [350, 50, 30], [230, 90], [200, 100],[250, 150],[200, 200]]
]
},
bubble: {
maxR: 50
},
grid: { y: { show: true } },
axis: {
x: {
label: { text: "AOV", position: "outer-left"},
height: 50,
tick: { format: function(x) { return ("$"+x);}}
},
y: {
fit: false,
min: {fit: true, value: 0},
max: 450,
labels: "yes",
label: { text: "Conversion Rate", position: "outer-bottom"},
tick: { format: function(x) { return (x+"%");}}
}
}
});
Checkout the allowed data for bubble type from API doc:
For 'bubble' type, data can contain dimension value:
- an array of [y, z] data following the order
- or an object with 'y' and 'z' key value
'y' is for y axis coordination and 'z' is the bubble radius value
I'm seeing from your example, that the first data of data2 contains additional value. Removing that will work fine.
this.d3Chart = bb.generate({
data: {
...
columns: [,
// the length for each bubble should be 2
["data2", [350, 50, 30], ...]
]
I am looking to add the word "Ages " to my tooltip title, to represent age groups as per in the chart.
Basically, title should be "Ages 11-20", for example. However, I get "Ages undefined"?
Anyone know why I am getting this issue?
Code (fiddle below):
var ageRangedata = {type: 'bar',
data:{datasets: [
{ data : [0,1,5,2,1,0,0, 0, 0, 0], backgroundColor: 'rgba(255, 209, 240, 0.6)', borderColor: 'rgba(255, 209, 240, 1)', borderWidth: 2, label: 'Female' },
{ data : [1,0,1,1,6,1,0, 1, 0, 0], backgroundColor: 'rgba(81, 187, 245, 0.6)', borderColor: 'rgba(81, 187, 245, 1)', borderWidth: 2, label: 'Male' }],
labels:['0-10','11-20','21-30','31-40','41-50','51-60','61-70', '71-80', '81-90', '90-']},
options: {maintainAspectRatio: false,responsive: true, tooltips: { callbacks: { title: function(tooltipItem, data) { return 'Ages ' + data.labels[tooltipItem.Index]; }}},legend: { display: false }}};
var ageR = document.getElementById("ageRange").getContext("2d");
var chart_ageR = new Chart(ageR, ageRangedata);
Extra points (side question, ignore if you want) to anyone who know what using afterLabel sends the text to just below the label instead of after it (as it sounds like it should be doing)"?
https://jsfiddle.net/unc76c7s/
Try it like this:
return 'Ages ' + tooltipItem[0].xLabel;
In any case your error is quite explicit. You could do a console.log of your tooltipItem in your callback to see if you're using it correctly.
Hope this helps.
I wrote a simple OpenGL program which merely renders a cube from an angle. It's as simple as you can get: vertex buffer only (no index buffer), a vertex shader which only multiplies the vertices by an MVP matrix from a uniform buffer, and a static fragment shader which just returns red. More recently, I have tried writing this same program in Vulkan, but I have run into some issues.
I started by following the Intel API without secrets tutorial to setup a simple 2d texture rendering program, but when I took the leap into 3d, I started having issues. In order to debug this, I simplified the program to match my older OpenGL program (removed texturing and some other extra stuff I did in Vulkan), and even went as far as to use the exact same vertex and MVP data. However, I just can't get the cube to render correctly in Vulkan.
I am aware that OpenGL coordinates do not map directly to Vulkan coordinates, as the Y coordinate is flipped, but if anything that should just flip the image upside down, and I already tried switching the Y values in the MVP. I feel like there is some other detail I am missing here with coordinates, but I just can't figure it out searching around and looking at guides about converting OpenGL code bases to Vulkan.
I'm including the data I am uploading to the shaders, and some of the core code from the Vulkan code base. The Vulkan code is in D, so it's similar to C++, but a little different. With the library I'm using for wrapping Vulkan (erupted), the device level functions are loaded into a device dispatch (access as device.dispatch in the code), and when they are called on the dispatch without the vk prefix, the device and command buffer (which is assigned to the dispatch in code) arguments of the function are auto populated.
Vertex Data:
[ [1, 1, 1, 1],
[1, 1, -1, 1],
[-1, 1, -1, 1],
[1, 1, 1, 1],
[-1, 1, -1, 1],
[-1, 1, 1, 1],
[1, 1, 1, 1],
[1, -1, 1, 1],
[1, -1, -1, 1],
[1, 1, 1, 1],
[1, -1, -1, 1],
[1, 1, -1, 1],
[1, 1, -1, 1],
[1, -1, -1, 1],
[-1, -1, -1, 1],
[1, 1, -1, 1],
[-1, -1, -1, 1],
[-1, 1, -1, 1],
[-1, 1, -1, 1],
[-1, -1, -1, 1],
[-1, -1, 1, 1],
[-1, 1, -1, 1],
[-1, -1, 1, 1],
[-1, 1, 1, 1],
[-1, 1, 1, 1],
[-1, -1, 1, 1],
[1, -1, 1, 1],
[-1, 1, 1, 1],
[1, -1, 1, 1],
[1, 1, 1, 1],
[1, -1, 1, 1],
[1, -1, -1, 1],
[-1, -1, -1, 1],
[1, -1, 1, 1],
[-1, -1, -1, 1],
[-1, -1, 1, 1] ]
MVP:
[ [-1.0864, -0.993682, -0.687368, -0.685994],
[0, 2.07017, 0.515526, -0.514496],
[-1.44853, 0.745262, 0.515526, 0.514496],
[-8.04095e-16, 0, 5.64243, 5.83095] ]
Graphics Pipeline Setup:
VkPipelineShaderStageCreateInfo[] shader_stage_infos = [
{
stage: VK_SHADER_STAGE_VERTEX_BIT,
_module: vertex_shader,
pName: "main"
},
{
stage: VK_SHADER_STAGE_FRAGMENT_BIT,
_module: fragment_shader,
pName: "main"
}
];
VkVertexInputBindingDescription[] vertex_binding_descriptions = [
{
binding: 0,
stride: VertexData.sizeof,
inputRate: VK_VERTEX_INPUT_RATE_VERTEX
}
];
VkVertexInputAttributeDescription[] vertex_attribute_descriptions = [
{
location: 0,
binding: vertex_binding_descriptions[0].binding,
format: VK_FORMAT_R32G32B32A32_SFLOAT,
offset: VertexData.x.offsetof
},
{
location: 1,
binding: vertex_binding_descriptions[0].binding,
format: VK_FORMAT_R32G32_SFLOAT,
offset: VertexData.u.offsetof
}
];
VkPipelineVertexInputStateCreateInfo vertex_input_state_info = {
vertexBindingDescriptionCount: vertex_binding_descriptions.length.to!uint,
pVertexBindingDescriptions: vertex_binding_descriptions.ptr,
vertexAttributeDescriptionCount: vertex_attribute_descriptions.length.to!uint,
pVertexAttributeDescriptions: vertex_attribute_descriptions.ptr
};
VkPipelineInputAssemblyStateCreateInfo input_assembly_state_info = {
topology: VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
primitiveRestartEnable: VK_FALSE
};
VkPipelineViewportStateCreateInfo viewport_state_info = {
viewportCount: 1,
pViewports: null,
scissorCount: 1,
pScissors: null
};
VkPipelineRasterizationStateCreateInfo rasterization_state_info = {
depthBiasClamp: 0.0,
polygonMode: VK_POLYGON_MODE_FILL,
cullMode: VK_CULL_MODE_FRONT_AND_BACK,
frontFace: VK_FRONT_FACE_COUNTER_CLOCKWISE,
lineWidth: 1
};
VkPipelineMultisampleStateCreateInfo multisample_state_info = {
rasterizationSamples: VK_SAMPLE_COUNT_1_BIT,
minSampleShading: 1
};
VkPipelineColorBlendAttachmentState[] color_blend_attachment_states = [
{
blendEnable: VK_FALSE,
srcColorBlendFactor: VK_BLEND_FACTOR_ONE,
dstColorBlendFactor: VK_BLEND_FACTOR_ZERO,
colorBlendOp: VK_BLEND_OP_ADD,
srcAlphaBlendFactor: VK_BLEND_FACTOR_ONE,
dstAlphaBlendFactor: VK_BLEND_FACTOR_ZERO,
alphaBlendOp: VK_BLEND_OP_ADD,
colorWriteMask:
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_A_BIT
}
];
VkPipelineColorBlendStateCreateInfo color_blend_state_info = {
logicOpEnable: VK_FALSE,
logicOp: VK_LOGIC_OP_COPY,
attachmentCount: color_blend_attachment_states.length.to!uint,
pAttachments: color_blend_attachment_states.ptr,
blendConstants: [ 0, 0, 0, 0 ]
};
VkDynamicState[] dynamic_states = [
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR
];
VkPipelineDynamicStateCreateInfo dynamic_state_info = {
dynamicStateCount: dynamic_states.length.to!uint,
pDynamicStates: dynamic_states.ptr
};
VkGraphicsPipelineCreateInfo pipeline_info = {
stageCount: shader_stage_infos.length.to!uint,
pStages: shader_stage_infos.ptr,
pVertexInputState: &vertex_input_state_info,
pInputAssemblyState: &input_assembly_state_info,
pTessellationState: null,
pViewportState: &viewport_state_info,
pRasterizationState: &rasterization_state_info,
pMultisampleState: &multisample_state_info,
pDepthStencilState: null,
pColorBlendState: &color_blend_state_info,
pDynamicState: &dynamic_state_info,
layout: pipeline_layout,
renderPass: render_pass,
subpass: 0,
basePipelineHandle: VK_NULL_HANDLE,
basePipelineIndex: -1
};
VkPipeline[1] pipelines;
checkVk(device.dispatch.CreateGraphicsPipelines(VK_NULL_HANDLE, 1, [pipeline_info].ptr, pipelines.ptr));
pipeline = pipelines[0];
Drawing:
if(device.dispatch.WaitForFences(1, [fence].ptr, VK_FALSE, 1000000000) != VK_SUCCESS)
throw new StringException("timed out waiting for fence");
device.dispatch.ResetFences(1, [fence].ptr);
uint image_index;
switch(device.dispatch.AcquireNextImageKHR(swapchain.swapchain, uint64_t.max, image_available_semaphore, VK_NULL_HANDLE, &image_index)) {
case VK_SUCCESS:
case VK_SUBOPTIMAL_KHR:
break;
case VK_ERROR_OUT_OF_DATE_KHR:
on_window_size_changed();
break;
default:
throw new StringException("unhandled vk result on swapchain image acquisition");
}
if(framebuffer != VK_NULL_HANDLE) device.dispatch.DestroyFramebuffer(framebuffer);
VkFramebufferCreateInfo framebuffer_info = {
renderPass: swapchain.render_pass,
attachmentCount: 1,
pAttachments: [swapchain.image_resources[image_index].image_view].ptr,
width: swapchain.extent.width,
height: swapchain.extent.height,
layers: 1
};
checkVk(device.dispatch.CreateFramebuffer(&framebuffer_info, &framebuffer));
VkCommandBufferBeginInfo cmd_begin_info = { flags: VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT };
VkImageSubresourceRange image_subresource_range = {
aspectMask: VK_IMAGE_ASPECT_COLOR_BIT,
baseMipLevel: 0,
levelCount: 1,
baseArrayLayer: 0,
layerCount: 1,
};
VkImageMemoryBarrier barrier_from_present_to_draw = {
srcAccessMask: VK_ACCESS_MEMORY_READ_BIT,
dstAccessMask: VK_ACCESS_MEMORY_READ_BIT,
oldLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
newLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
srcQueueFamilyIndex: device.present_queue.family_index,
dstQueueFamilyIndex: device.graphics_queue.family_index,
image: swapchain.image_resources[image_index].image,
subresourceRange: image_subresource_range
};
VkImageMemoryBarrier barrier_from_draw_to_present = {
srcAccessMask: VK_ACCESS_MEMORY_READ_BIT,
dstAccessMask: VK_ACCESS_MEMORY_READ_BIT,
oldLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
newLayout: VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
srcQueueFamilyIndex: device.graphics_queue.family_index,
dstQueueFamilyIndex: device.present_queue.family_index,
image: swapchain.image_resources[image_index].image,
subresourceRange: image_subresource_range
};
VkViewport viewport = {
x: 0,
y: 0,
width: swapchain.extent.width,
height: swapchain.extent.height,
minDepth: 0,
maxDepth: 1
};
VkRect2D scissor = {
offset: {
x: 0,
y: 0
},
extent: swapchain.extent
};
VkClearValue[] clear_values = [
{ color: { [ 1.0, 0.8, 0.4, 0.0 ] } }
];
VkRenderPassBeginInfo render_pass_begin_info = {
renderPass: swapchain.render_pass,
framebuffer: framebuffer,
renderArea: {
offset: {
x: 0,
y: 0
},
extent: swapchain.extent
},
clearValueCount: clear_values.length.to!uint,
pClearValues: clear_values.ptr
};
device.dispatch.commandBuffer = command_buffer;
device.dispatch.BeginCommandBuffer(&cmd_begin_info);
if(device.graphics_queue.handle != device.present_queue.handle)
device.dispatch.CmdPipelineBarrier(
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
0, 0, null, 0, null, 1,
&barrier_from_present_to_draw
);
device.dispatch.CmdBeginRenderPass(&render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE);
device.dispatch.CmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, swapchain.pipeline);
device.dispatch.CmdSetViewport(0, 1, &viewport);
device.dispatch.CmdSetScissor(0, 1, &scissor);
const(ulong) vertex_buffer_offset = 0;
device.dispatch.CmdBindVertexBuffers(0, 1, &vertex_buffer, &vertex_buffer_offset);
device.dispatch.CmdBindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptor_set, 0, null);
device.dispatch.CmdDraw(draw_count, 1, 0, 0);
device.dispatch.CmdEndRenderPass();
if(device.graphics_queue.handle != device.present_queue.handle)
device.dispatch.CmdPipelineBarrier(
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0, 0, null, 0, null, 1,
&barrier_from_draw_to_present
);
checkVk(device.dispatch.EndCommandBuffer());
device.dispatch.commandBuffer = VK_NULL_HANDLE;
VkSubmitInfo submit_info = {
waitSemaphoreCount: 1,
pWaitSemaphores: [image_available_semaphore].ptr,
pWaitDstStageMask: castFrom!(VkPipelineStageFlagBits*).to!(const(uint)*)([VK_PIPELINE_STAGE_TRANSFER_BIT].ptr),
commandBufferCount: 1,
pCommandBuffers: [command_buffer].ptr,
signalSemaphoreCount: 1,
pSignalSemaphores: [rendering_finished_semaphore].ptr
};
checkVk(device.dispatch.vkQueueSubmit(device.graphics_queue.handle, 1, [submit_info].ptr, fence));
VkPresentInfoKHR present_info = {
waitSemaphoreCount: 1,
pWaitSemaphores: [rendering_finished_semaphore].ptr,
swapchainCount: 1,
pSwapchains: [swapchain.swapchain].ptr,
pImageIndices: [image_index].ptr
};
switch(device.dispatch.vkQueuePresentKHR(device.present_queue.handle, &present_info)) {
case VK_SUCCESS:
break;
case VK_ERROR_OUT_OF_DATE_KHR:
case VK_SUBOPTIMAL_KHR:
on_window_size_changed();
break;
default:
throw new StringException("unhandled vk result on presentation");
}
(I can't embed the images because my rep is too low, sorry)
Program Outputs:
OpenGL draws the cube as expected
OpenGL Output
Vulkan does not render anything except for the clear color.
UPDATE:
After fixing the cull mode by changing it to VK_CULL_MODE_NONE, this is the result I get:
Output after cull mode fix
VK_CULL_MODE_FRONT_AND_BACK
I think this is your problem :)
After cull mode fix, seems that your problem in your vertex data layout. Vulkan expects (accordingly to your layout binding) something like
struct Vertex {
vec4 x;
vec2 u;
};
Vertex VertexData[] = {...};
because you set VK_VERTEX_INPUT_RATE_VERTEX in your vertex_binding_descriptions.inputRate field.
And it seems that in your case you should set VK_VERTEX_INPUT_RATE_INSTANCE instead to work with buffers after each other.
Fix: Have seen your new comment, it looks like i misunderstood your vertices layout, so it won't help.
I'm working in a rails 3 project, I want to change the pie chart colors that I generate with the LazyHighChart gem and I don;t know how to do that
This is my method controller
def set_pie_chart(data)
fixed_data = []
data.each_pair do |key, value|
fixed_data << [key.name, value]
end
#color = data.keys.map {|e| "#" + e.colour } # e.colour is like '333333'
#chart = LazyHighCharts::HighChart.new('pie') do |c|
c.chart({:defaultSeriesType=>"pie" , :margin=> [0, 0, 0, 0]})
series = {
type: 'pie',
name: 'total expenses',
data: fixed_data,
colors: ['green','red'] # intent
}
c.series(series)
c.colors = ['red','blue','black'] # intent
c.options[:colors] = ['green','blue','yellow'] # intent
c.options['colors'] = ['red','blue','yellow'] # intent
c.options[:title][:text] = nil
c.plot_options(:pie=>{
cursor: "pointer",
center: ['50%','37%'],
color: 'red', #intent
dataLabels: { enabled: false }
})
end
end
this method doesn't leave any error, what is the correct way or its not possible with this gem?
or what other good alternative gems could I use for my project?
I had the same problem and I solved it by putting the color options in my view. This is what I did:
#my_view_helper.rb
def chart_colors
html =
"[{linearGradient: [0, 0, 0, 200], stops: [[0, '#e28b02'],[1, '#f1bc70']]},
{linearGradient: [0, 0, 0, 200], stops: [[0, '#a5ba57'],[1, '#a8bb51']]},
{linearGradient: [0, 0, 0, 200], stops: [[0, '#1e93d6'],[1, '#35aff6']]},
{linearGradient: [0, 0, 0, 200], stops: [[0, '#c8cf99'],[1, '#cdcfa9']]},
{linearGradient: [0, 0, 0, 200], stops: [[0, '#709ab1'],[1, '#a7c5d0']]},
{linearGradient: [0, 0, 0, 200], stops: [[0, '#c76f4e'],[1, '#fba98e']]},
{linearGradient: [0, 0, 0, 200], stops: [[0, '#95d6e3'],[1, '#bbe8ed']]}]"
html
end
#my_view.html.haml
#chart
= high_chart("pie_1", #chart) do |c|
= "options.colors = #{chart_colors}".html_safe
#chart = LazyHighCharts::HighChart.new('pie') do |c|
c.colors(["red","green","blue"]);
end