本文整理汇总了C++中GraphicContext类的典型用法代码示例。如果您正苦于以下问题:C++ GraphicContext类的具体用法?C++ GraphicContext怎么用?C++ GraphicContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphicContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Texture
Texture2D::Texture2D(GraphicContext &context, int width, int height, TextureFormat texture_format, int levels)
: Texture(std::shared_ptr<Texture_Impl>(new Texture_Impl))
{
if ( (width<=0) || (height<=0) )
{
throw Exception("An attempt was made to create a Texture with an invalid size");
}
GraphicContextProvider *gc_provider = context.get_provider();
impl->provider = gc_provider->alloc_texture(texture_2d);
impl->provider->create(width, height, 1, 1, texture_format, levels);
impl->width = width;
impl->height = height;
impl->provider->set_wrap_mode(impl->wrap_mode_s, impl->wrap_mode_t);
}
示例2: max
PixelBuffer D3DTextureProvider::get_pixeldata(GraphicContext &gc, TextureFormat texture_format, int level) const
{
D3DGraphicContextProvider *gc_provider = static_cast<D3DGraphicContextProvider*>(gc.get_provider());
D3DTextureData::DeviceHandles &data_handles = data->get_handles(gc_provider->get_window()->get_device());
int width;
int height;
DXGI_FORMAT format;
if (data_handles.texture_type == D3DTextureData::cl_ID3D11Texture1D)
{
D3D11_TEXTURE1D_DESC texture_desc;
data_handles.get_texture_1d()->GetDesc(&texture_desc);
width = max(texture_desc.Width >> level, (UINT)1);
height = 1;
format = texture_desc.Format;
}
示例3: Texture
Texture3D::Texture3D(GraphicContext &context, const Vec3i &size, TextureFormat texture_format, int levels)
: Texture(std::shared_ptr<Texture_Impl>(new Texture_Impl))
{
if ( (size.x<=0) || (size.y<=0) || (size.z<=0) )
{
throw Exception("An attempt was made to create a Texture with an invalid size");
}
GraphicContextProvider *gc_provider = context.get_provider();
impl->provider = gc_provider->alloc_texture(texture_3d);
impl->provider->create(size.x, size.y, size.z, 1, texture_format, levels);
impl->width = size.x;
impl->height = size.y;
impl->depth = size.z;
impl->provider->set_wrap_mode(impl->wrap_mode_s, impl->wrap_mode_t, impl->wrap_mode_r);
}
示例4: render
void App::render(GraphicContext &gc)
{
gc.clear(Colorf(0.0f, 0.0f, 0.0f, 1.0f));
Rect viewport_rect(0, 0, Size(gc.get_width(), gc.get_height()));
gc.set_viewport(viewport_rect);
gc.clear_depth(1.0f);
Mat4f modelview_matrix = scene.gs->camera_modelview;
scene.Draw(modelview_matrix, gc);
gc.reset_program_object();
}
示例5: Exception
void D3DVertexArrayBufferProvider::upload_data(GraphicContext &gc, int offset, const void *data, int data_size)
{
if ((offset < 0) || (data_size < 0) || ((data_size + offset) > size))
throw Exception("Vertex array buffer, invalid size");
const ComPtr<ID3D11Device> &device = static_cast<D3DGraphicContextProvider*>(gc.get_provider())->get_window()->get_device();
ComPtr<ID3D11DeviceContext> device_context;
device->GetImmediateContext(device_context.output_variable());
D3D11_BOX box;
box.left = offset;
box.right = offset + data_size;
box.top = 0;
box.bottom = 1;
box.front = 0;
box.back = 1;
device_context->UpdateSubresource(get_handles(device).buffer, 0, &box, data, 0, 0);
}
示例6: vertex_shader
Shader::Shader(GraphicContext &gc)
{
ShaderLanguage shader_language = gc.get_shader_language();
ShaderObject vertex_shader(gc, shadertype_vertex, shader_language==shader_glsl ? vertex_glsl : vertex_hlsl);
if(!vertex_shader.compile())
{
std::string log = vertex_shader.get_info_log();
throw Exception(string_format("Unable to compile vertex shader object: %1", log));
}
ShaderObject fragment_shader(gc, shadertype_fragment, shader_language==shader_glsl ? fragment_glsl : fragment_hlsl);
if(!fragment_shader.compile())
{
std::string log = fragment_shader.get_info_log();
throw Exception(string_format("Unable to compile fragment shader object: %1", log));
}
program_object = ProgramObject(gc);
program_object.attach(vertex_shader);
program_object.attach(fragment_shader);
program_object.bind_attribute_location(0, "InPosition");
program_object.bind_attribute_location(1, "InNormal");
program_object.bind_attribute_location(2, "InMaterialAmbient");
program_object.bind_frag_data_location(0, "cl_FragColor");
if (!program_object.link())
{
throw Exception(string_format("Unable to link program object: %1", program_object.get_info_log()));
}
program_object.set_uniform_buffer_index("ProgramUniforms", 0);
gpu_uniforms = clan::UniformVector<ProgramUniforms>(gc, 1);
uniforms.LightAmbient = Vec4f(0.2f, 0.2f, 0.2f, 1.0f);
uniforms.LightVector = Vec3f(0.0f, 0.0f, -1.0f);
uniforms.LightDiffuse = Vec4f(0.7f, 0.7f, 0.7f, 1.0f);
}
示例7: Exception
void D3DStorageBufferProvider::copy_to(GraphicContext &gc, TransferBuffer &buffer, int dest_pos, int src_pos, int copy_size)
{
const ComPtr<ID3D11Device> &device = static_cast<D3DGraphicContextProvider*>(gc.get_provider())->get_window()->get_device();
ComPtr<ID3D11Buffer> &transfer_buffer = static_cast<D3DTransferBufferProvider*>(buffer.get_provider())->get_buffer(device);
int transfer_buffer_size = static_cast<D3DTransferBufferProvider*>(buffer.get_provider())->get_size();
if (copy_size == -1)
copy_size = transfer_buffer_size;
if (dest_pos < 0 || copy_size < 0 || dest_pos + copy_size > transfer_buffer_size || src_pos < 0 || src_pos + copy_size > size)
throw Exception("Out of bounds!");
ComPtr<ID3D11DeviceContext> device_context;
device->GetImmediateContext(device_context.output_variable());
D3D11_BOX box;
box.left = dest_pos;
box.right = dest_pos + copy_size;
box.top = 0;
box.bottom = 1;
box.front = 0;
box.back = 1;
device_context->CopySubresourceRegion(transfer_buffer, 0, src_pos, 0, 0, get_handles(device).buffer, 0, &box);
}
示例8: run
void ParticleEmitterPass::run(GraphicContext &gc, Scene_Impl *scene)
{
setup(gc);
Size viewport_size = viewport->get_size();
Mat4f eye_to_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 1.e10f, handed_left, gc.get_clip_z_range());
Mat4f eye_to_cull_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 150.0f, handed_left, clip_negative_positive_w);
FrustumPlanes frustum(eye_to_cull_projection * world_to_eye.get());
for (size_t i = 0; i < active_emitters.size(); i++)
active_emitters[i]->visible = false;
scene->visit_emitters(gc, world_to_eye.get(), eye_to_projection, frustum, this);
const int vectors_per_particle = 2;
size_t total_particle_count = 0;
for (size_t i = 0; i < active_emitters.size(); i++)
{
float depth_fade_distance = 1.0f;
ParticleUniforms uniforms;
uniforms.eye_to_projection = eye_to_projection;
uniforms.object_to_eye = world_to_eye.get();
uniforms.rcp_depth_fade_distance = 1.0f / depth_fade_distance;
uniforms.instance_vectors_offset = total_particle_count * vectors_per_particle;
active_emitters[i]->gpu_uniforms.upload_data(gc, &uniforms, 1);
total_particle_count += active_emitters[i]->cpu_particles.size();
}
if (total_particle_count == 0)
return;
if (instance_texture.is_null() || instance_texture.get_width() < (int)total_particle_count)
{
instance_texture = Texture2D(gc, total_particle_count * vectors_per_particle, 1, tf_rgba32f);
instance_transfer = TransferTexture(gc, total_particle_count * vectors_per_particle, 1, data_to_gpu, tf_rgba32f, 0, usage_stream_draw);
}
instance_transfer.lock(gc, access_write_discard);
Vec4f *vectors = instance_transfer.get_data<Vec4f>();
size_t vector_offset = 0;
for (size_t j = 0; j < active_emitters.size(); j++)
{
Vec3f eye_pos = scene->get_camera().get_position();
std::vector<ParticleOrderIndex> sorted_particles;
sorted_particles.reserve(active_emitters[j]->cpu_particles.size());
for (size_t i = 0; i < active_emitters[j]->cpu_particles.size(); i++)
{
Vec3f delta = active_emitters[j]->cpu_particles[i].position - eye_pos;
sorted_particles.push_back(ParticleOrderIndex(i, Vec3f::dot(delta, delta)));
}
std::sort(sorted_particles.begin(), sorted_particles.end());
for (size_t k = 0; k < sorted_particles.size(); k++)
{
int i = sorted_particles[k].index;
float size = mix(active_emitters[j]->cpu_particles[i].start_size, active_emitters[j]->cpu_particles[i].end_size, active_emitters[j]->cpu_particles[i].life);
vectors[vector_offset + k * vectors_per_particle + 0] = Vec4f(active_emitters[j]->cpu_particles[i].position, size);
vectors[vector_offset + k * vectors_per_particle + 1] = Vec4f(active_emitters[j]->cpu_particles[i].life, 0.0f, 0.0f, 0.0f);
}
vector_offset += active_emitters[j]->cpu_particles.size() * vectors_per_particle;
}
instance_transfer.unlock();
instance_texture.set_image(gc, instance_transfer);
gc.set_depth_range(0.0f, 0.9f);
gc.set_frame_buffer(fb);
gc.set_viewport(viewport_size);
gc.set_depth_stencil_state(depth_stencil_state);
gc.set_blend_state(blend_state);
gc.set_rasterizer_state(rasterizer_state);
gc.set_primitives_array(prim_array);
gc.set_program_object(program);
gc.set_texture(0, normal_z_gbuffer.get());
gc.set_texture(1, instance_texture);
for (size_t i = 0; i < active_emitters.size(); i++)
{
gc.set_uniform_buffer(0, active_emitters[i]->gpu_uniforms);
gc.set_texture(2, active_emitters[i]->particle_animation.get());
gc.set_texture(3, active_emitters[i]->life_color_gradient.get());
gc.draw_primitives_array_instanced(type_triangles, 0, 6, active_emitters[i]->cpu_particles.size());
}
gc.reset_primitives_array();
gc.reset_rasterizer_state();
gc.reset_depth_stencil_state();
gc.reset_program_object();
gc.reset_primitives_elements();
gc.reset_texture(0);
gc.reset_texture(1);
gc.reset_texture(2);
gc.reset_texture(3);
gc.reset_uniform_buffer(0);
gc.reset_frame_buffer();
gc.set_depth_range(0.0f, 1.0f);
//.........这里部分代码省略.........
示例9: find_lights
void LightsourceSimplePass::find_lights(GraphicContext &gc, Scene_Impl *scene)
{
lights.clear();
Size viewport_size = viewport->get_size();
Mat4f eye_to_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 1.e10f, handed_left, gc.get_clip_z_range());
Mat4f eye_to_cull_projection = Mat4f::perspective(field_of_view.get(), viewport_size.width/(float)viewport_size.height, 0.1f, 150.0f, handed_left, clip_negative_positive_w);
FrustumPlanes frustum(eye_to_cull_projection * world_to_eye.get());
scene->visit_lights(gc, world_to_eye.get(), eye_to_projection, frustum, this);
}
示例10:
void Texture2D::copy_subimage_from(GraphicContext &context, int offset_x, int offset_y, int x, int y, int width, int height, int level)
{
impl->provider->copy_subimage_from(offset_x, offset_y, x, y, width, height, level, context.get_provider());
}
示例11: provider
BlendState::BlendState(GraphicContext &context, const BlendStateDescription &desc)
: provider(context.get_provider()->create_blend_state(desc))
{
}
示例12: main
virtual int main(const std::vector<std::string> &args)
{
DisplayWindowDescription desc;
desc.set_size(Size(800,600), true);
desc.set_title("Span Layout Test");
DisplayWindow window(desc);
Canvas canvas(window);
GraphicContext gc = window.get_gc();
FontDescription font_desc1;
font_desc1.set_typeface_name("Verdana");
font_desc1.set_height(-13);
Font font1(canvas, font_desc1);
Image smiley(canvas, "smiley.png");
SpanLayout span;
span.add_text(" This is a ", font1, Colorf::white, 1);
span.add_text("red", font1, Colorf::red, 2);
span.add_text(" text! ", font1, Colorf::white, 3);
span.add_text("And this complete text is green with non-blocking space..", font1, Colorf::green, 4);
span.add_image(smiley, 10, 5);
span.add_text("This is a really long descriptive and interesting text. ", font1, Colorf::yellow, 6);
span.add_text("[", font1, Colorf::black, 7);
span.add_text("15:35", font1, Colorf::white, 8);
span.add_text("]", font1, Colorf::black, 9);
span.add_image(smiley, 0, 10);
span.add_image(smiley, 2, 11);
span.add_text("kthxbye!", font1, Colorf::blue, 12);
span.layout(gc, 200);
span.set_position(Point(10, 10));
while (!window.get_ic().get_keyboard().get_keycode(keycode_escape))
{
gc.clear(Colorf::gray70);
span.draw_layout(canvas);
Point mouse_pos = window.get_ic().get_mouse().get_position();
SpanLayout::HitTestResult result = span.hit_test(gc, mouse_pos);
std::string type;
switch(result.type)
{
case SpanLayout::HitTestResult::no_objects_available:
type = "no_objects_available";
break;
case SpanLayout::HitTestResult::outside_top:
type = "outside_top";
break;
case SpanLayout::HitTestResult::outside_left:
type = "outside_left";
break;
case SpanLayout::HitTestResult::outside_right:
type = "outside_right";
break;
case SpanLayout::HitTestResult::outside_bottom:
type = "outside_bottom";
break;
case SpanLayout::HitTestResult::inside:
type = "inside";
break;
}
std::string result_text = string_format("HitTestResult: Type:%1 ID:%2 Offset:%3", type, result.object_id, result.offset);
font1.draw_text(canvas, 10, 300, result_text);
window.flip();
KeepAlive::process();
System::sleep(50);
}
return 0;
}
示例13: dispatch
void ShaderEffect::dispatch(GraphicContext &gc, int x, int y, int z)
{
gc.set_program_object(impl->program);
for (auto & elem : impl->uniform_bindings)
{
gc.set_uniform_buffer(elem.first, elem.second);
}
for (auto & elem : impl->storage_bindings)
{
gc.set_storage_buffer(elem.first, elem.second);
}
for (auto & elem : impl->image_bindings)
{
gc.set_image_texture(elem.first, elem.second);
}
for (auto & elem : impl->texture_bindings)
{
gc.set_texture(elem.first, elem.second);
}
gc.dispatch(x, y, z);
for (auto & elem : impl->uniform_bindings)
{
gc.reset_uniform_buffer(elem.first);
}
for (auto & elem : impl->storage_bindings)
{
gc.reset_storage_buffer(elem.first);
}
for (auto & elem : impl->image_bindings)
{
gc.reset_image_texture(elem.first);
}
for (auto & elem : impl->texture_bindings)
{
gc.reset_texture(elem.first);
}
gc.reset_program_object();
}
示例14: compile_and_link
ProgramObject LightsourceSimplePass::compile_and_link(GraphicContext &gc, const std::string &shader_path, const std::string &type)
{
ProgramObject program;
std::string vertex_filename = PathHelp::combine(shader_path, string_format("LightsourceSimple/vertex_%1.%2", type, gc.get_shader_language() == shader_glsl ? "glsl" : "hlsl"));
std::string fragment_filename = PathHelp::combine(shader_path, string_format("LightsourceSimple/fragment_light.%1", gc.get_shader_language() == shader_glsl ? "glsl" : "hlsl"));
program = ShaderSetup::compile(gc, "", vertex_filename, fragment_filename, type == "rect" ? "RECT_PASS" : "");
program.bind_frag_data_location(0, "FragColor");
if (!program.link())
throw Exception("Shader linking failed!");
program.bind_attribute_location(0, "AttrPositionInObject");
program.set_uniform_buffer_index("Uniforms", 0);
program.set_uniform1i("InstanceTexture", 0);
program.set_uniform1i("NormalZTexture", 1);
program.set_uniform1i("DiffuseColorTexture", 2);
program.set_uniform1i("SpecularColorTexture", 3);
program.set_uniform1i("SpecularLevelTexture", 4);
program.set_uniform1i("ShadowMapsTexture", 5);
program.set_uniform1i("ShadowMapsTextureSampler", 5);
program.set_uniform1i("SelfIlluminationTexture", 6);
return program;
}
示例15: provider
DepthStencilState::DepthStencilState(GraphicContext &context, const DepthStencilStateDescription &desc)
: provider(context.get_provider()->create_depth_stencil_state(desc))
{
}