generated from RISC-OS-Community/StandardRepoTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced the concept of layers and render strategy, to be able to u…
…se both optimised C rendering and GPU accel rendering, depending on the HW used
- Loading branch information
Showing
6 changed files
with
277 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#include "layer.hpp" | ||
|
||
// Constructor implementation | ||
Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> strategy) | ||
: width(width), height(height), opacity(1.0f), visible(true), currentRenderStrategy(strategy) { | ||
pixels.resize(width * height, 0); // Initialize pixel buffer with default color (0) | ||
} | ||
|
||
// Destructor implementation | ||
Layer::~Layer() { | ||
// No manual resource management needed here due to use of smart pointers and vectors | ||
} | ||
|
||
// Clear the layer with a specific color | ||
void Layer::clear(color_t color) { | ||
std::fill(pixels.begin(), pixels.end(), color); | ||
} | ||
|
||
// Direct pixel manipulation | ||
void Layer::setPixel(pixel_t x, pixel_t y, color_t color) { | ||
if (x < width && y < height) { | ||
pixels[y * width + x] = color; | ||
} | ||
} | ||
|
||
// Draw a line (placeholder for actual line drawing algorithm, e.g., Bresenham's) | ||
void Layer::drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) { | ||
// Implementation of a line drawing algorithm goes here | ||
} | ||
|
||
// Draw a rectangle (simple example) | ||
void Layer::drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) { | ||
for (pixel_t i = x; i < x + w; ++i) { | ||
for (pixel_t j = y; j < y + h; ++j) { | ||
setPixel(i, j, color); | ||
} | ||
} | ||
} | ||
|
||
// Fill a rectangle | ||
void Layer::fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) { | ||
drawRect(x, y, w, h, color); // For simplicity, just using drawRect here | ||
} | ||
|
||
// Draw a circle (placeholder) | ||
void Layer::drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) { | ||
// Placeholder for circle drawing algorithm | ||
} | ||
|
||
// Fill a circle (placeholder) | ||
void Layer::fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) { | ||
// Placeholder for filled circle algorithm | ||
} | ||
|
||
// Draw an ellipse (placeholder) | ||
void Layer::drawEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) { | ||
// Placeholder for ellipse drawing algorithm | ||
} | ||
|
||
// Fill an ellipse (placeholder) | ||
void Layer::fillEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) { | ||
// Placeholder for filled ellipse algorithm | ||
} | ||
|
||
// Draw a polygon (placeholder) | ||
void Layer::drawPolygon(const std::vector<pixel_t>& points, color_t color) { | ||
// Placeholder for polygon drawing algorithm | ||
} | ||
|
||
// Fill a polygon (placeholder) | ||
void Layer::fillPolygon(const std::vector<pixel_t>& points, color_t color) { | ||
// Placeholder for filled polygon algorithm | ||
} | ||
|
||
// Draw text (placeholder) | ||
void Layer::drawText(pixel_t x, pixel_t y, const char* text, color_t color) { | ||
// Placeholder for text drawing algorithm | ||
} | ||
|
||
// Draw an image (placeholder) | ||
void Layer::drawImage(pixel_t x, pixel_t y, const Layer& image) { | ||
// Placeholder for image drawing algorithm | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#ifndef LAYER_HPP | ||
#define LAYER_HPP | ||
|
||
#include <vector> | ||
#include <cstdint> | ||
#include <memory> // For std::shared_ptr | ||
|
||
#include "render_strategy.hpp" | ||
|
||
typedef uint32_t color_t; // 32-bit color | ||
typedef uint32_t pixel_t; // 32-bit pixel, assuming it represents dimensions | ||
|
||
class Layer { | ||
private: | ||
std::shared_ptr<RenderStrategy> currentRenderStrategy; | ||
|
||
public: | ||
std::vector<color_t> pixels; // Pixel data for this layer | ||
float opacity; // Layer opacity | ||
bool visible; // Layer visibility | ||
pixel_t width, height; // Dimensions of the layer | ||
|
||
// Constructor and destructor | ||
Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> strategy); | ||
~Layer(); | ||
|
||
// Drawing operations | ||
void clear(color_t color); // Clear the layer with a specific color | ||
void setPixel(pixel_t x, pixel_t y, color_t color); // Direct pixel manipulation | ||
void drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color); // Draw a line | ||
void drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color); // Draw a rectangle | ||
void fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color); // Fill a rectangle | ||
void drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color); // Draw a circle | ||
void fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color); // Fill a circle | ||
void drawEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color); // Draw an ellipse | ||
void fillEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color); // Fill an ellipse | ||
void drawPolygon(const std::vector<pixel_t>& points, color_t color); // Draw a polygon | ||
void fillPolygon(const std::vector<pixel_t>& points, color_t color); // Fill a polygon | ||
void drawText(pixel_t x, pixel_t y, const char* text, color_t color); // Draw text | ||
void drawImage(pixel_t x, pixel_t y, const Layer& image); // Draw an image | ||
}; | ||
|
||
#endif // LAYER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#ifndef RENDERSTRATEGY_HPP | ||
#define RENDERSTRATEGY_HPP | ||
|
||
#include <memory> | ||
#include <vector> | ||
#include <cstdint> // For pixel_t and color_t types | ||
|
||
// Forward declaration of Layer to resolve circular dependency | ||
class Layer; | ||
|
||
typedef uint32_t color_t; // 32-bit color, assuming it represents ARGB or similar | ||
typedef uint32_t pixel_t; // 32-bit pixel, for dimensions | ||
|
||
class RenderStrategy { | ||
public: | ||
virtual ~RenderStrategy() {} | ||
|
||
// Pure virtual functions for rendering operations | ||
virtual void setPixel(Layer& layer, pixel_t x, pixel_t y, color_t color) = 0; | ||
virtual void drawLine(Layer& layer, pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) = 0; | ||
virtual void drawRect(Layer& layer, pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) = 0; | ||
virtual void fillRect(Layer& layer, pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) = 0; | ||
virtual void drawCircle(Layer& layer, pixel_t x, pixel_t y, pixel_t r, color_t color) = 0; | ||
virtual void fillCircle(Layer& layer, pixel_t x, pixel_t y, pixel_t r, color_t color) = 0; | ||
virtual void drawEllipse(Layer& layer, pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) = 0; | ||
virtual void fillEllipse(Layer& layer, pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) = 0; | ||
virtual void drawPolygon(Layer& layer, const std::vector<pixel_t>& points, color_t color) = 0; | ||
virtual void fillPolygon(Layer& layer, const std::vector<pixel_t>& points, color_t color) = 0; | ||
virtual void drawText(Layer& layer, pixel_t x, pixel_t y, const char* text, color_t color) = 0; | ||
virtual void drawImage(Layer& layer, pixel_t x, pixel_t y, const Layer& image) = 0; | ||
|
||
// Additional methods for setup, teardown, or state management can be added here | ||
}; | ||
|
||
#endif // RENDERSTRATEGY_HPP |