本文整理汇总了C++中ProgramObject类的典型用法代码示例。如果您正苦于以下问题:C++ ProgramObject类的具体用法?C++ ProgramObject怎么用?C++ ProgramObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProgramObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawArraysInstanced
void VertexBuffer::DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
{
ProgramObject *p = rc->GetCurProgram();
if (p) p->updateMatrices();
Bind();
glDrawArraysInstanced(mode, first, count, instanceCount);
}
示例2: cgGetProgramString
bool csShaderGLCGCommon::WriteToCache (iHierarchicalCache* cache,
const ProfileLimits& limits,
const ProfileLimitsPair& limitsPair,
const char* tag)
{
csString objectCode;
if (program != 0)
objectCode = cgGetProgramString (program, CG_COMPILED_PROGRAM);
ProgramObject programObj (objectCode,
programPositionInvariant ? ProgramObject::flagPositionInvariant : 0,
unusedParams);
const char* preprocSource (cgGetProgramString (program, CG_PROGRAM_SOURCE));
csString failReason;
ProgramObjectID progId;
if (!shaderPlug->progCache.WriteObject (preprocSource, limits, programObj,
progId, failReason))
{
if (shaderPlug->doVerbose)
{
csReport (objectReg, CS_REPORTER_SEVERITY_WARNING,
"crystalspace.graphics3d.shader.glcg",
"Error writing %s program for %s to compile cache: %s",
GetProgramType(), tag,
failReason.GetData());
}
return false;
}
programObj.SetID (progId);
return WriteToCache (cache, limits, limitsPair, tag, programObj);
}
示例3: DrawElementsInstanced
void VertexBuffer::DrawElementsInstanced(GLenum mode, GLsizei count,
GLenum type, GLsizei instanceCount, int offset)
{
ProgramObject *p = rc->GetCurProgram();
if (p) p->updateMatrices();
Bind();
glDrawElementsInstanced(mode, count, type, (void *)offset, instanceCount);
}
示例4: main
int main(int /*argc*/, char ** /*argv*/) {
BaseApp app;
ProgramObject program;
auto mainWindow = app.getMainWindow();
std::string prefix = app.getResourceDir() + "Shaders/Examples/e06_ModelLoader/";
PerspectiveCamera cam;
OrbitManipulator manipulator(&cam);
manipulator.setupCallbacks(app);
NodeShared root;
GLuint query[2];
app.addInitCallback([&]() {
auto vs = compileShader(GL_VERTEX_SHADER, Loader::text(prefix + "phong.vert"));
auto fs = compileShader(GL_FRAGMENT_SHADER, Loader::text(prefix + "phong.frag"));
program = createProgram(vs, fs);
root = Loader::scene(app.getResourceDir() + "Models/sponza/sponza.fbx");
glCreateQueries(GL_TIMESTAMP, 2, query);
SDL_GL_SetSwapInterval(0);
});
app.addResizeCallback([&](int w, int h) {
glViewport(0, 0, w, h);
cam.setAspect(float(w) / float(h));
});
app.addDrawCallback([&]() {
glQueryCounter(query[0], GL_TIMESTAMP);
glClearColor(0.2, 0.2, 0.2, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
//bunny
program.use();
program.setMatrix4fv("p", value_ptr(cam.getProjection()));
program.setMatrix4fv("v", value_ptr(cam.getView()));
drawNode(program, root);
glQueryCounter(query[1], GL_TIMESTAMP);
GLuint64 time1, time2;
glGetQueryObjectui64v(query[0], GL_QUERY_RESULT, &time1);
glGetQueryObjectui64v(query[1], GL_QUERY_RESULT, &time2);
std::string s = "fps: " + std::to_string(1e9 / (time2 - time1)) + " (" + std::to_string(ImGui::GetIO().Framerate) + ")";
label(s, 0, 0, 300, 100);
});
return app.run();
}
示例5: DrawElements
void VertexBuffer::DrawElements(GLenum mode, GLsizei count, GLenum type, int offset)
{
ProgramObject *p = rc->GetCurProgram();
if (p) p->updateMatrices();
if (GLEW_ARB_vertex_buffer_object) {
Bind();
glDrawElements(mode, count, type, (void *)offset);
}
else {
glDrawElements(mode, count, type, ptr->data + offset);
}
}
示例6:
void GL3GraphicContextProvider::set_program_object(const ProgramObject &program)
{
OpenGL::set_active(this);
if (glUseProgram == nullptr)
return;
if (program.is_null())
glUseProgram(0);
else
{
glUseProgram(program.get_handle());
}
}
示例7: create_shader_program
ProgramObject HSV::create_shader_program(GraphicContext &gc)
{
ProgramObject program = ProgramObject::load(gc, "Resources/vertex.glsl", "Resources/fragment.glsl");
program.bind_attribute_location(0, "Position");
program.bind_attribute_location(1, "TexCoord0");
program.set_uniform_buffer_index("ProgramUniforms", 0);
if (!program.link())
throw Exception("Unable to link program");
return program;
}
示例8: Color3f
void CubeBlock::DrawWhiteBorders(GLRenderingContext *rc, bool whiteBorders)
{
if (whiteBorders) {
borderAmbient = Color3f(0.8f);
borderDiffuse = Color3f(0.85f);
}
else {
borderAmbient = Color3f(0.0f);
borderDiffuse = Color3f(0.35f);
}
ProgramObject *p = rc->GetCurProgram();
p->Uniform("BorderMaterial.ambient", 1, borderAmbient.data);
p->Uniform("BorderMaterial.diffuse", 1, borderDiffuse.data);
}
示例9: draw_image
void App::draw_image(GraphicContext &gc, Texture &image, float xpos, float ypos, ProgramObject &program_object, Vec4f &draw_color_offset)
{
program_object.set_uniform1i("SourceTexture", 0);
program_object.set_uniform4f("color_offset", draw_color_offset);
gc.set_texture(0, image);
gc.set_program_object(program_object, cl_program_matrix_modelview_projection);
draw_texture(gc, Rectf(xpos, ypos, Sizef(image.get_width(), image.get_height())), Colorf::white, Rectf(0.0f, 0.0f, 1.0f, 1.0f));
gc.reset_program_object();
gc.reset_texture(0);
}
示例10: ProgramObject
void GLRC_Text2DModule::Initialize(GLRenderingContext *rc)
{
if (GLEW_ARB_shader_objects) {
prog = new ProgramObject(rc);
Shader vshader(GL_VERTEX_SHADER);
Shader fshader(GL_FRAGMENT_SHADER);
vshader.CompileSource(shaderSource[0]);
fshader.CompileSource(shaderSource[1]);
prog->AttachShader(vshader);
prog->AttachShader(fshader);
prog->Link();
prog->Uniform("ColorMap", 0);
}
else prog = NULL;
}
示例11: impl
UniformBuffer::UniformBuffer(GraphicContext &gc, ProgramObject &program, const std::string &name, int num_blocks, BufferUsage usage)
: impl(std::make_shared<UniformBuffer_Impl>())
{
GraphicContextProvider *gc_provider = gc.get_provider();
impl->provider = gc_provider->alloc_uniform_buffer();
impl->provider->create(program.get_uniform_buffer_size(name) * num_blocks, usage);
}
示例12: initSkinProgram
void Model::initSkinProgram(ProgramObject& program, Model::SkinLocations& locations) {
program.bind();
locations.clusterMatrices = program.uniformLocation("clusterMatrices");
locations.clusterIndices = program.attributeLocation("clusterIndices");
locations.clusterWeights = program.attributeLocation("clusterWeights");
locations.tangent = program.attributeLocation("tangent");
program.setUniformValue("diffuseMap", 0);
program.setUniformValue("normalMap", 1);
program.release();
}
示例13: createProgram
static ProgramObject* createProgram(const QString& name) {
ProgramObject* program = new ProgramObject();
program->addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/" + name + ".frag");
program->link();
program->bind();
program->setUniformValue("originalTexture", 0);
program->release();
return program;
}
示例14: window
int App::start(const std::vector<std::string> &args)
{
OpenGLWindowDescription description;
description.set_title("UniformBlock Shader");
//description.set_version(3, 1, false);
description.set_size(Size(1024, 768), true);
DisplayWindow window(description);
InputDevice keyboard = window.get_ic().get_keyboard();
GraphicContext gc = window.get_gc();
Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);
Slot slot_window_close = window.sig_window_close().connect(this, &App::window_close);
// Load and link shaders
ProgramObject shader = ProgramObject::load(gc, "Resources/vertex_shader.glsl", "Resources/fragment_shader.glsl");
shader.bind_attribute_location(0, "Position");
if (!shader.link())
throw Exception("Unable to link shader program: Error:" + shader.get_info_log());
int block_size = shader.get_uniform_block_size("TestBlock");
const int num_blocks = 16;
ProgramUniformBlock block(gc, block_size * num_blocks);
std::vector<float> data_to_upload;
data_to_upload.resize((num_blocks * block_size) / sizeof(float) );
float test_colour = 1.0f;
for (int cnt=0; cnt<num_blocks; cnt++)
{
int offset = cnt * block_size / sizeof(float) ;
data_to_upload[offset + 0] = test_colour;
data_to_upload[offset + 1] = 0.5f;
data_to_upload[offset + 2] = 1.0f;
test_colour -= 0.05f;
}
block.upload_data(0, &data_to_upload[0], block_size * num_blocks);
quit = false;
Font font(gc, "tahoma", 32);
clan::ubyte64 startTime = System::get_time();
//// Test code
//GLuint uniform_index = -1;
//const char *names[] = {"src_color"};
//glGetUniformIndices(handle, 1, names, &uniform_index);
//if (uniform_index >=0)
//{
// GLint offset;
// GLint singleSize;
// GLint uniform_type;
// glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_TYPE, &uniform_type);
// glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_OFFSET, &offset);
// glGetActiveUniformsiv(handle, 1, &uniform_index, GL_UNIFORM_SIZE, &singleSize);
// if ((uniform_type != GL_FLOAT_VEC3) || (offset !=0) || (singleSize != 1))
// {
// throw Exception("well it seems it does not work");
// }
//}
while (!quit)
{
gc.clear(Colorf(0.1f, 0.1f, 0.2f));
OpenGL::check_error();
for (int test_run_y=0; test_run_y < 16; test_run_y++)
{
shader.set_uniform_block("TestBlock", block, test_run_y*block_size);
for (int test_run_x=0; test_run_x < 16; test_run_x++)
{
Vec2f positions[3];
float size = 32.0f;
positions[0].x = test_run_x * size;
positions[0].y = test_run_y * size + size;
positions[1].x = test_run_x * size + size;
positions[1].y = test_run_y * size + size;
positions[2].x = test_run_x * size + size;
positions[2].y = test_run_y * size;
PrimitivesArray prim_array(gc);
prim_array.set_attributes(0, positions);
gc.set_program_object(shader, cl_program_matrix_modelview_projection);
gc.draw_primitives(cl_triangles, 3, prim_array);
gc.reset_program_object();
}
}
font.draw_text(gc, 32, 200, "Hello World");
window.flip(1);
KeepAlive::process();
//.........这里部分代码省略.........
示例15: getActivatedProgramWithTileData
void ChunkRenderer::renderChunkGlobally(const Chunk& chunk, const RenderData& data){
ProgramObject* programObject = getActivatedProgramWithTileData(
_globalRenderingShaderProvider.get(),
_globalProgramUniformHandler,
chunk);
if (programObject == nullptr) {
return;
}
const Ellipsoid& ellipsoid = chunk.owner()->ellipsoid();
bool performAnyBlending = false;
for (int i = 0; i < LayeredTextures::NUM_TEXTURE_CATEGORIES; ++i) {
LayeredTextures::TextureCategory category = (LayeredTextures::TextureCategory)i;
if(_tileProviderManager->getTileProviderGroup(i).levelBlendingEnabled && _tileProviderManager->getTileProviderGroup(category).getActiveTileProviders().size() > 0){
performAnyBlending = true;
break;
}
}
if (performAnyBlending) {
// Calculations are done in the reference frame of the globe. Hence, the camera
// position needs to be transformed with the inverse model matrix
glm::dmat4 inverseModelTransform = chunk.owner()->inverseModelTransform();
glm::dvec3 cameraPosition =
glm::dvec3(inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
float distanceScaleFactor = chunk.owner()->lodScaleFactor * ellipsoid.minimumRadius();
programObject->setUniform("cameraPosition", vec3(cameraPosition));
programObject->setUniform("distanceScaleFactor", distanceScaleFactor);
programObject->setUniform("chunkLevel", chunk.index().level);
}
// Calculate other uniform variables needed for rendering
Geodetic2 swCorner = chunk.surfacePatch().getCorner(Quad::SOUTH_WEST);
auto patchSize = chunk.surfacePatch().size();
dmat4 modelTransform = chunk.owner()->modelTransform();
dmat4 viewTransform = data.camera.combinedViewMatrix();
mat4 modelViewTransform = mat4(viewTransform * modelTransform);
mat4 modelViewProjectionTransform = data.camera.projectionMatrix() * modelViewTransform;
// Upload the uniform variables
programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform);
programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2()));
programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));
if (_tileProviderManager->getTileProviderGroup(
LayeredTextures::NightTextures).getActiveTileProviders().size() > 0 ||
_tileProviderManager->getTileProviderGroup(
LayeredTextures::WaterMasks).getActiveTileProviders().size() > 0) {
glm::vec3 directionToSunWorldSpace =
glm::normalize(-data.modelTransform.translation);
glm::vec3 directionToSunCameraSpace =
(viewTransform * glm::dvec4(directionToSunWorldSpace, 0));
data.modelTransform.translation;
programObject->setUniform("modelViewTransform", modelViewTransform);
programObject->setUniform("lightDirectionCameraSpace", -directionToSunCameraSpace);
}
// OpenGL rendering settings
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// render
_grid->geometry().drawUsingActiveProgram();
// disable shader
programObject->deactivate();
}