Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ if test "$PHP_GLFW" != "no"; then
phpglfw_texture.c \
phpglfw_objparser.c \
phpglfw_voxparser.c \
ogt_vox_c_wrapper.cpp \
src/ogt_vox_c_wrapper.cpp \
phpglfw_vg.c \
phpglfw_audio.c \
phpglfw_drawcall_assembler.c \
vendor/fastobj/fast_obj.c \
vendor/glad/src/glad.c \
vendor/nanovg/src/nanovg.c"
Expand All @@ -148,6 +149,8 @@ if test "$PHP_GLFW" != "no"; then


PHP_ADD_INCLUDE([$ext_srcdir])
PHP_ADD_INCLUDE([$ext_srcdir/include])
PHP_ADD_INCLUDE([$ext_srcdir/src])
PHP_ADD_INCLUDE([$ext_srcdir/vendor/glad/include])
PHP_ADD_INCLUDE([$ext_srcdir/vendor/cvector])
PHP_ADD_INCLUDE([$ext_srcdir/vendor/stb])
Expand All @@ -158,6 +161,7 @@ if test "$PHP_GLFW" != "no"; then
PHP_ADD_INCLUDE([$GLFW_DIR/include])

PHP_INSTALL_HEADERS([ext/glfw], [*.h \
include/*.h \
vendor/glad/include/glad/*.h \
vendor/glad/include/KHR/*.h \
vendor/cvector/*.h \
Expand Down
5 changes: 4 additions & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if (PHP_GLFW != "no") {
if (
CHECK_HEADER_ADD_INCLUDE("glad/glad.h", "CFLAGS_GLFW", configure_module_dirname + "\\vendor\\glad\\include;" + PHP_EXTRA_INCLUDES) &&
CHECK_HEADER_ADD_INCLUDE("GLFW/glfw3.h", "CFLAGS_GLFW", configure_module_dirname + "\\vendor\\glfw\\include;" + PHP_EXTRA_INCLUDES) &&
CHECK_HEADER_ADD_INCLUDE("ogt_vox_c_wrapper.h", "CFLAGS_GLFW", configure_module_dirname + "\\include;" + PHP_EXTRA_INCLUDES) &&
CHECK_HEADER_ADD_INCLUDE("cvector.h", "CFLAGS_GLFW", configure_module_dirname + "\\vendor\\cvector;" + PHP_EXTRA_INCLUDES) &&
CHECK_HEADER_ADD_INCLUDE("stb_image.h", "CFLAGS_GLFW", configure_module_dirname + "\\vendor\\stb;" + PHP_EXTRA_INCLUDES) &&
CHECK_HEADER_ADD_INCLUDE("stb_perlin.h", "CFLAGS_GLFW", configure_module_dirname + "\\vendor\\stb;" + PHP_EXTRA_INCLUDES) &&
Expand All @@ -19,7 +20,8 @@ if (PHP_GLFW != "no") {
CHECK_HEADER_ADD_INCLUDE("ogt_vox.h", "CFLAGS_GLFW", configure_module_dirname + "\\vendor\\opengametools\\src;" + PHP_EXTRA_INCLUDES)
) {

var sources = "phpglfw.c phpglfw_constants.c phpglfw_functions.c phpglfw_math.c phpglfw_buffer.c phpglfw_texture.c phpglfw_objparser.c phpglfw_voxparser.c ogt_vox_c_wrapper.cpp phpglfw_vg.c phpglfw_audio.c";
var sources = "phpglfw.c phpglfw_constants.c phpglfw_functions.c phpglfw_math.c phpglfw_buffer.c phpglfw_texture.c phpglfw_objparser.c phpglfw_voxparser.c phpglfw_vg.c phpglfw_audio.c phpglfw_drawcall_assembler.c";
var src_sources = "ogt_vox_c_wrapper.cpp";

var glad_sources = "glad.c";
var fastobj_sources = "fast_obj.c";
Expand All @@ -30,6 +32,7 @@ if (PHP_GLFW != "no") {

EXTENSION("glfw", sources);

ADD_SOURCES(configure_module_dirname + "\\src", src_sources, "glfw");
ADD_SOURCES(configure_module_dirname + "\\vendor\\glad\\src", glad_sources, "glfw");
ADD_SOURCES(configure_module_dirname + "\\vendor\\glfw\\src", glfw_sources, "glfw");
ADD_SOURCES(configure_module_dirname + "\\vendor\\fastobj", fastobj_sources, "glfw");
Expand Down
6 changes: 3 additions & 3 deletions docs/API/Geometry/ObjFileParserMaterial.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ This property is often also used for reflection color, shininess or highlights c
public readonly Vec3 $specular;
```

### $emmisive
### $emissive

The emmisive color of the material. (marked as "Ke")
The emissive color of the material. (marked as "Ke")
This property is often also used for illumination, self glow or light emission.

```php
/*
* @var \GL\Math\Vec3
*/
public readonly Vec3 $emmisive;
public readonly Vec3 $emissive;
```

### $transmittance
Expand Down
47 changes: 37 additions & 10 deletions docs/API/Texture/Texture2D.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ Read more about the [`glTexImage2D`](/API/OpenGL/glTexImage2D.html) function to
Loads a texture / image from a file on disk and returns a Texture2D object.

```php
static function fromDisk(string $path) : \GL\Texture\Texture2D
static function fromDisk(string $path, int $requestedChannelCount = 0, bool $flipVertically = true) : \GL\Texture\Texture2D
```

This method automatically detects HDR files (.hdr) and loads them into a FloatBuffer.
All other supported formats (PNG, JPG, GIF, BMP, TGA, etc.) are loaded into a UByteBuffer.

arguments

: 1. `string` `$file` The path to the image file to load.
: 1. `string` `$path` The path to the image file to load.
2. `int` `$requestedChannelCount` The number of channels to force. 0 means use the original channel count.
3. `bool` `$flipVertically` Whether to flip the image vertically on load (default: true).

returns

Expand All @@ -52,14 +57,25 @@ returns

### `fromBuffer`

Loads a texture / image from a buffer and returns a Texture2D object.
Loads a texture / image from a UByteBuffer and returns a Texture2D object.

```php
static function fromBuffer(int $width, int $height, \GL\Buffer\UByteBuffer $buffer, int $channels = \GL\Texture\Texture2D::CHANNEL_RGBA) : \GL\Texture\Texture2D
```

The buffer is not copied, the Texture2D object will hold a reference to the buffer given.

arguments

: 1. `int` `$width` The width of the image.
2. `int` `$height` The height of the image.
3. `\GL\Buffer\UByteBuffer` `$buffer` The buffer containing the image data.
4. `int` `$channels` The number of channels in the image data.

returns

: `\GL\Texture\Texture2D` The created texture object.

---

### `width`
Expand Down Expand Up @@ -106,15 +122,18 @@ returns

### `buffer`

Returns a reference to the internal `UByteBuffer` instance of the current texture.
Returns a reference to the internal buffer instance of the current texture.

```php
function buffer() : \GL\Buffer\UByteBuffer
function buffer() : \GL\Buffer\UByteBuffer|\GL\Buffer\FloatBuffer
```

For LDR images, this returns a `UByteBuffer`. For HDR images, this returns a `FloatBuffer`.
Use `isHDR()` to check which type of buffer is returned.

returns

: `\GL\UByteBuffer` The loaded image data.
: `\GL\Buffer\UByteBuffer|\GL\Buffer\FloatBuffer` The loaded image data.

---

Expand All @@ -126,9 +145,11 @@ Writes the image data to a file on disk. (JPEG)
function writeJPG(string $path, int $quality = 100) : void
```

Note: This method only works with LDR textures. For HDR textures, use writeHDR().

arguments

: 1. `string` `$file` The path to the file to write to.
: 1. `string` `$path` The path to the file to write to.
2. `int` `$quality` The quality of the image. (0 - 100)

returns
Expand All @@ -145,9 +166,11 @@ Writes the image data to a file on disk. (PNG)
function writePNG(string $path) : void
```

Note: This method only works with LDR textures. For HDR textures, use writeHDR().

arguments

: 1. `string` `$file` The path to the file to write to.
: 1. `string` `$path` The path to the file to write to.

---

Expand All @@ -159,9 +182,11 @@ Writes the image data to a file on disk. (BMP)
function writeBMP(string $path) : void
```

Note: This method only works with LDR textures. For HDR textures, use writeHDR().

arguments

: 1. `string` `$file` The path to the file to write to.
: 1. `string` `$path` The path to the file to write to.

---

Expand All @@ -173,9 +198,11 @@ Writes the image data to a file on disk. (TGA)
function writeTGA(string $path) : void
```

Note: This method only works with LDR textures. For HDR textures, use writeHDR().

arguments

: 1. `string` `$file` The path to the file to write to.
: 1. `string` `$path` The path to the file to write to.

---

Expand Down
121 changes: 119 additions & 2 deletions generator/templates/phpglfw.stub.php.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,19 @@ class Texture2D {
// public const CHANNEL_RGBA = 4;

public static function fromDisk(string $path, int $requestedChannelCount = 0, bool $flipVertically = true) : Texture2D {}
public static function fromBuffer(int $width, int $height, \GL\Buffer\UByteBuffer $buffer, int $channels = Texture2D::CHANNEL_RGBA) : Texture2D {}
public function buffer() : \GL\Buffer\UByteBuffer {}
public static function fromBuffer(int $width, int $height, \GL\Buffer\UByteBuffer $buffer, int $channels = Texture2D::CHANNEL_RGBA) : Texture2D {}
public static function fromBufferHDR(int $width, int $height, \GL\Buffer\FloatBuffer $buffer, int $channels = Texture2D::CHANNEL_RGBA) : Texture2D {}
public function buffer() : \GL\Buffer\UByteBuffer|\GL\Buffer\FloatBuffer {}
public function width() : int {}
public function height() : int {}
public function channels() : int {}
public function isHDR() : bool {}

public function writeJPG(string $path, int $quality = 100) : void {}
public function writePNG(string $path) : void {}
public function writeBMP(string $path) : void {}
public function writeTGA(string $path) : void {}
public function writeHDR(string $path) : void {}
}
}

Expand Down Expand Up @@ -305,6 +308,120 @@ public function dump() : string {}
<?php endforeach; ?>
};

namespace GL\Rendering
{
class DrawCallAssembler
{
/** @var int */
public const SORT_NONE = 0;
/** @var int */
public const SORT_FRONT_TO_BACK = 1;
/** @var int */
public const SORT_BACK_TO_FRONT = 2;

/** @var int */
public const PASS_OPAQUE = 0;
/** @var int */
public const PASS_TRANSPARENT = 1;
/** @var int */
public const PASS_DEPTH = 2;
/** @var int */
public const PASS_USER = 3;

/** @var int */
public const FLAG_IGNORE_CULLING = 2;
/** @var int */
public const FLAG_DISABLE_INSTANCING = 4;
/** @var int */
public const FLAG_CUSTOM_SORT_KEY = 8;

public readonly \GL\Buffer\UIntBuffer $commandBuffer;
public readonly \GL\Buffer\FloatBuffer $instanceTransformBuffer;
public readonly \GL\Buffer\UIntBuffer $instanceMetaBuffer;
public readonly \GL\Buffer\FloatBuffer $instancePayloadBuffer;

public readonly int $commandStride;
public readonly int $transformStride;
public readonly int $instanceMetaStride;

public function __construct(
int $initialMeshCapacity = 256,
int $initialInstanceCapacity = 2048,
int $initialCommandCapacity = 512
) {}

public function setAutoInstancing(bool $enabled) : void {}
public function setSortMode(int $mode) : void {}

public function setCameraData(
?\GL\Math\Vec3 $cameraPosition = null,
?\GL\Math\Mat4 $viewMatrix = null,
?\GL\Math\Mat4 $projectionMatrix = null
) : void {}

public function setFrustumPlanes(
\GL\Math\Vec4 $left,
\GL\Math\Vec4 $right,
\GL\Math\Vec4 $bottom,
\GL\Math\Vec4 $top,
\GL\Math\Vec4 $near,
\GL\Math\Vec4 $far
) : void {}

public function registerMesh(
int $vao,
int $vertexOffset = 0,
int $vertexCount = 0,
int $indexOffset = 0,
int $indexCount = 0,
?\GL\Math\Vec3 $aabbMin = null,
?\GL\Math\Vec3 $aabbMax = null,
int $materialHint = 0,
int $primitive = 0x0004
) : int {}

public function setMeshMaterial(int $meshHandle, int $materialId) : void {}

public function setLodTable(
int $meshHandle,
\GL\Buffer\FloatBuffer $distanceThresholds,
\GL\Buffer\UIntBuffer $meshHandles
) : void {}

public function bindTransformBuffer(int $vao, int $offset = 1) : int {}

public function bindPayloadData(\GL\Buffer\FloatBuffer $payloadBuffer, int $stride) : void {}
public function bindPayloadBuffer(int $vao, int $offset, int $stride = 0) : int {}

public function clearInstances() : void {}

public function submit(
int $meshHandle,
\GL\Math\Mat4 $transform,
int $materialId,
int $pass = 0,
int $programId = 0,
int $flags = 0,
float $sortBias = 0.0,
int $userId = 0
) : void {}

public function build() : int {}

public function execute(callable $drawCallback) : void {}

public function commandCount() : int {}

public function instanceCount() : int {}

public function builtInstanceCount() : int {}

public function clearMeshes() : void {}

public function reset() : void {}
}
}

namespace GL\VectorGraphics
{
class VGColor {
Expand Down
5 changes: 3 additions & 2 deletions generator/templates/phpglfw_buffer.c.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@
return NULL;
}

iterator = emalloc(sizeof(<?php echo $buffer->getIteratorObjectName(); ?>));
iterator = ecalloc(1, sizeof(<?php echo $buffer->getIteratorObjectName(); ?>));

zend_iterator_init((zend_object_iterator*)iterator);
zend_iterator_init((zend_object_iterator*)iterator);
ZVAL_UNDEF(&iterator->current);

ZVAL_OBJ_COPY(&iterator->intern.data, Z_OBJ_P(object));
iterator->intern.funcs = &<?php echo $buffer->getIteratorHandlersVarName(); ?>;
Expand Down
13 changes: 6 additions & 7 deletions generator/templates/phpglfw_functions.c.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,28 @@ class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES;
zval *<?php echo $ipo->getObjectReadPropertyFunctionName(); ?>(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv)
{
<?php echo $ipo->getObjectStructName(); ?> *intern = <?php echo $ipo->getObjectStructPtrFromZObjPtrFunctionName(); ?>(object);
zval *retval = &EG(uninitialized_zval);

if (intern-><?php echo $ipo->getObjectStructPointerVar(); ?>) {
<?php foreach($ipo->structAccessMembers as $i => $member) : ?>
<?php echo $i === 0 ? '' : 'else '; ?>if (zend_string_equals_literal(member, "<?php echo $member[0]; ?>")) {
<?php if ($member[1] === 'int') : ?>
ZVAL_LONG(retval, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
ZVAL_LONG(rv, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
<?php elseif ($member[1] === 'float') : ?>
ZVAL_DOUBLE(retval, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
ZVAL_DOUBLE(rv, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
<?php elseif ($member[1] === 'string') : ?>
ZVAL_STRING(retval, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
ZVAL_STRING(rv, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
<?php elseif ($member[1] === 'bool') : ?>
ZVAL_BOOL(retval, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
ZVAL_BOOL(rv, intern-><?php echo $ipo->getObjectStructPointerVar(); ?>-><?php echo $member[0]; ?>);
<?php endif; ?>
return retval;
return rv;
}
<?php endforeach; ?>
else {
zend_throw_error(NULL, "Trying to access invalid property '%s' on <?php echo $ipo->getPHPClassName(); ?>", ZSTR_VAL(member));
}
}

return retval;
return &EG(uninitialized_zval);
}


Expand Down
Loading