Skip to content

Commit 4e5513b

Browse files
authored
Update README.md
1 parent a0f6161 commit 4e5513b

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

README.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ DebugMessage::setCallback([](const DebugMessage & message) {
345345
346346
Wraps a canvas with multiple render targets to render on.
347347
```cpp
348-
Framebuffer * fbo = new Framebuffer();
348+
auto fbo = new Framebuffer();
349349
fbo->attachTexture(GL_COLOR_ATTACHMENT0, texture1);
350350
fbo->attachTexture(GL_COLOR_ATTACHMENT1, texture2);
351351
fbo->attachRenderbuffer(GL_DEPTH_ATTACHMENT, depthRenderbuffer);
@@ -355,28 +355,32 @@ fbo->printStatus(true); // Print errors if fbo is not complete
355355
fbo->clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
356356
fbo->clearBuffer(GL_COLOR, 0, glm::vec4(1.0f, 1.0f, 1.0f, 0.0f));
357357
358-
fbo->blit(GL_COLOR_ATTACHMENT0, {{ 0, 0, width, height }}, Framebuffer::defaultFBO(), GL_BACK_LEFT, {{ 0, 0, width, height }}, GL_COLOR_BUFFER_BIT, GL_NEAREST);
358+
fbo->blit(GL_COLOR_ATTACHMENT0, {{ 0, 0, width, height }}, Framebuffer::defaultFBO(),
359+
GL_BACK_LEFT, {{ 0, 0, width, height }}, GL_COLOR_BUFFER_BIT, GL_NEAREST);
359360
```
360361

361362
##### Named String
362363

363-
Register compile-time shader replacements for shader ```#include```s.
364+
Register compile-time shader replacements for shader includes.
364365
```cpp
365366
// typically the only function call you'll need
366-
NamedString * namedString = new NamedString("/upNormal.glsl", "const vec3 up = vec3(0.0, 1.0, 0.0);");
367+
auto namedString1 = new NamedString("/upNormal.glsl", "const vec3 up = vec3(0.0, 1.0, 0.0);");
368+
369+
// or reference an actual source file
370+
auto namedString2 = new NamedString("/phong.glsl", new File("data/shaders/phong.glsl"));
367371
```
368372

369373
##### Program
370374

371-
Can represent both render programs and compute programs. Is automatically relinked upon shader changes.
375+
The Program object can represent both render programs and compute programs. Prior usage it automatically relinks upon shader changes.
372376
```cpp
373-
Program * renderProgram = new Program();
377+
auto renderProgram = new Program();
374378
renderProgram->attach(vertexShader, fragmentShader);
375379
renderProgram->addUniform("viewProjection", glm::mat4(1.0));
376380

377381
renderProgram->use(); // compiles shaders, links and uses program
378382

379-
Program * computeProgram = new Program();
383+
auto computeProgram = new Program();
380384
computeProgram->attach(computeShader);
381385

382386
computeProgram->dispatchCompute(128, 1, 1);
@@ -385,7 +389,7 @@ computeProgram->dispatchCompute(128, 1, 1);
385389
##### Program Pipeline
386390
387391
```cpp
388-
ProgramPipeline pipeline = new ProgramPipeline();
392+
auto pipeline = new ProgramPipeline();
389393
pipeline->useStages(vertexProgram, gl::GL_VERTEX_SHADER_BIT);
390394
pipeline->useStages(fragmentProgram, gl::GL_FRAGMENT_SHADER_BIT);
391395
pipeline->use(); // as Program interface
@@ -395,7 +399,7 @@ pipeline->use(); // as Program interface
395399

396400
Query and measure time and perform conditional rendering with passed samples.
397401
```cpp
398-
Query * query = new Query();
402+
auto query = new Query();
399403
query->begin(GL_TIME_ELAPSED);
400404
// calls
401405
query->end(GL_TIME_ELAPSED);
@@ -405,22 +409,21 @@ if (!query->resultsAvailable())
405409
query->wait();
406410
}
407411

408-
GLint elapsed = query->get(GL_QUERY_RESULT);
412+
auto elapsed = query->get(GL_QUERY_RESULT);
409413
```
410414
411415
##### Renderbuffer
412416
413-
Use Renderbuffers if you don't care that much about internal formats and you don't want to sample from the image.
414417
```cpp
415-
Renderbuffer * renderBuffer = new Renderbuffer();
418+
auto renderBuffer = new Renderbuffer();
416419
renderBuffer->storage(GL_RGBA32F, 512, 512);
417420
```
418421

419422
##### Sampler
420423

421-
For temporary overrides of texture parameters.
424+
For temporary overrides of texture parameters. Note: a newly created sampler is not configured by default, and thus invalid.
422425
```cpp
423-
Sampler * sampler = new Sampler();
426+
auto sampler = new Sampler();
424427
sampler->setParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
425428
sampler->setParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
426429
sampler->setParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -431,8 +434,8 @@ sampler->bind(0); // override sampler state for texture at binding point 0
431434
##### Shader
432435
433436
```cpp
434-
Shader * shader1 = new Shader::fromFile(GL_VERTEX_SHADER, filename);
435-
Shader * shader2 = new Shader::fromString(GL_FRAGMENT_SHADER, shaderSource);
437+
auto shader1 = new Shader::fromFile(GL_VERTEX_SHADER, filename);
438+
auto shader2 = new Shader::fromString(GL_FRAGMENT_SHADER, shaderSource);
436439
437440
Shader::globalReplace("#version 140", "#version 150"); // e.g., useful for OS X
438441
@@ -445,7 +448,7 @@ std::cout << shader2->infoLog() << std::endl; // acess compile info log, althoug
445448
##### Sync
446449

447450
```cpp
448-
Sync * sync = Sync::fence(GL_SYNC_GPU_COMMANDS_COMPLETE);
451+
auto sync = Sync::fence(GL_SYNC_GPU_COMMANDS_COMPLETE);
449452

450453
sync->clientWait(GL_SYNC_FLUSH_COMMANDS_BIT, 2000000000); // wait on GPU; 2 secs
451454
sync->waitSync(1000000); // wait on CPU; 1 millisecond
@@ -455,7 +458,7 @@ sync->waitSync(1000000); // wait on CPU; 1 millisecond
455458
456459
Connect shader outputs to buffers and restart drawing.
457460
```cpp
458-
TransformFeedback * tf = new TransformFeedback();
461+
auto tf = new TransformFeedback();
459462
tf->setVaryings(program, { { "next_position" } }, GL_INTERLEAVED_ATTRIBS);
460463
461464
tf->bind();
@@ -472,8 +475,8 @@ tf->draw(GL_TRIANGLE_STRIP);
472475

473476
Uniforms attached to Programs are updated automatically, even after relinking.
474477
```cpp
475-
Uniform * uniform1 = new Uniform<glm::vec3>("lightPos", glm::vec3(10.0f, 5.0f, 0.0f)); // name-based uniform binding
476-
Uniform * uniform2 = new Uniform<glm::mat4>(0, glm::mat4(1.0f)); // location-based uniform binding
478+
auto uniform1 = new Uniform<glm::vec3>("lightPos", glm::vec3(10.0f, 5.0f, 0.0f)); // name-based uniform binding
479+
auto uniform2 = new Uniform<glm::mat4>(0, glm::mat4(1.0f)); // location-based uniform binding
477480

478481
program->addUniform(uniform1);
479482
program->addUniform(uniform2);
@@ -485,7 +488,7 @@ program->use(); // uniform values are updated if required
485488
486489
Use uniform blocks for large, often switched chunks of uniforms.
487490
```cpp
488-
UniformBlock * block = program->uniformBlock("uniforms");
491+
auto block = program->uniformBlock("uniforms");
489492
block->setBinding(0);
490493
buffer->bindBase(GL_UNIFORM_BUFFER, 0);
491494
```
@@ -494,7 +497,7 @@ buffer->bindBase(GL_UNIFORM_BUFFER, 0);
494497

495498
Use to configure vertex shader inputs and trigger render pipeline processes.
496499
```cpp
497-
VertexArray * vao = new VertexArray();
500+
auto vao = new VertexArray();
498501
// configure bindings (see next section)
499502

500503
vao->enable(0);
@@ -507,12 +510,12 @@ vao->drawArrays(GL_POINTS, 0, 10);
507510
508511
```cpp
509512
// For attribute pointers
510-
VertexAttributeBinding * binding1 = vao->binding(0);
513+
auto binding1 = vao->binding(0);
511514
binding1->setBuffer(vertexBuffer, 0, sizeof(glm::vec3));
512515
binding1->setFormat(3, GL_FLOAT, GL_FALSE, 0);
513516
514517
// For static attributes for each vertex
515-
VertexAttributeBinding * binding2 = vao->binding(0);
518+
auto binding2 = vao->binding(0);
516519
binding2->setValue<float>(1.0f);
517520
```
518521

@@ -522,7 +525,7 @@ binding2->setValue<float>(1.0f);
522525

523526
globjects uses the RAII (resource allocation is initialization) principle, meaning that created objects are also created on the GPU.
524527
To effectively manage the dual-allocated memory, we use reference pointers.
525-
We advise that every globjects Object pointer is stored in a ```ref_ptr```.
528+
We advise that every globjects ```Object``` pointer is stored in a ```ref_ptr```.
526529
```cpp
527530
{
528531
ref_ptr<Query> query = new Query(); // allocate on CPU and GPU
@@ -539,17 +542,17 @@ program->unref(); // decreare reference count; potentially free program pointer
539542

540543
##### Shader Templates
541544

542-
The sources of Shaders, ```ShaderSource```s, can be configured and templated.
545+
The sources of Shaders (```ShaderSource```) can be configured and templated.
543546
```cpp
544-
StringTemplate * template = new StringTemplate(new File("fragmentShader.frag"));
545-
template->replace("REPLACE","WITH THIS");
547+
auto template = new StringTemplate(new File("fragmentShader.frag"));
548+
template->replace("REPLACE", "WITH THIS");
546549

547-
Shader * shader = new Shader(template);
550+
auto shader = new Shader(template);
548551
```
549552
550553
##### Strategy Override
551554
552-
Although globjects try to use most current OpenGL APIs, you can override this automatic process.
555+
Although globjects tries to use most current OpenGL APIs, you can override this automatic process.
553556
```cpp
554557
// Enable CPU shader includes (although supported, some drivers have problems, so disable it)
555558
globjects::init(Shader::IncludeImplementation::Fallback);
@@ -560,7 +563,7 @@ Buffer::hintBindlessImplementation(Buffer::BindlessImplementation::Legacy);
560563

561564
##### Logging
562565

563-
Log globjects and glm objects.
566+
globjects provides logging interfaces to its objects as well as glm objects.
564567
```cpp
565568
std::cout << Framebuffer::defaultFBO();
566569
std::cout << glm::vec4(1.0, 0.0, 0.0, 1.0);

0 commit comments

Comments
 (0)