Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ add_library(${TARGET} STATIC
src/image_DXT.c
src/image_DXT.h
src/opengx.h
src/pixel_stream.cpp
src/pixel_stream.h
src/pixels.cpp
src/pixels.h
src/raster.cpp
src/selection.c
src/state.h
src/stencil.c
src/stencil.h
src/texel.h
src/texture.c
src/utils.h
src/vertex.cpp
Expand Down
19 changes: 15 additions & 4 deletions src/efb.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ POSSIBILITY OF SUCH DAMAGE.

OgxEfbContentType _ogx_efb_content_type = OGX_EFB_SCENE;

void _ogx_efb_save_to_buffer(uint8_t format, uint16_t width, uint16_t height,
void *texels, OgxEfbFlags flags)
void _ogx_efb_save_area_to_buffer(uint8_t format,
uint16_t x, uint16_t y,
uint16_t width, uint16_t height,
void *texels, OgxEfbFlags flags)
{
GX_SetCopyFilter(GX_FALSE, NULL, GX_FALSE, NULL);
GX_SetTexCopySrc(glparamstate.viewport[0],
glparamstate.viewport[1],
GX_SetTexCopySrc(x,
y,
width,
height);
GX_SetTexCopyDst(width, height, format, GX_FALSE);
Expand All @@ -59,6 +61,15 @@ void _ogx_efb_save_to_buffer(uint8_t format, uint16_t width, uint16_t height,
GX_WaitDrawDone();
}

void _ogx_efb_save_to_buffer(uint8_t format, uint16_t width, uint16_t height,
void *texels, OgxEfbFlags flags)
{
_ogx_efb_save_area_to_buffer(format,
glparamstate.viewport[0],
glparamstate.viewport[1],
width, height, texels, flags);
}

void _ogx_efb_restore_texobj(GXTexObj *texobj)
{
_ogx_setup_2D_projection();
Expand Down
12 changes: 12 additions & 0 deletions src/efb.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <ogc/gx.h>
#include <ogc/system.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
OGX_EFB_NONE = 0,
OGX_EFB_CLEAR = 1 << 0,
Expand All @@ -55,6 +59,10 @@ extern OgxEfbContentType _ogx_efb_content_type;

void _ogx_efb_save_to_buffer(uint8_t format, uint16_t width, uint16_t height,
void *texels, OgxEfbFlags flags);
void _ogx_efb_save_area_to_buffer(uint8_t format,
uint16_t x, uint16_t y,
uint16_t width, uint16_t height,
void *texels, OgxEfbFlags flags);
void _ogx_efb_restore_texobj(GXTexObj *texobj);

typedef struct {
Expand Down Expand Up @@ -84,4 +92,8 @@ static inline void _ogx_efb_set_content_type(OgxEfbContentType content_type) {
_ogx_efb_set_content_type_real(content_type);
}

#ifdef __cplusplus
} // extern C
#endif

#endif /* OPENGX_EFB_H */
1 change: 0 additions & 1 deletion src/gc_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,6 @@ void glPushAttrib(GLbitfield mask) {}
void glPopAttrib(void) {}
void glPushClientAttrib(GLbitfield mask) {}
void glPopClientAttrib(void) {}
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *data) {}

/*
****** NOTES ******
Expand Down
12 changes: 12 additions & 0 deletions src/getters.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ void glGetFloatv(GLenum pname, GLfloat *params)
case GL_CURRENT_RASTER_POSITION:
floatcpy(params, glparamstate.raster_pos, 4);
break;
case GL_DEPTH_BIAS:
*params = glparamstate.transfer_depth_bias;
break;
case GL_DEPTH_RANGE:
params[0] = glparamstate.depth_near;
params[1] = glparamstate.depth_far;
break;
case GL_DEPTH_SCALE:
*params = glparamstate.transfer_depth_scale;
break;
case GL_MODELVIEW_MATRIX:
for (int i = 0; i < 3; i++)
for (int j = 0; j < 4; j++)
Expand Down Expand Up @@ -173,6 +179,12 @@ void glGetIntegerv(GLenum pname, GLint *params)
case GL_READ_BUFFER:
*params = glparamstate.active_buffer;
break;
case GL_INDEX_OFFSET:
*params = glparamstate.transfer_index_offset;
break;
case GL_INDEX_SHIFT:
*params = glparamstate.transfer_index_shift;
break;
case GL_MAX_CLIP_PLANES:
*params = MAX_CLIP_PLANES;
return;
Expand Down
65 changes: 65 additions & 0 deletions src/pixel_stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*****************************************************************************
Copyright (c) 2024 Alberto Mardegan (mardy@users.sourceforge.net)
All rights reserved.

Attention! Contains pieces of code from others such as Mesa and GRRLib

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of copyright holders nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

#include "pixel_stream.h"

const struct MasksPerType _ogx_pixels_masks_per_type[] = {
{GL_UNSIGNED_BYTE_3_3_2, 1, 3, 3, 2, 0, 0, 3, 6, 0 },
{GL_UNSIGNED_BYTE_2_3_3_REV, 1, 3, 3, 2, 0, 5, 2, 0, 0 },
{GL_UNSIGNED_SHORT_5_6_5, 2, 5, 6, 5, 0, 0, 5, 11, 0 },
{GL_UNSIGNED_SHORT_5_6_5_REV, 2, 5, 6, 5, 0, 11, 5, 0, 0 },
{GL_UNSIGNED_SHORT_4_4_4_4, 2, 4, 4, 4, 4, 0, 4, 8, 12 },
{GL_UNSIGNED_SHORT_4_4_4_4_REV, 2, 4, 4, 4, 4, 12, 8, 4, 0 },
{GL_UNSIGNED_SHORT_5_5_5_1, 2, 5, 5, 5, 1, 0, 5, 10, 15 },
{GL_UNSIGNED_SHORT_1_5_5_5_REV, 2, 5, 5, 5, 1, 11, 6, 1, 0 },
{GL_UNSIGNED_INT_8_8_8_8, 4, 8, 8, 8, 8, 0, 8, 16, 24 },
{GL_UNSIGNED_INT_8_8_8_8_REV, 4, 8, 8, 8, 8, 24, 16, 8, 0 },
{GL_UNSIGNED_INT_10_10_10_2, 4, 10, 10, 10, 2, 0, 10, 20, 30 },
{GL_UNSIGNED_INT_2_10_10_10_REV, 4, 10, 10, 10, 2, 22, 12, 2, 0 },
{0, }
};

const struct ComponentsPerFormat _ogx_pixels_components_per_format[] = {
{ GL_RGBA, 4, { 0, 1, 2, 3 }},
{ GL_BGRA, 4, { 2, 1, 0, 3 }},
{ GL_RGB, 3, { 0, 1, 2 }},
{ GL_BGR, 3, { 2, 1, 0 }},
{ GL_LUMINANCE_ALPHA, 2, { 0, 3 }},
{ GL_INTENSITY, 1, { 0 }},
{ GL_LUMINANCE, 1, { 0 }},
{ GL_RED, 1, { 0 }},
{ GL_GREEN, 1, { 1 }},
{ GL_BLUE, 1, { 2 }},
{ GL_ALPHA, 1, { 3 }},
{ GL_DEPTH_COMPONENT, 1, {}},
{ GL_STENCIL_INDEX, 1, { 0 }},
{ 0, }
};
Loading